Login  Register

Re: Pbuffers best way to render offscreen?

Posted by Sven Gothel on Nov 21, 2011; 2:16am
URL: https://forum.jogamp.org/Pbuffers-best-way-to-render-offscreen-tp3523149p3523679.html

On Sunday, November 20, 2011 09:11:44 PM Demoscene Passivist [via jogamp] wrote:
>
> State of the art for offscreen rendering is now the "Framebuffer Object"
> (FBO). If u have now backward compatiblity issues with legacy hardware
> definitly go FBO.

FBO is specified in OpenGL, where pbuffers are specified at a lower layer,
eg EGL, GLX, WGL, ..

Technically it doesn't really make a difference today
and depends totally on your use case.

UC1 : Onscreen/Offscreen Agnostic Code [Path]
-----------------------------------------------
For example, if you don't need any onscreen rendering at all
and want to offload everything offscreen w/o any special code,
pbuffer might be easier for you .. especially how we handle it in JOGL/NEWT:
  caps.setOnscreen(false);

The above would be enough to create an offscreen drawable,
eg. directly via the drawable factory, via the GLPBuffer auto drawable, or NEWT.
We utilize this code path in a transparent way for OS X's offscreen JAWT CALAYER for example.

However, you can also create one or more GLContext bound to one FBO
and do with it whatever you like to.

http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java;hb=HEAD
http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java;hb=HEAD#l43

Both code paths (pbuffer/FBO) require almost the same handling of retrieving
the offscreen data from the OpenGL HOST memory to CPU memory, either via a texture, or readpixel (w/ or w/o PBO).


UC2 : Utilizing multiple [offscreen] buffer
---------------------------------------------

One pattern is called FBO MRT (multiple render target), where you write to multiple target buffer,
eg. from within your fragment program (fbo-mrt1.fp). A last render path may merge the data (fbo-mrt2.fp).

TestFBOMRTNEWT01 utilizes our FBObject utility class, aimed to make FBO usage a bit more convenient.

http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java;hb=HEAD
http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/fbo-mrt-1.fp;hb=HEAD
http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/fbo-mrt-2.fp;hb=HEAD

+++

Bottom line, both techniques can be considered stable today and it depends on your use case.
Since FBO is part of the OpenGL specification, it might be the better choice - if possible and convenient.

In respect to our automatic offscreen code path in JOGL and NEWT, we currently have no transparent FBO usage,
which actually should be analyzed a bit more thorough.

>
> For an example on how to setup and use FBO's in JOGL2 u may take a look
> here:
> https://github.com/demoscenepassivist/SocialCoding/blob/master/code_demos_jogamp/src/framework/base/BaseFrameBufferObjectRendererExecutor.java
> BaseFrameBufferObjectRendererExecutor.java

great example w/ 'unrolled code'.

~Sven