diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_icons.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_icons.cpp index 69e6887e..3e46d3a6 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_icons.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_icons.cpp @@ -343,11 +343,11 @@ void PlacefileIcons::Impl::Update() { // Icon lat, lon, lx, by, ls, bt, mc0, mc1, mc2, mc3, a, // BL - lat, lon, lx, by, ls, tt, mc0, mc1, mc2, mc3, a, // TL - lat, lon, rx, ty, rs, bt, mc0, mc1, mc2, mc3, a, // BR - lat, lon, rx, ty, rs, bt, mc0, mc1, mc2, mc3, a, // BR + lat, lon, lx, ty, ls, tt, mc0, mc1, mc2, mc3, a, // TL + lat, lon, rx, by, rs, bt, mc0, mc1, mc2, mc3, a, // BR + lat, lon, rx, by, rs, bt, mc0, mc1, mc2, mc3, a, // BR lat, lon, rx, ty, rs, tt, mc0, mc1, mc2, mc3, a, // TR - lat, lon, lx, by, ls, tt, mc0, mc1, mc2, mc3, a // TL + lat, lon, lx, ty, ls, tt, mc0, mc1, mc2, mc3, a // TL }); numVertices_ += 6; diff --git a/scwx-qt/source/scwx/qt/gl/gl_context.cpp b/scwx-qt/source/scwx/qt/gl/gl_context.cpp index d0e0fd80..f875bf14 100644 --- a/scwx-qt/source/scwx/qt/gl/gl_context.cpp +++ b/scwx-qt/source/scwx/qt/gl/gl_context.cpp @@ -77,9 +77,11 @@ GLuint GlContext::GetTextureAtlas() { std::unique_lock lock(p->textureMutex_); - if (p->textureAtlas_ == GL_INVALID_INDEX) + auto& textureAtlas = util::TextureAtlas::Instance(); + + if (p->textureAtlas_ == GL_INVALID_INDEX || textureAtlas.NeedsBuffered()) { - p->textureAtlas_ = util::TextureAtlas::Instance().BufferAtlas(p->gl_); + p->textureAtlas_ = textureAtlas.BufferAtlas(p->gl_); } return p->textureAtlas_; diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 2b055454..91c823e3 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -45,6 +45,7 @@ void DrawLayer::Initialize() void DrawLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params) { gl::OpenGLFunctions& gl = p->context_->gl(); + p->textureAtlas_ = p->context_->GetTextureAtlas(); gl.glActiveTexture(GL_TEXTURE0); gl.glBindTexture(GL_TEXTURE_2D, 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 841c42d3..a23a119c 100644 --- a/scwx-qt/source/scwx/qt/util/texture_atlas.cpp +++ b/scwx-qt/source/scwx/qt/util/texture_atlas.cpp @@ -38,27 +38,22 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class TextureAtlas::Impl { public: - explicit Impl() : - texturePathMap_ {}, - texturePathMutex_ {}, - atlas_ {}, - atlasMap_ {}, - atlasMutex_ {} - { - } + explicit Impl() {} ~Impl() {} static boost::gil::rgba8_image_t LoadImage(const std::string& imagePath); - std::unordered_map texturePathMap_; - std::shared_mutex texturePathMutex_; + std::unordered_map texturePathMap_ {}; + std::shared_mutex texturePathMutex_ {}; - std::shared_mutex textureCacheMutex_; - std::unordered_map textureCache_; + std::shared_mutex textureCacheMutex_ {}; + std::unordered_map textureCache_ {}; - boost::gil::rgba8_image_t atlas_; - std::unordered_map atlasMap_; - std::shared_mutex atlasMutex_; + boost::gil::rgba8_image_t atlas_ {}; + std::unordered_map atlasMap_ {}; + std::shared_mutex atlasMutex_ {}; + + bool needsBuffered_ {true}; }; TextureAtlas::TextureAtlas() : p(std::make_unique()) {} @@ -67,6 +62,11 @@ TextureAtlas::~TextureAtlas() = default; TextureAtlas::TextureAtlas(TextureAtlas&&) noexcept = default; TextureAtlas& TextureAtlas::operator=(TextureAtlas&&) noexcept = default; +bool TextureAtlas::NeedsBuffered() const +{ + return p->needsBuffered_; +} + void TextureAtlas::RegisterTexture(const std::string& name, const std::string& path) { @@ -275,6 +275,9 @@ void TextureAtlas::BuildAtlas(size_t width, size_t height) logger_->warn("Unable to pack texture: {}", images[i].first); } } + + // Mark the need to buffer the atlas + p->needsBuffered_ = true; } GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) @@ -318,6 +321,9 @@ 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 5bf07018..5faff70d 100644 --- a/scwx-qt/source/scwx/qt/util/texture_atlas.hpp +++ b/scwx-qt/source/scwx/qt/util/texture_atlas.hpp @@ -66,6 +66,8 @@ public: static TextureAtlas& Instance(); + bool NeedsBuffered() const; + void RegisterTexture(const std::string& name, const std::string& path); bool CacheTexture(const std::string& name, const std::string& path); void BuildAtlas(size_t width, size_t height);