Scirenderer: Fix GLException due to JOGL 2.1.2 update 23/13123/4
Calixte DENIZET [Fri, 8 Nov 2013 16:09:06 +0000 (17:09 +0100)]
Change-Id: I50d9c21d47c6f8a9b887e88631ec1001124eaf12

scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java

index 16d9246..2f66dc2 100644 (file)
@@ -623,193 +623,99 @@ public class JoGLTextureManager implements TextureManager {
         private ByteBuffer data;
         private int shift;
 
-        public JoGLTextureData(GLProfile glp, TextureDataProvider.ImageType type, ByteBuffer data, int width, int height, int x, int y, int totalWidth, int totalHeight) {
-            super(glp);
+        public JoGLTextureData(GLProfile glp, int[] infos, ByteBuffer data, int width, int height, int x, int y, int totalWidth, int totalHeight) {
+            super(glp, infos[0], width, height, 0, infos[1], infos[2], false, false, true, null, null);
             this.data = data;
-            this.mipmap = false;
-            this.width = width;
-            this.height = height;
-            this.mustFlipVertically = true;
             this.shift = ((x == 0 && y == 0) || data.capacity() == 0) ? 0 : (data.capacity() / (totalWidth * totalHeight) * (x + y * totalWidth));
             this.rowLength = totalWidth;
+            this.alignment = infos[3];
+        }
+
+        public JoGLTextureData(GLProfile glp, TextureDataProvider.ImageType type, ByteBuffer data, int width, int height) {
+            this(glp, getInfos(type), data, width, height, 0, 0, width, height);
+        }
+
+        public JoGLTextureData(GLProfile glp, TextureDataProvider.ImageType type, ByteBuffer data, int width, int height, int x, int y, int totalWidth, int totalHeight) {
+            this(glp, getInfos(type), data, width, height, x, y, totalWidth, totalHeight);
+        }
+
+        public ByteBuffer getBuffer() {
+            if (shift == 0) {
+                return data;
+            } else {
+                data.position(shift);
+                ByteBuffer b = data.slice();
+                data.rewind();
+
+                return b;
+            }
+        }
+
+        public void setData(ByteBuffer data) {
+            this.data = data;
+        }
+
+        public void destroy() {
+            super.destroy();
+            this.data = null;
+        }
 
+        public static int[] getInfos(TextureDataProvider.ImageType type) {
             switch (type) {
                 case RGB:
-                    this.internalFormat = GL2.GL_RGB;
-                    setPixelFormat(GL.GL_RGB);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    //internalFormat, pixelFormat, pixelType, alignment
+                    return new int[] {GL2.GL_RGB, GL.GL_RGB, GL2.GL_UNSIGNED_BYTE, 1};
                 case RGB_RGBA:
-                    this.internalFormat = GL2.GL_RGB;
-                    setPixelFormat(GL.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_INT_8_8_8_8);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2.GL_RGB, GL.GL_RGBA, GL2.GL_UNSIGNED_INT_8_8_8_8, 4};
                 case BGR:
-                    this.internalFormat = GL2GL3.GL_RGB;
-                    setPixelFormat(GL2GL3.GL_BGR);
-                    setPixelType(GL.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2GL3.GL_RGB, GL2GL3.GL_BGR, GL.GL_UNSIGNED_BYTE, 1};
                 case GRAY:
-                    this.internalFormat = GL.GL_LUMINANCE;
-                    setPixelFormat(GL.GL_LUMINANCE);
-                    setPixelType(GL.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL.GL_LUMINANCE, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE, 1};
                 case GRAY_16:
-                    this.internalFormat = GL2.GL_LUMINANCE16;
-                    setPixelFormat(GL2.GL_LUMINANCE);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_LUMINANCE16, GL2.GL_LUMINANCE, GL2.GL_UNSIGNED_SHORT, 2};
                 case RGBA:
-                    this.internalFormat = GL2.GL_RGBA;
-                    setPixelFormat(GL.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_INT_8_8_8_8);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2.GL_RGBA, GL.GL_RGBA, GL2.GL_UNSIGNED_INT_8_8_8_8, 4};
                 case RGBA_REV:
-                    this.internalFormat = GL2.GL_RGBA;
-                    setPixelFormat(GL2.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_INT_8_8_8_8_REV);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2.GL_RGBA, GL2.GL_RGBA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV, 4};
                 case ABGR:
-                    this.internalFormat = GL2.GL_RGBA;
-                    setPixelFormat(GL2.GL_ABGR_EXT);
-                    setPixelType(GL.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_RGBA, GL2.GL_ABGR_EXT, GL.GL_UNSIGNED_BYTE, 1};
                 case RGB_332:
-                    this.internalFormat = GL2.GL_R3_G3_B2;
-                    setPixelFormat(GL2.GL_RGB);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE_3_3_2);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_R3_G3_B2, GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE_3_3_2, 1};
                 case RED:
-                    this.internalFormat = GL2.GL_RED;
-                    setPixelFormat(GL2.GL_RED);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_RED, GL2.GL_RED, GL2.GL_UNSIGNED_BYTE, 1};
                 case GREEN:
