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

Method createVBOAndVAO

testbed/common/Sphere.cpp:154–206  ·  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

152// Create the Vertex Buffer Objects used to render with OpenGL.
153/// We create two VBOs (one for vertices and one for indices)
154void Sphere::createVBOAndVAO() {
155
156 // Create the VBO for the vertices data
157 mVBOVertices.create();
158 mVBOVertices.bind();
159 size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
160 mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
161 mVBOVertices.unbind();
162
163 // Create the VBO for the normals data
164 mVBONormals.create();
165 mVBONormals.bind();
166 size_t sizeNormals = mNormals.size() * sizeof(openglframework::Vector3);
167 mVBONormals.copyDataIntoVBO(sizeNormals, getNormalsPointer(), GL_STATIC_DRAW);
168 mVBONormals.unbind();
169
170 if (hasTexture()) {
171 // Create the VBO for the texture co data
172 mVBOTextureCoords.create();
173 mVBOTextureCoords.bind();
174 size_t sizeTextureCoords = mUVs.size() * sizeof(openglframework::Vector2);
175 mVBOTextureCoords.copyDataIntoVBO(sizeTextureCoords, getUVTextureCoordinatesPointer(), GL_STATIC_DRAW);
176 mVBOTextureCoords.unbind();
177 }
178
179 // Create th VBO for the indices data
180 mVBOIndices.create();
181 mVBOIndices.bind();
182 size_t sizeIndices = mIndices[0].size() * sizeof(unsigned int);
183 mVBOIndices.copyDataIntoVBO(sizeIndices, getIndicesPointer(), GL_STATIC_DRAW);
184 mVBOIndices.unbind();
185
186 // Create the VAO for both VBOs
187 mVAO.create();
188 mVAO.bind();
189
190 // Bind the VBO of vertices
191 mVBOVertices.bind();
192
193 // Bind the VBO of normals
194 mVBONormals.bind();
195
196 if (hasTexture()) {
197 // Bind the VBO of texture coords
198 mVBOTextureCoords.bind();
199 }
200
201 // Bind the VBO of indices
202 mVBOIndices.bind();
203
204 // Unbind the VAO
205 mVAO.unbind();
206}

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