I'm unable to make glGetTextureSubImage work. On the other hand, glGetTextureImage works fine for me.
Test code:
const unsigned int sizeX=16;
const unsigned int sizeY=16;
// Init texture.
unsigned int texId;
glCreateTextures (GL_TEXTURE_2D, 1, &texId);
if (texId == 0)
return false;
glTextureStorage2D (texId, 1, GL_RGBA8, sizeX, sizeY);
CheckGlError ("glTextureStorage Error: "); // OK
// Create simple image.
unsigned int bufSize = sizeX * sizeY * 4;
unsigned char *buffer = new unsigned char [bufSize];
// fill buffer with anything...
// Upload image to texture.
glTextureSubImage2D (texId, 0, 0,0, sizeX,sizeY, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
CheckGlError ("glTextureSubImage Error: "); // OK
// Test downloads.
glGetTextureImage (texId, 0, GL_RGBA, GL_UNSIGNED_BYTE, bufSize, buffer);
CheckGlError ("glGetTextureImage Error: "); // OK
glGetTextureSubImage (texId, 0, 0,0,0, sizeX,sizeY,0, GL_RGBA, GL_UNSIGNED_BYTE, bufSize, buffer);
CheckGlError ("glGetTextureSubImage Error: "); // 0x502 (INVALID OPERATION)
I have tried all kinds of alternatives and always gives the same error, even to download a single pixel. Also tried typical solutions like GL_UNPACK_ALIGNMENT=1 or all the glTextureParameters that I have come up with, quite desperate.
GL_INVALID_OPERATION
is the wrong error code. It should be GL_INVALID_VALUE
, because the depth
parameter you passed in was 0. It should be 1, since you're extracting one depth layer.