Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / OpenCLClothDemo / clstuff.cpp
1 /*\r
2 Bullet Continuous Collision Detection and Physics Library\r
3 Copyright (c) 2008 Advanced Micro Devices\r
4 \r
5 This software is provided 'as-is', without any express or implied warranty.\r
6 In no event will the authors be held liable for any damages arising from the use of this software.\r
7 Permission is granted to anyone to use this software for any purpose, \r
8 including commercial applications, and to alter it and redistribute it freely, \r
9 subject to the following restrictions:\r
10 \r
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.\r
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\r
13 3. This notice may not be removed or altered from any source distribution.\r
14 */\r
15 \r
16 \r
17 \r
18 #include "clstuff.h"\r
19 #include "gl_win.h"\r
20 \r
21 #include "btOpenCLUtils.h"\r
22 \r
23 #include "LinearMath/btScalar.h"\r
24 #include <stdio.h>\r
25 \r
26 cl_context                      g_cxMainContext;\r
27 cl_device_id            g_cdDevice;\r
28 cl_command_queue        g_cqCommandQue;\r
29 \r
30 void initCL( void* glCtx, void* glDC )\r
31 {\r
32         int ciErrNum = 0;\r
33 \r
34 #if defined(CL_PLATFORM_MINI_CL)\r
35         cl_device_type deviceType = CL_DEVICE_TYPE_CPU;//or use CL_DEVICE_TYPE_DEBUG to debug MiniCL\r
36 #elif defined(CL_PLATFORM_INTEL)\r
37         cl_device_type deviceType = CL_DEVICE_TYPE_CPU;\r
38 #elif defined(CL_PLATFORM_AMD)\r
39         cl_device_type deviceType = CL_DEVICE_TYPE_GPU;\r
40 #elif defined(CL_PLATFORM_NVIDIA)\r
41         cl_device_type deviceType = CL_DEVICE_TYPE_GPU;\r
42 #else\r
43 #ifdef __APPLE__\r
44         cl_device_type deviceType = CL_DEVICE_TYPE_ALL;//GPU;\r
45 #else\r
46         cl_device_type deviceType = CL_DEVICE_TYPE_CPU;//CL_DEVICE_TYPE_ALL\r
47 #endif//__APPLE__\r
48 #endif\r
49         \r
50         g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);\r
51         oclCHECKERROR(ciErrNum, CL_SUCCESS);\r
52 \r
53         \r
54         int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);\r
55         if (!numDev)\r
56         {\r
57                 btAssert(0);\r
58                 exit(0);//this is just a demo, exit now\r
59         }\r
60 \r
61         g_cdDevice = btOpenCLUtils::getDevice(g_cxMainContext,0);\r
62         oclCHECKERROR(ciErrNum, CL_SUCCESS);\r
63 \r
64         btOpenCLDeviceInfo clInfo;\r
65         btOpenCLUtils::getDeviceInfo(g_cdDevice,clInfo);\r
66         btOpenCLUtils::printDeviceInfo(g_cdDevice);\r
67         \r
68         // create a command-queue\r
69         g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_cdDevice, 0, &ciErrNum);\r
70         oclCHECKERROR(ciErrNum, CL_SUCCESS);\r
71 }\r