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_INTEGER) which is understandable but I had to try it, as
glReadPixels doesn’t support
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.