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

Function checkGLInterop

examples/opencl/cl_helpers.h:36–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34#endif
35
36bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const forge::Window &wnd)
37{
38 bool ret_val = false;
39 // find the extension required
40 std::string exts = pDevice.getInfo<CL_DEVICE_EXTENSIONS>();
41 std::stringstream ss(exts);
42 std::string item;
43
44 while (std::getline(ss,item,' ')) {
45 if (item == CL_GL_SHARING_EXT) {
46 ret_val = true;
47 break;
48 }
49 }
50
51 if (!ret_val) return false;
52
53#if !defined(OS_MAC) // Check on Linux, Windows
54 // Check if current OpenCL device is belongs to the OpenGL context
55
56#if defined(OS_LNX)
57 cl_context_properties cps[] = {
58 CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
59 CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
60 CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
61 0
62 };
63#else /* OS_WIN */
64 cl_context_properties cps[] = {
65 CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
66 CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
67 CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
68 0
69 };
70#endif
71
72 // Load the extension
73 // If cl_khr_gl_sharing is available, this function should be present
74 // This has been checked earlier, it comes to this point only if it is found
75 auto func = (clGetGLContextInfoKHR_fn)
76 clGetExtensionFunctionAddressForPlatform(plat(), "clGetGLContextInfoKHR");
77
78 if (!func) return false;
79
80 // Get all devices associated with opengl context
81 std::vector<cl_device_id> devices(16);
82 size_t ret = 0;
83 cl_int err = func(cps,
84 CL_DEVICES_FOR_GL_CONTEXT_KHR,
85 devices.size() * sizeof(cl_device_id),
86 devices.data(),
87 &ret);
88
89 if (err != CL_SUCCESS) return false;
90
91 int num = (int)(ret / sizeof(cl_device_id));
92 devices.resize(num);
93

Callers 1

createCLGLContextFunction · 0.85

Calls 3

contextMethod · 0.45
displayMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected