Hello Guest

Saving compressed textures

  • 1 Replies

Offline exp_function

  • *
  • 1
  • Queen
Saving compressed textures
« on: June 30, 2020, 23:18:53 »
I'm trying to get the compressed pixels using;
Code: [Select]
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?

Re: Saving compressed textures
« Reply #1 on: January 03, 2021, 18:25:49 »
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?
Code: [Select]
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);