diff options
author | Kenneth Russel <[email protected]> | 2007-09-04 02:35:52 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-09-04 02:35:52 +0000 |
commit | 6cead503317fa6e771b371bfb4dd381472b60113 (patch) | |
tree | 7343627d103c91f577069b8fd1c866e1aeb5750e /src/classes/com/sun/opengl/util/texture/spi/DDSImage.java | |
parent | fb452d0124202c707d3dac9488a5c97233dc7635 (diff) |
Added support for loading non-mipmapped, non-power-of-two compressed
textures on pre-OpenGL 2.0 hardware by first loading an "empty"
compressed texture and then updating a sub-rectangle of its image.
Straightforward port of this code to the mipmapped case did not work;
added error checking for this case and throwing of GLException. Bug
pointed out by Dave Collins from NASA World Wind Java project.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1354 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util/texture/spi/DDSImage.java')
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/spi/DDSImage.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/classes/com/sun/opengl/util/texture/spi/DDSImage.java b/src/classes/com/sun/opengl/util/texture/spi/DDSImage.java index 52dbc25b1..835025b5c 100755 --- a/src/classes/com/sun/opengl/util/texture/spi/DDSImage.java +++ b/src/classes/com/sun/opengl/util/texture/spi/DDSImage.java @@ -43,6 +43,9 @@ import java.io.*; import java.nio.*; import java.nio.channels.*; +import javax.media.opengl.*; +import com.sun.opengl.util.*; + /** A reader and writer for DirectDraw Surface (.dds) files, which are used to describe textures. These files can contain multiple mipmap levels in one file. This class is currently minimal and does not @@ -469,6 +472,39 @@ public class DDSImage { return buf.toString(); } + /** Allocates a temporary, empty ByteBuffer suitable for use in a + call to glCompressedTexImage2D. This is used by the Texture + class to expand non-power-of-two DDS compressed textures to + power-of-two sizes on hardware not supporting OpenGL 2.0 and the + NPOT texture extension. The specified OpenGL internal format + must be one of GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT. + */ + public static ByteBuffer allocateBlankBuffer(int width, + int height, + int openGLInternalFormat) { + int size = width * height; + switch (openGLInternalFormat) { + case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + size /= 2; + break; + + case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + break; + + default: + throw new IllegalArgumentException("Illegal OpenGL texture internal format " + + openGLInternalFormat); + } + if (size == 0) + size = 1; + return BufferUtil.newByteBuffer(size); + } + public void debugPrint() { PrintStream tty = System.err; tty.println("Compressed texture: " + isCompressed()); |