Hi Hank,

Any solution that assumes OpenGL is the native rendering library is not something that we would consider including in JavaFX. We use DirectX to render on Windows, and don't build or ship the OpenGL pipeline on Windows (there are issues on various graphics adapters, and it isn't a focus of graphics vendors on Windows). Also, Apple has deprecated OpenGL on Mac and we will be moving to Metal in the not-to-distant future.

Even if we could assume a particular native rendering library, I don't believe that using the same graphics context for applications that JavaFX Prism uses internally is the right approach (even with saving / restoring the context).

I would instead recommend that you look at using the new NIO Buffer-based PixelBuffer [1] API added in JavaFX 13. It can be used to implement a less-tight coupling of a native graphics library with JavaFX without having to have any knowledge of what JavaFX is using as its renderer, or hooks into the JavaFX internals.

We could consider additional follow-on improvements to PixelBuffer as long as they could be done without assuming a particular native rendering library, and without having to rely on internal implementation details of Prism.

-- Kevin

[1] https://openjfx.io/javadoc/14/javafx.graphics/javafx/scene/image/PixelBuffer.html

On 5/6/2020 3:53 AM, Hall Hank wrote:
Hi everyone.

I'm pretty new to this mailing list so, i hope i write my email as you expect.
I'm working on integration between OpenGL and JavaFX, and i was not really 
satisfied by the different library that i found on the internet. That is why, i 
started my own implementation by extending NGRegion (yes, it's private 🙂).

Here is my idea :
In the NGRegion, we are able to manage the OpenGL context created by JavaFX.
With LWJGL, it's then pretty easy to start to draw everything we want, by 
sharing this context. The only thing that we MUST be careful is the opengl 
context state. We must first save the states, draw what we want, and then 
restore the previous states.
In this way, JavaFX don't really know that we drew something with his own 
context.
This implementation is approximately the same approcah as FXGL, but without 
GLFW and hidden window and without creating a new OpenGL context.

I created a really small simple exemple that i would share with you. It's not 
production ready because i saved only the minimal states but this works really 
well for the hello world.
In this example, i just draw a green square, just by clearing the color. (no 
use of glDraw here, but of course it's possible)
I also did some advanced things with this approach, but saving/restoring a lot 
of states in some advanced JavaFX layout, and really it works great with very 
good performance.

You will find my little Main.java with few line of code to illustrate the 
principe. If you want to launch this example you just need the lwjgl 
dependencies that you can download from their website.
This example use Java 8, because i used to use it and i didn't want to have 
some problem due to Java 9 modules.

Now, my question is : would it be possible to include something like this in 
openjfx if we make it production ready ?
The interop between JavaFX & OpenGL is a recurrent question, and i think that 
it would be great to have a really easy solution like this directly in JavaFX.

I'm really interested about your feelings.

Thank you for reading.
Best regards.

Hank.



Reply via email to