Parcourir la source

Improves OpenGL-ES support (especially for Raspberry Pi), contribution of Erkki Nokso-Koivisto (with small changes), converts ABGR to RGBA only if the extension GL_EXT_abgr is not supported

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10440 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
jul..om il y a 12 ans
Parent
commit
ce31958ece
1 fichiers modifiés avec 26 ajouts et 2 suppressions
  1. 26 2
      engine/src/jogl/com/jme3/renderer/jogl/TextureUtil.java

+ 26 - 2
engine/src/jogl/com/jme3/renderer/jogl/TextureUtil.java

@@ -43,6 +43,8 @@ import javax.media.opengl.GL2GL3;
 import javax.media.opengl.GLContext;
 
 public class TextureUtil {
+    
+    private static boolean abgrToRgbaConversionEnabled = false;
 
     public static int convertTextureFormat(Format fmt) {
         switch (fmt) {
@@ -157,8 +159,9 @@ public class TextureUtil {
         GL gl = GLContext.getCurrentGL();
         switch (fmt){
             case ABGR8:
-                if (!gl.isExtensionAvailable("GL_EXT_abgr")){
-                    return null;
+                if (!gl.isExtensionAvailable("GL_EXT_abgr") && !abgrToRgbaConversionEnabled) {
+                    setFormat(Format.ABGR8,   GL.GL_RGBA,        GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false);
+                    abgrToRgbaConversionEnabled = true;
                 }
                 break;
             case BGR8:
@@ -257,6 +260,9 @@ public class TextureUtil {
         int depth = image.getDepth();
 
         if (data != null) {
+            if (abgrToRgbaConversionEnabled) {
+                convertABGRtoRGBA(data);
+            }
             gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
         }
 
@@ -385,4 +391,22 @@ public class TextureUtil {
             pos += mipSizes[i];
         }
     }
+    
+    private static void convertABGRtoRGBA(ByteBuffer buffer) {
+
+        for (int i = 0; i < buffer.capacity(); i++) {
+
+            int a = buffer.get(i++);
+            int b = buffer.get(i++);
+            int g = buffer.get(i++);
+            int r = buffer.get(i);
+
+            buffer.put(i - 3, (byte) r);
+            buffer.put(i - 2, (byte) g);
+            buffer.put(i - 1, (byte) b);
+            buffer.put(i, (byte) a);
+
+        }
+
+    }
 }