Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBilly Biggs2005-09-12 19:06:29 +0000
committerBilly Biggs2005-09-12 19:06:29 +0000
commit8d760222238ab1b6818bb0321d0416a8678a608d (patch)
treeeef8f7f7dbbc3d9e6450d824cf68e28b0cbdeb2c /bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java
parent23f757176a8d3abfea06e74cb18d8bda8c4c4100 (diff)
downloadeclipse.platform.swt-8d760222238ab1b6818bb0321d0416a8678a608d.tar.gz
eclipse.platform.swt-8d760222238ab1b6818bb0321d0416a8678a608d.tar.xz
eclipse.platform.swt-8d760222238ab1b6818bb0321d0416a8678a608d.zip
87503 - Implement OSX opengl binding
Diffstat (limited to 'bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java')
-rwxr-xr-xbundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java
new file mode 100755
index 0000000000..5fc3576ac2
--- /dev/null
+++ b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLCanvas.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.opengl;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.internal.carbon.*;
+import org.eclipse.swt.internal.opengl.carbon.*;
+
+public class GLCanvas extends Canvas {
+ int glContext;
+ static final int MAX_ATTRIBUTES = 32;
+
+public GLCanvas (Composite parent, int style, GLFormatData data) {
+ super (parent, style);
+ if (data == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ int aglAttrib [] = new int [MAX_ATTRIBUTES];
+ int pos = 0;
+ aglAttrib [pos++] = AGL.AGL_RGBA;
+ if (data.doubleBuffer) aglAttrib [pos++] = AGL.AGL_DOUBLEBUFFER;
+ if (data.stereo) aglAttrib [pos++] = AGL.AGL_STEREO;
+ if (data.redSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_RED_SIZE;
+ aglAttrib [pos++] = data.redSize;
+ }
+ if (data.greenSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_GREEN_SIZE;
+ aglAttrib [pos++] = data.greenSize;
+ }
+ if (data.blueSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_BLUE_SIZE;
+ aglAttrib [pos++] = data.blueSize;
+ }
+ if (data.depthSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_DEPTH_SIZE;
+ aglAttrib [pos++] = data.depthSize;
+ }
+ if (data.stencilSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_STENCIL_SIZE;
+ aglAttrib [pos++] = data.stencilSize;
+ }
+ if (data.accumRedSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_ACCUM_RED_SIZE;
+ aglAttrib [pos++] = data.accumRedSize;
+ }
+ if (data.accumGreenSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_ACCUM_GREEN_SIZE;
+ aglAttrib [pos++] = data.accumGreenSize;
+ }
+ if (data.accumBlueSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_ACCUM_BLUE_SIZE;
+ aglAttrib [pos++] = data.accumBlueSize;
+ }
+ if (data.accumAlphaSize > 0) {
+ aglAttrib [pos++] = AGL.AGL_ACCUM_ALPHA_SIZE;
+ aglAttrib [pos++] = data.accumAlphaSize;
+ }
+ if (data.sampleBuffers > 0) {
+ aglAttrib [pos++] = AGL.AGL_SAMPLE_BUFFERS_ARB;
+ aglAttrib [pos++] = data.sampleBuffers;
+ }
+ if (data.samples > 0) {
+ aglAttrib [pos++] = AGL.AGL_SAMPLES_ARB;
+ aglAttrib [pos++] = data.samples;
+ }
+ aglAttrib [pos++] = AGL.AGL_NONE;
+ int pixelFormat = AGL.aglChoosePixelFormat (0, 0, aglAttrib);
+ glContext = AGL.aglCreateContext (pixelFormat, 0);
+ int window = OS.GetControlOwner (handle);
+ int port = OS.GetWindowPort (window);
+ AGL.aglSetDrawable (glContext, port);
+
+ Listener listener = new Listener () {
+ public void handleEvent (Event event) {
+ switch (event.type) {
+ case SWT.Resize: handleResize (event); break;
+ }
+ }
+ };
+ addListener (SWT.Resize, listener);
+}
+
+void handleResize (Event event) {
+ Rectangle bounds = getBounds ();
+ AGL.aglUpdateContext (glContext);
+ int[] glbounds = new int[4];
+ glbounds[0] = bounds.x;
+ glbounds[1] = bounds.y;
+ glbounds[2] = bounds.width;
+ glbounds[3] = bounds.height;
+ AGL.aglSetInteger (glContext, AGL.AGL_BUFFER_RECT, glbounds);
+ AGL.aglEnable (glContext, AGL.AGL_BUFFER_RECT);
+}
+
+public boolean isCurrent () {
+ return AGL.aglGetCurrentContext () == glContext;
+}
+
+public void setCurrent () {
+ if (AGL.aglGetCurrentContext () == glContext) return;
+ AGL.aglSetCurrentContext (glContext);
+}
+
+public void swapBuffers () {
+ AGL.aglSwapBuffers (glContext);
+}
+}

Back to the top