]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/texture.cxx
Fix a problem with systems that don't define GLXPbufferSGIX or GLXFBConfigSGIX
[simgear.git] / simgear / screen / texture.cxx
index 892e6bdbbfa7c7a68d095369b35666b3b774b955..56fd95409d4ddb84492c09daa3254e4176e79bfa 100644 (file)
@@ -49,9 +49,7 @@ SGTexture::SGTexture(unsigned int width, unsigned int height)
 
 SGTexture::~SGTexture()
 {
-    if ( texture_data ) {
-        delete texture_data;
-    }
+    delete[] texture_data;
 
     if ( texture_id != 0 ) {
         free_id();
@@ -182,8 +180,7 @@ SGTexture::read_alpha_texture(const char *name)
     SGTexture::ImageRec *image;
     int y;
 
-    if (texture_data)
-        delete texture_data;
+    delete[] texture_data;
 
     image = ImageOpen(name);
     if(!image) {
@@ -225,8 +222,7 @@ SGTexture::read_rgb_texture(const char *name)
     SGTexture::ImageRec *image;
     int y;
 
-    if (texture_data)
-        delete texture_data;
+    delete[] texture_data;
 
     image = ImageOpen(name);
     if(!image) {
@@ -249,11 +245,11 @@ SGTexture::read_rgb_texture(const char *name)
     bbuf = new GLubyte[ image->xsize ];
     abuf = new GLubyte[ image->xsize ];
     if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
-      delete texture_data;
-      delete rbuf;
-      delete gbuf;
-      delete bbuf;
-      delete abuf;
+      delete[] texture_data;
+      delete[] rbuf;
+      delete[] gbuf;
+      delete[] bbuf;
+      delete[] abuf;
       errstr = OUT_OF_MEMORY;
       return;
     }
@@ -277,10 +273,10 @@ SGTexture::read_rgb_texture(const char *name)
     }
 
     ImageClose(image);
-    delete rbuf;
-    delete gbuf;
-    delete bbuf;
-    delete abuf;
+    delete[] rbuf;
+    delete[] gbuf;
+    delete[] bbuf;
+    delete[] abuf;
 }
 
 
@@ -293,8 +289,7 @@ SGTexture::read_rgba_texture(const char *name)
     SGTexture::ImageRec *image;
     int y;
 
-    if (texture_data)
-        delete texture_data;
+    delete[] texture_data;
 
     image = ImageOpen(name);
     if(!image) {
@@ -317,11 +312,11 @@ SGTexture::read_rgba_texture(const char *name)
     bbuf = new GLubyte[ image->xsize ];
     abuf = new GLubyte[ image->xsize ];
     if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
-      delete texture_data;
-      delete rbuf;
-      delete gbuf;
-      delete bbuf;
-      delete abuf;
+      delete[] texture_data;
+      delete[] rbuf;
+      delete[] gbuf;
+      delete[] bbuf;
+      delete[] abuf;
       errstr = OUT_OF_MEMORY;
       return;
     }
@@ -346,10 +341,10 @@ SGTexture::read_rgba_texture(const char *name)
     }
 
     ImageClose(image);
-    delete rbuf;
-    delete gbuf;
-    delete bbuf;
-    delete abuf;
+    delete[] rbuf;
+    delete[] gbuf;
+    delete[] bbuf;
+    delete[] abuf;
 }
 
 void
@@ -359,8 +354,7 @@ SGTexture::read_raw_texture(const char *name)
     SGTexture::ImageRec *image;
     int y;
 
-    if (texture_data)
-        delete texture_data;
+    delete[] texture_data;
 
     image = RawImageOpen(name);
 
@@ -394,8 +388,7 @@ SGTexture::read_r8_texture(const char *name)
     SGTexture::ImageRec *image;
     int xy;
 
-    if (texture_data)
-        delete texture_data;
+    delete[] texture_data;
 
     //it wouldn't make sense to write a new function ...
     image = RawImageOpen(name);
@@ -544,7 +537,7 @@ void
 SGTexture::ImageClose(SGTexture::ImageRec *image) {
     if (image->file)  gzclose(image->file);
     if (file) fclose(file);
-    delete image->tmp;
+    delete[] image->tmp;
     delete image;
 }
 