-                    this.internalFormat = GL2.GL_RGB8;
-                    setPixelFormat(GL2.GL_GREEN);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_RGB8, GL2.GL_GREEN, GL2.GL_UNSIGNED_BYTE, 1};
                 case BLUE:
-                    this.internalFormat = GL2.GL_RGB8;
-                    setPixelFormat(GL2.GL_BLUE);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_RGB8, GL2.GL_BLUE, GL2.GL_UNSIGNED_BYTE, 1};
                 case INTENSITY:
-                    this.internalFormat = GL2.GL_INTENSITY;
-                    setPixelFormat(GL2.GL_LUMINANCE);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
+                    return new int[] {GL2.GL_INTENSITY, GL2.GL_LUMINANCE, GL2.GL_UNSIGNED_BYTE, 1};
                 case RGBA_4444:
-                    this.internalFormat = GL2.GL_RGBA4;
-                    setPixelFormat(GL2.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT_4_4_4_4);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_RGBA4, GL2.GL_RGBA, GL2.GL_UNSIGNED_SHORT_4_4_4_4, 2};
                 case RGBA_5551:
-                    this.internalFormat = GL2.GL_RGB5_A1;
-                    setPixelFormat(GL2.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT_5_5_5_1);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_RGB5_A1, GL2.GL_RGBA, GL2.GL_UNSIGNED_SHORT_5_5_5_1, 2};
                 case RGB_FLOAT:
-                    this.internalFormat = GL2ES1.GL_RGB16F;
-                    setPixelFormat(GL2.GL_RGB);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2ES1.GL_RGB16F, GL2.GL_RGB, GL2.GL_FLOAT, 4};
                 case RGBA_FLOAT:
-                    this.internalFormat = GL2.GL_RGBA16F;
-                    setPixelFormat(GL2.GL_RGBA);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT, 4};
                 case GRAY_FLOAT:
-                    this.internalFormat = GL2.GL_LUMINANCE16F;
-                    setPixelFormat(GL2.GL_LUMINANCE);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2.GL_LUMINANCE16F, GL2.GL_LUMINANCE, GL2.GL_FLOAT, 4};
                 case RED_16:
-                    this.internalFormat = GL2.GL_RGB16;
-                    setPixelFormat(GL2.GL_RED);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_RGB16, GL2.GL_RED, GL2.GL_UNSIGNED_SHORT, 2};
                 case GREEN_16:
-                    this.internalFormat = GL2.GL_RGB16;
-                    setPixelFormat(GL2.GL_GREEN);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_RGB16, GL2.GL_GREEN, GL2.GL_UNSIGNED_SHORT, 2};
                 case BLUE_16:
-                    this.internalFormat = GL2.GL_RGB16;
-                    setPixelFormat(GL2.GL_BLUE);
-                    setPixelType(GL2.GL_UNSIGNED_SHORT);
-                    this.alignment = 2;
-                    break;
+                    return new int[] {GL2.GL_RGB16, GL2.GL_BLUE, GL2.GL_UNSIGNED_SHORT, 2};
                 case RED_FLOAT:
-                    this.internalFormat = GL2ES1.GL_RGB16F;
-                    setPixelFormat(GL2.GL_RED);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2ES1.GL_RGB16F, GL2.GL_RED, GL2.GL_FLOAT, 4};
                 case GREEN_FLOAT:
-                    this.internalFormat = GL2ES1.GL_RGB16F;
-                    setPixelFormat(GL2.GL_GREEN);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2ES1.GL_RGB16F, GL2.GL_GREEN, GL2.GL_FLOAT, 4};
                 case BLUE_FLOAT:
-                    this.internalFormat = GL2ES1.GL_RGB16F;
-                    setPixelFormat(GL2.GL_BLUE);
-                    setPixelType(GL2.GL_FLOAT);
-                    this.alignment = 4;
-                    break;
+                    return new int[] {GL2ES1.GL_RGB16F, GL2.GL_BLUE, GL2.GL_FLOAT, 4};
                 case RGBA_BYTE:
-                    this.internalFormat = GL2.GL_RGBA;
-                    setPixelFormat(GL2.GL_RGBA);
-                    setPixelType(GL2.GL_UNSIGNED_BYTE);
-                    this.alignment = 1;
-                    break;
-            }
-        }
-
-        public JoGLTextureData(GLProfile glp, TextureDataProvider.ImageType type, ByteBuffer data, int width, int height) {
-            this(glp, type, data, width, height, 0, 0, width, height);
-        }
-
-        public ByteBuffer getBuffer() {
-            if (shift == 0) {
-                return data;
-            } else {
-                data.position(shift);
-                ByteBuffer b = data.slice();
-                data.rewind();
-
-                return b;
+                    return new int[] {GL2.GL_RGBA, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, 1};
             }
-        }
 
-        public void setData(ByteBuffer data) {
-            this.data = data;
-        }
-
-        public void destroy() {
-            super.destroy();
-            this.data = null;
+            return new int[] {GL2.GL_RGB, GL.GL_RGB, GL2.GL_UNSIGNED_BYTE, 1};
         }
     }
 }