aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl/src/main/java/com/ardor3d
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2014-01-29 00:06:13 +0100
committerJulien Gouesse <[email protected]>2014-01-29 00:06:13 +0100
commite7135433bc0623f838186f27dee81148e8e063fa (patch)
treed0dccf5ec8b1c545a51f4482e37cd2f9710941e7 /ardor3d-jogl/src/main/java/com/ardor3d
parentcf16e3f1886f3746f5b176ab65a576dcb40cb182 (diff)
Adds the very first blueprint of JoglNewtSwtCanvas into the JogAmp backend
Diffstat (limited to 'ardor3d-jogl/src/main/java/com/ardor3d')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtSwtCanvas.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtSwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtSwtCanvas.java
new file mode 100644
index 0000000..f75367d
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtSwtCanvas.java
@@ -0,0 +1,108 @@
+/**
+ * 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 java.util.concurrent.CountDownLatch;
+
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLRunnable;
+
+import org.eclipse.swt.widgets.Composite;
+
+import com.ardor3d.annotation.MainThread;
+import com.ardor3d.framework.Canvas;
+import com.ardor3d.framework.DisplaySettings;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.swt.NewtCanvasSWT;
+
+public class JoglNewtSwtCanvas extends NewtCanvasSWT implements Canvas, NewtWindowContainer {
+
+ private final JoglCanvasRenderer _canvasRenderer;
+ private boolean _inited = false;
+
+ private final DisplaySettings _settings;
+
+ private final JoglDrawerRunnable _drawerGLRunnable;
+
+ public JoglNewtSwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer,
+ final Composite composite, final int style) {
+ this(settings, canvasRenderer, new CapsUtil(), composite, style);
+ }
+
+ public JoglNewtSwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer,
+ final CapsUtil capsUtil, final Composite composite, final int style) {
+ super(composite, style, GLWindow.create(capsUtil.getCapsForSettings(settings)));
+ _drawerGLRunnable = new JoglDrawerRunnable(canvasRenderer);
+ getNewtWindow().setUndecorated(true);
+ _settings = settings;
+ _canvasRenderer = canvasRenderer;
+
+ setSize(_settings.getWidth(), _settings.getHeight());
+ getNewtWindow().setAutoSwapBufferMode(false);
+ }
+
+ @Override
+ @MainThread
+ public void init() {
+ if (_inited) {
+ return;
+ }
+
+ // Make the window visible to realize the OpenGL surface.
+ setVisible(true);
+ if (getNewtWindow().isRealized()) {
+ _canvasRenderer.setContext(getNewtWindow().getContext());
+ getNewtWindow().invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ _canvasRenderer.init(_settings, true);// true - do swap in renderer.
+ return true;
+ }
+ });
+ _inited = true;
+ }
+ }
+
+ @Override
+ public void draw(final CountDownLatch latch) {
+ if (!_inited) {
+ init();
+ }
+
+ if (isVisible()) {
+ getNewtWindow().invoke(true, _drawerGLRunnable);
+ }
+ if (latch != null) {
+ latch.countDown();
+ }
+ }
+
+ @Override
+ public JoglCanvasRenderer getCanvasRenderer() {
+ return _canvasRenderer;
+ }
+
+ @Override
+ public GLWindow getNewtWindow() {
+ return (GLWindow) getNEWTChild();
+ }
+
+ public void setVSyncEnabled(final boolean enabled) {
+ getNewtWindow().invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0);
+ return false;
+ }
+ });
+ }
+
+}