Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
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);
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