1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 17:42:29 +01:00

Close #21825: Only lock OpenGL texture cache when using multi-threading (#21952)

Fixes #21825 by making 'DrawingLocks' which lock only if multi threaded drawing is enabled. Refactors TTF.cpp to use this.

Also cleans up some header files, modernises constants, and removes code to avoid using shared_mutex on MacOS builds. This was originally added because older versions of MacOS didn't support this in the STL.
This commit is contained in:
mrmbernardi
2024-05-05 12:54:50 +02:00
committed by GitHub
parent f3bb57a54c
commit 489ae58c5c
6 changed files with 84 additions and 62 deletions

View File

@@ -21,11 +21,11 @@
using namespace OpenRCT2::Ui;
constexpr uint32_t UNUSED_INDEX = 0xFFFFFFFF;
constexpr uint32_t kUnusedIndex = 0xFFFFFFFF;
TextureCache::TextureCache()
{
std::fill(_indexMap.begin(), _indexMap.end(), UNUSED_INDEX);
std::fill(_indexMap.begin(), _indexMap.end(), kUnusedIndex);
}
TextureCache::~TextureCache()
@@ -38,13 +38,13 @@ void TextureCache::InvalidateImage(ImageIndex image)
unique_lock lock(_mutex);
uint32_t index = _indexMap[image];
if (index == UNUSED_INDEX)
if (index == kUnusedIndex)
return;
AtlasTextureInfo& elem = _textureCache.at(index);
_atlases[elem.index].Free(elem);
_indexMap[image] = UNUSED_INDEX;
_indexMap[image] = kUnusedIndex;
if (index == _textureCache.size() - 1)
{
@@ -76,7 +76,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(const ImageId imageId)
shared_lock lock(_mutex);
index = _indexMap[imageId.GetIndex()];
if (index != UNUSED_INDEX)
if (index != kUnusedIndex)
{
const auto& info = _textureCache[index];
return {
@@ -144,7 +144,7 @@ BasicTextureInfo TextureCache::GetOrLoadBitmapTexture(ImageIndex image, const vo
shared_lock lock(_mutex);
index = _indexMap[image];
if (index != UNUSED_INDEX)
if (index != kUnusedIndex)
{
const auto& info = _textureCache[index];
return {
@@ -394,7 +394,7 @@ void TextureCache::FreeTextures()
// Free array texture
glDeleteTextures(1, &_atlasesTexture);
_textureCache.clear();
std::fill(_indexMap.begin(), _indexMap.end(), UNUSED_INDEX);
std::fill(_indexMap.begin(), _indexMap.end(), kUnusedIndex);
}
DrawPixelInfo TextureCache::CreateDPI(int32_t width, int32_t height)