From cf9e8022a05a73ecaa28741e42a8ecadd9bb6581 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 26 Jul 2020 18:46:23 +0100 Subject: [PATCH] Fix #12297: OpenGL renderer causing artifacts Do not re-allocate texture memory if we don't need to and aren't going to restore the old pixels. --- distribution/changelog.txt | 1 + .../drawing/engines/opengl/TextureCache.cpp | 22 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 580ec9fb88..06452d282d 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -51,6 +51,7 @@ - Fix: [#12211] Map Generator shows incorrect map sizes (e.g. "150 x 0"). - Fix: [#12221] Map Generation tool doesn't place any trees. - Fix: [#12285] On-ride photo profit assumes every guest buys one. +- Fix: [#12297] OpenGL renderer causing artifacts. - Fix: [#12312] Softlock when loading save file via command line fails. - Fix: RCT1 scenarios have more items in the object list than are present in the park or the research list. - Improved: [#6530] Allow water and land height changes on park borders. diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp index 6b36f14ac1..51a5dd8f91 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp @@ -215,19 +215,19 @@ void TextureCache::EnlargeAtlasesTexture(GLuint newEntries) // Initial capacity will be 12 which covers most cases of a fully visible park. _atlasesTextureCapacity = (_atlasesTextureCapacity + 6) << 1UL; - } - glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture); - glTexImage3D( - GL_TEXTURE_2D_ARRAY, 0, GL_R8UI, _atlasesTextureDimensions, _atlasesTextureDimensions, _atlasesTextureCapacity, 0, - GL_RED_INTEGER, GL_UNSIGNED_BYTE, nullptr); + glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture); + glTexImage3D( + GL_TEXTURE_2D_ARRAY, 0, GL_R8UI, _atlasesTextureDimensions, _atlasesTextureDimensions, _atlasesTextureCapacity, 0, + GL_RED_INTEGER, GL_UNSIGNED_BYTE, nullptr); - // Restore old data - if (!oldPixels.empty()) - { - glTexSubImage3D( - GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _atlasesTextureDimensions, _atlasesTextureDimensions, _atlasesTextureIndices, - GL_RED_INTEGER, GL_UNSIGNED_BYTE, oldPixels.data()); + // Restore old data + if (!oldPixels.empty()) + { + glTexSubImage3D( + GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _atlasesTextureDimensions, _atlasesTextureDimensions, _atlasesTextureIndices, + GL_RED_INTEGER, GL_UNSIGNED_BYTE, oldPixels.data()); + } } _atlasesTextureIndices = newIndices;