Manage texture atlas in GL context

This commit is contained in:
Dan Paulat 2022-10-06 00:32:15 -05:00
parent e4629eb9ef
commit fb37139073
2 changed files with 16 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include <scwx/qt/gl/gl_context.hpp>
#include <scwx/qt/util/streams.hpp>
#include <scwx/qt/util/texture_atlas.hpp>
#include <scwx/util/hash.hpp>
#include <scwx/util/logger.hpp>
@ -29,6 +30,7 @@ public:
shaderProgramMap_ {},
shaderProgramMutex_ {},
textureMap_ {},
textureAtlas_ {GL_INVALID_INDEX},
textureMutex_ {}
{
}
@ -45,6 +47,7 @@ public:
std::mutex shaderProgramMutex_;
std::unordered_map<std::string, GLuint> textureMap_;
GLuint textureAtlas_;
std::mutex textureMutex_;
};
@ -84,6 +87,18 @@ GlContext::GetShaderProgram(const std::string& vertexPath,
return shaderProgram;
}
GLuint GlContext::GetTextureAtlas()
{
std::unique_lock lock(p->textureMutex_);
if (p->textureAtlas_ == GL_INVALID_INDEX)
{
p->textureAtlas_ = util::TextureAtlas::Instance().BufferAtlas(p->gl_);
}
return p->textureAtlas_;
}
GLuint GlContext::GetTexture(const std::string& texturePath)
{
GLuint texture = GL_INVALID_INDEX;

View file

@ -28,6 +28,7 @@ public:
GetShaderProgram(const std::string& vertexPath,
const std::string& fragmentPath);
GLuint GetTextureAtlas();
GLuint GetTexture(const std::string& texturePath);
private: