diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-09-17 01:33:32 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-13 22:41:06 +0100 |
commit | 11e4937c9f9af5e064ad7434b2e4bf47b5fe31f6 (patch) | |
tree | 79390376632122609c710230390c0f4710c3b3e7 /src/menu/background_image.cpp | |
parent | 368ff00d125f00e9fcfc536f198697aba79c2d40 (diff) | |
download | usdx-11e4937c9f9af5e064ad7434b2e4bf47b5fe31f6.tar.gz usdx-11e4937c9f9af5e064ad7434b2e4bf47b5fe31f6.tar.xz usdx-11e4937c9f9af5e064ad7434b2e4bf47b5fe31f6.zip |
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.
Diffstat (limited to 'src/menu/background_image.cpp')
-rw-r--r-- | src/menu/background_image.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/menu/background_image.cpp b/src/menu/background_image.cpp index 4db81967..15229284 100644 --- a/src/menu/background_image.cpp +++ b/src/menu/background_image.cpp @@ -24,6 +24,7 @@ #include "background_image.hpp" #include "drawable_control.hpp" +#include "utils/activator.hpp" namespace usdx { @@ -31,21 +32,16 @@ namespace usdx boost::filesystem::wpath filename) : Background(control), color(255,255,255) { - texture = new Texture(filename); - - this->tex[0] = 0.0f; - this->tex[1] = 1.0f; - this->tex[2] = 1.0f; - this->tex[3] = 1.0f; - this->tex[4] = 1.0f; - this->tex[5] = 0.0f; - this->tex[6] = 0.0f; - this->tex[7] = 0.0f; + texture = new Disposer<Texture>(new Texture(filename)); } BackgroundImage::~BackgroundImage() { - delete texture; + if (texture != NULL) { + delete texture; + texture = NULL; + } + } } void BackgroundImage::draw(void) @@ -59,8 +55,7 @@ namespace usdx this->vertices[6] = 0; this->vertices[7] = 0; - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture->get_texture()); + Activator<Texture> t(texture->get()); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -68,14 +63,12 @@ namespace usdx glVertexPointer(2, GL_INT, 0, vertices); glColorPointer(3, GL_UNSIGNED_BYTE, 0, color.get_array(4)); - glTexCoordPointer(2, GL_FLOAT, 0, tex); + glTexCoordPointer(2, GL_FLOAT, 0, Texture::default_vertices); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - - glDisable(GL_TEXTURE_2D); } }; |