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

Method createVBOAndVAO

testbed/common/ConcaveMesh.cpp:169–221  ·  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

167// Create the Vertex Buffer Objects used to render with OpenGL.
168/// We create two VBOs (one for vertices and one for indices)
169void ConcaveMesh::createVBOAndVAO() {
170
171 // Create the VBO for the vertices data
172 mVBOVertices.create();
173 mVBOVertices.bind();
174 size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
175 mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
176 mVBOVertices.unbind();
177
178 // Create the VBO for the normals data
179 mVBONormals.create();
180 mVBONormals.bind();
181 size_t sizeNormals = mNormals.size() * sizeof(openglframework::Vector3);
182 mVBONormals.copyDataIntoVBO(sizeNormals, getNormalsPointer(), GL_STATIC_DRAW);
183 mVBONormals.unbind();
184
185 if (hasTexture()) {
186 // Create the VBO for the texture co data
187 mVBOTextureCoords.create();
188 mVBOTextureCoords.bind();
189 size_t sizeTextureCoords = mUVs.size() * sizeof(openglframework::Vector2);
190 mVBOTextureCoords.copyDataIntoVBO(sizeTextureCoords, getUVTextureCoordinatesPointer(), GL_STATIC_DRAW);
191 mVBOTextureCoords.unbind();
192 }
193
194 // Create th VBO for the indices data
195 mVBOIndices.create();
196 mVBOIndices.bind();
197 size_t sizeIndices = mIndices[0].size() * sizeof(unsigned int);
198 mVBOIndices.copyDataIntoVBO(sizeIndices, getIndicesPointer(), GL_STATIC_DRAW);
199 mVBOIndices.unbind();
200
201 // Create the VAO for both VBOs
202 mVAO.create();
203 mVAO.bind();
204
205 // Bind the VBO of vertices
206 mVBOVertices.bind();
207
208 // Bind the VBO of normals
209 mVBONormals.bind();
210
211 if (hasTexture()) {
212 // Bind the VBO of texture coords
213 mVBOTextureCoords.bind();
214 }
215
216 // Bind the VBO of indices
217 mVBOIndices.bind();
218
219 // Unbind the VAO
220 mVAO.unbind();
221}

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