Saving compressed textures

Started by exp_function, June 30, 2020, 23:18:53

Previous topic - Next topic

exp_function

Hi,
I'm trying to get the compressed pixels using;
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texBuff);
int comSiz =  glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE);
ByteBuffer comBuf = ByteBuffer.allocateDirect(comSiz);
byte[] comByt = new byte[comSiz];
glGetCompressedTexImage(GL_TEXTURE_2D, 0, comBuf);
comBuf.get(comByt, 0, comSiz);


but I can only read zero values from both comByt and comBuf buffers. What could be the reason for that?
Thanks.

Source_of_Truth

First of all, after writing data into the buffer, it is full. Ensure that the buffer is flipped or rewinded.

Anything else...   is hard to see from your limited example alone. For example if there was ever all call to 'glBindTexture(GL_TEXTURE_2D, id)'.
Assuming texBuff does indeed contain sensible data, my best guess is that your pixel-formats are incorrect. And taking a look at that, I must first raise the question why you are using 'GL_COMPRESSED_RGB_S3TC_DXT1_EXT'...

Is something like this not what you actually want for uploading the data?
var internalTextureFormat = useCompression ? ( hasAlpha ? GL_COMPRESSED_RGBA : GL_COMPRESSED_RGB ) :  ( hasAlpha ? GL_RGBA : GL_RGB );
var rawTexelDataFormat = hasAlpha ? GL_RGBA : GL_RGB ;
glTexImage2D(GL_TEXTURE_2D, 0, internalTextureFormat, width, height, 0, rawTexelDataFormat, GL_UNSIGNED_BYTE, texBuff);