aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl/src/main/java/com
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2014-02-03 22:29:41 +0100
committerJulien Gouesse <[email protected]>2014-02-03 22:29:41 +0100
commitdd5315febdd558070458b2fdd16bc2aed74bcc11 (patch)
tree50ab937d72a338d9a58ed0806c30a386011fbe40 /ardor3d-jogl/src/main/java/com
parentb635e6de0c36f0bc7a4ed4131b3c0b0a4aa762cf (diff)
Adds a canvas based on the JOGL SWT heavyweight GLCanvas into Ardor3D
Diffstat (limited to 'ardor3d-jogl/src/main/java/com')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtCanvas.java105
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtInitializerRunnable.java42
2 files changed, 147 insertions, 0 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtCanvas.java
new file mode 100644
index 0000000..a659d49
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtCanvas.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2008-2014 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 java.util.concurrent.CountDownLatch;
+
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLRunnable;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+import com.ardor3d.annotation.MainThread;
+import com.ardor3d.framework.Canvas;
+import com.ardor3d.framework.DisplaySettings;
+import com.jogamp.opengl.swt.GLCanvas;
+
+/**
+ * Ardor3D JOGL SWT heavyweight canvas, SWT control for the OpenGL rendering of Ardor3D with JOGL that supports the SWT
+ * input system directly and its abstraction in Ardor3D (com.ardor3d.input.swt)
+ */
+public class JoglSwtCanvas extends GLCanvas implements Canvas {
+
+ private final JoglCanvasRenderer _canvasRenderer;
+ private boolean _inited = false;
+
+ private final DisplaySettings _settings;
+
+ private final JoglDrawerRunnable _drawerGLRunnable;
+
+ private final JoglSwtInitializerRunnable _initializerRunnable;
+
+ public JoglSwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer,
+ final Composite composite, final int style) {
+ this(settings, canvasRenderer, new CapsUtil(), composite, style);
+ }
+
+ public JoglSwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer,
+ final CapsUtil capsUtil, final Composite composite, final int style) {
+ super(composite, style, capsUtil.getCapsForSettings(settings), null);
+ _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer);
+ _initializerRunnable = new JoglSwtInitializerRunnable(this, settings);
+ _settings = settings;
+ _canvasRenderer = canvasRenderer;
+
+ setFocus();
+ setSize(_settings.getWidth(), _settings.getHeight());
+ setAutoSwapBufferMode(false);
+ }
+
+ @Override
+ @MainThread
+ public void init() {
+ if (_inited) {
+ return;
+ }
+
+ // if we aren't on SWT user interface thread
+ if (Display.getCurrent() == null) {
+ Display.getDefault().syncExec(_initializerRunnable);
+ } else {
+ _initializerRunnable.run();
+ }
+
+ _inited = isRealized();
+ }
+
+ @Override
+ public void draw(final CountDownLatch latch) {
+ if (!_inited) {
+ init();
+ }
+
+ if (isVisible()) {
+ 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;
+ }
+ });
+ }
+
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtInitializerRunnable.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtInitializerRunnable.java
new file mode 100644
index 0000000..f580221
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglSwtInitializerRunnable.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 JoglSwtInitializerRunnable implements Runnable {
+
+ private final JoglSwtCanvas _joglSwtCanvas;
+
+ private final DisplaySettings _settings;
+
+ public JoglSwtInitializerRunnable(final JoglSwtCanvas joglSwtCanvas, final DisplaySettings settings) {
+ _joglSwtCanvas = joglSwtCanvas;
+ _settings = settings;
+ }
+
+ @Override
+ public void run() {
+ // Make the window visible to realize the OpenGL surface.
+ _joglSwtCanvas.setVisible(true);
+ // Force the realization
+ _joglSwtCanvas.display();
+ if (_joglSwtCanvas.getDelegatedDrawable().isRealized()) {
+ // Request the focus here as it cannot work when the window is not visible
+ _joglSwtCanvas.setFocus();
+ // The OpenGL context has been created after the realization of the surface
+ _joglSwtCanvas.getCanvasRenderer().setContext(_joglSwtCanvas.getContext());
+ // As the canvas renderer knows the OpenGL context, it can be initialized
+ _joglSwtCanvas.getCanvasRenderer().init(_settings, true);
+ }
+ }
+
+}