aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-09-02 05:33:27 +0000
committerSven Gothel <[email protected]>2008-09-02 05:33:27 +0000
commit6e14457eac32f838fcdfe9b4b4e26fe7a7d13936 (patch)
tree6b1396b4c6d7a5bf891cf78c0c42cb27b830426b /src/classes/com/sun
parentc7e5336fe362e721fdafdf55e1304b63b33026fc (diff)
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
Diffstat (limited to 'src/classes/com/sun')
-rwxr-xr-xsrc/classes/com/sun/opengl/util/texture/TextureData.java19
-rwxr-xr-xsrc/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp6
-rwxr-xr-xsrc/classes/com/sun/opengl/util/texture/TextureIO.java.javase6
-rwxr-xr-xsrc/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp45
-rwxr-xr-xsrc/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javase45
5 files changed, 92 insertions, 29 deletions
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<height; ++i) {
+ for(int j=0; j<bWidth; j+=bpp) {
+ k=i*bWidth+j;
+ b=data[k+0];
+ r=data[k+2];
+ data[k+0]=r;
+ data[k+2]=b;
+ }
+ }
+ }
+
/** Returns the width of the image. */
public int getWidth() { return header.width(); }
@@ -323,6 +351,9 @@ public class TGAImage {
/** Returns the OpenGL format for this texture; e.g. GL.GL_BGR or GL.GL_BGRA. */
public int getGLFormat() { return format; }
+ /** Returns the bytes per pixel */
+ public int getBytesPerPixel() { return bpp; }
+
/** Returns the raw data for this texture in the correct
(bottom-to-top) order for calls to glTexImage2D. */
public ByteBuffer getData() { return data; }
diff --git a/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javase b/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javase
index 2738536f0..0ba47d500 100755
--- a/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javase
+++ b/src/classes/com/sun/opengl/util/texture/spi/TGAImage.java.javase
@@ -74,6 +74,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) {
@@ -295,13 +296,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);
@@ -313,9 +307,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<height; ++i) {
+ for(int j=0; j<bWidth; j+=bpp) {
+ k=i*bWidth+j;
+ b=data[k+0];
+ r=data[k+2];
+ data[k+0]=r;
+ data[k+2]=b;
+ }
+ }
+ }
+
/** Returns the width of the image. */
public int getWidth() { return header.width(); }
@@ -325,6 +353,9 @@ public class TGAImage {
/** Returns the OpenGL format for this texture; e.g. GL.GL_BGR or GL.GL_BGRA. */
public int getGLFormat() { return format; }
+ /** Returns the bytes per pixel */
+ public int getBytesPerPixel() { return bpp; }
+
/** Returns the raw data for this texture in the correct
(bottom-to-top) order for calls to glTexImage2D. */
public ByteBuffer getData() { return data; }