glReadPixels and glCopyTexSubImage2D return partial results

I’m working on a very old application which was originally developed for the Mac and I ported to Windows. The application does some work with images in OpenGL then saves the result. I get good results on AMD cards, but on GeForce cards the results are sometimes very wrong (this depends on the system).

I traced this to some accumulation code which used glReadPixels and did accumulation on the CPU side. Saving the result of glReadPixels I saw that only part of the image was written to the buffer. This is often the top part, but sometimes several rows at the top are written, then some aren’t, then the bottom is written.

I decided to change the code to copy the viewport to a texture using glCopyTexSubimage2D, and then do the accumulation on the GPU side. Again this works well on AMD but shows the same problems on the NVIDIA system I tried it on.

Has anyone encountered this problem? Am I doing something wrong or is it that so few people use these functions that they just aren’t tested and don’t work?

I will try to revise the system to draw directly to a texture instead of the viewport and see if that works. It’s a complex application but I think I can hack this. I’d still appreciate a response about this problem.

Do the read regions pass the pixelownership test? That is, is there any overlapping region where the pixel data is undefined (implementation dependent behavior)?
Then changing your rendering target to be an FBO resp. texture attachment is the recommended method. It will always be unclipped and the only reliable solution to pass the pixelownership test independently of the window clipping situation.

Thanks. The region read is from a pbuffer (sorry, forgot to mention that), so I don’t think it should suffer from pixel ownership issues. Correct me if I’m wrong.

Anyway, I rewrote the code to use an FBO, and now I have a different problem. I’m creating a new post for that.

Correct, P-Buffer contexts shouldn’t fail the pixel-ownership test either, but they are more of a legacy feature and have the additional complication of reading from a separate context. That is, P-Buffers aren’t recommended anymore after FBOs went mainstream.