diff options
4 files changed, 76 insertions, 42 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/framework/DisplaySettings.java b/ardor3d-core/src/main/java/com/ardor3d/framework/DisplaySettings.java index a7a75ef..a94b451 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/framework/DisplaySettings.java +++ b/ardor3d-core/src/main/java/com/ardor3d/framework/DisplaySettings.java @@ -11,26 +11,34 @@ package com.ardor3d.framework; public class DisplaySettings { + /** canvas (unrotated) width */ private final int _width; + /** canvas (unrotated) height */ private final int _height; + /** number of color bits used to represent the color of a single pixel */ private final int _colorDepth; private final int _frequency; private final int _alphaBits; private final int _depthBits; private final int _stencilBits; + /** number of samples used to anti-alias */ private final int _samples; + /** true if the canvas should assume exclusive access to the screen */ private final boolean _fullScreen; + /** true if the canvas should be rendered stereoscopically (for 3D glasses) */ private final boolean _stereo; + /** OpenGL shared canvas renderer, can be null */ private final CanvasRenderer _shareContext; + /** rotation in degrees, can be equal to 0, 90, 180 or 270 */ private final int _rotation; /** * Creates a new <code>DisplaySettings</code> object. * * @param width - * the canvas width + * the canvas (unrotated) width * @param height - * the canvas height + * the canvas (unrotated) height * @param colorDepth * the number of color bits used to represent the color of a single pixel * @param frequency @@ -81,9 +89,9 @@ public class DisplaySettings { * Convenience method * * @param width - * the canvas width + * the canvas (unrotated) width * @param height - * the canvas height + * the canvas (unrotated) height * @param depthBits * the number of bits making up the z-buffer * @param samples @@ -99,9 +107,9 @@ public class DisplaySettings { * Convenience method * * @param width - * the canvas width + * the canvas (unrotated) width * @param height - * the canvas height + * the canvas (unrotated) height * @param colorDepth * the number of color bits used to represent the color of a single pixel * @param frequency @@ -120,9 +128,9 @@ public class DisplaySettings { * alphaBits, depthBits, stencilBits, samples, fullScreen, stereo, null, 0)</code> * * @param width - * the canvas width + * the canvas (unrotated) width * @param height - * the canvas height + * the canvas (unrotated) height * @param colorDepth * the number of color bits used to represent the color of a single pixel * @param frequency @@ -155,9 +163,9 @@ public class DisplaySettings { * Creates a new <code>DisplaySettings</code> object with no rotation. * * @param width - * the canvas width + * the canvas (unrotated) width * @param height - * the canvas height + * the canvas (unrotated) height * @param colorDepth * the number of color bits used to represent the color of a single pixel * @param frequency @@ -252,16 +260,16 @@ public class DisplaySettings { return _colorDepth == that._colorDepth && _frequency == that._frequency - && _fullScreen != that._fullScreen - && _height != that._height - && _width != that._width - && _alphaBits != that._alphaBits - && _depthBits != that._depthBits - && _stencilBits != that._stencilBits - && _samples != that._samples - && _stereo != that._stereo + && _fullScreen == that._fullScreen + && _height == that._height + && _width == that._width + && _alphaBits == that._alphaBits + && _depthBits == that._depthBits + && _stencilBits == that._stencilBits + && _samples == that._samples + && _stereo == that._stereo && ((_shareContext == that._shareContext) || (_shareContext != null && _shareContext - .equals(that._shareContext))); + .equals(that._shareContext))) && _rotation == that._rotation; } @Override @@ -278,7 +286,8 @@ public class DisplaySettings { result = 31 * result + _samples; result = 31 * result + (_fullScreen ? 1 : 0); result = 31 * result + (_stereo ? 1 : 0); - result = 31 * result + (_shareContext != null ? _shareContext.hashCode() : 0); + result = 31 * result + (_shareContext == null ? 0 : _shareContext.hashCode()); + result = 31 * result + _rotation; return result; } } 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 8d46d28..4410604 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 @@ -10,9 +10,12 @@ package com.ardor3d.framework.jogl; +import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.framework.DisplaySettings; import com.ardor3d.util.Ardor3dException; +import com.jogamp.newt.MonitorMode; import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLCapabilitiesImmutable; import com.jogamp.opengl.GLProfile; public class CapsUtil { @@ -78,6 +81,12 @@ public class CapsUtil { throw new Ardor3dException("Invalid pixel depth: " + settings.getColorDepth()); } + // Validate rotation + if (settings.getRotation() != MonitorMode.ROTATE_0 && settings.getRotation() != MonitorMode.ROTATE_90 + && settings.getRotation() != MonitorMode.ROTATE_180 && settings.getRotation() != MonitorMode.ROTATE_270) { + throw new Ardor3dException("Invalid rotation: " + settings.getRotation()); + } + final GLCapabilities caps = new GLCapabilities(getProfile()); caps.setHardwareAccelerated(true); caps.setDoubleBuffered(true); @@ -109,4 +118,12 @@ public class CapsUtil { return caps; } + public DisplaySettings getSettingsForCaps(final GLCapabilitiesImmutable glCaps, final int width, final int height, + final int frequency, final boolean fullscreen, final CanvasRenderer shareContext, final int rotation) { + final int colorDepth = glCaps.getRedBits() + glCaps.getGreenBits() + glCaps.getBlueBits(); + final DisplaySettings settings = new DisplaySettings(width, height, colorDepth, frequency, + glCaps.getAlphaBits(), glCaps.getDepthBits(), glCaps.getStencilBits(), glCaps.getNumSamples(), + fullscreen, glCaps.getStereo(), shareContext, rotation); + return settings; + } } diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java index 6bc4c87..a66f534 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java @@ -12,12 +12,6 @@ package com.ardor3d.framework.jogl; import java.util.logging.Logger; -import com.jogamp.opengl.GL; -import com.jogamp.opengl.GLContext; -import com.jogamp.opengl.GLDrawableFactory; -import com.jogamp.opengl.GLException; -import com.jogamp.opengl.GLPipelineFactory; - import com.ardor3d.annotation.MainThread; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.framework.DisplaySettings; @@ -35,6 +29,11 @@ import com.ardor3d.renderer.jogl.JoglRenderContext; import com.ardor3d.renderer.jogl.JoglRenderer; import com.ardor3d.util.Ardor3dException; import com.ardor3d.util.geom.jogl.DirectNioBuffersSet; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLContext; +import com.jogamp.opengl.GLDrawableFactory; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.GLPipelineFactory; public class JoglCanvasRenderer implements CanvasRenderer { @@ -203,6 +202,7 @@ public class JoglCanvasRenderer implements CanvasRenderer { _renderer.setBackgroundColor(ColorRGBA.BLACK); if (_camera == null) { + // TODO take into account the rotation /** Set up how our camera sees. */ _camera = new Camera(settings.getWidth(), settings.getHeight()); _camera.setFrustumPerspective(45.0f, (float) settings.getWidth() / (float) settings.getHeight(), 1, 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 1063026..045324a 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 @@ -32,6 +32,7 @@ import com.jogamp.newt.event.WindowListener; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.util.MonitorModeUtil; import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLCapabilitiesImmutable; import com.jogamp.opengl.GLContext; import com.jogamp.opengl.GLRunnable; @@ -45,8 +46,8 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { private final JoglCanvasRenderer _canvasRenderer; private boolean _inited = false; private boolean _isClosing = false; - - private final DisplaySettings _settings; + /** chosen display settings. Note that they may differ from the requested display settings */ + private DisplaySettings _settings; private final JoglDrawerRunnable _drawerGLRunnable; @@ -55,6 +56,8 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { /** list of monitor devices used in fullscreen mode, ignored in windowed mode */ private List<MonitorDevice> _monitorDevices; + private final CapsUtil _capsUtil; + public JoglNewtWindow(final JoglCanvasRenderer canvasRenderer, final DisplaySettings settings) { this(canvasRenderer, settings, true, false, false, false); } @@ -68,6 +71,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { public JoglNewtWindow(final JoglCanvasRenderer canvasRenderer, final DisplaySettings settings, final boolean onscreen, final boolean bitmapRequested, final boolean pbufferRequested, final boolean fboRequested, final CapsUtil capsUtil) { + _capsUtil = capsUtil; // FIXME rather pass the monitor(s) to the constructor, create a screen to get the primary monitor _newtWindow = GLWindow.create(capsUtil.getCapsForSettingsWithHints(settings, onscreen, bitmapRequested, pbufferRequested, fboRequested)); @@ -80,17 +84,20 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { _newtWindow.setSurfaceScale(new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }); _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + final int width, height; if (settings.isFullScreen() && settings.getWidth() == 0 || settings.getHeight() == 0) { // FIXME use all available monitor devices to compute the size final DimensionImmutable currentResolution = primaryMonitor.queryCurrentMode().getSurfaceSize() .getResolution(); - _settings = new DisplaySettings(currentResolution.getWidth(), currentResolution.getHeight(), - settings.getColorDepth(), settings.getFrequency(), settings.getAlphaBits(), - settings.getDepthBits(), settings.getStencilBits(), settings.getSamples(), true, - settings.isStereo(), settings.getShareContext(), settings.getRotation()); + width = currentResolution.getWidth(); + height = currentResolution.getHeight(); } else { - _settings = settings; + width = settings.getWidth(); + height = settings.getHeight(); } + _settings = new DisplaySettings(width, height, settings.getColorDepth(), settings.getFrequency(), + settings.getAlphaBits(), settings.getDepthBits(), settings.getStencilBits(), settings.getSamples(), + settings.isFullScreen(), settings.isStereo(), settings.getShareContext(), settings.getRotation()); _canvasRenderer = canvasRenderer; _canvasRenderer._doSwap = true;// true - do swap in renderer. setAutoSwapBufferMode(false);// false - doesn't swap automatically in JOGL itself @@ -159,8 +166,9 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { if (!byBppMonitorModes.isEmpty()) { monitorModes = byBppMonitorModes; } - if (_settings.getRotation() == 0 || _settings.getRotation() == 90 || _settings.getRotation() == 180 - || _settings.getRotation() == 270) { + if (_settings.getRotation() == MonitorMode.ROTATE_0 || _settings.getRotation() == MonitorMode.ROTATE_90 + || _settings.getRotation() == MonitorMode.ROTATE_180 + || _settings.getRotation() == MonitorMode.ROTATE_270) { final List<MonitorMode> rotatedMonitorModes = MonitorModeUtil.filterByRotation(monitorModes, _settings.getRotation()); if (!rotatedMonitorModes.isEmpty()) { @@ -300,16 +308,14 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { } // Set the size very early to prevent the default one from being used (typically when exiting full screen mode) - if (_settings.getWidth() == 0 || _settings.getHeight() == 0) { - final DimensionImmutable currentResolution = _monitorDevices.get(0).queryCurrentMode().getSurfaceSize() - .getResolution(); - setSize(currentResolution.getWidth(), currentResolution.getHeight()); - } else { - setSize(_settings.getWidth(), _settings.getHeight()); - } + setSize(_settings.getWidth(), _settings.getHeight()); // Make the window visible to realize the OpenGL surface. setVisible(true); if (_newtWindow.isRealized()) { + final GLCapabilitiesImmutable glCaps = _newtWindow.getChosenGLCapabilities(); + _settings = _capsUtil.getSettingsForCaps(glCaps, _settings.getWidth(), _settings.getHeight(), + _settings.getFrequency(), _settings.isFullScreen(), _settings.getShareContext(), + _settings.getRotation()); _newtWindow.addWindowListener(new WindowAdapter() { @Override public void windowDestroyNotify(final WindowEvent e) { @@ -468,6 +474,8 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer { // FIXME recompute the width and the height of the settings, apply the settings anew } + // TODO return all available monitor modes + @Override public GLWindow getNewtWindow() { return _newtWindow; |