我无法使 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,非常绝望。
答案 0 :(得分:2)
GL_INVALID_OPERATION
是错误的错误代码。它应该是GL_INVALID_VALUE
,因为您传入的depth
参数是0.它应该是1,因为您正在提取一个深度图层。