diff options
author | Julien Gouesse <[email protected]> | 2013-01-28 22:44:22 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2013-01-28 22:44:22 +0100 |
commit | b71670d1ae77b734b0259504f2e5b5a28396b2a3 (patch) | |
tree | f22db50aa15209b367d56ddda00765280f2c01f1 /ardor3d-jogl/src/main/java | |
parent | be62dac324bc0f84ef4bae61893cb6acb36ba36e (diff) |
Adds offscreen support
Diffstat (limited to 'ardor3d-jogl/src/main/java')
-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 | 140 |
2 files changed, 84 insertions, 67 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..394715e 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,104 @@ 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) { + 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)); _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 +144,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 +168,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 +186,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { init(); } - if (/*isShowing()*/isVisible()) { + if (/* isShowing() */isVisible()) { _newtWindow.invoke(true, _drawerGLRunnable); } if (latch != null) { @@ -208,10 +214,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 +225,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; |