From: ehofman Date: Fri, 11 Jul 2003 09:57:28 +0000 (+0000) Subject: Allow removing of the texture data after it is sent to OpenGL X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=505b4c434dbc905bb47a8998299e57756ccb569e;p=simgear.git Allow removing of the texture data after it is sent to OpenGL --- diff --git a/simgear/screen/texture.cxx b/simgear/screen/texture.cxx index 9b918975..e3dd69ba 100644 --- a/simgear/screen/texture.cxx +++ b/simgear/screen/texture.cxx @@ -47,13 +47,15 @@ SGTexture::~SGTexture() void SGTexture::bind() { - if (!texture_data) { + bool gen = false; + if (!texture_id) { #ifdef GL_VERSION_1_1 glGenTextures(1, &texture_id); #elif GL_EXT_texture_object glGenTexturesEXT(1, &texture_id); #endif + gen = true; } #ifdef GL_VERSION_1_1 @@ -63,7 +65,7 @@ SGTexture::bind() glBindTextureEXT(GL_TEXTURE_2D, texture_id); #endif - if (!texture_data) { + if (gen) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -334,6 +336,9 @@ SGTexture::read_r8_texture(const char *name) void SGTexture::set_pixel(GLuint x, GLuint y, sgVec3 &c) { + if (!texture_data) + return; + unsigned int pos = (x + y*texture_width)*3; texture_data[pos] = c[0]; texture_data[pos+1] = c[1]; @@ -345,6 +350,11 @@ sgVec3 * SGTexture::get_pixel(GLuint x, GLuint y) { static sgVec3 c; + + sgSetVec3(c, 0.0, 0.0, 0.0); + if (!texture_data) + return; + unsigned int pos = (x + y*texture_width)*3; sgSetVec3(c, texture_data[pos], texture_data[pos+1], texture_data[pos+2]); diff --git a/simgear/screen/texture.hxx b/simgear/screen/texture.hxx index 00ce0e1c..4a4a2f22 100644 --- a/simgear/screen/texture.hxx +++ b/simgear/screen/texture.hxx @@ -104,10 +104,15 @@ public: sgVec3 *get_pixel(GLuint x, GLuint y); void bind(); - inline void select() { + inline void select(bool keep_data = false) { glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, texture_width, texture_height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_data ); + + if (!keep_data) { + delete[] texture_data; + texture_data = 0; + } } // Nowhere does it say that resident textures have to be in video memory!