How to get raw (non-converted) texture data in OpenGL?

I need to serialize an arbitrary OpenGL texture object in order to subsequently restore it using the same state and data.

I am looking for a way to get texture image data. Here is what I have found so far:

  • There is glGetTexImage .

    It allows you to get a texture image, but this requires a specified form / type pair (for example ( GL_RGB , GL_HALF_FLOAT )), to which it performs the conversion.

    Allowed formats and types do not display the 1: 1 format in image formats and will not allow for more obscure formats such as GL_R3_G3_B2 without additional conversion.

    Also, the correct definition of type C for basic internal formats (for example, GL_RGB without size) implies some nontrivial work.

  • Here's ARB_internalformat_query2 , which allows you to query GL_GET_TEXTURE_IMAGE_FORMAT and GL_GET_TEXTURE_IMAGE_TYPE , which represent the best choice for glGetTexImage for a given texture.

    Nice, but has the same limitations as glGetTexImage , and is not widely available.

  • There is a wonderful glGetCompressedTexImage that elegantly returns compressed texture data as is, but it does not work for uncompressed images and does not have an analogue to be.

None of them allow you to get or set raw data for uncompressed textures. Is there any way?

+6
source share
1 answer

The trick is to find format matches and enter the result of the correct data layout.

Allowed formats and types do not display the 1: 1 format in image formats, and will not allow more obscure formats, such as GL_R3_G3_B2, without additional conversion.

It will be GL_RGB, GL_UNSIGNED_BYTE_3_3_2

Also, the correct definition of type C for basic internal formats (for example, GL_RGB without size) implies some nontrivial work.

Yes Yes. * put on sunglasses * Deal with this !;)

As for the internal format. Hereby refers to

 glGetTexLevelParameter(GL_TEXTURE_…, …, GL_TEXTURE_INTERNAL_FORMAT,…); glGetTexLevelParameter(GL_TEXTURE_…, …, GL_TEXTURE_{RED,GREEN,BLUE,ALPHA,DEPTH}_TYPE, …); glGetTexLevelParameter(GL_TEXTURE_…, …, GL_TEXTURE_{RED,GREEN,BLUE,ALPHA,DEPTH}_SIZE, …); 
+2
source

All Articles