]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/texture.hxx
Don't bother other develoers with problems caused by MipsPro (version < 7.3) compilers
[simgear.git] / simgear / screen / texture.hxx
index 2a1b5c5c1c4dd8ceba401f512bc1295074c1d4c1..bb99b5c2dec5932db576d465d997efb8f99bd03d 100644 (file)
@@ -1,3 +1,14 @@
+/**
+ * \file texture.hxx
+ * Texture manipulation routines
+ *
+ * Copyright (c) Mark J. Kilgard, 1997.
+ * Code added in april 2003 by Erik Hofman
+ *
+ * This program is freely distributable without licensing fees 
+ * and is provided without guarantee or warrantee expressed or 
+ * implied. This program is -not- in the public domain.
+ */
 
 #ifndef __SG_TEXTURE_HXX
 #define __SG_TEXTURE_HXX 1
@@ -7,6 +18,10 @@
 
 #include <plib/sg.h>
 
+/**
+ * A class to encapsulate all the info surrounding an OpenGL texture
+ * and also query various info and load various file formats
+ */
 class SGTexture {
 
 private:
@@ -46,6 +61,16 @@ 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
+        texture_id = 0;
+    }
+
+
 public:
 
     SGTexture();
@@ -58,10 +83,11 @@ public:
     void read_raw_texture(const char *name);
     void read_r8_texture(const char *name);
 
-    inline bool usable() { return texture_data ? true : false; }
+    inline bool usable() { return (texture_id > 0) ? true : false; }
 
     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; }
@@ -75,14 +101,27 @@ public:
 
     // texture pixel manipulation functions.
     void set_pixel(GLuint x, GLuint y, sgVec3 &c);
-    sgVec3 *get_pixel(GLuint x, GLuint y);
+    float *get_pixel(GLuint x, GLuint y);
 
     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 );
+    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!
+    // 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;
     }
 };