From ce31958ecea0316de4f6bb37c9cca471cc74f8b9 Mon Sep 17 00:00:00 2001 From: "jul..om" Date: Tue, 26 Feb 2013 20:00:03 +0000 Subject: [PATCH] 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 --- .../com/jme3/renderer/jogl/TextureUtil.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/engine/src/jogl/com/jme3/renderer/jogl/TextureUtil.java b/engine/src/jogl/com/jme3/renderer/jogl/TextureUtil.java index 600572da7..6a0c26da4 100644 --- a/engine/src/jogl/com/jme3/renderer/jogl/TextureUtil.java +++ b/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); + + } + + } }