From ac37f3c90aab60ff11d89f3bafcc4e7e1f5782ce Mon Sep 17 00:00:00 2001 From: enjalot <enjalot+github@gmail.com> Date: Thu, 17 Feb 2011 17:07:42 -0500 Subject: [PATCH] 2nd round of Mac OS X GL context sharing --- examples/gl_interop_demo.py | 11 ++++++++--- pyopencl/tools.py | 2 +- src/wrapper/wrap_cl.hpp | 24 +++++++++++++----------- src/wrapper/wrap_constants.cpp | 6 +++--- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/gl_interop_demo.py b/examples/gl_interop_demo.py index 3a18c648..964682bb 100644 --- a/examples/gl_interop_demo.py +++ b/examples/gl_interop_demo.py @@ -24,9 +24,14 @@ def initialize(): plats = cl.get_platforms() from pyopencl.tools import get_gl_sharing_context_properties - ctx = cl.Context(properties=[ - (cl.context_properties.PLATFORM, plats[0])] - + get_gl_sharing_context_properties()) + import sys + if sys.platform == "darwin": + ctx = cl.Context(properties=get_gl_sharing_context_properties(), + devices=[]) + else: + ctx = cl.Context(properties=[ + (cl.context_properties.PLATFORM, plats[0])] + + get_gl_sharing_context_properties()) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) diff --git a/pyopencl/tools.py b/pyopencl/tools.py index 40e2b411..0bdfa292 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -271,7 +271,7 @@ def get_gl_sharing_context_properties(): WGL.wglGetCurrentDC())) elif sys.platform == "darwin": props.append( - (ctx_props.USE_CGL_SHAREGROUP_APPLE, cl. get_apple_cgl_share_group())) + (ctx_props.CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, cl.get_apple_cgl_share_group())) 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 2460b497..60edadd3 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -2,8 +2,6 @@ #define _AFJHAYYTA_PYOPENCL_HEADER_SEEN_CL_HPP - - // {{{ includes #ifdef __APPLE__ @@ -660,6 +658,8 @@ namespace pyopencl case CL_GLX_DISPLAY_KHR: case CL_WGL_HDC_KHR: case CL_CGL_SHAREGROUP_KHR: +#elif defined(__APPLE__) && defined(HAVE_GL) + case CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE: #endif value = py::object(result[i+1]); break; @@ -715,11 +715,22 @@ namespace pyopencl reinterpret_cast<cl_context_properties>(value().data())); } #if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1) +#if defined(_WIN32) + else if (prop == CL_WGL_HDC_KHR) + { + // size_t is a stand-in for HANDLE, hopefully has the same size. + size_t hnd = py::extract<size_t>(prop_tuple[1]); + props.push_back(hnd); + } +#endif else if (prop == CL_GL_CONTEXT_KHR || prop == CL_EGL_DISPLAY_KHR || prop == CL_GLX_DISPLAY_KHR || prop == CL_CGL_SHAREGROUP_KHR ) +#elif defined(__APPLE__) && defined(HAVE_GL) + else if(prop == CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) +#endif { py::object ctypes = py::import("ctypes"); py::object prop = prop_tuple[1], c_void_p = ctypes.attr("c_void_p"); @@ -727,15 +738,6 @@ namespace pyopencl py::extract<cl_context_properties> value(ptr.attr("value")); props.push_back(value); } -#if defined(_WIN32) - else if (prop == CL_WGL_HDC_KHR) - { - // size_t is a stand-in for HANDLE, hopefully has the same size. - size_t hnd = py::extract<size_t>(prop_tuple[1]); - props.push_back(hnd); - } -#endif -#endif else throw error("Context", CL_INVALID_VALUE, "invalid context property"); } diff --git a/src/wrapper/wrap_constants.cpp b/src/wrapper/wrap_constants.cpp index 9104618e..94df0cf4 100644 --- a/src/wrapper/wrap_constants.cpp +++ b/src/wrapper/wrap_constants.cpp @@ -262,10 +262,10 @@ void pyopencl_expose_constants() ADD_ATTR( ,GLX_DISPLAY_KHR); ADD_ATTR( ,WGL_HDC_KHR); ADD_ATTR( ,CGL_SHAREGROUP_KHR); -#ifdef __APPLE__ - ADD_ATTR( ,CGL_SHAREGROUP_APPLE); -#endif /* __APPLE__ */ #endif +#ifdef __APPLE__ && defined(HAVE_GL) + ADD_ATTR( ,CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE); +#endif /* __APPLE__ */ } { -- GitLab