From 11e4937c9f9af5e064ad7434b2e4bf47b5fe31f6 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 17 Sep 2012 01:33:32 +0200 Subject: menu/texture: implement GlDelayedAllocation interface Textures are now initialized during their first use, destroyed after their last used and could be use with the Activator. --- src/menu/texture.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/menu/texture.cpp') diff --git a/src/menu/texture.cpp b/src/menu/texture.cpp index bae6dc2c..4ad0c39e 100644 --- a/src/menu/texture.cpp +++ b/src/menu/texture.cpp @@ -29,13 +29,24 @@ namespace usdx log4cpp::Category& Texture::log = log4cpp::Category::getInstance("usdx.base.texture"); + const GLfloat Texture::default_vertices[] = { 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f }; + Texture::Texture(boost::filesystem::wpath filename) : filename(filename), texture(0), size(0, 0), rotation(0) { - Image image(filename); + } - size.set_width(image.get_surface()->w); - size.set_height(image.get_surface()->h); + Texture::~Texture() + { + } + + void Texture::gl_initialize() + { + Image image(filename); + size = image.get_size(); // // Check that the image dimensions are a power of 2 // if ((image.get_surface()->w & (image.get_surface()->w - 1)) != 0 ) { @@ -98,15 +109,26 @@ namespace usdx image.get_surface()->pixels); } - Texture::~Texture() + void Texture::gl_cleanup() { if (glIsTexture(texture)) { glDeleteTextures(1, &texture); } } - GLuint Texture::get_texture(void) const + void Texture::enable(void) + { + GlDelayedAllocation::enable(); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture); + + } + + void Texture::disable(void) { - return texture; + GlDelayedAllocation::disable(); + + glDisable(GL_TEXTURE_2D); } }; -- cgit v1.2.3