Buffer texture atlas on more than the first context after change

- Icons now work on all maps
This commit is contained in:
Dan Paulat 2023-08-02 20:49:48 -05:00
parent 4ff95094a3
commit 0be94c4de3
3 changed files with 11 additions and 10 deletions

View file

@ -35,6 +35,8 @@ public:
GLuint textureAtlas_;
std::mutex textureMutex_;
std::uint64_t textureBufferCount_ {};
};
GlContext::GlContext() : p(std::make_unique<Impl>()) {}
@ -79,8 +81,10 @@ 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->textureBufferCount_ = textureAtlas.BuildCount();
p->textureAtlas_ = textureAtlas.BufferAtlas(p->gl_);
}

View file

@ -54,7 +54,7 @@ public:
std::unordered_map<std::string, TextureAttributes> atlasMap_ {};
std::shared_mutex atlasMutex_ {};
bool needsBuffered_ {true};
std::uint64_t buildCount_ {0u};
};
TextureAtlas::TextureAtlas() : p(std::make_unique<Impl>()) {}
@ -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;
}

View file

@ -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);