@@ -585,7 +578,7 @@ SGTexture::RawImageOpen(const char *fileName)
 
 
     //just allocate a pseudo value as I'm too lazy to change ImageClose()...
-    image->tmp = new GLubyte;
+    image->tmp = new GLubyte[1];
 
     if (image->tmp == 0) {
         errstr = OUT_OF_MEMORY;
@@ -809,7 +802,7 @@ SGTexture::make_monochrome(float contrast, GLubyte r, GLubyte g, GLubyte b) {
 
          if (contrast != 1.0) {
             float pixcol = -1.0 + (avg/128);
-            avg = 128 + 128*powf(pixcol, contrast);
+            avg = 128 + int(128*pow(pixcol, contrast));
          }
 
          ap[0] = avg*r/255;
@@ -827,7 +820,7 @@ SGTexture::make_grayscale(float contrast) {
       return;
 
    int colors = (num_colors == 3) ? 1 : 2;
-   GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * colors);
+   GLubyte *map = new GLubyte[ texture_width * texture_height * colors ];
 
    for (int y=0; y<texture_height; y++)
       for (int x=0; x<texture_width; x++)
@@ -837,7 +830,7 @@ SGTexture::make_grayscale(float contrast) {
 
          if (contrast != 1.0) {
             float pixcol = -1.0 + (avg/128);
-            avg = 128 + 128*powf(pixcol, contrast);
+            avg = 128 + int(128*pow(pixcol, contrast));
          }
 
          int pos = (x + y*texture_width)*colors;
@@ -846,7 +839,7 @@ SGTexture::make_grayscale(float contrast) {
             map[pos+1] = rgb[3];
       }
 
-   free (texture_data);
+   delete[] texture_data;
    texture_data = map;
    num_colors = colors;
 }
@@ -856,8 +849,8 @@ void
 SGTexture::make_maxcolorwindow() {
    GLubyte minmaxc[2] = {255, 0};
 
-   unsigned int pos = 0;
-   unsigned int max = num_colors;
+   int pos = 0;
+   int max = num_colors;
    if (num_colors == 2) max = 1;
    if (num_colors == 4) max = 3; 
    while (pos < texture_width * texture_height * num_colors) {
@@ -877,7 +870,7 @@ SGTexture::make_maxcolorwindow() {
    while (pos < texture_width * texture_height * num_colors) {
       for (int i=0; i < max; i++) {
          texture_data[pos+i] -= offs;
-         texture_data[pos+i] *= factor;
+         texture_data[pos+i] = int(factor * texture_data[pos+i]);
       }
       pos += num_colors;
    }
@@ -892,7 +885,7 @@ SGTexture::make_normalmap(float brightness, float contrast) {
    int colors = (num_colors == 1) ? 3 : 4;
    bool alpha = (colors > 3);
    int tsize = texture_width * texture_height * colors;
-   GLubyte *map = (GLubyte *)malloc (tsize);
+   GLubyte *map = new GLubyte[ tsize ];
 
    int mpos = 0, dpos = 0;
    for (int y=0; y<texture_height; y++) {
@@ -923,14 +916,14 @@ SGTexture::make_normalmap(float brightness, float contrast) {
 
          map[mpos+0] = (128+(cx1-c)/2);
          map[mpos+1] = (128+(cy1-c)/2);
-         map[mpos+2] = 127+brightness*128; // 255-c/2;
+         map[mpos+2] = 127+int(brightness*128); // 255-c/2;
 
          mpos += colors;
          dpos += num_colors;
       }
    }
 
-   free (texture_data);
+   delete[] texture_data;
    texture_data = map;
    num_colors = colors;
 }
@@ -941,7 +934,7 @@ SGTexture::make_bumpmap(float brightness, float contrast) {
    make_grayscale(contrast);
 
    int colors = (num_colors == 1) ? 1 : 2;
-   GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * colors);
+   GLubyte *map = new GLubyte[ texture_width * texture_height * colors ];
 
    for (int y=0; y<texture_height; y++)
       for (int x=0; x<texture_width; x++)
@@ -960,7 +953,7 @@ SGTexture::make_bumpmap(float brightness, float contrast) {
             map[mpos+1] = texture_data[dpos+1];
       }
 
-   free (texture_data);
+   delete[] texture_data;
    texture_data = map;
    num_colors = colors;
 }