Crude texture caching

This commit is contained in:
2014-04-06 21:25:05 +02:00
parent 412d53a1f7
commit 0896f540fe
3 changed files with 16 additions and 8 deletions
+8 -4
View File
@@ -6,21 +6,25 @@ Texture::Texture(std::string path)
Load(path);
}
void Texture::Load(std::string path)
{
texture = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y);
auto cachedTexture = m_TextureCache.find(path);
if (cachedTexture == m_TextureCache.end()) {
m_TextureCache[path] = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y);
}
m_Texture = m_TextureCache[path];
}
void Texture::Bind()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
}
Texture::~Texture()
{
glDeleteTextures(1, &texture);
glDeleteTextures(1, &m_Texture);
}