MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / createVBOAndVAO

Method createVBOAndVAO

testbed/common/ConvexMesh.cpp:199–251  ·  view source on GitHub ↗

Create the Vertex Buffer Objects used to render with OpenGL. We create two VBOs (one for vertices and one for indices)

Source from the content-addressed store, hash-verified

197// Create the Vertex Buffer Objects used to render with OpenGL.
198/// We create two VBOs (one for vertices and one for indices)
199void ConvexMesh::createVBOAndVAO() {
200
201 // Create the VBO for the vertices data
202 mVBOVertices.create();
203 mVBOVertices.bind();
204 size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
205 mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
206 mVBOVertices.unbind();
207
208 // Create the VBO for the normals data
209 mVBONormals.create();
210 mVBONormals.bind();
211 size_t sizeNormals = mNormals.size() * sizeof(openglframework::Vector3);
212 mVBONormals.copyDataIntoVBO(sizeNormals, getNormalsPointer(), GL_STATIC_DRAW);
213 mVBONormals.unbind();
214
215 if (hasTexture()) {
216 // Create the VBO for the texture co data
217 mVBOTextureCoords.create();
218 mVBOTextureCoords.bind();
219 size_t sizeTextureCoords = mUVs.size() * sizeof(openglframework::Vector2);
220 mVBOTextureCoords.copyDataIntoVBO(sizeTextureCoords, getUVTextureCoordinatesPointer(), GL_STATIC_DRAW);
221 mVBOTextureCoords.unbind();
222 }
223
224 // Create th VBO for the indices data
225 mVBOIndices.create();
226 mVBOIndices.bind();
227 size_t sizeIndices = mIndices[0].size() * sizeof(unsigned int);
228 mVBOIndices.copyDataIntoVBO(sizeIndices, getIndicesPointer(), GL_STATIC_DRAW);
229 mVBOIndices.unbind();
230
231 // Create the VAO for both VBOs
232 mVAO.create();
233 mVAO.bind();
234
235 // Bind the VBO of vertices
236 mVBOVertices.bind();
237
238 // Bind the VBO of normals
239 mVBONormals.bind();
240
241 if (hasTexture()) {
242 // Bind the VBO of texture coords
243 mVBOTextureCoords.bind();
244 }
245
246 // Bind the VBO of indices
247 mVBOIndices.bind();
248
249 // Unbind the VAO
250 mVAO.unbind();
251}
252
253// Return the index of a given vertex in the mesh
254int ConvexMesh::findVertexIndex(const std::vector<openglframework::Vector3>& vertices, const openglframework::Vector3& vertex) {

Callers

nothing calls this directly

Calls 5

copyDataIntoVBOMethod · 0.80
createMethod · 0.45
bindMethod · 0.45
sizeMethod · 0.45
unbindMethod · 0.45

Tested by

no test coverage detected