diff --git a/src/java/org/lwjgl/opengl/ContextGL.java b/src/java/org/lwjgl/opengl/ContextGL.java index 41e73566..3ab1df2d 100644 --- a/src/java/org/lwjgl/opengl/ContextGL.java +++ b/src/java/org/lwjgl/opengl/ContextGL.java @@ -36,6 +36,7 @@ import org.lwjgl.LWJGLUtil; import org.lwjgl.PointerBuffer; import org.lwjgl.Sys; import org.lwjgl.opencl.KHRGLSharing; +import org.lwjgl.opencl.APPLEGLSharing; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -275,8 +276,16 @@ final class ContextGL implements Context { properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR).put(implLinux.getGLXContext(handle)); properties.put(KHRGLSharing.CL_GLX_DISPLAY_KHR).put(implLinux.getDisplay(peer_handle)); break; + case LWJGLUtil.PLATFORM_MACOSX: + if (LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6)) { // only supported on OS X 10.6+ + // http://oscarbg.blogspot.com/2009/10/about-opencl-opengl-interop.html + final MacOSXContextImplementation implMacOSX = (MacOSXContextImplementation)implementation; + final long CGLShareGroup = implMacOSX.getCGLShareGroup(handle); + properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE).put(CGLShareGroup); + break; + } default: - throw new UnsupportedOperationException("CL/GL context sharing is not supposed on this platform."); + throw new UnsupportedOperationException("CL/GL context sharing is not supported on this platform."); } } finally { peer_info.unlock(); diff --git a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java index fae1f7d1..c47d8c87 100644 --- a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java +++ b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java @@ -63,6 +63,8 @@ final class MacOSXContextImplementation implements ContextImplementation { } } + native long getCGLShareGroup(ByteBuffer context_handle); + private static native void nSwapBuffers(ByteBuffer context_handle) throws LWJGLException; public void update(ByteBuffer context_handle) { diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m index 5de60559..aecebe1c 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m @@ -38,6 +38,9 @@ */ #import +#import +#import +#import #import #import "org_lwjgl_opengl_MacOSXContextImplementation.h" #import "context.h" @@ -78,6 +81,16 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nCre return context_handle; } +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_getCGLShareGroup + (JNIEnv *env, jclass clazz, jobject context_handle) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + MacOSXContext *context_info = (MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle); + CGLContextObj cgl_context = [context_info->context CGLContextObj]; + CGLShareGroupObj share_group = CGLGetShareGroup(cgl_context); + [pool release]; + return share_group; +} + JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nSwapBuffers (JNIEnv *env, jclass clazz, jobject context_handle) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];