MCPcopy Create free account
hub / github.com/arrayfire/forge / createCLGLContext

Function createCLGLContext

examples/opencl/cl_helpers.h:103–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103cl::Context createCLGLContext(const forge::Window &wnd)
104{
105 std::vector<cl::Platform> platforms;
106 Platform::get(&platforms);
107
108 for (auto platform : platforms) {
109 std::vector<cl::Device> devices;
110
111 try {
112 platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
113 } catch(const cl::Error &err) {
114 if (err.err() != CL_DEVICE_NOT_FOUND) {
115 throw;
116 } else {
117 continue;
118 }
119 }
120
121 for (auto device : devices) {
122 if (!checkGLInterop(platform, device, wnd)) continue;
123#if defined(OS_MAC)
124 CGLContextObj cgl_current_ctx = CGLGetCurrentContext();
125 CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_ctx);
126
127 cl_context_properties cps[] = {
128 CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)cgl_share_group,
129 0
130 };
131#elif defined(OS_LNX)
132 cl_context_properties cps[] = {
133 CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
134 CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
135 CL_CONTEXT_PLATFORM, (cl_context_properties)platform(),
136 0
137 };
138#else /* OS_WIN */
139 cl_context_properties cps[] = {
140 CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
141 CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
142 CL_CONTEXT_PLATFORM, (cl_context_properties)platform(),
143 0
144 };
145#endif
146 std::cout << "Platform: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl;
147 std::cout << "Device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
148 return cl::Context(device, cps);
149 }
150 }
151
152 throw std::runtime_error("No CL-GL sharing contexts found");
153}
154
155cl::CommandQueue queue;
156cl::Context context;

Callers 8

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

checkGLInteropFunction · 0.85
contextMethod · 0.45
displayMethod · 0.45

Tested by

no test coverage detected