aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorMichael Esemplare <[email protected]>2013-12-11 13:43:03 -0800
committerMichael Esemplare <[email protected]>2013-12-11 13:49:00 -0800
commit82d7bae212ad5a540a29003aaec8c7e026615f68 (patch)
tree239cb2557018df8e7661702216e6fb53aad4fecb /src/jogl/classes/com
parent45525950b0ad41b10790515c8b6142d746cd24f5 (diff)
Fix Bug 362: calculated dimensions for MipMaps smaller than 16x16
Added method to calculate mipmap blocksize for uncompressed and DXTn images
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java
index d75bb3767..7311f20b3 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java
@@ -766,6 +766,8 @@ public class DDSImage {
// Now check the mipmaps against this size
int curSize = topmostMipmapSize;
+ int mipmapWidth = width;
+ int mipmapHeight = height;
int totalSize = 0;
for (int i = 0; i < mipmapData.length; i++) {
if (mipmapData[i].remaining() != curSize) {
@@ -773,7 +775,10 @@ public class DDSImage {
" didn't match expected data size (expected " + curSize + ", got " +
mipmapData[i].remaining() + ")");
}
- curSize /= 4;
+ // Compute next mipmap size
+ if (mipmapWidth > 1) mipmapWidth /= 2;
+ if (mipmapHeight > 1) mipmapHeight /= 2;
+ curSize = computeBlockSize(mipmapWidth, mipmapHeight, 1, d3dFormat);
totalSize += mipmapData[i].remaining();
}
@@ -852,6 +857,32 @@ public class DDSImage {
return blockSize;
}
+ private static int computeBlockSize(int width,
+ int height,
+ int depth,
+ int pixelFormat) {
+ int blocksize;
+ switch (pixelFormat) {
+ case D3DFMT_R8G8B8:
+ blocksize = width*height*3;
+ break;
+ case D3DFMT_A8R8G8B8:
+ case D3DFMT_X8R8G8B8:
+ blocksize = width*height*4;
+ break;
+ case D3DFMT_DXT1:
+ case D3DFMT_DXT2:
+ case D3DFMT_DXT3:
+ case D3DFMT_DXT4:
+ case D3DFMT_DXT5:
+ blocksize = computeCompressedBlockSize(width, height, 1, pixelFormat);
+ break;
+ default:
+ throw new IllegalArgumentException("d3dFormat must be one of the known formats");
+ }
+ return blocksize;
+ }
+
private int mipMapWidth(int map) {
int width = getWidth();
for (int i = 0; i < map; i++) {