Reading from and Writing to renderbuffers

Dear all,


Now my questions are:

  1. How should I read from and write to the color renderbuffer (although the latter is not required for picking… just wondering)? Do I need to make any API calls besides glReadPixels and glDrawPixels (like setting glReadBuffer and glDrawBuffer, etc.)? Please be as specific as you can.

  2. Besides, in case the FBO is not active anymore (the backbuffer is set as the active framebuffer for instance), should I re-bind the FBO every time I need to read from these renderbuffers? Can’t I just rebind the renderbuffer itself (via glBindRenderbuffer( GL_RENDERBUFFER, 0 )) and be done with it?

Many thanks.

Hi Ashkan,



Hi scratt,

Thanks for your help.


As for choosing textures over renderbuffers, I’m not sure if that’s going to improve performance. If I’m not mistaken, glReadPixels and glDrawPixels go through a plethora of unnecessary transformations which makes them quite slow (not to mention the fact that read-backs are slow in nature due to GPU-CPU synchronization issues they cause), so that’s a minus for glReadPixels and renderbuffers, but the problem with textures is that glGetTexImage doesn’t allow read-backs of sub-regions. All I need is the value of a single pixel. Considering that this texture must be the size of the window, which can be quite large at times, downloading millions of pixels is a hefty price to pay. I think using glReadPixels would result in better performance.


Any more ideas?


glTexSubImage2D is used for submitting texels to a sub-region of a mip level of a texture. In other words, it’s used for uploading texels to the card not reading it back. Am I missing something?

The 1x1 texture trick you mentioned is something I hadn’t thought of. Very nice indeed. Thanks man.

Uh, sorry, I don’t know what I was thinking when I suggested to use glTexSubImage2D :slight_smile: Ignore that part.