Bugzilla – Bug 607
JavaFX 2+ and JOGL should work together
Last modified: 2014-01-14 17:55:56 CET
There is currently no way to integrate JOGL in a pure JavaFX 2+ GUI.
Swing is deprecated, and JavaFX is the new way to make GUIs in Java.
So this possibility would be useful:
- to take advantage of JavaFX
- and necessary on the long term
There are several technical aspects driving such an interoperability with JavaFX 2 almost impossible or very difficult to implement. I advise you to look at this document:
At first, I have found no way of forcing JavaFX to use its Java2D backend or in the best case its OpenGL backend. It means that there is a risk of conflict at driver level with Direct3D. I posted a question on the mailing list of JavaFX developers and they have never replied.
Then, I have to think about another way of supporting this technology. As you can see on the document, JavaFX uses its own equivalent of NEWT (Glass windowing toolkit) and its own scenegraph (Prism).
In my humble opinion, the support of JavaFX with hardware acceleration goes beyond the scope of any Java binding for the OpenGL API, it is rather a potential feature for an existing scenegraph supporting JOGL 2.0. Such a scenegraph would have to replace Prism and to allow you to use plain JOGL code in render delegates. Moreover, it would have to rely on NEWT and to modify Quantum so that it uses NEWT instead of Glass WT. Glass WT and NEWT may have some similarities.
To conclude, we can look at the source code of JavaFX (OpenJFX) to investigate deeper but this feature can only be implemented in Ardor3D with "my" renderer based on JOGL 2.0, it is none of JogAmp's concern.
(In reply to comment #1)
I see it's in the JavaFX roadmap (http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html) to add "3D Graphics Support", but I doubt they mean low level access to the hardware. On the bright side, their development might unlock access to their rendering pipeline, so that we can hook ourselves somehow.
Anyway, this isn't going to happen soon, so I'll just use Swing with applications that need OpenGL, and JavaFX with the others. I'll see whether JavaFX in Swing is practical or not.
Thanks for taking the time to investigate the issue :)
It seems possible to override com.sun.javafx.sg.prism.NGNode.render() in order to create an external drawable with GLDrawableFactory.createExternalGLDrawable() so that we can do whatever we want with the OpenGL context and render with JOGL 2.0. However, there is still no way to force JavaFX to use OpenGL under Windows. The suggested solution only works under Mac OS X and probably under GNU Linux (but it requires at least GLX 1.3).
I have no access to the source code of Quantum (com.sun.javafx.tk.quantum) and Glass. We have to force com.sun.javafx.sg.BaseNode or another class to create an overridden node and use it as a delegate.
Keep in mind that such an hacky solution could be broken by changes in JavaFX/OpenJFX. It would be safer to be able to override a node of the public API.
Someone succeeded in mixing JavaFX 2 with OpenGL under Mac here:
NGNode is abstract like BaseNode and I don't find its child classes.
I would like to know Sven's opinion about my reply here:
It is possible to force the use of OpenGL with "-Dprism.order=es2,es1" or force the use of Java2D with "-Dprism.order=j2d" but then Direct3D must be disabled in Java2D too.
Is there any downloadable source example of JOGL2 integration to JavaFX?
Thanks in advance,
(In reply to comment #7)
> Is there any downloadable source example of JOGL2 integration to JavaFX?
> Thanks in advance,
There is no such example working with JavaFX 2.0. "Deejay" published some source code on BitBucket. In theory, rendering a JavaFX widget in a FBO is possible. You can use JavaFX in a Swing application thanks to JFXPanel. However, there is no more fully JOGL-based backend unlike what was available for JavaFX 1 several years ago.
I don't want to spend any time on a hacky solution that could be broken by a change in an obscure private API and Oracle wants to keep JavaFX self-contained.
Keep in mind that mixing JavaFX with JOGL might drive your application unstable. Some developers had to use dirty kludges to make it possible. For example, JavaFX seems to cause troubles in AWT on some platforms.
I will invest some time in implementing this interoperability if and only if the JogAmp Foundation considers JavaFX to be really viable on the long term and if it is modularized enough to allow me not to rewrite everything.
There is one possibility that I have not yet tested: it is possible to force the use of the Java 2D backend in Prism and GLG2D allows to use JOGL 2.0 in Java 2D. It would probably be less slow than rendering JavaFX widgets in a FBO but less fast than a fully hardware accelerated pipeline. Feel free to contribute ;)
Thanks for the suggestions.
I could find Dejay's works here: https://bitbucket.org/dejayberlin/joglfxpipeline/
If I come with something helpfull, no worry I'll contribute :)
A member of Java-Gaming.org used our competitor to render JavaFX widgets in a FBO, maybe you could port his code to JOGL 2.0. It would probably work reliably and we could use GLOffscreenAutoDrawable to get something more viable on low end graphics cards.
I don't know whether the selected toolkit may influence the threading, it can be set with "-Djavafx.toolkit=", the default value is "glass", the others are:
The ES2 pipeline is not shipped by default with the JRE under Windows:
JavaFX users will have an hard time if they are to use the software renderer with JOGL 2.0 especially on low end machines.
Oracle will ease the interoperability with natives APIs, the implementation of a GLNode is planned:
Oracle seems to be aware of some blocking aspects.
An experimental API of JavaFX 8 allows to use a single thread for JavaFX and Swing, you can use -Djavafx.embed.singleThread=true to do that:
You can already use JavaFX in a Swing application thanks to JFXPanel but now you can use Swing in a JavaFX application thanks to SwingNode:
It allows to use existing JOGL Swing based UIs with JavaFX until we provide a better solution.
Christoph worked on JavaFX with JOGL too:
According to him, I have to put the JOGL pipeline for OpenJFX/JavaFX into com.sun.prism.jogl.JOGLPipeline and load it from the same classloader than jfxrt.jar to make it work, I have to set prism.order to "jogl" to respect the naming convention.
http://j661.sourceforge.net already uses JavaFX, Swing and JOGL. I have to look at EmbeddedWindowsManager.
As I said in the comment 13, Oracle employees are aware of the difficulties to use JavaFX with native APIs:
I'll have to decide how to implement this enhancement:
- just render the 3D scene into an offscreen FBO and put the result into a JavaFX node. Render a JavaFX node into an image and use it as an OpenGL texture as it is done in this project: http://tinyurl.com/n9naya8
- use Prism/Glass/Quantum to implement another thin pipeline
- get rid of Prism/Glass/Quantum, use NEWT, provide a completely alternative implementation of OpenJFX/JavaFX