]> git.mxchange.org Git - simgear.git/commitdiff
Allow removing of the texture data after it is sent to OpenGL
authorehofman <ehofman>
Fri, 11 Jul 2003 09:57:28 +0000 (09:57 +0000)
committerehofman <ehofman>
Fri, 11 Jul 2003 09:57:28 +0000 (09:57 +0000)
simgear/screen/texture.cxx
simgear/screen/texture.hxx

index 9b9189756477d339c09a2abfcaef4a1020feb677..e3dd69badfe3f4af10706a2dad26d4b33277fa88 100644 (file)
@@ -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]);
index 00ce0e1c3027c5f257b692ab859aae67d6f0ce14..4a4a2f22a9a38b04f8f6f72caa54daf82491875c 100644 (file)
@@ -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!