Exceedingly expensive glReadPixels operation on Mac

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Exceedingly expensive glReadPixels operation on Mac

karelknoes
This post was updated on .
On one particular MacBook Pro 6.1 (Geforce GT 330M, Mac OS X 10.6.8), the operation below takes about 0,02 milliseconds per pixel. For a 900 x 600 applet, that adds up to about 10 seconds. On another Mac and on several other pc's, this operation does however run smoothly.

gl.glReadPixels(0, 0, 1, 1, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, pickingZBuffer);

I'm hoping it rings some bells. Any pointers that can help to avoid this problem are very much appreciated :).

EDIT: There are by the way no exceptions or log messages to indicate something is awry.



Reply | Threaded
Open this post in threaded view
|

Re: Exceedingly expensive glReadPixels operation on Mac

gouessej
Administrator
Hi

glReadPixels is generally considered as very slow and it is even worse when mixing it with shaders. Sometimes it is completely emulated in software, it depends on the driver. Actually, even the official OpenGL FAQ discourages the use of OpenGL picking.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Exceedingly expensive glReadPixels operation on Mac

karelknoes
A work around I discoved: first store the depth information as a texture and then read out the texture.

FloatBuffer pickingZBuffer = Buffers.newDirectFloatBuffer(canvasWidth * canvasHeight);
int depthTexture = 0;

gl.glBindTexture(GL2.GL_TEXTURE_2D, depthTexture);
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_DEPTH_COMPONENT, canvasWidth, canvasHeight, 0,
    GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, null);
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, canvasWidth, canvasHeight);
gl.glGetTexImage(GL2.GL_TEXTURE_2D, 0, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, pickingZBuffer);
Reply | Threaded
Open this post in threaded view
|

Re: Exceedingly expensive glReadPixels operation on Mac

karelknoes
A follow-up after hardware testing: Certain hardware captures only the top-left quarter of the depth buffer we're reading. Hence not a perfect solution either.