husker-dev / openglfx

OpenGL node for JavaFX
Apache License 2.0
88 stars 12 forks source link

Use of GL3ES3 #38

Closed detsikas closed 1 year ago

detsikas commented 1 year ago

Hi. I was wondering, what it would take to use GL3ES3, In particular, I have a lot of OpenGL ES3, I tried to make changes to the library for using GL3ES3, but I have a problem with framebuffers an cannot render to and then read from a framebuffer.

Thank you, Nikos

husker-dev commented 1 year ago

Hi! I would like to ask you the following:

  1. Your OS name;
  2. Java and JavaFX version;
  3. OpenGL version from glGetIntegerv(GL_MAJOR_VERSION) and glGetIntegerv(GL_MINOR_VERSION);
  4. What GL library you are using (jogl or lwjgl).
detsikas commented 1 year ago

I am using

  1. Ubuntu 22.04, but I will also run the app on windows and MacOS
  2. openjdk 20 and JavaFX 20.0.1
  3. MAJOR 4, MINOR 6
  4. I am using JOGL
husker-dev commented 1 year ago

If you are planning to support MacOS, then it is better to use LWJGL, because with JOGL there is a problem (https://github.com/husker-dev/openglfx/issues/22) in initialization.


Regardeles to your issue - have you specified profile at the canvas creation?

OpenGLCanvas.create(LWJGL_MODULE, CORE_PROFILE)

Also, it would be better if you show part of your code

detsikas commented 1 year ago

Thank you for the warning. I will certainly consider it. I will share code, but I think I should first explain better what I did. First of all, I need an opengl canvas in a JavaFX gui and since there is non in JavaFX, I came across openglfx.

What I am doing is applying opengl filtering on images. There is no 3D rendering. When I use only one shader everything works perfect. When more shaders are needed, where one renders to a framebuffer which the next one uses as input, nothing is rendered.

All the opengl code works wihtout any changes when I render to a GLCanvas. The code also works on Android, without any changes.

But it does not work with openglfx. To begin with, in order to use OpenGL ES3, I did some modifications to the opengl fx (I believe the Apache license allows for that). My opengl knowledge is not too deep so I merely did changes of the form of text replacing GL with GL3ES3. It actually works to the extent that I have described.

To give another hint of what is different compared to GLCanvas and Android, when I create a texture and bind it to a framebuffer, the ids returned are numbers like 36, 40 etc, while in GLCanvas and Android I get ids like 1 and 2. This looks like an indication that something is different there.

I hope I described better. If any of there help you give me a hint as to what I have forgotten to port to GL3ES3 I will be happy.

Otherwise, I can share the openglfx modifications.

Best regards, Nikos

husker-dev commented 1 year ago

In your case, the modification to use GL3ES3 was unnecessary, since JOGL has a function that converts objects from one version of OpenGL to another:

gl2 = gl.getGL2();
gl3 = gl.getGL3();
// And probably there is something like this
gl3es2 = gl.getGL3ES3();

You can try to test the code independenly from openglfx, for example on pure lwjgl. It looks like it's not a problem with openglfx itself.

The difference in texture ids is not important, but I explain it below.


DETAILS In your case (Linux) openglfx will render into JavaFX frame using 'shared contexts'. It will bind the OpenGL context on which JavaFX renders the interface to your new context. This means that FBO can have consecutive id's. This gives a way to display custom opengl in javafx (what openglfx library does). If 20 FBO were created somewhere in the JavaFX context, then in your context the id of the first FBO will be 21. It doesn't matter for rendering itself, as the OpenGL spec says IDs can be random at all. Also, it does not affect the use of FBO.

detsikas commented 1 year ago

I reverted the changes and used openglfx as is and got GL3ES3 as you suggested, but still no change.

I would insist on the framebuffer index issue, not as an error, but as an indication that I am taking a different path to opengl when using openglfx as to the one when I am using jogl directly.

In any case, for now I will not pursue this problem any more.

I am very grateful for the help!

Best regards, Nikos

husker-dev commented 1 year ago

Universal is a mode that should not be used specifically. It is made as a fallback for cases when something goes wrong. It also has very very poor rendering performance. Again, I repeat - texture indexes do not affect the program.


Your problem is probably that you are using OpenGL commands on more than one render thread. This may explain your error even in Universal mode. With your commands in the wrong place, you interfere with the JavaFX rendering, and therefore it crashes.

Keep in mind that there are two OpenGL rendering threads (when you using Linux or MacOS):

  1. JavaFX thread Roughly speaking, it is everywhere
  2. OpenGLFX thread Inside openglfx events:
    • addOnRenderEvent
    • addOnReshapeEvent
    • addOnDisposeEvent
    • addOnInitEvent

This means that you must carefully watch in which thread you are calling commands.

If there is a need to change the thread, then you can use makeCurrent(). But be sure you have to return the context to the end of the openglfx event.

detsikas commented 1 year ago

Thank you for the response. I deleted my message because it was again about numbering and after reading your previous answer it became clear that numbers like 35, 36 etc, probably occur because JavaFX creates buffers too. If this is the reason, I will no longer investigate in that direction.

I am not doing anything related to threads nor am I creating new threads.

If I trace the code, all event code (renderEvent, reshapeEvent etc) is executed in QuantumRenderer-0 while the rest of the code in a JavaFXApplicationThread.

husker-dev commented 1 year ago

I will close this issue. If you have any questions, feel free to reopen it.