husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

Will multithreading synchronization cause Javafx to get stuck? #54

Closed qq1053831109 closed 7 months ago

qq1053831109 commented 7 months ago

Is there a wait timeout for multithreaded rendering? If the timeout exceeds 30ms, the current frame will be discarded directly. This ensures that Javafx is running the process. The opengl thread may be loading a weight model or initializing a scene, etc. The main solution of multithreading is that getting stuck in Opengl will not cause Javafx to get stuck.

qq1053831109 commented 7 months ago

I often get stuck while working on the game editor Opengl. I hope that at this point, Javafx won't get stuck to play the loaded animation

qq1053831109 commented 7 months ago

点击在独立游戏中测试

qq1053831109 commented 7 months ago

image

husker-dev commented 7 months ago

Asynchronous rendering is performed entirely on a separate thread. When the frame is ready, it asks JavaFX to display it. This operation can only affect UI performance if you are using Windows and your video card does not support NVDX_interop. There are no restrictions on frame time. When testing, I deliberately stopped the render thread for a few seconds, and it did not interfere with the main thread.

qq1053831109 commented 7 months ago

ok i am update to 4.0. it has a lot change。

qq1053831109 commented 7 months ago

PassthroughShader parallelContext resultContext?Seems a bit troublesome? Are you sure this is the best solution? Is it not possible to switch between two FBOs in one context?

qq1053831109 commented 7 months ago

private change to protected 。we need hook by extends

husker-dev commented 7 months ago

I'm sure this is not the best solution. But it's working for now.

Let's figure it out:


What I do:

Rendering thread steps looks like this:

  1. *rendering*
  2. Blit rendered data to temporary texture.
  3. *signals to JavaFX to redraw*

JavaFX steps:

  1. *gets signal from rendering thread*
  2. Switching to proxy GL context
  3. Copy temporary texture data to JavaFX texture using PassthroughShader
  4. Switching back to JavaFX context
  5. Render texture

A little later I will remake this mechanism into something lighter and smaller.

qq1053831109 commented 7 months ago

ok,I haven't thought of a better plan yet