Posted by
Sven Gothel on
Jan 29, 2013; 4:47pm
URL: https://forum.jogamp.org/glReadBuffer-behavior-on-MAC-tp4028039p4028045.html
On 01/29/2013 04:23 PM, stepasite [via jogamp] wrote:
> Hi Sven,
>
> thanks for the reply, I wasn't aware of getDefaultReadBuffer() method. Anyway,
> I always want to read data from front buffer (from the screen). Is it possible
> with FBO rendering enabled?
Of course - all our unit tests creating snapshots via UITestCase.SnapshotGLEventListener
read from the FBO buffer. However to select the buffer, you would need to have it bound.
Our GLFBODrawableImpl reads:
int getDefaultDrawFramebuffer() { return initialized ? fbos[fboIBack].getWriteFramebuffer() : 0; }
int getDefaultReadFramebuffer() { return initialized ? fbos[fboIFront].getReadFramebuffer() : 0; }
int getDefaultReadBuffer(GL gl) { return initialized ? fbos[fboIFront].getDefaultReadBuffer() : GL.GL_COLOR_ATTACHMENT0 ; }
Note-1: You cannot use the back buffer in MSAA mode!
Note-2: We separate front/back buffer via a full FBO object, not by the attachment.
Hence we always use GL.GL_COLOR_ATTACHMENT0 as the read buffer name.
Hence you would need to bind the right FBO name to select front/back.
FBOObject reads:
gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
This leads to:
gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, getDefaultDrawFramebuffer());
gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, getDefaultReadFramebuffer());
This results reading from the front buffer, and draw to the back buffer by default,
as recommended in the GL spec. The latter discourages you to read from the
current draw buffer.
>
> I think it should as:
>
> glCanvas.getChosenGLCapabilities().getDoubleBuffered();
>
> returns true when:
>
> glCanvas.getChosenGLCapabilities().isFBO();
>
> returns true.
You can use both queries, yes.
FBO doesn't necessarily imply double buffering, but w/ MSAA enabled.
However, since the default GLCaps has double buffering enabled ..
>
> But I am not sure whether GL_COLOR_ATTACHMENT0 is considered as front or back
> buffer (in the case that such terminology is meaningful with FBO rendering).
See Note-2 above - using [our] FBO, makes it easy to use the front buffer (default)
and hard to use the back buffer - since you need to either switch the FBO
or change the point in time you read the buffer.
You will notice that in our unit tests w/ UITestCase.SnapshotGLEventListener using ReadBufferUtil
we simply don't do anything but call glReadPixels .. hence using the complete front buffer.
Hope it helps.
>
>
> Thanks in advance,
> Pavel
>