如何在OSX上使用glfw3在OpenGL和OpenCL之间创建共享上下文?

如何在OSX上使用glfw3在OpenGL和OpenCL之间创建共享上下文?

问题描述:

我正在使用OpenGL和OpenCL构建粒子系统。我需要在OpenGL和OpenCL之间共享VBO,因此创建一个具有相应属性的OpenCL上下文。

I am building a particle system using OpenGL and OpenCL. I need to share VBOs between OpenGL and OpenCL and therefore create an OpenCL context with the appropriate properties.

我知道glfw3暴露了一些本机API函数,了解如何访问CGL。

I am aware that glfw3 exposes some native API functions however I can't figure out how to access the CGL ones.

https://github.com/glfw/glfw/blob/master/include/GLFW/glfw3native.h

我基本上需要找到如何使用glfw3运行这个:

I basically need to find how to run this with glfw3:

CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);

cl_context_properties properties[] =
{
    CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
    (cl_context_properties)kCGLShareGroup,
    0
};

问题也是在glfw github上讨论,但是没有回答OSX的问题。

The problem is also discussed on the glfw github but doesn't answer the question for OSX.

请参阅

Please take a look at my answer to a similar post.

其实你不需要 glfw3

In fact you don't need glfw3's methods to access the current OpenGL context. Just #include the following header files and you should be good to go with your example code.

#include <OpenCL/opencl.h>
#include <OpenGL/OpenGL.h>