]> git.mxchange.org Git - simgear.git/commitdiff
Add a function which might return whether a texture is in video memory, delete the...
authorehofman <ehofman>
Tue, 1 Jul 2003 09:49:45 +0000 (09:49 +0000)
committerehofman <ehofman>
Tue, 1 Jul 2003 09:49:45 +0000 (09:49 +0000)
simgear/screen/texture.cxx
simgear/screen/texture.hxx

index 58f69ef60e5e4e23b789d4bf46abb49f4bb48782..62e8c74b11f9d6f35bfff2a823bcd068a3d848db 100644 (file)
 #include "colours.h"
 
 SGTexture::SGTexture()
+   : texture_id(0),
+     texture_data(0)
 {
-    texture_data = 0;
 }
 
 SGTexture::SGTexture(unsigned int width, unsigned int height)
+   : texture_id(0)
 {
     texture_data = new GLubyte[ width * height * 3 ];
 }
 
 SGTexture::~SGTexture()
 {
-    delete texture_data;
+    if (texture_data)
+        delete texture_data;
+
+    if (texture_id)
+        free_id();
 }
 
 void
@@ -323,6 +329,7 @@ SGTexture::read_r8_texture(const char *name)
 }
 
 
+#if 0
 void
 SGTexture::set_pixel(GLuint x, GLuint y, sgVec3 &c)
 {
@@ -343,6 +350,7 @@ SGTexture::get_pixel(GLuint x, GLuint y)
 
     return &c;
 }
+#endif
 
 
 SGTexture::ImageRec *
index ec41b2cea82394a360ff3580359a7e2ddaa8138a..7a947429e207d09e51a8c2e8d2808ba0e9cb74c4 100644 (file)
@@ -61,6 +61,15 @@ protected:
     void ImageClose(ImageRec *image);
     void ImageGetRow(ImageRec *image, GLubyte *buf, int y, int z);
 
+    inline void free_id() {
+#ifdef GL_VERSION_1_1
+        glDeleteTextures(1, &texture_id);
+#else
+        glDeleteTexturesEXT(1, &texture_id);
+#endif
+    }
+
+
 public:
 
     SGTexture();
@@ -77,6 +86,7 @@ public:
 
     inline GLuint id() { return texture_id; }
     inline GLubyte *texture() { return texture_data; }
+    inline void set_data(GLubyte *data) { texture_data = data; }
 
     inline int width() { return texture_width; }
     inline int height() { return texture_height; }
@@ -88,16 +98,28 @@ public:
     void prepare(unsigned int width = 256, unsigned int height = 256);
     void finish(unsigned int width, unsigned int height);
 
+#if 0
     // texture pixel manipulation functions.
     void set_pixel(GLuint x, GLuint y, sgVec3 &c);
     sgVec3 *get_pixel(GLuint x, GLuint y);
+#endif
 
     void bind();
     inline void select() {
-        // if (texture_data)
-            glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
-                          texture_width, texture_height, 0,
-                          GL_RGB, GL_UNSIGNED_BYTE, texture_data );
+        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
+                      texture_width, texture_height, 0,
+                      GL_RGB, GL_UNSIGNED_BYTE, texture_data );
+
+        delete texture_data;
+    }
+
+    // Nowhere does it say that resident textures have to be in video memory!
+    // NVidia's OpenGL drivers implement glAreTexturesResident() correctly,
+    // but the Matrox G400, for example, doesn't.
+    inline bool is_resident() {
+        GLboolean is_res;
+        glAreTexturesResident(1, &texture_id, &is_res);
+        return is_res;
     }
 };