PDA

View Full Version : Problem with glReadPixels from GL_BACK on FireGL only?



robosport
03-15-2006, 10:55 PM
I've been using the back-buffer picking technique from the Red Book for years. I draw a color value from a unique object ID into the back buffer and then use glReadPixels to get the single pixel from the mouse position from the back buffer to find the hit object .

I've recently run into three configurations where this doesn't work properly. When I say it doesn't work - my debugging is finding the values read are equal to those in the front buffer not the back buffer.

The cards giving me problems are the ATI FireGL v7100, ATI Mobility FireGL, and ATI Mobility M6. Works great on other Radeon cards and all NVIDIA cards.

I've confirmed the OpenGL context has a back buffer and all smooth and other effects are off during rendering and reading from the back buffer.

Does anybody have a clue how to fix this (without giving up pixel based selection) or have you heard of this problem before? Here is the code used:


glDrawBuffer( GL_BACK );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glDisable( GL_LIGHTING );
glDisable( GL_TEXTURE_2D );
glDisable( GL_MULTISAMPLE_ARB );
glDisable( GL_BLEND );
glShadeModel( GL_FLAT );
glEnable( GL_DEPTH_TEST );

DrawSelectionObjects();

glFlush();
glFinish(); // put here while tyring to debug problem

unsigned int pixelValue = 0;
glReadBuffer( GL_BACK );
glReadPixels( mouseX, flippedMouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelValue );Thanks in advance! robo

V-man
03-16-2006, 03:33 AM
glReadBuffer should be GL_BACK, but this is by default if you have double buffer. Same thing for glDrawBUffer.

I could suggest that you not use multisampling at all. Are those ATI cards able to disable it? Try to render to the front buffer to see.

On a very old Matrox card, I had to call glFinish else it would crash or return garbage.

Another thing to watch out for with this method is the alpha. You might want to just use the RGB part.

robosport
03-16-2006, 06:39 AM
Yes, I only set it to GL_BACK. Also I've swapped the buffer to confirm it is drawing the selection IDs correctly into the back buffer.

The problem is that:
glReadBuffer( GL_BACK );glReadPixels( mouseX, flippedMouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelValue );

is always returning the color values of the front buffer instead of back.

Any other thoughts?

sqrt[-1]
03-16-2006, 01:00 PM
I have had similar problems with ATI, but only when multi-sample was enabled (and I think only in windowed mode)

robosport
03-16-2006, 07:45 PM
Thanks for the feedback. Now that I know it wasn't just me I invested a little time to make an optional pbuffer to render the selection buffer to as a workaround to not being able to read from the back buffer.

[Update] It worked just fine from the pbuffer.

Thanks again!