Posted by
Sven Gothel on
Oct 24, 2012; 10:40am
URL: https://forum.jogamp.org/querying-textures-bound-to-default-draw-read-framebuffers-tp4026564p4026596.html
On 10/24/2012 04:47 AM, ac [via jogamp] wrote:
> Thanks. I'm trying to get the contents of the texture used as the sink of the
> MSAA rendering, but still having some issues (for example, rendering the
> texture results in garbage). My final goal consists in grabbing the contents
> of the screen at a specific time, and applying a post-processing shader to it.
>
> The following is a simplified snippet of the display() function in my
> GLEventListener:
> Do you see anything drastically wrong here?
Why don't you simply use the FRONT texture/FBO after rendering
content and sync the FBO ?
Again, the BACK of an MSAA FBO only has a
multisampled [unusable] colorbuffer not a texture
and cannot be used (due to the OpenGL framebuffer spec).
After sampling w/ syncSamplingSink() you can use the FRONT texture.
Also be aware that the GLFBOAutoDrawable's intent is to handle swap-buffer
and hence deliver the final image. Ofc you can circumvent this by disabling
auto-swap buffer. Below I mention a manual swap-buffer step.
It would be more clear if you can produce a small complete unit test
stating your goals.
There is for example a unit test which mixes 2 GLFBODrawable's:
TestFBOMix2DemosES2NEWT/FBOMix2DemosES2.
The 'inner' offscreen mix source drawables are FBObject and could be
GLFBODrawables ofc. The outer drawable is an auto drawable (FBO or onscreen, doesn't matter).
However .. I try to comment a bit on your code snippet,
maybe it helps:
> public void display(GLAutoDrawable drawable) {
> GLCanvas canvas = (GLCanvas)drawable;
> GLContext context = drawable.getContext();
> GL gl = context.getGL();
>
> // Obtain the texture used a MSAA sink:
> GLFBODrawable fboDrawable = (GLFBODrawable)canvas.getDelegatedDrawable();
> FBObject backFbo = fboDrawable.getFBObject(GL.GL_BACK);
backFbo is the sampling sink, you want FRONT !
Note, FRONT is the last frame's content !
> FBObject.TextureAttachment texAttach = fboBack.getSamplingSink();
>
> // Draw geometry... *
>
> fboBack.syncSamplingSink(gl);
> fboBack.bind(gl);
>
> // Now texAttach should be up-to-date with the geometry rendered in (*)
>
> ...
If you don't want to use the last frames content (see snippet below),
but this frames .. you simply need to swap 'one more time'
which also will sample the content.
This is only required if both rendering contents shall be sampled,
otherwise I would use another drawable target!
public void display(GLAutoDrawable drawable) {
GLContext context = drawable.getContext();
GL gl = context.getGL();
// Draw some stuff 1
// This will do the BACK -> FRONT swap
// including MSAA sampling (sync).
// Now we can use the FRONT buffer.
drawable.swapBuffer();
// Obtain the texture used a MSAA sink:
// getDelegatedDrawable() is specified in GLAutoDrawable!
final GLFBODrawable fboDrawable = (GLFBODrawable)drawable.getDelegatedDrawable();
final TextureAttachment texAttach = fboDrawable.getTextureBuffer (GL.GL_FRONT);
gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit); // DO THAT IF USING MULTI TEX UNITS ..
gl.glBindTexture(GL.GL_TEXTURE_2D, texAttach.getName()); // use it ..
gl.glEnable(GL.GL_TEXTURE_2D); // if not using ES2 or GLSL!!
// now texUnit / texAttach is being used for texturing
// use prev. frame texture ..
// Draw some stuff 2
}
The swapBuffer() will be issued within the current context
and (w/ _latest_ JOGL code) will not issue a recursive call w/ GLDrawableHelper
but use a direct call of the drawable.swapBuffer().
+++
Let's try a simple use case, where you want to reuse
the FRONT buffer of the prev. frame while rendering the current frame.
This way you could to some motion blur or whatever ..
It is important to understand the 'timing' detail,
i.e. front/back buffers and when what get synced/swapped!
public void display(GLAutoDrawable drawable) {
GLContext context = drawable.getContext();
GL gl = context.getGL();
// Draw some stuff 1
// Obtain the texture used a MSAA sink:
// getDelegatedDrawable() is specified in GLAutoDrawable!
final GLFBODrawable fboDrawable = (GLFBODrawable)drawable.getDelegatedDrawable();
final TextureAttachment texAttach = fboDrawable.getTextureBuffer (GL.GL_FRONT);
gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit); // DO THAT IF USING MULTI TEX UNITS ..
gl.glBindTexture(GL.GL_TEXTURE_2D, texAttach.getName()); // use it ..
gl.glEnable(GL.GL_TEXTURE_2D); // if not using ES2 or GLSL!!
// now texUnit / texAttach is being used for texturing
// use prev. frame texture ..
// Draw some stuff 2
}
+++
Hope this helps a bit.
~Sven