How to use Threading.invokeOnOpenGLThread()

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use Threading.invokeOnOpenGLThread()

cubus
hi,

i am trying the following in my NEWT app:

1) create a new TextRenderer. this throws an exception (exception 1) but the TextRenderer gets created and does render correctly with the specified Font.

public void keyPressed(KeyEvent e) {
        Threading.invokeOnOpenGLThread(false, new Runnable() {
                public void run() {
                        textRenderer = new TextRenderer(font);
                }
        });
}


2) change the swap interval. this throws an exception (exception 2) and does not change the swap interval.

public void keyPressed(KeyEvent e) {
        Threading.invokeOnOpenGLThread(false, new Runnable() {
                public void run() {
                        isVSyncEnabled = !isVSyncEnabled;
                        gl.setSwapInterval(isVSyncEnabled ? 1 : 0);
                }
        });
}

i also tried to call GLContext.makeCurrent() in the run() method which result in
java.lang.RuntimeException: Waited 5000ms for: <17ce4e7, 982589>[count 1, qsz 0, owner <AWT-EventQueue-0>] - <main>


exception 1

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: AWT-EventQueue-0: No OpenGL context current on this thread
        at javax.media.opengl.GLContext.getCurrentGL(GLContext.java:397)
        at com.jogamp.opengl.util.awt.TextureRenderer.init(TextureRenderer.java:616)
        at com.jogamp.opengl.util.awt.TextureRenderer.<init>(TextureRenderer.java:136)
        at com.jogamp.opengl.util.awt.TextureRenderer.createAlphaOnlyRenderer(TextureRenderer.java:154)
        at com.jogamp.opengl.util.awt.TextRenderer$Manager.allocateBackingStore(TextRenderer.java:1149)
        at com.jogamp.opengl.util.packrect.RectanglePacker.getBackingStore(RectanglePacker.java:87)
        at com.jogamp.opengl.util.awt.TextRenderer.getBackingStore(TextRenderer.java:610)
        at com.jogamp.opengl.util.awt.TextRenderer.getGraphics2D(TextRenderer.java:627)
        at com.jogamp.opengl.util.awt.TextRenderer.getFontRenderContext(TextRenderer.java:361)


exception 2

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: AWT-EventQueue-0: This context is not current. Current context: null, this context WindowsOnscreenWGLContext [OpenGL 4.2, options 0x303, 4.2 (Compatibility profile, arb, ES2 compatible, FBO, hardware) - 4.2.0, this 0x1d04653, handle 0x20000, jogamp.opengl.gl4.GL4bcImpl@b8f82d,
         quirks: [NoDoubleBufferedBitmap],
        Drawable: WindowsOnscreenWGLDrawable[Realized true,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@21b220,
        Handle    0x3a011544,
        Surface   jogamp.newt.driver.windows.WindowDriver[Config WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 7, ARB-Choosen true,
        requested GLCaps[rgba 0x8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms: 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        chosen    GLCaps[wgl vid 0x7 arb: rgba 0x8/8/8/0, trans-rgba 0x0/0/0/0, accum-rgba 16/16/16/16, dp/st/ms: 24/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]]]
, NEWT-Screen[.windows_nil-1-s0, idx 0, refCount 1, 3840x1200, DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], NEWT-Display[.windows_nil-1, excl false, refCount 1, hasEDT true, edtRunning true, WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]]]]
, ParentWindow null
, ParentWindowHandle 0x0 (false)
, WindowHandle 0x1206d0
, SurfaceHandle 0x3a011544 (lockedExt window true, surface true)
, Pos 359/50 (auto false), size 1280x720
, Visible true, focus false
, Undecorated false (false)
, AlwaysOnTop false, Fullscreen false
, WrappedWindow null
, ChildWindows 0, SurfaceUpdatedListeners num 0 [], WindowListeners num 1 [com.jogamp.newt.opengl.GLWindow$2@3570b0, ], MouseListeners num 2 [main.Main@8a0d5d, jogamp.newt.driver.windows.WindowDriver$1@79717e, ], KeyListeners num 1 [main.Main@8a0d5d, ], windowLock <10a2d64, 12a3722>[count 2, qsz 0, owner <main>], surfaceLockCount 1]]]
        at javax.media.opengl.GLContext.validateCurrent(GLContext.java:425)
        at javax.media.opengl.GLContext.setSwapInterval(GLContext.java:930)
        at jogamp.opengl.gl4.GL4bcImpl.setSwapInterval(GL4bcImpl.java:34206)


what's the correct way to use Threading.invokeOnOpenGLThread() or is there another way to get this code executed on the GL thread except posting the Runnable to my own handler and execute it in GLEventListener.display()?
Reply | Threaded
Open this post in threaded view
|

Re: How to use Threading.invokeOnOpenGLThread()

gouessej
Administrator
Rather use GLDrawable.invoke(boolean, GLRunnable).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to use Threading.invokeOnOpenGLThread()

cubus
great that works, thank you very much!

is it enough to store the reference to the GLAutoDrawable only once in GLEventListener.init(GLAutoDrawable) or should i store it in every call to reshape() and/or display() too?
Reply | Threaded
Open this post in threaded view
|

Re: How to use Threading.invokeOnOpenGLThread()

gouessej
Administrator
GLWindow implements the interface GLAutoDrawable so just call myGLWindow.invoke(boolean, GLRunnable), don't store the GLAutoDrawable passed by init(). Never store GL instances, it is explained in the user's guide.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to use Threading.invokeOnOpenGLThread()

cubus
thanks a lot!!