Reading back an integer texture (texture_integer)


I want to read back a texture from the GPU and I’m using glGetTexImage for that. While I managed to get it to work for floating-point textures GL_RGBA32F_ARB, I have quite some difficulties reading back an integer GL_RGBA32UI_EXT texture.

Here’s the test case I’m using:

  • initialization

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, width, height, 0, GL_RGB, GL_FLOAT, 0);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI_EXT, width, height, 0, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT, 0);

  • attach the texture to the FBO

  • just clear the screen with some color
    glClearColorIuiEXT(1, 2, 3, 4);

  • read back
    GLuint *arr = new GLuint[width * height * 4];
    for (int i = 0; i < width * height * 4; i++)
    arr[i] = 3;
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT, arr);

for the floating-point case - all values of arr are 0’s
for the unsigned int one - all values remain 3

So, glGetTexImage doesn’t change the array at all :stuck_out_tongue:

The extension is reported to be supported:
glewGetExtension(“GL_EXT_texture_integer”) return GL_TRUE

Would appreciate any help!


Getting any errors?

On a quick scan I didn’t see anything in the spec about GetTexImage. You’d normally see dedicated entrypoints or a section beginning with something like, “Accepted by the XXX of YYY”, with a list of valid enums to use with this existing function or that.

Maybe I missed something.

The spec is broken.

Actually, I do get an error when using glGetTexImage() with the integer texture - invalid operation.
The glGetTexImage spec says this means that it is executed in a glBegin/glEnd block, but this is not the case. And with the float texture, I don’t get any errors.

Does this mean I cannot use glGetTexImage with GL_RGBA32UI textures? If so, is there any other way I can read back the texture?

Also, what does the spec is broken mean? It actually should or shouldn’t support glGetTexImage?


With the help of some people on the IRC channel, we found where the problem was:

GL_RGBA should be replaced by GL_RGBA_INTEGER_EXT

This is not documented in the spec for glGetTexImage(), but for glReadPixels(), so one has to extrapolate from there :slight_smile:

Thanks for the help!

If you have to extrapolate, the spec is broken. The purpose of the spec is so driver writers and application writers have a defined API and behavior to work with.