Texture compression

I have a scene with some really hige textures. Is it possible to have JOGL store these in compressed format internally on the 3D card?

*Huge, not hige… :slight_smile:

Yes, is it possible because it’s in OpenGL and Jogl is a nice OpenGL binding. I’ve found some nice infos on the OpenGL compression on Nvidia’s OpenGL dev site.

First, find out at runtime (!) if the 3d card supports texture compression at all:[quote]
boolean compSupport = gl.isExtensionAvailable(“GL_ARB_texture_compression”)
[/quote]
Then, at texture bind time, use something like this small code fragment:[quote]
int tmpids[] = new int[1];
int picformat, internformat;

picformat = GL.GL_RGBA; // or GL.GL_RGB;
if (compSupport)
internformat = GL.GL_COMPRESSED_RGBA_ARB; // or GL.GL_COMPRESSED_RGB_ARB;
else
internformat = picformat;

gl.glGenTextures(1, tmpids);
texturobjectId = tmpids[0];

gl.glBindTexture(GL.GL_TEXTURE_2D, texturobjektId);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, internformat, textureWidth, textureHeight, 0, picformat, GL.GL_UNSIGNED_BYTE, yourPictureBytearray);
[/quote]
Later on, you can ask the 3d card if and how it did compress your texture:[quote]
gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_COMPRESSED, tmpids);
boolean isCompressed = tmpids[0] > 0;

gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_INTERNAL_FORMAT, tmpids);
int kompressedFormat = tmpids[0];

gl.glGetTexLevelParameteriv(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_COMPRESSED_IMAGE_SIZE, tmpids);
int kompressedSize = tmpids[0];
[/quote]
The actual compressing format depends on the 3d card’s + driver’s implementation. Some recent Jogl versions knew these values:
06407: “GL_RGB”
06408: “GL_RGBA”
33776: “GL_COMPRESSED_RGB_S3TC_DXT1_EXT”
33777: “GL_COMPRESSED_RGBA_S3TC_DXT1_EXT”
33778: “GL_COMPRESSED_RGBA_S3TC_DXT3_EXT”
33779: “GL_COMPRESSED_RGBA_S3TC_DXT5_EXT”

It did work for me some time ago.
Corrections and/or additions welcome.

Very nice! :smiley:

I will let you know how it goes once I get some transparency problem sorted out here… :slight_smile: