diff options
author | Joshua Slack <[email protected]> | 2013-02-09 09:03:17 -0800 |
---|---|---|
committer | Joshua Slack <[email protected]> | 2013-02-09 09:03:17 -0800 |
commit | 95583e464d52079dee2f92f6d6875e5706e27ff5 (patch) | |
tree | 6dc8768ee98a50bad860850984fe1061dead25d5 | |
parent | b7f0d44c85dcdd9b9906fd78d60d40f6a545832d (diff) | |
parent | 0a42f36d760b657024e4fdbc377e304b0a53126b (diff) |
Merge pull request #22 from gouessej/master
Adds offscreen support into the JOGL backend
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java | 11 | ||||
-rw-r--r-- | ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java | 143 |
2 files changed, 86 insertions, 68 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java index 733fbfe..78ccd40 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/CapsUtil.java @@ -19,6 +19,11 @@ import com.ardor3d.util.Ardor3dException; public class CapsUtil { public static GLCapabilities getCapsForSettings(final DisplaySettings settings) { + return getCapsForSettings(settings, true, false, false, false); + } + + public static GLCapabilities getCapsForSettings(final DisplaySettings settings, final boolean onscreen, + final boolean bitmapRequested, final boolean pbufferRequested, final boolean fboRequested) { // Validate window dimensions. if (settings.getWidth() <= 0 || settings.getHeight() <= 0) { @@ -53,6 +58,12 @@ public class CapsUtil { caps.setGreenBits(4); break; } + caps.setOnscreen(onscreen); + if (!onscreen) { + caps.setBitmap(bitmapRequested); + caps.setPBuffer(pbufferRequested); + caps.setFBO(fboRequested); + } return caps; } diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java index 3333d90..9490dea 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java @@ -12,10 +12,12 @@ package com.ardor3d.framework.jogl; import java.util.List; import java.util.concurrent.CountDownLatch; + import javax.media.nativewindow.util.Dimension; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLContext; import javax.media.opengl.GLRunnable; + import com.ardor3d.annotation.MainThread; import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.NativeCanvas; @@ -30,100 +32,105 @@ import com.jogamp.newt.event.WindowListener; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.util.ScreenModeUtil; - public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { - + private final JoglCanvasRenderer _canvasRenderer; private boolean _inited = false; private boolean _isClosing = false; private final DisplaySettings _settings; - + private final JoglDrawerRunnable _drawerGLRunnable; - + private final GLWindow _newtWindow; public JoglNewtWindow(final JoglCanvasRenderer canvasRenderer, final DisplaySettings settings) { - _newtWindow = GLWindow.create(CapsUtil.getCapsForSettings(settings)); + this(canvasRenderer, settings, true, false, false, false); + } + + public JoglNewtWindow(final JoglCanvasRenderer canvasRenderer, final DisplaySettings settings, + final boolean onscreen, final boolean bitmapRequested, final boolean pbufferRequested, + final boolean fboRequested) { + _newtWindow = GLWindow.create(CapsUtil.getCapsForSettings(settings, onscreen, bitmapRequested, + pbufferRequested, fboRequested)); _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); _settings = settings; - _canvasRenderer = canvasRenderer; + _canvasRenderer = canvasRenderer; setAutoSwapBufferMode(false); } - + /** - * Applies all settings not related to OpenGL (screen resolution, - * screen size, etc...) + * Applies all settings not related to OpenGL (screen resolution, screen size, etc...) * */ private void applySettings() { _newtWindow.setUndecorated(_settings.isFullScreen()); - _newtWindow.setFullscreen(_settings.isFullScreen()); - //FIXME Ardor3D does not allow to change the resolution + _newtWindow.setFullscreen(_settings.isFullScreen()); + // FIXME Ardor3D does not allow to change the resolution /** - * uses the filtering relying on resolution with the size to fetch only the screen - * mode matching with the current resolution + * uses the filtering relying on resolution with the size to fetch only the screen mode matching with the + * current resolution */ if (_settings.isFullScreen()) { - Screen screen = _newtWindow.getScreen(); - List<ScreenMode> screenModes = screen.getScreenModes(); - //the resolution is provided by the user - Dimension dimension=new Dimension(_settings.getWidth(),_settings.getHeight()); - screenModes = ScreenModeUtil.filterByResolution(screenModes,dimension); + final Screen screen = _newtWindow.getScreen(); + List<ScreenMode> screenModes = screen.getScreenModes(); + // the resolution is provided by the user + final Dimension dimension = new Dimension(_settings.getWidth(), _settings.getHeight()); + screenModes = ScreenModeUtil.filterByResolution(screenModes, dimension); screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); if (_settings.getFrequency() > 0) { - screenModes = ScreenModeUtil.filterByRate(screenModes, _settings.getFrequency()); - } else { - screenModes = ScreenModeUtil.getHighestAvailableRate(screenModes); - } + screenModes = ScreenModeUtil.filterByRate(screenModes, _settings.getFrequency()); + } else { + screenModes = ScreenModeUtil.getHighestAvailableRate(screenModes); + } screen.setCurrentScreenMode(screenModes.get(0)); } } - - public void addKeyListener(KeyListener keyListener) { + + public void addKeyListener(final KeyListener keyListener) { _newtWindow.addKeyListener(keyListener); } - - public void addMouseListener(MouseListener mouseListener) { + + public void addMouseListener(final MouseListener mouseListener) { _newtWindow.addMouseListener(mouseListener); } - - public void addWindowListener(WindowListener windowListener) { + + public void addWindowListener(final WindowListener windowListener) { _newtWindow.addWindowListener(windowListener); } - + public GLContext getContext() { return _newtWindow.getContext(); } - + public int getWidth() { return _newtWindow.getWidth(); } - + public int getHeight() { return _newtWindow.getHeight(); } - + public int getX() { return _newtWindow.getX(); } - + public int getY() { return _newtWindow.getY(); } - + public boolean isVisible() { return _newtWindow.isVisible(); } - - public void setSize(int width, int height) { + + public void setSize(final int width, final int height) { _newtWindow.setTopLevelSize(width, height); } - - public void setVisible(boolean visible) { + + public void setVisible(final boolean visible) { _newtWindow.setVisible(visible); } - - public void setAutoSwapBufferMode(boolean autoSwapBufferModeEnabled) { + + public void setAutoSwapBufferMode(final boolean autoSwapBufferModeEnabled) { _newtWindow.setAutoSwapBufferMode(autoSwapBufferModeEnabled); } @@ -138,23 +145,23 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { public void windowDestroyNotify(final WindowEvent e) { _isClosing = true; } - -// public void windowResized(final WindowEvent e) { -// _newtWindow.invoke(true, new GLRunnable() { -// -// @Override -// public boolean run(GLAutoDrawable glAutoDrawable) { -// _canvasRenderer._camera.resize(_newtWindow.getWidth(), _newtWindow.getHeight()); -// _canvasRenderer._camera.setFrustumPerspective(_canvasRenderer._camera.getFovY(), -// (float) _newtWindow.getWidth() / (float) _newtWindow.getHeight(), -// _canvasRenderer._camera.getFrustumNear(), -// _canvasRenderer._camera.getFrustumFar()); -// return true; -// } -// }); -// } + + // public void windowResized(final WindowEvent e) { + // _newtWindow.invoke(true, new GLRunnable() { + // + // @Override + // public boolean run(GLAutoDrawable glAutoDrawable) { + // _canvasRenderer._camera.resize(_newtWindow.getWidth(), _newtWindow.getHeight()); + // _canvasRenderer._camera.setFrustumPerspective(_canvasRenderer._camera.getFovY(), + // (float) _newtWindow.getWidth() / (float) _newtWindow.getHeight(), + // _canvasRenderer._camera.getFrustumNear(), + // _canvasRenderer._camera.getFrustumFar()); + // return true; + // } + // }); + // } }); - + // Set the size very early to prevent the default one from being used (typically when exiting full screen mode) setSize(_settings.getWidth(), _settings.getHeight()); // Make the window visible to realize the OpenGL surface. @@ -162,12 +169,12 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { // Request the focus here as it cannot work when the window is not visible _newtWindow.requestFocus(); applySettings(); - + _canvasRenderer.setContext(getContext()); - + _newtWindow.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; } @@ -180,7 +187,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { init(); } - if (/*isShowing()*/isVisible()) { + if (/* isShowing() */isVisible()) { _newtWindow.invoke(true, _drawerGLRunnable); } if (latch != null) { @@ -208,10 +215,10 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { } @Override - public void setVSyncEnabled(final boolean enabled) { + public void setVSyncEnabled(final boolean enabled) { _newtWindow.invoke(true, new GLRunnable() { @Override - public boolean run(GLAutoDrawable glAutoDrawable) { + public boolean run(final GLAutoDrawable glAutoDrawable) { _newtWindow.getGL().setSwapInterval(enabled ? 1 : 0); return false; } @@ -219,20 +226,20 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { } @Override - public void setTitle(String title) { + public void setTitle(final String title) { _newtWindow.setTitle(title); } @Override - public void setIcon(Image[] iconImages) { - //FIXME not supported by NEWT + public void setIcon(final Image[] iconImages) { + // FIXME not supported by NEWT } @Override - public void moveWindowTo(int locX, int locY) { - _newtWindow.setPosition(locX, locY); + public void moveWindowTo(final int locX, final int locY) { + _newtWindow.setPosition(locX, locY); } - + @Override public GLWindow getNewtWindow() { return _newtWindow; |