Pbuffers best way to render offscreen?

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

Pbuffers best way to render offscreen?

kitfox
I have an app that is running pretty well in a JGLPanel.  I'd like to create some renderings of it from different camera angles and write them to disk as images (without affecting what is being shown in the viewport).

The docs I've found say that pbuffers are the way to go, and I used something similar back in JOGL 1.1.1.  However, I also vaguely recall something about pbuffers being deprecated, or about them being MS Windows specific.

Are pbuffers still the best way to render to an image, or is there a new way now?
Reply | Threaded
Open this post in threaded view
|

Re: Pbuffers best way to render offscreen?

Demoscene Passivist
Administrator
State of the art for offscreen rendering is now the "Framebuffer Object" (FBO). If u have no backward compatiblity issues with legacy hardware definitly go FBO.

For an example on how to setup and use FBO's in JOGL2 u may take a look here: BaseFrameBufferObjectRendererExecutor.java
Reply | Threaded
Open this post in threaded view
|

Re: Pbuffers best way to render offscreen?

kitfox
I've used FBOs before.  I still need to know how to create a second OpenGL context, though, to be able to use FBOs.  The way my program is designed, it would be an ugly hack to reach over to the window doing the rendering and ask it to render one frame with completely different settings.
Reply | Threaded
Open this post in threaded view
|

Re: Pbuffers best way to render offscreen?

Sven Gothel
Administrator
In reply to this post by Demoscene Passivist
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