Bullet Collision Detection & Physics Library
btSoftBodySolverVertexBuffer_OpenGL.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 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 #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
17 #define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
18 
19 
21 #ifdef USE_MINICL
22  #include "MiniCL/cl.h"
23 #else //USE_MINICL
24  #ifdef __APPLE__
25  #include <OpenCL/OpenCL.h>
26  #else
27  #include <CL/cl.h>
28  #include <CL/cl_gl.h>
29  #endif //__APPLE__
30 #endif//USE_MINICL
31 
32 
33 #ifdef _WIN32//for glut.h
34 #include <windows.h>
35 #endif
36 
37 //think different
38 #if defined(__APPLE__) && !defined (VMDMESA)
39 #include <OpenGL/OpenGL.h>
40 #include <OpenGL/gl.h>
41 #include <OpenGL/glu.h>
42 #include <GLUT/glut.h>
43 #else
44 
45 
46 #ifdef _WINDOWS
47 #include <windows.h>
48 #include <GL/gl.h>
49 #include <GL/glu.h>
50 #else
51 #include <GL/glut.h>
52 #endif //_WINDOWS
53 #endif //APPLE
54 
55 
56 
58 {
59 protected:
62 
65 
68 
70  GLuint m_openGLVBO;
71 
72 
73 public:
81  btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride )
82  {
83 #ifndef USE_MINICL
84  cl_int ciErrNum = CL_SUCCESS;
85  m_context = context;
86  m_commandQueue = cqCommandQue;
87 
88  m_vertexOffset = vertexOffset;
89  m_vertexStride = vertexStride;
90 
91  m_openGLVBO = openGLVBO;
92 
93  m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
94  if( ciErrNum != CL_SUCCESS )
95  {
96  btAssert( 0 && "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
97  }
98 
99  m_hasVertexPositions = true;
100 #else
101  btAssert(0);//MiniCL shouldn't get here
102 #endif
103  }
104 
114  btOpenGLInteropVertexBufferDescriptor( cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride, int normalOffset, int normalStride )
115  {
116 #ifndef USE_MINICL
117  cl_int ciErrNum = CL_SUCCESS;
118  m_context = context;
119  m_commandQueue = cqCommandQue;
120 
121  m_openGLVBO = openGLVBO;
122 
123  m_buffer = clCreateFromGLBuffer(m_context, CL_MEM_WRITE_ONLY, openGLVBO, &ciErrNum);
124  if( ciErrNum != CL_SUCCESS )
125  {
126  btAssert( 0 && "clEnqueueAcquireGLObjects(copySoftBodyToVertexBuffer)");
127  }
128 
129  m_vertexOffset = vertexOffset;
130  m_vertexStride = vertexStride;
131  m_hasVertexPositions = true;
132 
133  m_normalOffset = normalOffset;
134  m_normalStride = normalStride;
135  m_hasNormals = true;
136 #else
137  btAssert(0);
138 #endif //USE_MINICL
139 
140  }
141 
143  {
145  }
146 
150  virtual BufferTypes getBufferType() const
151  {
152  return OPENGL_BUFFER;
153  }
154 
155  virtual cl_context getContext() const
156  {
157  return m_context;
158  }
159 
160  virtual cl_mem getBuffer() const
161  {
162  return m_buffer;
163  }
164 };
165 
166 #endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_OPENGL_H
struct _cl_context * cl_context
Definition: cl.h:41
CL_API_ENTRY cl_int CL_API_CALL clReleaseMemObject(cl_mem) CL_API_SUFFIX__VERSION_1_0
Definition: MiniCL.cpp:333
btOpenGLInteropVertexBufferDescriptor(cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride)
context is the OpenCL context this interop buffer will work in.
#define btAssert(x)
Definition: btScalar.h:101
btOpenGLInteropVertexBufferDescriptor(cl_command_queue cqCommandQue, cl_context context, GLuint openGLVBO, int vertexOffset, int vertexStride, int normalOffset, int normalStride)
context is the OpenCL context this interop buffer will work in.
int32_t cl_int
Definition: cl_platform.h:70
#define CL_SUCCESS
Definition: cl.h:91
struct _cl_mem * cl_mem
Definition: cl.h:43
CL_API_ENTRY cl_mem CL_API_CALL clCreateFromGLBuffer(cl_context, cl_mem_flags, GLuint, int *) CL_API_SUFFIX__VERSION_1_0
#define CL_MEM_WRITE_ONLY
Definition: cl.h:258
cl_command_queue m_commandQueue
OpenCL command queue.
virtual BufferTypes getBufferType() const
Return the type of the vertex buffer descriptor.
struct _cl_command_queue * cl_command_queue
Definition: cl.h:42
GLuint m_openGLVBO
VBO in GL that is the basis of the interop buffer.