From 0be94c4de305f5ac3655542f98e50c9e46c71eb6 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Wed, 2 Aug 2023 20:49:48 -0500 Subject: [PATCH] Buffer texture atlas on more than the first context after change - Icons now work on all maps --- scwx-qt/source/scwx/qt/gl/gl_context.cpp | 8 ++++++-- scwx-qt/source/scwx/qt/util/texture_atlas.cpp | 11 ++++------- scwx-qt/source/scwx/qt/util/texture_atlas.hpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scwx-qt/source/scwx/qt/gl/gl_context.cpp b/scwx-qt/source/scwx/qt/gl/gl_context.cpp index f875bf14..e09ed177 100644 --- a/scwx-qt/source/scwx/qt/gl/gl_context.cpp +++ b/scwx-qt/source/scwx/qt/gl/gl_context.cpp @@ -35,6 +35,8 @@ public: GLuint textureAtlas_; std::mutex textureMutex_; + + std::uint64_t textureBufferCount_ {}; }; GlContext::GlContext() : p(std::make_unique()) {} @@ -79,9 +81,11 @@ GLuint GlContext::GetTextureAtlas() auto& textureAtlas = util::TextureAtlas::Instance(); - if (p->textureAtlas_ == GL_INVALID_INDEX || textureAtlas.NeedsBuffered()) + if (p->textureAtlas_ == GL_INVALID_INDEX || + p->textureBufferCount_ != textureAtlas.BuildCount()) { - p->textureAtlas_ = textureAtlas.BufferAtlas(p->gl_); + p->textureBufferCount_ = textureAtlas.BuildCount(); + p->textureAtlas_ = textureAtlas.BufferAtlas(p->gl_); } return p->textureAtlas_; diff --git a/scwx-qt/source/scwx/qt/util/texture_atlas.cpp b/scwx-qt/source/scwx/qt/util/texture_atlas.cpp index 0b272a3f..65de8c16 100644 --- a/scwx-qt/source/scwx/qt/util/texture_atlas.cpp +++ b/scwx-qt/source/scwx/qt/util/texture_atlas.cpp @@ -54,7 +54,7 @@ public: std::unordered_map atlasMap_ {}; std::shared_mutex atlasMutex_ {}; - bool needsBuffered_ {true}; + std::uint64_t buildCount_ {0u}; }; TextureAtlas::TextureAtlas() : p(std::make_unique()) {} @@ -63,9 +63,9 @@ TextureAtlas::~TextureAtlas() = default; TextureAtlas::TextureAtlas(TextureAtlas&&) noexcept = default; TextureAtlas& TextureAtlas::operator=(TextureAtlas&&) noexcept = default; -bool TextureAtlas::NeedsBuffered() const +std::uint64_t TextureAtlas::BuildCount() const { - return p->needsBuffered_; + return p->buildCount_; } void TextureAtlas::RegisterTexture(const std::string& name, @@ -278,7 +278,7 @@ void TextureAtlas::BuildAtlas(size_t width, size_t height) } // Mark the need to buffer the atlas - p->needsBuffered_ = true; + ++p->buildCount_; } GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) @@ -322,9 +322,6 @@ GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) pixelData.data()); } - // Atlas has been successfully buffered - p->needsBuffered_ = false; - return texture; } diff --git a/scwx-qt/source/scwx/qt/util/texture_atlas.hpp b/scwx-qt/source/scwx/qt/util/texture_atlas.hpp index 5faff70d..5aae76b4 100644 --- a/scwx-qt/source/scwx/qt/util/texture_atlas.hpp +++ b/scwx-qt/source/scwx/qt/util/texture_atlas.hpp @@ -66,7 +66,7 @@ public: static TextureAtlas& Instance(); - bool NeedsBuffered() const; + std::uint64_t BuildCount() const; void RegisterTexture(const std::string& name, const std::string& path); bool CacheTexture(const std::string& name, const std::string& path);