diff options
author | Julien Gouesse <[email protected]> | 2018-01-27 16:40:51 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2018-01-27 16:40:51 +0100 |
commit | 484a7bc1b7354f80027e45d0fd0d97473cc454dd (patch) | |
tree | 8522c4fa7d8759c0b89d6bdf478a57469edb9642 /ardor3d-jogl-awt | |
parent | b476eeed7ebee18a310ba02b3a740fe34b87cec2 (diff) | |
parent | 3725d8321774e80b84f302eb16089dde387822e1 (diff) |
Merges several Renanse's commits
Diffstat (limited to 'ardor3d-jogl-awt')
4 files changed, 287 insertions, 235 deletions
diff --git a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtCanvas.java b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtCanvas.java index c92b275..e4d2372 100644 --- a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtCanvas.java +++ b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtCanvas.java @@ -26,96 +26,109 @@ import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.jogl.CapsUtil; import com.ardor3d.framework.jogl.JoglCanvasRenderer; import com.ardor3d.framework.jogl.JoglDrawerRunnable; +import com.ardor3d.input.MouseManager; /** * Ardor3D JOGL AWT heavyweight canvas, AWT component for the OpenGL rendering of Ardor3D with JOGL that supports the * AWT input system directly and its abstraction in Ardor3D (com.ardor3d.input.awt) - * + * */ public class JoglAwtCanvas extends GLCanvas implements Canvas { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final JoglCanvasRenderer _canvasRenderer; - private boolean _inited = false; + private final JoglCanvasRenderer _canvasRenderer; + private boolean _inited = false; - private final DisplaySettings _settings; + private final DisplaySettings _settings; - private final JoglDrawerRunnable _drawerGLRunnable; + private final JoglDrawerRunnable _drawerGLRunnable; - private final JoglAwtInitializerRunnable _initializerRunnable; + private final JoglAwtInitializerRunnable _initializerRunnable; - public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { - this(settings, canvasRenderer, new CapsUtil()); - } + public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { + this(settings, canvasRenderer, new CapsUtil()); + } - public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, - final CapsUtil capsUtil) { - super(capsUtil.getCapsForSettings(settings)); - _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); - _initializerRunnable = new JoglAwtInitializerRunnable(this, settings); - _settings = settings; - _canvasRenderer = canvasRenderer; + public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, + final CapsUtil capsUtil) { + super(capsUtil.getCapsForSettings(settings)); + _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + _initializerRunnable = new JoglAwtInitializerRunnable(this, settings); + _settings = settings; + _canvasRenderer = canvasRenderer; - setFocusable(true); - requestFocus(); - setSize(_settings.getWidth(), _settings.getHeight()); - setIgnoreRepaint(true); - setAutoSwapBufferMode(false); - // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 + setFocusable(true); + requestFocus(); + setSize(_settings.getWidth(), _settings.getHeight()); + setIgnoreRepaint(true); + setAutoSwapBufferMode(false); + // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 setSurfaceScale(new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }); - } + } - @Override - @MainThread - public void init() { - if (_inited) { - return; - } + @Override + @MainThread + public void init() { + if (_inited) { + return; + } // Calling setVisible(true) on the GLCanvas not from the AWT-EDT can freeze the Intel GPU under Windows - if (!SwingUtilities.isEventDispatchThread()) { - try { - SwingUtilities.invokeAndWait(_initializerRunnable); - } catch (final InterruptedException ex) { - ex.printStackTrace(); - } catch (final InvocationTargetException ex) { - ex.printStackTrace(); - } - } else { - _initializerRunnable.run(); - } - - _inited = isRealized(); - } - - @Override - public void draw(final CountDownLatch latch) { - if (!_inited) { - init(); - } - - if (isShowing()) { - invoke(true, _drawerGLRunnable); - } - if (latch != null) { - latch.countDown(); - } - } - - @Override - public JoglCanvasRenderer getCanvasRenderer() { - return _canvasRenderer; - } - - public void setVSyncEnabled(final boolean enabled) { - invoke(true, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable glAutoDrawable) { - glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); - return false; - } - }); - } + if (!SwingUtilities.isEventDispatchThread()) { + try { + SwingUtilities.invokeAndWait(_initializerRunnable); + } catch (final InterruptedException ex) { + ex.printStackTrace(); + } catch (final InvocationTargetException ex) { + ex.printStackTrace(); + } + } else { + _initializerRunnable.run(); + } + + _inited = isRealized(); + } + + @Override + public void draw(final CountDownLatch latch) { + if (!_inited) { + init(); + } + + if (isShowing()) { + invoke(true, _drawerGLRunnable); + } + if (latch != null) { + latch.countDown(); + } + } + + @Override + public JoglCanvasRenderer getCanvasRenderer() { + return _canvasRenderer; + } + + protected MouseManager _manager; + + @Override + public MouseManager getMouseManager() { + return _manager; + } + + @Override + public void setMouseManager(final MouseManager manager) { + _manager = manager; + } + + public void setVSyncEnabled(final boolean enabled) { + invoke(true, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable glAutoDrawable) { + glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); + return false; + } + }); + } } diff --git a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtWindow.java b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtWindow.java index 8e8ca09..b049a27 100644 --- a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtWindow.java +++ b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglAwtWindow.java @@ -35,6 +35,7 @@ import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.NativeCanvas; import com.ardor3d.framework.jogl.JoglCanvasRenderer; import com.ardor3d.image.Image; +import com.ardor3d.input.MouseManager; import com.ardor3d.renderer.jogl.JoglPbufferTextureRenderer; /** @@ -241,6 +242,18 @@ public class JoglAwtWindow extends Frame implements NativeCanvas { return _glCanvas.getCanvasRenderer(); } + protected MouseManager _manager; + + @Override + public MouseManager getMouseManager() { + return _manager; + } + + @Override + public void setMouseManager(final MouseManager manager) { + _manager = manager; + } + @Override public void close() { try { diff --git a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglNewtAwtCanvas.java b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglNewtAwtCanvas.java index e72f045..f61f3e7 100644 --- a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglNewtAwtCanvas.java +++ b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglNewtAwtCanvas.java @@ -21,111 +21,124 @@ import com.ardor3d.framework.jogl.CapsUtil; import com.ardor3d.framework.jogl.JoglCanvasRenderer; import com.ardor3d.framework.jogl.JoglDrawerRunnable; import com.ardor3d.framework.jogl.NewtWindowContainer; +import com.ardor3d.input.MouseManager; import com.jogamp.nativewindow.ScalableSurface; 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; + private static final long serialVersionUID = 1L; - private final JoglCanvasRenderer _canvasRenderer; - private boolean _inited = false; + private final JoglCanvasRenderer _canvasRenderer; + private boolean _inited = false; - private final DisplaySettings _settings; + private final DisplaySettings _settings; - private final JoglDrawerRunnable _drawerGLRunnable; + private final JoglDrawerRunnable _drawerGLRunnable; - public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { - this(settings, canvasRenderer, new CapsUtil()); - } + public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { + this(settings, canvasRenderer, new CapsUtil()); + } + + public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, + final CapsUtil capsUtil) { + this(createNewtChildWindow(settings, capsUtil), settings, canvasRenderer, capsUtil); + } - public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, - final CapsUtil capsUtil) { - this(createNewtChildWindow(settings, capsUtil), settings, canvasRenderer, capsUtil); - } - public JoglNewtAwtCanvas(final GLWindow newtChildWindow, final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, final CapsUtil capsUtil) { - super(newtChildWindow); - _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); - getNewtWindow().setUndecorated(true); - _settings = settings; - _canvasRenderer = canvasRenderer; - - setFocusable(true); - setSize(_settings.getWidth(), _settings.getHeight()); - setIgnoreRepaint(true); - getNewtWindow().setAutoSwapBufferMode(false); - } - - private static GLWindow createNewtChildWindow(final DisplaySettings settings, final CapsUtil capsUtil) { - final GLWindow newtChildWindow = GLWindow.create(capsUtil.getCapsForSettings(settings)); - // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 + super(newtChildWindow); + _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + getNewtWindow().setUndecorated(true); + _settings = settings; + _canvasRenderer = canvasRenderer; + + setFocusable(true); + setSize(_settings.getWidth(), _settings.getHeight()); + setIgnoreRepaint(true); + getNewtWindow().setAutoSwapBufferMode(false); + } + + private static GLWindow createNewtChildWindow(final DisplaySettings settings, final CapsUtil capsUtil) { + final GLWindow newtChildWindow = GLWindow.create(capsUtil.getCapsForSettings(settings)); + // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 newtChildWindow.setSurfaceScale(new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }); - return newtChildWindow; - } - - @Override - @MainThread - public void init() { - if (_inited) { - return; - } - - // Make the window visible to realize the OpenGL surface. - setVisible(true); - if (getNewtWindow().isRealized()) { - // Request the focus here as it cannot work when the window is not visible - requestFocus(); - /** + return newtChildWindow; + } + + @Override + @MainThread + public void init() { + if (_inited) { + return; + } + + // Make the window visible to realize the OpenGL surface. + setVisible(true); + if (getNewtWindow().isRealized()) { + // Request the focus here as it cannot work when the window is not visible + requestFocus(); + /** * 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(final GLAutoDrawable glAutoDrawable) { - _canvasRenderer.init(_settings, true);// true - do swap in renderer. - return true; - } - }); - _inited = true; - } - } - - @Override - public void draw(final CountDownLatch latch) { - if (!_inited) { - init(); - } - - if (isShowing()) { - getNewtWindow().invoke(true, _drawerGLRunnable); - } - if (latch != null) { - latch.countDown(); - } - } - - @Override - public JoglCanvasRenderer getCanvasRenderer() { - return _canvasRenderer; - } - - @Override - public GLWindow getNewtWindow() { - return (GLWindow) getNEWTChild(); - } - - public void setVSyncEnabled(final boolean enabled) { - getNewtWindow().invoke(true, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable glAutoDrawable) { - glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); - return false; - } - }); - } + _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; + } + }); + _inited = true; + } + } + + @Override + public void draw(final CountDownLatch latch) { + if (!_inited) { + init(); + } + + if (isShowing()) { + getNewtWindow().invoke(true, _drawerGLRunnable); + } + if (latch != null) { + latch.countDown(); + } + } + + @Override + public JoglCanvasRenderer getCanvasRenderer() { + return _canvasRenderer; + } + + protected MouseManager _manager; + + @Override + public MouseManager getMouseManager() { + return _manager; + } + + @Override + public void setMouseManager(final MouseManager manager) { + _manager = manager; + } + + @Override + public GLWindow getNewtWindow() { + return (GLWindow) getNEWTChild(); + } + + public void setVSyncEnabled(final boolean enabled) { + getNewtWindow().invoke(true, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable glAutoDrawable) { + glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); + return false; + } + }); + } } diff --git a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglSwingCanvas.java b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglSwingCanvas.java index c9ef568..b379692 100644 --- a/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglSwingCanvas.java +++ b/ardor3d-jogl-awt/src/main/java/com/ardor3d/framework/jogl/awt/JoglSwingCanvas.java @@ -21,6 +21,7 @@ import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.jogl.CapsUtil; import com.ardor3d.framework.jogl.JoglCanvasRenderer; import com.ardor3d.framework.jogl.JoglDrawerRunnable; +import com.ardor3d.input.MouseManager; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLRunnable; @@ -33,89 +34,101 @@ import com.jogamp.opengl.awt.GLJPanel; * when mixing heavyweight and lightweight components. */ public class JoglSwingCanvas extends GLJPanel implements Canvas { - - private static final long serialVersionUID = 1L; - private final JoglCanvasRenderer _canvasRenderer; - private boolean _inited = false; + private static final long serialVersionUID = 1L; - private final DisplaySettings _settings; + private final JoglCanvasRenderer _canvasRenderer; + private boolean _inited = false; - private final JoglDrawerRunnable _drawerGLRunnable; + private final DisplaySettings _settings; - private final JoglSwingInitializerRunnable _initializerRunnable; + private final JoglDrawerRunnable _drawerGLRunnable; - public JoglSwingCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { - this(settings, canvasRenderer, new CapsUtil()); - } + private final JoglSwingInitializerRunnable _initializerRunnable; - public JoglSwingCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, - final CapsUtil capsUtil) { - super(capsUtil.getCapsForSettings(settings)); - _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); - _initializerRunnable = new JoglSwingInitializerRunnable(this, settings); - _settings = settings; - _canvasRenderer = canvasRenderer; + public JoglSwingCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { + this(settings, canvasRenderer, new CapsUtil()); + } - setFocusable(true); - requestFocus(); - setSize(_settings.getWidth(), _settings.getHeight()); - setIgnoreRepaint(true); - setAutoSwapBufferMode(false); - // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 + public JoglSwingCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer, + final CapsUtil capsUtil) { + super(capsUtil.getCapsForSettings(settings)); + _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + _initializerRunnable = new JoglSwingInitializerRunnable(this, settings); + _settings = settings; + _canvasRenderer = canvasRenderer; + + setFocusable(true); + requestFocus(); + setSize(_settings.getWidth(), _settings.getHeight()); + setIgnoreRepaint(true); + setAutoSwapBufferMode(false); + // disables HiDPI, see https://github.com/gouessej/Ardor3D/issues/14 setSurfaceScale(new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }); - } + } - @Override - @MainThread - public void init() { - if (_inited) { - return; - } + @Override + @MainThread + public void init() { + if (_inited) { + return; + } // Calling setVisible(true) on the GLCanvas not from the AWT-EDT can freeze the Intel GPU under Windows - if (!SwingUtilities.isEventDispatchThread()) { - try { - SwingUtilities.invokeAndWait(_initializerRunnable); - } catch (final InterruptedException ex) { - ex.printStackTrace(); - } catch (final InvocationTargetException ex) { - ex.printStackTrace(); - } - } else { - _initializerRunnable.run(); - } - - _inited = isRealized(); - } - - @Override - public void draw(final CountDownLatch latch) { - if (!_inited) { - init(); - } - - if (isShowing()) { - invoke(true, _drawerGLRunnable); - } - if (latch != null) { - latch.countDown(); - } - } - - @Override - public JoglCanvasRenderer getCanvasRenderer() { - return _canvasRenderer; - } - - public void setVSyncEnabled(final boolean enabled) { - invoke(true, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable glAutoDrawable) { - glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); - return false; - } - }); - } + if (!SwingUtilities.isEventDispatchThread()) { + try { + SwingUtilities.invokeAndWait(_initializerRunnable); + } catch (final InterruptedException ex) { + ex.printStackTrace(); + } catch (final InvocationTargetException ex) { + ex.printStackTrace(); + } + } else { + _initializerRunnable.run(); + } + + _inited = isRealized(); + } + + @Override + public void draw(final CountDownLatch latch) { + if (!_inited) { + init(); + } + + if (isShowing()) { + invoke(true, _drawerGLRunnable); + } + if (latch != null) { + latch.countDown(); + } + } + + @Override + public JoglCanvasRenderer getCanvasRenderer() { + return _canvasRenderer; + } + + protected MouseManager _manager; + + @Override + public MouseManager getMouseManager() { + return _manager; + } + + @Override + public void setMouseManager(final MouseManager manager) { + _manager = manager; + } + + public void setVSyncEnabled(final boolean enabled) { + invoke(true, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable glAutoDrawable) { + glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0); + return false; + } + }); + } } |