Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8114426

Prism/ES2: FX application with multiple stages throws GLException on Windows

    XMLWordPrintable

    Details

      Description

      To reproduce the issue just run any sample with multiple FX stages (for example, HelloAlert, HelloModality).

      The stack trace of the exception:

           [java] com.sun.prism.opengl.GLException: Context not current on current thread
           [java] at com.sun.prism.opengl.impl.GLContextImpl.release(GLContextImpl.java:190)
           [java] at com.sun.prism.opengl.impl.windows.wgl.WindowsExternalWGLContext.release(WindowsExternalWGLContext.java:101)
           [java] at com.sun.prism.es2.ES2Context$State.releaseCurrentContext(ES2Context.java:432)
           [java] at com.sun.prism.es2.ES2Context.makeCurrentState(ES2Context.java:75)
           [java] at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:136)
           [java] at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:113)
           [java] at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:36)
           [java] at com.sun.prism.impl.ps.BaseShaderContext.setRenderTarget(BaseShaderContext.java:625)
           [java] at com.sun.prism.impl.BaseContext.setRenderTarget(BaseContext.java:67)
           [java] at com.sun.prism.impl.BaseGraphics.<init>(BaseGraphics.java:81)
           [java] at com.sun.prism.impl.ps.BaseShaderGraphics.<init>(BaseShaderGraphics.java:44)
           [java] at com.sun.prism.es2.ES2Graphics.<init>(ES2Graphics.java:19)
           [java] at com.sun.prism.es2.ES2Graphics.create(ES2Graphics.java:33)
           [java] at com.sun.prism.es2.ES2SwapChain.createGraphics(ES2SwapChain.java:153)
           [java] at com.sun.prism.es2.ES2SwapChain.createGraphics(ES2SwapChain.java:21)
           [java] at com.sun.javafx.tk.quantum.PaintRunnable.run(PaintRunnable.java:233)
           [java] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
           [java] at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
           [java] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
           [java] at com.sun.prism.render.RenderJob.run(RenderJob.java:29)
           [java] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
           [java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
           [java] at com.sun.javafx.tk.quantum.QuantumRenderer$ObservedRunnable.run(QuantumRenderer.java:70)
           [java] at java.lang.Thread.run(Thread.java:619)

      The root cause of the issue seems to be inconsistency between managing OpenGL rendering contexts on Mac and managing contexts on Windows.

      In Prism/ES2 we maintain "external" GLContext instances: external GLContext instance is created for each native OpenGL rendering context and it represents the existing native OpenGL rendering context created.
      (here's more info about the external JOGL contexts - runtime\prism-jogl\src\jogl\classes\com\sun\prism\opengl\GLDrawableFactory.java, GLDrawableFactory.createExternalGLContext).

      On Mac, Glass provides some API for managing the native OpenGL rendering contexts (and calls to makeCurrent/release on the corresponding external GLContext instances have no effect).

      The particular place (where Glass makes the native rendering contexts current or releases the context) is Pen.begin and Pen.end. On Windows, the implementation of the Pen.begin/end methods is no-op and the current native OpenGL rendering context never changes and this implicitly causes the GLException exception to be thrown.

      If we want to continue managing OpenGL rendering contexts from Quantum/Glass (like Quantum/Glass already does on Mac), it probably makes sense to implement the following items on Windows (to be consistent with Mac-implementation):

      1. move the creation of native OpenGL rendering contexts from Prism/ES2 to Glass

      in Prism/ES2 it's currently implemented here - prism-jogl\src\jogl\classes\com\sun\prism\opengl\impl\windows\wgl\WindowsWGLDrawableFactory.java, WindowsWGLDrawableFactory.createNativeGLContext

      2. provide implementation of the Pen.begin/end method (make native OpenGL rendering current/restore previous OpenGL native context).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dcherepanov Dmitry Cherepanov
              Reporter:
              dcherepanov Dmitry Cherepanov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: