如何基于Mac OS X上的OpenGL上下文创建OpenCL上下文 [英] How to create OpenCL context based on the openGL context on mac os x
问题描述
我创建一个有关Mac OS X上的粒子系统项目。我发现在互联网上类似的问题,我的问题是一样的<一个href=\"http://stackoverflow.com/questions/28955023/how-can-i-create-an-shared-context-between-opengl-and-opencl-with-glfw3-on-osx\">How我可以创建的OpenGL和OpenCL之间的共享上下文与OSX glfw3?
,但我仍然没有解决我的问题呢。请帮帮我,谢谢你。
I am creating a project about particle system on mac os x. I found similar questions on Internet, and my question is the same as How can I create an shared context between OpenGL and OpenCL with glfw3 on OSX? ,but I still haven't solved my problem yet. Please help me, thank you.
这是我的code的一部分:
This is a part of my code:
CGLContextObj glContext = CGLGetCurrentContext();
CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
cl_context_properties props[] =
{
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties)kCGLShareGroup,`
0
};
我的错误信息是:
my error messages are :
particles.cpp:522:2:错误:CGLContextObj在此范围未声明
CGLContextObj glContext = CGLGetCurrentContext();
particles.cpp:523:2:错误:CGLShareGroupObj在此范围未声明
CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
particles.cpp:527:2:错误:CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE在此范围未声明
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
particles.cpp:528:25:错误:'kCGLShareGroup在此范围未声明(cl_context_properties)kCGLShareGroup,0
推荐答案
你包含哪些头文件?在头文件中的符号位置:
What header files do you include? Location of symbols in header files:
-
的#include&LT;的OpenCL / cl_gl_ext.h&GT;
为CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
-
的#include&LT;的OpenGL / CGLDevice.h&GT;
为CGLGetShareGroup()
-
的#include&LT;的OpenGL / CGLCurrent.h&GT;
为CGLGetCurrentContext()
#include <OpenCL/cl_gl_ext.h>
forCL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
#include <OpenGL/CGLDevice.h>
forCGLGetShareGroup()
#include <OpenGL/CGLCurrent.h>
forCGLGetCurrentContext()
虽然你的可能的包括上面的头文件,我觉得更方便,只是包括下列2头文件:
Although you could include the header files above, I find it more convenient to just include the following 2 header files:
#include <OpenCL/opencl.h>
#include <OpenGL/OpenGL.h>
举例code:
CGLContextObj gl_ctx = CGLGetCurrentContext();
CGLShareGroupObj gl_sharegroup = CGLGetShareGroup(gl_ctx);
cl_context default_ctx;
cl_context_properties properties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties) gl_sharegroup,
0
};
cl_int err_code;
default_ctx = clCreateContext( properties,
1,
&device, /* cl_device */
[](const char* errinfo, const void* private_info, size_t cb, void* user_data) -> void {
/* context-creation and runtime error handler */
cout << "Context error: " << errinfo << endl;
}, /* C++11, this parameter can be nullptr */
nullptr /*user_data*/,
&err_code);
这篇关于如何基于Mac OS X上的OpenGL上下文创建OpenCL上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!