From 6e14457eac32f838fcdfe9b4b4e26fe7a7d13936 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 2 Sep 2008 05:33:27 +0000 Subject: Fix: TextureIO/TGA for ES2 (GL formats/types) git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1768 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/opengl/util/texture/TextureData.java | 19 +++------ .../util/texture/TextureIO.java.javame_cdc_fp | 6 ++- .../sun/opengl/util/texture/TextureIO.java.javase | 6 ++- .../util/texture/spi/TGAImage.java.javame_cdc_fp | 45 ++++++++++++++++++---- .../opengl/util/texture/spi/TGAImage.java.javase | 45 ++++++++++++++++++---- 5 files changed, 92 insertions(+), 29 deletions(-) (limited to 'src/classes/com/sun') diff --git a/src/classes/com/sun/opengl/util/texture/TextureData.java b/src/classes/com/sun/opengl/util/texture/TextureData.java index 5316ed191..dcaee52f2 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureData.java +++ b/src/classes/com/sun/opengl/util/texture/TextureData.java @@ -319,25 +319,18 @@ public class TextureData { public void flush(); } + public String toString() { + return "TextureData["+width+"x"+height+", internFormat "+internalFormat+", pixelFormat "+pixelFormat+", pixelType "+pixelType+", border "+border+", estSize "+estimatedMemorySize+", alignment "+alignment+", rowlen "+rowLength; + } + //---------------------------------------------------------------------- // Internals only below this point // - protected int estimatedMemorySize(Buffer buffer) { + protected static int estimatedMemorySize(Buffer buffer) { if (buffer == null) { return 0; } - int capacity = buffer.capacity(); - if (buffer instanceof ByteBuffer) { - return capacity; - } else if (buffer instanceof IntBuffer) { - return capacity * BufferUtil.SIZEOF_INT; - } else if (buffer instanceof FloatBuffer) { - return capacity * BufferUtil.SIZEOF_FLOAT; - } else if (buffer instanceof ShortBuffer) { - return capacity * BufferUtil.SIZEOF_SHORT; - } - throw new RuntimeException("Unexpected buffer type " + - buffer.getClass().getName()); + return buffer.capacity() * BufferUtil.sizeOfBufferElem(buffer); } } diff --git a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp index c6b6271da..f39f1e4c0 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp +++ b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp @@ -1001,7 +1001,11 @@ public class TextureIO { pixelFormat = image.getGLFormat(); } if (internalFormat == 0) { - internalFormat = GL.GL_RGBA8; + if(GLProfile.isGL2()) { + internalFormat = GL.GL_RGBA8; + } else { + internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + } } return new TextureData(internalFormat, image.getWidth(), diff --git a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase index d9ae5b6c4..ebb59fa6f 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase +++ b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase @@ -1003,7 +1003,11 @@ public class TextureIO { pixelFormat = image.getGLFormat(); } if (internalFormat == 0) { - internalFormat = GL.GL_RGBA8; + if(GLProfile.isGL2()) { + internalFormat = GL.GL_RGBA8; + } else { + internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + } } return new TextureData(internalFormat, image.getWidth(), diff --git a/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp b/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp index be4ac36d2..6214d43b2 100755 --- a/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp +++ b/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp @@ -73,6 +73,7 @@ import com.sun.opengl.util.texture.*; public class TGAImage { private Header header; private int format; + private int bpp; private ByteBuffer data; private TGAImage(Header header) { @@ -293,13 +294,6 @@ public class TGAImage { byte[] rawBuf = new byte[rawWidth]; byte[] tmpData = new byte[rawWidth * header.height()]; - if (header.pixelDepth() == 24) { - format = GL2.GL_BGR; - } else { - assert header.pixelDepth() == 32; - format = GL2.GL_BGRA; - } - for (i = 0; i < header.height(); ++i) { dIn.readFully(rawBuf, 0, rawWidth); @@ -311,9 +305,43 @@ public class TGAImage { System.arraycopy(rawBuf, 0, tmpData, y * rawWidth, rawBuf.length); } + if (header.pixelDepth() == 24) { + bpp=3; + if(GLProfile.isGL2()) { + format = GL2.GL_BGR; + } else { + format = GL.GL_RGB; + swapBGR(tmpData, rawWidth, header.height(), bpp); + } + } else { + assert header.pixelDepth() == 32; + bpp=4; + + if(GLProfile.isGL2()) { + format = GL2.GL_BGRA; + } else { + format = GL.GL_RGBA; + swapBGR(tmpData, rawWidth, header.height(), bpp); + } + } + data = ByteBuffer.wrap(tmpData); } + private static void swapBGR(byte[] data, int bWidth, int height, int bpp) { + byte r,b; + int k; + for(int i=0; i