I recently went to a lecture on the benefits of Parallelism in regards to tapping the power of multicore processors more efficiently for real time 3d graphics applications. This discussion was about C++ and TBB (Threading Building Blocks) (Intel). I have found out about Fork/Join in Java 7 but I would like to learn more about running realtime 3d graphics through OpenGL / JOGL.
I have heard that OpenGL/JOGL must exist in one thread. I do not know if this is true. If you have experience with Parallelism / Multicore programming in Java in regards to real time graphic applications and could point me towards some resources that would be fantastic.
Is JOGL restricted to one thread?
No, JOGL itself is not bound to one thread. Only AWT GLCanvas is. The latter is one of its GLAutoDrawable implementations. AWT GLCanvas is restricted due to AWT itself, where manipulation of native resources are required to run on the AWT EDT.
How to work with JOGL lock free?
To work 'almost' lock free, you can use NEWT.
NEWT allows you to render multiple windows from multiple threads,
while they don't block each other .. interfere, etc.
Also NEWT event handling will not interfere w/ rendering.
Example of multithreading use
Another example of multithreading use of OpenGL (w/ JOGL or not)
is to fill textures or other GL related resources from a dedicated
thread holding a shared offscreen OpenGL context [w/ the onscreen context].
The dedicated thread could signal the rendering loop available resources etc.
Have a look in our GLDrawableFactory were plenty of drawable factory
methods are public. Note: offscreen mode can be selected via the GLCapabilities.
You may like to browse through out unit tests in one of the
git repos
.
Pls check class 'TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT' and
shared OpenGL context tests include the name 'Shared'.
You can use:
- Pixel buffer or pBuffer is an extension to OpenGL which allows to do off-screen rendering
- Framebuffer Object or FBO
- Shared context (for different threads)
http://jogamp.org/git/?p=jogl.git;a=tree;f=src/test/com/jogamp/opengl/test/junit/jogl/offscreen;hb=HEAD
http://jogamp.org/git/?p=jogl.git;a=tree;f=src/test/com/jogamp/opengl/test/junit/jogl/demos/es2;hb=HEAD