Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Demos / OpenCLClothDemo / btOpenCLSupport.h
1 #ifndef BT_OPENCL_SUPPORT_HPP\r
2 #define BT_OPENCL_SUPPORT_HPP\r
3 \r
4 // OpenCL support\r
5 #include <CL/cl.hpp>\r
6 \r
7 namespace BTAcceleratedSoftBody\r
8 {\r
9         class OpenCLSupportHelper\r
10         {\r
11         private:\r
12                 cl::Context m_context;\r
13                 std::vector<cl::Device> m_devices;\r
14                 cl::CommandQueue m_queue;\r
15         public:\r
16                 OpenCLSupportHelper()\r
17                 {\r
18                 }\r
19 \r
20                 virtual ~OpenCLSupportHelper()\r
21                 {\r
22                 }\r
23 \r
24                 cl::Device getDevice()\r
25                 {\r
26                         return m_devices[0];\r
27                 }\r
28 \r
29                 cl::CommandQueue getCommandQueue()\r
30                 {\r
31                         return m_queue;\r
32                 }\r
33 \r
34                 cl::Context getContext()\r
35                 {\r
36                         return m_context;\r
37                 }\r
38 \r
39                 bool InitOpenCLDevice()\r
40                 {\r
41                         cl_int err;\r
42 \r
43                         std::vector<cl::Platform> platforms;\r
44                         err = cl::Platform::get(&platforms);\r
45                         checkErr(platforms.size() != 0 ? CL_SUCCESS : -1, "Platform::get()");\r
46 \r
47                         std::string platformVendor;\r
48                         platforms[0].getInfo(CL_PLATFORM_VENDOR, &platformVendor);\r
49                         //std::cout << "Platform is by: " << platformVendor << "\n";\r
50 \r
51                         intptr_t properties[] = {\r
52                                 CL_CONTEXT_PLATFORM, (intptr_t)platforms[0](),\r
53                                 0, 0\r
54                         };\r
55                         m_context = cl::Context(\r
56                                 CL_DEVICE_TYPE_GPU, \r
57                                 properties, \r
58                                 NULL, \r
59                                 NULL, \r
60                                 &err);\r
61 \r
62                         if (err != CL_SUCCESS)\r
63                         {\r
64                                 btAssert( "Context::Context()" );\r
65                         }\r
66 \r
67                         m_devices = m_context.getInfo<CL_CONTEXT_DEVICES>();\r
68                         if( m_devices.size() <= 0 ) \r
69                         {\r
70                                 btAssert( "devices.size() > 0" );\r
71                         }\r
72                 \r
73                         m_queue = cl::CommandQueue(m_context, m_devices[0], 0, &err);\r
74                     if (err != CL_SUCCESS) \r
75                         {\r
76                                 btAssert( "CommandQueue::CommandQueue()");\r
77                         }\r
78                 }\r
79         };\r
80 \r
81 \r
82 } // namespace BTAcceleratedSoftBody\r
83 \r
84 #endif // #ifndef BT_OPENCL_SUPPORT_HPP