PDA

View Full Version : reading back compressed texture array.



alariq
10-16-2013, 03:45 AM
Hello I am loading set of textures and create texture array from them in compressed format. This works fine because I see my shaders are working.
But later I decided to use compressed data from the beginning, so I want to read my texture array back and write it to hdd, so I can later load it as compressed data.

I was trying to use glGetCompressedTexImage, but there is no GL_TEXTURE_2D_ARRAY allowed as "target" for this function (I do not see it in documentation), so I am not sure if I can use it at all?
Or should I create separate 2d textures and save them instead?

Just to try out something I did like this:



glBindTexture(GL_TEXTURE_2D_ARRAY, tex );

GLint csize, is_comp;
GLint lod = 0;
glGetTexLevelParameteriv( ptex->m_Type, lod, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &csize);
glGetTexLevelParameteriv( ptex->m_Type, lod, GL_TEXTURE_COMPRESSED, &is_comp);
assert(is_comp);
GLvoid* pdata = new unsigned char[csize];
glGetCompressedTexImage(GL_TEXTURE_2D_ARRAY, lod, pdata);
glBindTexture(GL_TEXTURE_2D_ARRAY, 0 );


But I have error "Invalid operation" after glGetCompressedTexImage.
Passing GL_TEXTURE_3D instead of GL_TEXTURE_2D_ARRAY to glGetCompressedTexImage also did not help :(

Any suggestions how that could be done?

Thanks

UPDATE: problem solved, it was me, who forgot to glBindTexture(GL_TEXTURE_2D_ARRAY, tex ) in actual code, but put it in this test code :-)
However I still cannot understand how it works, because there is no GL_TEXTURE_2D_ARRAY present in documentation for "target" of glGetCompressedTexImage

arekkusu
10-16-2013, 11:42 AM
What documentation are you looking at?


Starting with the GL3.0 spec it seems documented well enough:

The command
void GetCompressedTexImage(enum target, int lod, void *img );
is used to obtain texture images stored in compressed form. The parameters target, lod, and img are interpreted in the same manner as in GetTexImage.



The command
void GetTexImage(enum tex, int lod, enum format, enum type, void *img );
is used to obtain texture images. ... TEXTURE_1D, TEXTURE_2D,TEXTURE_3D, TEXTURE_1D_ARRAY, and TEXTURE_2D_ARRAY indicate ...

alariq
10-17-2013, 09:26 AM
arekkusu, you are right I noticed this also. But, at the same, time if you look at description of valid targets for glGetCompressedTexImage you'll see that TEXTURE_2D_ARRAY is not listed.
Moreover
"interpreted in the same manner" does not necessarily mean that same targets are allowed. So I think there is ambiguity.