diff options
author | Billy Biggs <bbiggs> | 2005-09-12 19:06:29 +0000 |
---|---|---|
committer | Billy Biggs <bbiggs> | 2005-09-12 19:06:29 +0000 |
commit | 8d760222238ab1b6818bb0321d0416a8678a608d (patch) | |
tree | eef8f7f7dbbc3d9e6450d824cf68e28b0cbdeb2c /bundles/org.eclipse.swt.opengl | |
parent | 23f757176a8d3abfea06e74cb18d8bda8c4c4100 (diff) | |
download | eclipse.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')
13 files changed, 565 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt.opengl/.classpath_carbon b/bundles/org.eclipse.swt.opengl/.classpath_carbon new file mode 100755 index 0000000000..027aa0d963 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/.classpath_carbon @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/> + <classpathentry kind="src" path="common"/> + <classpathentry kind="src" path="carbon"> + <attributes> + <attribute value="org.eclipse.swt.opengl.carbon" name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="/org.eclipse.swt"/> + <classpathentry kind="output" path="bin"/> +</classpath>
\ No newline at end of file diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/agl.c b/bundles/org.eclipse.swt.opengl/carbon/library/agl.c new file mode 100644 index 0000000000..ce3bfc6480 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/agl.c @@ -0,0 +1,159 @@ +/******************************************************************************* +* 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 +*******************************************************************************/ + +#include "swt.h" +#include "agl_structs.h" +#include "agl_stats.h" + +#define AGL_NATIVE(func) Java_org_eclipse_swt_internal_opengl_carbon_AGL_##func + +#ifndef NO_aglChoosePixelFormat +JNIEXPORT jint JNICALL AGL_NATIVE(aglChoosePixelFormat) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2) +{ + jint *lparg2=NULL; + jint rc = 0; + AGL_NATIVE_ENTER(env, that, aglChoosePixelFormat_FUNC); + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)aglChoosePixelFormat(arg0, arg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + AGL_NATIVE_EXIT(env, that, aglChoosePixelFormat_FUNC); + return rc; +} +#endif + +#ifndef NO_aglCreateContext +JNIEXPORT jint JNICALL AGL_NATIVE(aglCreateContext) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + jint rc = 0; + AGL_NATIVE_ENTER(env, that, aglCreateContext_FUNC); + rc = (jint)aglCreateContext(arg0, arg1); + AGL_NATIVE_EXIT(env, that, aglCreateContext_FUNC); + return rc; +} +#endif + +#ifndef NO_aglDescribePixelFormat +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglDescribePixelFormat) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2) +{ + jint *lparg2=NULL; + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglDescribePixelFormat_FUNC); + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jboolean)aglDescribePixelFormat(arg0, arg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + AGL_NATIVE_EXIT(env, that, aglDescribePixelFormat_FUNC); + return rc; +} +#endif + +#ifndef NO_aglDestroyContext +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglDestroyContext) + (JNIEnv *env, jclass that, jint arg0) +{ + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglDestroyContext_FUNC); + rc = (jboolean)aglDestroyContext(arg0); + AGL_NATIVE_EXIT(env, that, aglDestroyContext_FUNC); + return rc; +} +#endif + +#ifndef NO_aglEnable +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglEnable) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglEnable_FUNC); + rc = (jboolean)aglEnable(arg0, arg1); + AGL_NATIVE_EXIT(env, that, aglEnable_FUNC); + return rc; +} +#endif + +#ifndef NO_aglGetCurrentContext +JNIEXPORT jint JNICALL AGL_NATIVE(aglGetCurrentContext) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + AGL_NATIVE_ENTER(env, that, aglGetCurrentContext_FUNC); + rc = (jint)aglGetCurrentContext(); + AGL_NATIVE_EXIT(env, that, aglGetCurrentContext_FUNC); + return rc; +} +#endif + +#ifndef NO_aglSetCurrentContext +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglSetCurrentContext) + (JNIEnv *env, jclass that, jint arg0) +{ + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglSetCurrentContext_FUNC); + rc = (jboolean)aglSetCurrentContext(arg0); + AGL_NATIVE_EXIT(env, that, aglSetCurrentContext_FUNC); + return rc; +} +#endif + +#ifndef NO_aglSetDrawable +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglSetDrawable) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglSetDrawable_FUNC); + rc = (jboolean)aglSetDrawable(arg0, arg1); + AGL_NATIVE_EXIT(env, that, aglSetDrawable_FUNC); + return rc; +} +#endif + +#ifndef NO_aglSetInteger +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglSetInteger) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2) +{ + jint *lparg2=NULL; + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglSetInteger_FUNC); + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jboolean)aglSetInteger(arg0, arg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + AGL_NATIVE_EXIT(env, that, aglSetInteger_FUNC); + return rc; +} +#endif + +#ifndef NO_aglSwapBuffers +JNIEXPORT void JNICALL AGL_NATIVE(aglSwapBuffers) + (JNIEnv *env, jclass that, jint arg0) +{ + AGL_NATIVE_ENTER(env, that, aglSwapBuffers_FUNC); + aglSwapBuffers(arg0); + AGL_NATIVE_EXIT(env, that, aglSwapBuffers_FUNC); +} +#endif + +#ifndef NO_aglUpdateContext +JNIEXPORT jboolean JNICALL AGL_NATIVE(aglUpdateContext) + (JNIEnv *env, jclass that, jint arg0) +{ + jboolean rc = 0; + AGL_NATIVE_ENTER(env, that, aglUpdateContext_FUNC); + rc = (jboolean)aglUpdateContext(arg0); + AGL_NATIVE_EXIT(env, that, aglUpdateContext_FUNC); + return rc; +} +#endif + diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/agl.h b/bundles/org.eclipse.swt.opengl/carbon/library/agl.h new file mode 100644 index 0000000000..9a87d429a7 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/agl.h @@ -0,0 +1,3 @@ + +#include <OpenGL/gl.h> + diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.c b/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.c new file mode 100644 index 0000000000..2178ccbd78 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.c @@ -0,0 +1,53 @@ +/******************************************************************************* +* 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 +*******************************************************************************/ + +#include "swt.h" +#include "agl_stats.h" + +#ifdef NATIVE_STATS + +int AGL_nativeFunctionCount = 11; +int AGL_nativeFunctionCallCount[11]; +char * AGL_nativeFunctionNames[] = { + "aglChoosePixelFormat", + "aglCreateContext", + "aglDescribePixelFormat", + "aglDestroyContext", + "aglEnable", + "aglGetCurrentContext", + "aglSetCurrentContext", + "aglSetDrawable", + "aglSetInteger", + "aglSwapBuffers", + "aglUpdateContext", +}; + +#define STATS_NATIVE(func) Java_org_eclipse_swt_tools_internal_NativeStats_##func + +JNIEXPORT jint JNICALL STATS_NATIVE(AGL_1GetFunctionCount) + (JNIEnv *env, jclass that) +{ + return AGL_nativeFunctionCount; +} + +JNIEXPORT jstring JNICALL STATS_NATIVE(AGL_1GetFunctionName) + (JNIEnv *env, jclass that, jint index) +{ + return (*env)->NewStringUTF(env, AGL_nativeFunctionNames[index]); +} + +JNIEXPORT jint JNICALL STATS_NATIVE(AGL_1GetFunctionCallCount) + (JNIEnv *env, jclass that, jint index) +{ + return AGL_nativeFunctionCallCount[index]; +} + +#endif diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.h b/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.h new file mode 100644 index 0000000000..28d1639d03 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/agl_stats.h @@ -0,0 +1,35 @@ +/******************************************************************************* +* 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 +*******************************************************************************/ + +#ifdef NATIVE_STATS +extern int AGL_nativeFunctionCount; +extern int AGL_nativeFunctionCallCount[]; +extern char* AGL_nativeFunctionNames[]; +#define AGL_NATIVE_ENTER(env, that, func) AGL_nativeFunctionCallCount[func]++; +#define AGL_NATIVE_EXIT(env, that, func) +#else +#define AGL_NATIVE_ENTER(env, that, func) +#define AGL_NATIVE_EXIT(env, that, func) +#endif + +typedef enum { + aglChoosePixelFormat_FUNC, + aglCreateContext_FUNC, + aglDescribePixelFormat_FUNC, + aglDestroyContext_FUNC, + aglEnable_FUNC, + aglGetCurrentContext_FUNC, + aglSetCurrentContext_FUNC, + aglSetDrawable_FUNC, + aglSetInteger_FUNC, + aglSwapBuffers_FUNC, + aglUpdateContext_FUNC, +} AGL_FUNCS; diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/agl_structs.h b/bundles/org.eclipse.swt.opengl/carbon/library/agl_structs.h new file mode 100644 index 0000000000..36531f5373 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/agl_structs.h @@ -0,0 +1,13 @@ +/******************************************************************************* +* 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 +*******************************************************************************/ + +#include "agl.h" + diff --git a/bundles/org.eclipse.swt.opengl/carbon/library/build.sh b/bundles/org.eclipse.swt.opengl/carbon/library/build.sh new file mode 100755 index 0000000000..dc26d12412 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/library/build.sh @@ -0,0 +1,29 @@ +#!/bin/sh +#******************************************************************************* +# 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 +#******************************************************************************* + +if [ "${OS}" = "" ]; then + OS=`uname -s` +fi + +case $OS in + "Linux") + makefile="make_linux.mak" + echo "Building Linux GTK version of SWT OpenGL" + ;; + *) + echo "*** Unknown OS <${OS}>" + ;; +esac + +export JAVA_HOME + +make -f $makefile ${1+"$@"} diff --git a/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/internal/opengl/carbon/AGL.java b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/internal/opengl/carbon/AGL.java new file mode 100644 index 0000000000..2aa8e29257 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/internal/opengl/carbon/AGL.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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.internal.opengl.carbon; + +import org.eclipse.swt.opengl.Library; + +public class AGL { + +static { + Library.loadLibrary("gl"); +} + +public static final int AGL_NONE = 0; +public static final int AGL_BUFFER_SIZE = 2; +public static final int AGL_LEVEL = 3; +public static final int AGL_RGBA = 4; +public static final int AGL_DOUBLEBUFFER = 5; +public static final int AGL_STEREO = 6; +public static final int AGL_AUX_BUFFERS = 7; +public static final int AGL_RED_SIZE = 8; +public static final int AGL_GREEN_SIZE = 9; +public static final int AGL_BLUE_SIZE = 10; +public static final int AGL_ALPHA_SIZE = 11; +public static final int AGL_DEPTH_SIZE = 12; +public static final int AGL_STENCIL_SIZE = 13; +public static final int AGL_ACCUM_RED_SIZE = 14; +public static final int AGL_ACCUM_GREEN_SIZE = 15; +public static final int AGL_ACCUM_BLUE_SIZE = 16; +public static final int AGL_ACCUM_ALPHA_SIZE = 17; + +public static final int AGL_SAMPLE_BUFFERS_ARB = 55; +public static final int AGL_SAMPLES_ARB = 56; + +public static final int AGL_BUFFER_RECT = 202; +public static final int AGL_CLIP_REGION = 254; + +public static final native int aglChoosePixelFormat(int gdevs, int ndev, int[] attribs); +public static final native int aglCreateContext(int pix, int share); +public static final native boolean aglDescribePixelFormat(int pix, int attrib, int[] value); +public static final native boolean aglDestroyContext(int ctx); +public static final native boolean aglEnable(int ctx, int pname); +public static final native int aglGetCurrentContext(); +public static final native boolean aglSetCurrentContext(int ctx); +public static final native boolean aglSetDrawable(int ctx, int draw); +public static final native boolean aglSetInteger(int ctx, int pname, int[] params); +public static final native void aglSwapBuffers(int ctx); +public static final native boolean aglUpdateContext(int ctx); +}
\ No newline at end of file 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); +} +} diff --git a/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLFormatData.java b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLFormatData.java new file mode 100644 index 0000000000..d0aa927c57 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLFormatData.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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; + +public class GLFormatData { + public int bufferSize; + public boolean doubleBuffer; + public boolean stereo; + public int redSize; + public int greenSize; + public int blueSize; + public int alphaSize; + public int depthSize; + public int stencilSize; + public int accumRedSize; + public int accumGreenSize; + public int accumBlueSize; + public int accumAlphaSize; + public int sampleBuffers; + public int samples; +} diff --git a/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLPBuffer.java b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLPBuffer.java new file mode 100644 index 0000000000..53ebf1c7c1 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/carbon/org/eclipse/swt/opengl/GLPBuffer.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * 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 GLPBuffer { + int glContext; + static final int MAX_ATTRIBUTES = 32; + +public GLPBuffer (int width, int height, GLFormatData attributes) { + if (attributes == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + int aglAttrib [] = new int [MAX_ATTRIBUTES]; + int pos = 0; + aglAttrib [pos++] = 4; + aglAttrib [pos++] = 5; + aglAttrib [pos++] = 12; + aglAttrib [pos++] = 16; + aglAttrib [pos++] = 0; + int pixelFormat = AGL.aglChoosePixelFormat(0, 0, aglAttrib); + glContext = AGL.aglCreateContext(pixelFormat, 0); + //create the pbuffer for this context + +// System.out.println("context: " + glContext); +// int window = OS.GetControlOwner(handle); +// int port = OS.GetWindowPort(window); +// System.out.println("setdrawable: " + AGL.aglSetDrawable(glContext, port)); +} + +public boolean isCurrent () { + return AGL.aglGetCurrentContext () == glContext; +} + +public void setCurrent () { + if (AGL.aglGetCurrentContext () == glContext) return; + AGL.aglSetCurrentContext (glContext); +} + +} diff --git a/bundles/org.eclipse.swt.opengl/common/library/gl.h b/bundles/org.eclipse.swt.opengl/common/library/gl.h index 4fb1ae239f..c8f0a1251a 100644 --- a/bundles/org.eclipse.swt.opengl/common/library/gl.h +++ b/bundles/org.eclipse.swt.opengl/common/library/gl.h @@ -1,6 +1,10 @@ +#ifdef __APPLE__ +#include <OpenGL/gl.h> +#else #ifdef WIN32 #include <windows.h> #endif #include <GL/gl.h> +#endif extern int IS_JNI_1_2; diff --git a/bundles/org.eclipse.swt.opengl/common/library/glu.h b/bundles/org.eclipse.swt.opengl/common/library/glu.h index 9ec3bbb147..96f8b03c23 100644 --- a/bundles/org.eclipse.swt.opengl/common/library/glu.h +++ b/bundles/org.eclipse.swt.opengl/common/library/glu.h @@ -1,6 +1,10 @@ +#ifdef __APPLE__ +#include <OpenGL/glu.h> +#else #ifdef WIN32 #include <windows.h> #endif #include <GL/glu.h> +#endif extern int IS_JNI_1_2; |