Copying pixels from single channel uint attachment

Hi.

I was trying to implement mouse picking in a tool that I’m developing and got very confused when trying to read pixels from the framebuffer attachment.
What I’m doing is; every object in the scene has an id (uint32) associated with it and I write this id during rendering to a seperate texture which I create like this

 glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, 1280, 720, 0, GL_RED_INTEGER, UNSIGNED_INT, NULL);

Later I attach it to the framebuffer and everything works just fine, the ids are rendered as I’d expected (I view them in RenderDoc).
The problem is that glReadPixels doesn’t read anything

glReadPixels(0, 0, 1280, 720,  GL_RED, GL_UNSIGNED_INT, CachedHitMap.CachedTextureData);

and I suspect that it’s because of the mismatch in the format of pixel data (GL_RED vs GL_RED_INTEGER) which is understandable but I had to try it, as glReadPixels doesn’t support GL_RED_INTEGER).

So is there any way to read back values from an attachment configured like this?
I’m curious how RenderDoc does it, as it properly displays the texture in the viewer.

Yes, it does. What makes you think that it does not?

@Alfonse_Reinheart The official docs https://www.khronos.org/registry/OpenGL-Refpages/gl4/
(sorry for the dots, for some reason I can’t post links)

This is spam prevention for new user accounts. Keep using the forums and this ability will be automatically unlocked.

Unfortunately, the online reference pages aren’t always up to date. New functions tend to be added promptly, but extensions to the behaviour of existing functions are often overlooked. In particular, where a parameter is specified as accepting an enumerant (manifest constant), any list of accepted values won’t necessarily be exhaustive.

If you want a definitive answer, refer to the specification. Although it isn’t particularly easy to read.

In this case, the relevant language (§18.2.3) is

Most of the details regarding the format and type arguments, including allowed combinations for a given internal format, are covered in §8.4.4, “Transfer of Pixel Rectangles”.