2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #include "SerializeDemo.h"
17 #include "GlutStuff.h"
18 #include "GLDebugDrawer.h"
19 #include "btBulletDynamicsCommon.h"
20 #include "LinearMath/btHashMap.h"
21 #include "btBulletFile.h"
22 #include "CommandLineArguments.h"
29 #include "btOpenCLUtils.h"
31 #include <LinearMath/btScalar.h>
33 cl_context g_cxMainContext;
34 cl_device_id g_cdDevice;
35 cl_command_queue g_cqCommandQue;
38 // Returns true if OpenCL is initialized properly, false otherwise.
39 bool initCL( void* glCtx, void* glDC )
41 const char* vendorSDK = btOpenCLUtils::getSdkVendorName();
42 printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
47 ciErrNum = clewInit( "OpenCL.dll" );
48 if ( ciErrNum != CLEW_SUCCESS ) {
53 #if defined(CL_PLATFORM_MINI_CL)
54 cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
55 #elif defined(CL_PLATFORM_AMD)
56 cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
57 #elif defined(CL_PLATFORM_NVIDIA)
58 cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
60 cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
63 g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
64 oclCHECKERROR(ciErrNum, CL_SUCCESS);
66 int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);
70 g_cdDevice = btOpenCLUtils::getDevice(g_cxMainContext,0);
72 btOpenCLDeviceInfo clInfo;
73 btOpenCLUtils::getDeviceInfo(g_cdDevice,clInfo);
74 btOpenCLUtils::printDeviceInfo(g_cdDevice);
76 // create a command-queue
77 g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_cdDevice, 0, &ciErrNum);
78 oclCHECKERROR(ciErrNum, CL_SUCCESS);
83 #endif //#ifdef USE_AMD_OPENCL
86 int main(int argc,char** argv)
88 CommandLineArguments arg(argc,argv);
90 arg.GetCmdLineArgument("filename", filename);
91 bool dumpXml = arg.CheckCmdLineFlag("dump_xml");
92 if (!dumpXml && !filename)
94 printf("There are some optional commandline arguments for this demo:\n");
95 printf("Load another .bullet file instead of testFile.bullet:\n");
96 printf("--filename=testfile.bullet\n");
97 printf("Dump the imported .bullet file to XML\n");
98 printf("--dump_xml\n");
104 GLDebugDrawer gDebugDrawer;
105 #ifdef USE_AMD_OPENCL
107 bool initialized = initCL(0,0);
108 btAssert(initialized);
109 #endif //USE_AMD_OPENCL
112 SerializeDemo serializeDemo;
116 mode |=bParse::FD_VERBOSE_EXPORT_XML;
118 serializeDemo.setFileName(filename);
119 serializeDemo.setVerboseMode(mode);
121 serializeDemo.initPhysics();
122 serializeDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
125 #ifdef CHECK_MEMORY_LEAKS
126 serializeDemo.exitPhysics();
128 return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.org",&serializeDemo);
131 //default glut doesn't return from mainloop