From c7004c8901e299019b612aa90a99803b78025ba7 Mon Sep 17 00:00:00 2001 From: enjalot <enjalot+github@gmail.com> Date: Wed, 16 Feb 2011 23:25:59 -0500 Subject: [PATCH] Added support for GL context sharing on Mac OS X --- examples/gl_interop_demo.py | 9 +++++++-- src/wrapper/wrap_cl.hpp | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/gl_interop_demo.py b/examples/gl_interop_demo.py index 8b1e248e..09a0e65c 100644 --- a/examples/gl_interop_demo.py +++ b/examples/gl_interop_demo.py @@ -25,18 +25,23 @@ def initialize(): plats = cl.get_platforms() ctx_props = cl.context_properties - props = [(ctx_props.PLATFORM, plats[0]), - (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())] + props = [(ctx_props.PLATFORM, plats[0])] import sys if sys.platform == "linux2": + props.append( + (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())) props.append( (ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": + props.append( + (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())) props.append( (ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) + elif sys.platform == "darwin": + pass else: raise NotImplementedError("platform '%s' not yet supported" % sys.platform) diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 4f07f1d7..533074c4 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -10,6 +10,7 @@ // Mac ------------------------------------------------------------------------ #include <OpenCL/opencl.h> #ifdef HAVE_GL +#include <OpenGL/OpenGL.h> #include <OpenCL/cl_gl.h> #include <OpenCL/cl_gl_ext.h> #endif @@ -786,6 +787,20 @@ namespace pyopencl // from dev_type else { +#ifdef __APPLE__ + //If the user passes in no devices we assume GL context sharing for Apple + CGLContextObj kCGLContext = CGLGetCurrentContext(); + CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext); + cl_context_properties propsarr[] = + { + CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, + 0 + }; + + ctx = clCreateContext(propsarr, 0, 0, NULL, NULL, &status_code); + + PYOPENCL_PRINT_CALL_TRACE("clCreateContext Apple GL Sharing"); +#else cl_device_type dev_type = CL_DEVICE_TYPE_DEFAULT; if (py_dev_type.ptr() != Py_None) dev_type = py::extract<cl_device_type>(py_dev_type)(); @@ -793,6 +808,7 @@ namespace pyopencl ctx = clCreateContextFromType(props_ptr, dev_type, 0, 0, &status_code); PYOPENCL_PRINT_CALL_TRACE("clCreateContextFromType"); +#endif } if (status_code != CL_SUCCESS) -- GitLab