Bug 607 - JavaFX 2+ and JOGL should work together
: JavaFX 2+ and JOGL should work together
Status: UNCONFIRMED
Product: Jogl
Classification: JogAmp_Core
Component: core
: 2
: All all
: P5 enhancement
Assigned To: Sven Gothel
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-20 00:06 CEST by Arnaud Couturier
Modified: 2014-01-14 17:55 CET (History)
4 users (show)

See Also:
Type: ---
SCM Refs:
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arnaud Couturier 2012-07-20 00:06:39 CEST
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
Comment 1 Julien Gouesse 2012-07-29 12:38:00 CEST
Hi

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:
http://docs.oracle.com/javafx/2/architecture/jfxpub-architecture.htm

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.
Comment 2 Arnaud Couturier 2012-08-03 03:23:24 CEST
(In reply to comment #1)
Understood.
Nice article.

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 :)
Comment 3 Julien Gouesse 2012-08-26 13:11:13 CEST
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:
http://www.java-gaming.org/topics/jogl-in-javafx/26881/msg/242906/view.html#msg242906
Comment 4 Julien Gouesse 2012-08-26 13:47:42 CEST
NGNode is abstract like BaseNode and I don't find its child classes.
Comment 5 Julien Gouesse 2013-02-22 13:31:47 CET
Hi

I would like to know Sven's opinion about my reply here:
http://www.java-gaming.org/topics/javafx-3d-api-and-opengl/28797/msg/262932/view.html#msg262932
Comment 6 Julien Gouesse 2013-03-14 10:50:06 CET
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.
Comment 7 Martin 2013-03-21 12:43:41 CET
Hi,
Is there any downloadable source example of JOGL2 integration to JavaFX?
Thanks in advance,
Martin
Comment 8 Julien Gouesse 2013-03-21 13:38:41 CET
(In reply to comment #7)
> Hi,
> Is there any downloadable source example of JOGL2 integration to JavaFX?
> Thanks in advance,
> Martin

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 ;)
Comment 9 Martin 2013-03-27 15:04:25 CET
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 :)
Comment 10 Julien Gouesse 2013-03-27 15:40:08 CET
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.
Comment 11 Julien Gouesse 2013-07-30 14:39:57 CEST
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:
com.sun.javafx.tk.DummyToolkit
com.sun.javafx.tk.prism.TVToolkit
com.sun.javafx.tk.prism.PrismToolkit
com.sun.javafx.tk.swing.SwingToolkit
com.sun.javafx.pgstub.StubToolkit
Comment 12 Julien Gouesse 2013-07-30 14:55:44 CEST
The ES2 pipeline is not shipped by default with the JRE under Windows:
https://forums.oracle.com/message/11016899#11016899

JavaFX users will have an hard time if they are to use the software renderer with JOGL 2.0 especially on low end machines.
Comment 13 Julien Gouesse 2013-12-19 14:04:46 CET
Oracle will ease the interoperability with natives APIs, the implementation of a GLNode is planned:
https://oracleus.activeevents.com/2013/connect/fileDownload/session/C3B800733D28DB105AB5FC964843D1AB/CON1905_Heidrich.pptx

Oracle seems to be aware of some blocking aspects.
Comment 14 Julien Gouesse 2013-12-19 16:31:29 CET
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:
http://stackoverflow.com/a/18675377

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:
http://download.java.net/jdk8/jfxdocs/javafx/embed/swing/SwingNode.html

It allows to use existing JOGL Swing based UIs with JavaFX until we provide a better solution.
Comment 15 Julien Gouesse 2014-01-14 17:27:01 CET
Christoph worked on JavaFX with JOGL too:
https://bitbucket.org/redrezo/prism-jogl-playground/src

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:
http://www.parleys.com/play/524ee4dbe4b0ab14e307d7b1

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