diff options
5 files changed, 153 insertions, 94 deletions
diff --git a/ardor3d-effects/src/main/java/com/ardor3d/extension/effect/particle/Particle.java b/ardor3d-effects/src/main/java/com/ardor3d/extension/effect/particle/Particle.java index 48ff5ff..6917d70 100644 --- a/ardor3d-effects/src/main/java/com/ardor3d/extension/effect/particle/Particle.java +++ b/ardor3d-effects/src/main/java/com/ardor3d/extension/effect/particle/Particle.java @@ -250,9 +250,6 @@ public class Particle implements Savable { * (interpolating between start and end size), spin (using parent's spin speed) and current age of particle. If this * particle's age is greater than its lifespan, it is set to status DEAD. * </p> - * <p> - * Note that this only changes the parameters of the Particle, not the geometry the particle is associated with. - * </p> * * @param secondsPassed * number of seconds passed since last update. 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 c23b8a0..733fbfe 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 @@ -40,6 +40,19 @@ public class CapsUtil { caps.setSampleBuffers(settings.getSamples() != 0); caps.setStereo(settings.isStereo()); caps.setStencilBits(settings.getStencilBits()); + switch (settings.getColorDepth()) { + case 32: + case 24: + caps.setRedBits(8); + caps.setBlueBits(8); + caps.setGreenBits(8); + break; + case 16: + caps.setRedBits(4); + caps.setBlueBits(4); + caps.setGreenBits(4); + break; + } return caps; } diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java index 5c95cd8..58fef71 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java @@ -10,10 +10,12 @@ 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.media.opengl.awt.GLCanvas; +import javax.swing.SwingUtilities; + import com.ardor3d.annotation.MainThread; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.DisplaySettings; @@ -21,7 +23,7 @@ import com.ardor3d.framework.DisplaySettings; /** * FIXME there is still a deadlock when using several instances of this class in the same container, see JOGL bug 572 * Rather use JoglNewtAwtCanvas in this case. - * + * */ public class JoglAwtCanvas extends GLCanvas implements Canvas { @@ -31,12 +33,15 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { private boolean _inited = false; private final DisplaySettings _settings; - + private final JoglDrawerRunnable _drawerGLRunnable; + private final JoglInitializerRunnable _initializerRunnable; + public JoglAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) { super(CapsUtil.getCapsForSettings(settings)); _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer); + _initializerRunnable = new JoglInitializerRunnable(this, settings); _settings = settings; _canvasRenderer = canvasRenderer; @@ -49,25 +54,23 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { @MainThread public void init() { - if (_inited) { + if (_inited) { return; } - - // Make the window visible to realize the OpenGL surface. - setVisible(true); - - // Request the focus here as it cannot work when the window is not visible - requestFocus(); - - _canvasRenderer.setContext(getContext()); - - invoke(true, new GLRunnable() { - @Override - public boolean run(GLAutoDrawable glAutoDrawable) { - _canvasRenderer.init(_settings, true);// true - do swap in renderer. - return true; + + // 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 = true; } @@ -77,7 +80,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas { } if (isShowing()) { - invoke(true, _drawerGLRunnable); + invoke(true, _drawerGLRunnable); } if (latch != null) { latch.countDown(); 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 e6d8b00..6618fbf 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 @@ -27,11 +27,11 @@ import com.ardor3d.framework.Scene; import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Camera;
+import com.ardor3d.renderer.Camera.ProjectionMode;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.Renderer;
-import com.ardor3d.renderer.Camera.ProjectionMode;
import com.ardor3d.renderer.jogl.JoglContextCapabilities;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.util.Ardor3dException;
@@ -72,42 +72,45 @@ public class JoglCanvasRenderer implements CanvasRenderer { int value = GLContext.CONTEXT_NOT_CURRENT;
int attempt = 0;
do {
- try {
- value = _context.makeCurrent();
- } catch(GLException gle) {
- gle.printStackTrace();
- } finally {
- attempt++;
- if (attempt == MAX_CONTEXT_GRAB_ATTEMPTS) {
+ try {
+ value = _context.makeCurrent();
+ } catch (final GLException gle) {
+ gle.printStackTrace();
+ } finally {
+ attempt++;
+ if (attempt == MAX_CONTEXT_GRAB_ATTEMPTS) {
// failed, throw exception
throw new Ardor3dException("Failed to claim OpenGL context.");
}
- }
- try {
- Thread.sleep(5);
- } catch (final InterruptedException e1) {
- e1.printStackTrace();
- }
- }
- while(value == GLContext.CONTEXT_NOT_CURRENT);
- if (value == GLContext.CONTEXT_CURRENT_NEW) {
- ContextManager.getCurrentContext().contextLost();
+ }
+ try {
+ Thread.sleep(5);
+ } catch (final InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ } while (value == GLContext.CONTEXT_NOT_CURRENT);
+ if (ContextManager.getCurrentContext() != null) {
+ if (value == GLContext.CONTEXT_CURRENT_NEW) {
+ ContextManager.getCurrentContext().contextLost();
+
+ // Whenever the context is created or replaced, the GL chain
+ // is lost. Debug will have to be added if desired.
+ _debugEnabled = false;
+ }
- // Whenever the context is created or replaced, the GL chain
- // is lost. Debug will have to be added if desired.
- _debugEnabled = false;
+ if (ContextManager.getContextForKey(_context) != null) {
+ ContextManager.switchContext(_context);
+ }
}
-
- ContextManager.switchContext(_context);
}
public void releaseCurrentContext() {
- if (_context.equals(GLContext.getCurrent())) {
+ if (_context.equals(GLContext.getCurrent())) {
try {
- _context.release();
- } catch(GLException gle) {
- gle.printStackTrace();
- }
+ _context.release();
+ } catch (final GLException gle) {
+ gle.printStackTrace();
+ }
}
}
@@ -123,52 +126,53 @@ public class JoglCanvasRenderer implements CanvasRenderer { _context = GLDrawableFactory.getFactory(GLProfile.getMaxFixedFunc(true)).createExternalGLContext();
}
- _context.makeCurrent();
+ makeCurrentContext();
try {
- // Look up a shared context, if a shared JoglCanvasRenderer is given.
- RenderContext sharedContext = null;
- if (settings.getShareContext() != null) {
- sharedContext = ContextManager.getContextForKey(settings.getShareContext().getRenderContext()
- .getContextKey());
- }
-
- final ContextCapabilities caps = createContextCapabilities();
- _currentContext = new RenderContext(_context, caps, sharedContext);
-
- ContextManager.addContext(_context, _currentContext);
- ContextManager.switchContext(_context);
-
- _renderer = new JoglRenderer();
-
- if (settings.getSamples() != 0 && caps.isMultisampleSupported()) {
- final GL gl = GLU.getCurrentGL();
- gl.glEnable(GL.GL_MULTISAMPLE);
- }
-
- _renderer.setBackgroundColor(ColorRGBA.BLACK);
-
- if (_camera == null) {
- /** Set up how our camera sees. */
- _camera = new Camera(settings.getWidth(), settings.getHeight());
- _camera.setFrustumPerspective(45.0f, (float) settings.getWidth() / (float) settings.getHeight(), 1, 1000);
- _camera.setProjectionMode(ProjectionMode.Perspective);
-
- final Vector3 loc = new Vector3(0.0f, 0.0f, 10.0f);
- final Vector3 left = new Vector3(-1.0f, 0.0f, 0.0f);
- final Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
- final Vector3 dir = new Vector3(0.0f, 0f, -1.0f);
- /** Move our camera to a correct place and orientation. */
- _camera.setFrame(loc, left, up, dir);
- } else {
- // use new width and height to set ratio.
- _camera.setFrustumPerspective(_camera.getFovY(),
- (float) settings.getWidth() / (float) settings.getHeight(), _camera.getFrustumNear(), _camera
- .getFrustumFar());
- }
+ // Look up a shared context, if a shared JoglCanvasRenderer is given.
+ RenderContext sharedContext = null;
+ if (settings.getShareContext() != null) {
+ sharedContext = ContextManager.getContextForKey(settings.getShareContext().getRenderContext()
+ .getContextKey());
+ }
+
+ final ContextCapabilities caps = createContextCapabilities();
+ _currentContext = new RenderContext(_context, caps, sharedContext);
+
+ ContextManager.addContext(_context, _currentContext);
+ ContextManager.switchContext(_context);
+
+ _renderer = new JoglRenderer();
+
+ if (settings.getSamples() != 0 && caps.isMultisampleSupported()) {
+ final GL gl = GLU.getCurrentGL();
+ gl.glEnable(GL.GL_MULTISAMPLE);
+ }
+
+ _renderer.setBackgroundColor(ColorRGBA.BLACK);
+
+ if (_camera == null) {
+ /** Set up how our camera sees. */
+ _camera = new Camera(settings.getWidth(), settings.getHeight());
+ _camera.setFrustumPerspective(45.0f, (float) settings.getWidth() / (float) settings.getHeight(), 1,
+ 1000);
+ _camera.setProjectionMode(ProjectionMode.Perspective);
+
+ final Vector3 loc = new Vector3(0.0f, 0.0f, 10.0f);
+ final Vector3 left = new Vector3(-1.0f, 0.0f, 0.0f);
+ final Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
+ final Vector3 dir = new Vector3(0.0f, 0f, -1.0f);
+ /** Move our camera to a correct place and orientation. */
+ _camera.setFrame(loc, left, up, dir);
+ } else {
+ // use new width and height to set ratio.
+ _camera.setFrustumPerspective(_camera.getFovY(),
+ (float) settings.getWidth() / (float) settings.getHeight(), _camera.getFrustumNear(),
+ _camera.getFrustumFar());
+ }
} finally {
- _context.release();
+ releaseCurrentContext();
}
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java new file mode 100644 index 0000000..2a93f38 --- /dev/null +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.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 JoglInitializerRunnable implements Runnable { + + private final JoglAwtCanvas _joglAwtCanvas; + + private final DisplaySettings _settings; + + public JoglInitializerRunnable(final JoglAwtCanvas joglAwtCanvas, final DisplaySettings settings) { + _joglAwtCanvas = joglAwtCanvas; + _settings = settings; + } + + @Override + public void run() { + // Make the window visible to realize the OpenGL surface. + _joglAwtCanvas.setVisible(true); + // Force the realization + _joglAwtCanvas.display(); + if (!_joglAwtCanvas.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 + _joglAwtCanvas.requestFocus(); + // The OpenGL context has been created after the realization of the surface + _joglAwtCanvas.getCanvasRenderer().setContext(_joglAwtCanvas.getContext()); + // As the canvas renderer knows the OpenGL context, it can be initialized + _joglAwtCanvas.getCanvasRenderer().init(_settings, true); + } +}
\ No newline at end of file |