我无法使glGetTextureSubImage工作。另一方面,glGetTextureImage对我来说效果很好。
测试代码:
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)
我尝试了各种替代方案,但总是给出相同的错误,即使下载单个像素也是如此。还尝试了典型的解决方案,如 GL_UNPACK_ALIGNMENT=1 或我想出的所有 glTextureParameters,非常绝望。
GL_INVALID_OPERATION
是错误的错误代码。它应该是 GL_INVALID_VALUE
,因为您传入的depth
参数是 0。它应该是 1,因为您正在提取一个深度图层。