diff options
author | Julien Gouesse <[email protected]> | 2013-03-03 18:31:15 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2013-03-03 18:31:15 +0100 |
commit | 49807120feb0c7bc22b5db5f4f6a43852e0bacbb (patch) | |
tree | 60e29019e6c758fccd1b04aef7bda0bf9945b657 /ardor3d-jogl/src/main/java | |
parent | e567b28dd5933b8f86604f8e3db2fc75592b62bb (diff) |
Fix for JoglNewtAwtCanvas
Diffstat (limited to 'ardor3d-jogl/src/main/java')
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java | 53 | ||||
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtInitializerRunnable.java | 42 |
2 files changed, 76 insertions, 19 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java index 8b2517a..dea1317 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java @@ -10,16 +10,17 @@ 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.swing.SwingUtilities; + import com.ardor3d.annotation.MainThread; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.DisplaySettings; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; - public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWindowContainer { private static final long serialVersionUID = 1L; @@ -28,12 +29,15 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind private boolean _inited = false; private final DisplaySettings _settings; - + private final JoglDrawerRunnable _drawerGLRunnable; + private final JoglNewtAwtInitializerRunnable _initializerRunnable; + public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { super(GLWindow.create(CapsUtil.getCapsForSettings(settings))); _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + _initializerRunnable = new JoglNewtAwtInitializerRunnable(this, settings); getNewtWindow().setUndecorated(true); _settings = settings; _canvasRenderer = canvasRenderer; @@ -41,7 +45,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind setFocusable(true); setSize(_settings.getWidth(), _settings.getHeight()); setIgnoreRepaint(true); - getNewtWindow().setAutoSwapBufferMode(false); + getNewtWindow().setAutoSwapBufferMode(false); } @MainThread @@ -49,24 +53,35 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind if (_inited) { return; } - + // Make the window visible to realize the OpenGL surface. - setVisible(true); + // setVisible(true); // Request the focus here as it cannot work when the window is not visible - requestFocus(); + // requestFocus(); /** - * I do not understand why I cannot get the context earlier, I failed in - * getting it from addNotify() and setVisible(true) + * I do not understand why I cannot get the context earlier, I failed in getting it from addNotify() and + * setVisible(true) * */ - _canvasRenderer.setContext(getNewtWindow().getContext()); - - getNewtWindow().invoke(true, new GLRunnable() { - @Override - public boolean run(GLAutoDrawable glAutoDrawable) { - _canvasRenderer.init(_settings, true);// true - do swap in renderer. - return true; + /* + * _canvasRenderer.setContext(getNewtWindow().getContext()); + * + * getNewtWindow().invoke(true, new GLRunnable() { + * + * @Override public boolean run(final GLAutoDrawable glAutoDrawable) { _canvasRenderer.init(_settings, true);// + * true - do swap in renderer. return true; } }); + */ + if (!SwingUtilities.isEventDispatchThread()) { + try { + SwingUtilities.invokeAndWait(_initializerRunnable); + } catch (final InterruptedException ex) { + ex.printStackTrace(); + } catch (final InvocationTargetException ex) { + ex.printStackTrace(); } - }); + } else { + _initializerRunnable.run(); + } + _inited = true; } @@ -86,7 +101,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind public JoglCanvasRenderer getCanvasRenderer() { return _canvasRenderer; } - + @Override public GLWindow getNewtWindow() { return (GLWindow) getNEWTChild(); diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtInitializerRunnable.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtInitializerRunnable.java new file mode 100644 index 0000000..71080f2 --- /dev/null +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtInitializerRunnable.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2008-2010 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.framework.jogl; + +import com.ardor3d.framework.DisplaySettings; + +public class JoglNewtAwtInitializerRunnable implements Runnable { + + private final JoglNewtAwtCanvas _joglNewtAwtCanvas; + + private final DisplaySettings _settings; + + public JoglNewtAwtInitializerRunnable(final JoglNewtAwtCanvas joglAwtCanvas, final DisplaySettings settings) { + _joglNewtAwtCanvas = joglAwtCanvas; + _settings = settings; + } + + @Override + public void run() { + // Make the window visible to realize the OpenGL surface. + _joglNewtAwtCanvas.setVisible(true); + // Force the realization + _joglNewtAwtCanvas.getNewtWindow().display(); + if (!_joglNewtAwtCanvas.getNewtWindow().getDelegatedDrawable().isRealized()) { + throw new RuntimeException("The heavyweight AWT drawable cannot be realized"); + } + // Request the focus here as it cannot work when the window is not visible + _joglNewtAwtCanvas.requestFocus(); + // The OpenGL context has been created after the realization of the surface + _joglNewtAwtCanvas.getCanvasRenderer().setContext(_joglNewtAwtCanvas.getNewtWindow().getContext()); + // As the canvas renderer knows the OpenGL context, it can be initialized + _joglNewtAwtCanvas.getCanvasRenderer().init(_settings, true); + } +}
\ No newline at end of file |