resetting manifest requested domain to floor
[platform/upstream/libbullet.git] / Demos / SerializeDemo / main.cpp
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/
4
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:
10
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.
14 */
15
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"
23
24
25 #ifdef USE_AMD_OPENCL
26
27
28
29 #include "btOpenCLUtils.h"
30
31 #include <LinearMath/btScalar.h>
32
33 cl_context        g_cxMainContext;
34 cl_device_id      g_cdDevice;
35 cl_command_queue  g_cqCommandQue;
36
37
38 // Returns true if OpenCL is initialized properly, false otherwise.
39 bool initCL( void* glCtx, void* glDC )
40 {
41         const char* vendorSDK = btOpenCLUtils::getSdkVendorName();
42         printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
43
44     int ciErrNum = 0;
45
46 #ifdef BT_USE_CLEW
47     ciErrNum = clewInit( "OpenCL.dll" );
48     if ( ciErrNum != CLEW_SUCCESS ) {
49         return false;
50     }
51 #endif
52
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;
59 #else
60     cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
61 #endif
62
63         g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
64     oclCHECKERROR(ciErrNum, CL_SUCCESS);
65
66         int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);
67         if (!numDev)
68                 return false;
69
70     g_cdDevice =  btOpenCLUtils::getDevice(g_cxMainContext,0);
71     
72     btOpenCLDeviceInfo clInfo;
73         btOpenCLUtils::getDeviceInfo(g_cdDevice,clInfo);
74         btOpenCLUtils::printDeviceInfo(g_cdDevice);
75
76     // create a command-queue
77     g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_cdDevice, 0, &ciErrNum);
78     oclCHECKERROR(ciErrNum, CL_SUCCESS);
79
80     return true;
81 }
82
83 #endif //#ifdef USE_AMD_OPENCL
84
85         
86 int main(int argc,char** argv)
87 {
88         CommandLineArguments arg(argc,argv);
89         char* filename=0;
90         arg.GetCmdLineArgument("filename", filename);
91         bool dumpXml = arg.CheckCmdLineFlag("dump_xml");
92         if (!dumpXml && !filename)
93         {
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");
99                 
100         }
101
102         
103         
104         GLDebugDrawer   gDebugDrawer;
105 #ifdef USE_AMD_OPENCL
106         
107         bool initialized = initCL(0,0);
108         btAssert(initialized);
109 #endif //USE_AMD_OPENCL
110
111         
112         SerializeDemo serializeDemo;
113         
114         int mode = 0;
115         if (dumpXml)
116                 mode |=bParse::FD_VERBOSE_EXPORT_XML;
117         if (filename)
118                 serializeDemo.setFileName(filename);
119         serializeDemo.setVerboseMode(mode);
120         
121         serializeDemo.initPhysics();
122         serializeDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
123
124
125 #ifdef CHECK_MEMORY_LEAKS
126         serializeDemo.exitPhysics();
127 #else
128         return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.org",&serializeDemo);
129 #endif
130         
131         //default glut doesn't return from mainloop
132         return 0;
133 }
134