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
This commit is contained in:
@@ -44,6 +44,8 @@ import javax.media.opengl.GLContext;
|
|||||||
|
|
||||||
public class TextureUtil {
|
public class TextureUtil {
|
||||||
|
|
||||||
|
private static boolean abgrToRgbaConversionEnabled = false;
|
||||||
|
|
||||||
public static int convertTextureFormat(Format fmt) {
|
public static int convertTextureFormat(Format fmt) {
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case Alpha16:
|
case Alpha16:
|
||||||
@@ -157,8 +159,9 @@ public class TextureUtil {
|
|||||||
GL gl = GLContext.getCurrentGL();
|
GL gl = GLContext.getCurrentGL();
|
||||||
switch (fmt){
|
switch (fmt){
|
||||||
case ABGR8:
|
case ABGR8:
|
||||||
if (!gl.isExtensionAvailable("GL_EXT_abgr")){
|
if (!gl.isExtensionAvailable("GL_EXT_abgr") && !abgrToRgbaConversionEnabled) {
|
||||||
return null;
|
setFormat(Format.ABGR8, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false);
|
||||||
|
abgrToRgbaConversionEnabled = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BGR8:
|
case BGR8:
|
||||||
@@ -257,6 +260,9 @@ public class TextureUtil {
|
|||||||
int depth = image.getDepth();
|
int depth = image.getDepth();
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
if (abgrToRgbaConversionEnabled) {
|
||||||
|
convertABGRtoRGBA(data);
|
||||||
|
}
|
||||||
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
|
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,4 +391,22 @@ public class TextureUtil {
|
|||||||
pos += mipSizes[i];
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user