How can I create an shared context between OpenGL and OpenCL with glfw3 on OSX?

扶醉桌前 提交于 2019-12-12 10:15:44

问题


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.

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

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
};

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


回答1:


The documentation for glfw3native.h is here: http://www.glfw.org/docs/latest/glfw3native_8h.html

I'm not familiar with OSX, but I'm assuming you'll want to use glfwGetNSGLContext to get the GL context. I believe you can still use CGLGetCurrentContext even if you are using GLFW, and it appears you'll still have to use CGLGetShareGroup anyway.




回答2:


One option is to use the opengl_create_shared_context() function provided by the Boost.Compute library. This function takes care of handling the platform-specific issues involved when creating a shared OpenCL-OpenGL context.




回答3:


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

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>


来源:https://stackoverflow.com/questions/28955023/how-can-i-create-an-shared-context-between-opengl-and-opencl-with-glfw3-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!