diff options
author | Renanse <[email protected]> | 2013-01-04 21:51:51 -0600 |
---|---|---|
committer | Renanse <[email protected]> | 2013-01-04 21:51:51 -0600 |
commit | d0495e72b3c4f1161327183e3edbf8a850993584 (patch) | |
tree | 3786b6cd315ec0590b18a2f0514ace062df5a75c /ardor3d-jogl/src/main/java | |
parent | 8908ac9904c3acc8bd40b4c16b13d0934ca81ee5 (diff) |
Make better use of the AWT dispatch thread.
Diffstat (limited to 'ardor3d-jogl/src/main/java')
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java index 5c95cd8..df55d06 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java @@ -10,10 +10,14 @@ package com.ardor3d.framework.jogl; +import java.lang.reflect.InvocationTargetException; import java.util.concurrent.CountDownLatch; + import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLRunnable; import javax.media.opengl.awt.GLCanvas; +import javax.swing.SwingUtilities; + import com.ardor3d.annotation.MainThread; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.DisplaySettings; @@ -21,7 +25,7 @@ import com.ardor3d.framework.DisplaySettings; /** * FIXME there is still a deadlock when using several instances of this class in the same container, see JOGL bug 572 * Rather use JoglNewtAwtCanvas in this case. - * + * */ public class JoglAwtCanvas extends GLCanvas implements Canvas { @@ -31,7 +35,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { private boolean _inited = false; private final DisplaySettings _settings; - + private final JoglDrawerRunnable _drawerGLRunnable; public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { @@ -49,21 +53,38 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { @MainThread public void init() { - if (_inited) { + if (_inited) { return; } - - // Make the window visible to realize the OpenGL surface. - setVisible(true); - + + // Calling setVisible(true) on the GLCanvas not from the AWT-EDT can freeze the Intel GPU under Windows + if (!SwingUtilities.isEventDispatchThread()) { + try { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + // Make the window visible to realize the OpenGL surface. + setVisible(true); + } + }); + } catch (final InterruptedException ex) { + ex.printStackTrace(); + } catch (final InvocationTargetException ex) { + ex.printStackTrace(); + } + } else { + // Make the window visible to realize the OpenGL surface. + setVisible(true); + } + // Request the focus here as it cannot work when the window is not visible requestFocus(); - + _canvasRenderer.setContext(getContext()); - + invoke(true, new GLRunnable() { @Override - public boolean run(GLAutoDrawable glAutoDrawable) { + public boolean run(final GLAutoDrawable glAutoDrawable) { _canvasRenderer.init(_settings, true);// true - do swap in renderer. return true; } @@ -77,7 +98,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { } if (isShowing()) { - invoke(true, _drawerGLRunnable); + invoke(true, _drawerGLRunnable); } if (latch != null) { latch.countDown(); |