我正在mac os x上创建一个关于粒子系统的项目。我在互联网上发现了类似的问题,我的问题与How can I create an shared context between OpenGL and OpenCL with glfw3 on OSX?相同 ,但我还没有解决我的问题。请帮帮我,谢谢。
这是我的代码的一部分:
CGLContextObj glContext = CGLGetCurrentContext();
CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
cl_context_properties props[] =
{
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties)kCGLShareGroup,`
0
};
我的错误消息是:
particles.cpp:522:2: error: ‘CGLContextObj’ was not declared in this scope
CGLContextObj glContext = CGLGetCurrentContext();
particles.cpp:523:2: error: ‘CGLShareGroupObj’ was not declared in this scope
CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
particles.cpp:527:2: error: ‘CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE’ was not declared in this scope
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
particles.cpp:528:25: error: ‘kCGLShareGroup’ was not declared in this scope (cl_context_properties)kCGLShareGroup,0
答案 0 :(得分:3)
您包含哪些头文件?头文件中符号的位置:
#include <OpenCL/cl_gl_ext.h>
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
{li> #include <OpenGL/CGLDevice.h>
CGLGetShareGroup()
{li> #include <OpenGL/CGLCurrent.h>
CGLGetCurrentContext()
虽然可以包含上面的头文件,但我发现只包含以下2个头文件更方便:
#include <OpenCL/opencl.h>
#include <OpenGL/OpenGL.h>
示例代码:
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);