2 Bullet Continuous Collision Detection and Physics Library
\r
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
\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
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
16 #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
\r
17 #define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
\r
20 #include "BulletSoftBody/btSoftBodySolverVertexBuffer.h"
\r
22 #include "MiniCL/cl.h"
\r
25 #include <OpenCL/OpenCL.h>
\r
28 #include <CL/cl_gl.h>
\r
33 #ifdef _WIN32//for glut.h
\r
34 #include <windows.h>
\r
38 #if defined(__APPLE__) && !defined (VMDMESA)
\r
39 #include <OpenGL/OpenGL.h>
\r
40 #include <OpenGL/gl.h>
\r
41 #include <OpenGL/glu.h>
\r
42 #include <GLUT/glut.h>
\r
47 #include <windows.h>
\r
51 #include <GL/glut.h>
\r
57 class btOpenGLInteropVertexBufferDescriptor : public btVertexBufferDescriptor
\r
60 /** OpenCL context */
\r
61 cl_context m_context;
\r
63 /** OpenCL command queue */
\r
64 cl_command_queue m_commandQueue;
\r
66 /** OpenCL interop buffer */
\r
69 /** VBO in GL that is the basis of the interop buffer */
\r
75 * context is the OpenCL context this interop buffer will work in.
\r
76 * queue is the command queue that kernels and data movement will be enqueued into.
\r
77 * openGLVBO is the OpenGL vertex buffer data will be copied into.
\r
78 * vertexOffset is the offset in floats to the first vertex.
\r
79 * vertexStride is the stride in floats between vertices.
\r
81 btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride )
\r
84 cl_int ciErrNum = CL_SUCCESS;
\r
85 m_context = context;
\r
86 m_commandQueue = cqCommandQue;
\r
88 m_vertexOffset = vertexOffset;
\r
89 m_vertexStride = vertexStride;
\r
91 m_openGLVBO = openGLVBO;
\r
93 m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
\r
94 if( ciErrNum != CL_SUCCESS )
\r
96 btAssert( 0 && "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
\r
99 m_hasVertexPositions = true;
\r
101 btAssert(0);//MiniCL shouldn't get here
\r
106 * context is the OpenCL context this interop buffer will work in.
\r
107 * queue is the command queue that kernels and data movement will be enqueued into.
\r
108 * openGLVBO is the OpenGL vertex buffer data will be copied into.
\r
109 * vertexOffset is the offset in floats to the first vertex.
\r
110 * vertexStride is the stride in floats between vertices.
\r
111 * normalOffset is the offset in floats to the first normal.
\r
112 * normalStride is the stride in floats between normals.
\r
114 btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride, int normalOffset, int normalStride )
\r
117 cl_int ciErrNum = CL_SUCCESS;
\r
118 m_context = context;
\r
119 m_commandQueue = cqCommandQue;
\r
121 m_openGLVBO = openGLVBO;
\r
123 m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
\r
124 if( ciErrNum != CL_SUCCESS )
\r
126 btAssert( 0 && "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
\r
129 m_vertexOffset = vertexOffset;
\r
130 m_vertexStride = vertexStride;
\r
131 m_hasVertexPositions = true;
\r
133 m_normalOffset = normalOffset;
\r
134 m_normalStride = normalStride;
\r
135 m_hasNormals = true;
\r
138 #endif //USE_MINICL
\r
142 virtual ~btOpenGLInteropVertexBufferDescriptor()
\r
144 clReleaseMemObject( m_buffer );
\r
148 * Return the type of the vertex buffer descriptor.
\r
150 virtual BufferTypes getBufferType() const
\r
152 return OPENGL_BUFFER;
\r
155 virtual cl_context getContext() const
\r
160 virtual cl_mem getBuffer() const
\r
166 #endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
\r