btSoftBodySolverVertexBuffer_OpenGL.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
00017 #define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H 
00018 
00019 
00020 #include "BulletSoftBody/btSoftBodySolverVertexBuffer.h"
00021 #ifdef USE_MINICL
00022         #include "MiniCL/cl.h"
00023 #else //USE_MINICL
00024         #ifdef __APPLE__
00025                 #include <OpenCL/OpenCL.h>
00026         #else
00027                 #include <CL/cl.h>
00028                 #include <CL/cl_gl.h>
00029         #endif //__APPLE__
00030 #endif//USE_MINICL
00031 
00032 
00033 #ifdef _WIN32//for glut.h
00034 #include <windows.h>
00035 #endif
00036 
00037 //think different
00038 #if defined(__APPLE__) && !defined (VMDMESA)
00039 #include <OpenGL/OpenGL.h>
00040 #include <OpenGL/gl.h>
00041 #include <OpenGL/glu.h>
00042 #include <GLUT/glut.h>
00043 #else
00044 
00045 
00046 #ifdef _WINDOWS
00047 #include <windows.h>
00048 #include <GL/gl.h>
00049 #include <GL/glu.h>
00050 #else
00051 #include <GL/glut.h>
00052 #endif //_WINDOWS
00053 #endif //APPLE
00054 
00055 
00056 
00057 class btOpenGLInteropVertexBufferDescriptor : public btVertexBufferDescriptor
00058 {
00059 protected:
00061         cl_context                      m_context;
00062 
00064         cl_command_queue        m_commandQueue;
00065         
00067         cl_mem m_buffer;
00068 
00070         GLuint m_openGLVBO;
00071 
00072 
00073 public:
00081         btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride )
00082         {
00083 #ifndef USE_MINICL
00084                 cl_int ciErrNum = CL_SUCCESS;
00085                 m_context = context;
00086                 m_commandQueue = cqCommandQue;
00087                 
00088                 m_vertexOffset = vertexOffset;
00089                 m_vertexStride = vertexStride;
00090 
00091                 m_openGLVBO = openGLVBO;
00092                 
00093                 m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
00094                 if( ciErrNum != CL_SUCCESS )
00095                 {
00096                         btAssert( 0 &&  "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
00097                 }
00098 
00099                 m_hasVertexPositions = true;
00100 #else
00101                 btAssert(0);//MiniCL shouldn't get here
00102 #endif
00103         }
00104 
00114         btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride, int normalOffset, int normalStride )
00115         {
00116 #ifndef USE_MINICL
00117                 cl_int ciErrNum = CL_SUCCESS;
00118                 m_context = context;
00119                 m_commandQueue = cqCommandQue;
00120                 
00121                 m_openGLVBO = openGLVBO;
00122                 
00123                 m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
00124                 if( ciErrNum != CL_SUCCESS )
00125                 {
00126                         btAssert( 0 &&  "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
00127                 }
00128 
00129                 m_vertexOffset = vertexOffset;
00130                 m_vertexStride = vertexStride;
00131                 m_hasVertexPositions = true;
00132 
00133                 m_normalOffset = normalOffset;
00134                 m_normalStride = normalStride;
00135                 m_hasNormals = true;
00136 #else
00137                 btAssert(0);
00138 #endif //USE_MINICL
00139                 
00140         }
00141 
00142         virtual ~btOpenGLInteropVertexBufferDescriptor()
00143         {
00144                 clReleaseMemObject( m_buffer );
00145         }
00146 
00150         virtual BufferTypes getBufferType() const
00151         {
00152                 return OPENGL_BUFFER;
00153         }
00154 
00155         virtual cl_context getContext() const
00156         {
00157                 return m_context;
00158         }
00159 
00160         virtual cl_mem getBuffer() const
00161         {
00162                 return m_buffer;
00163         }       
00164 };
00165 
00166 #endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H