Create the Vertex Buffer Objects used to render with OpenGL. We create two VBOs (one for vertices and one for indices)
| 226 | // Create the Vertex Buffer Objects used to render with OpenGL. |
| 227 | /// We create two VBOs (one for vertices and one for indices) |
| 228 | void HeightField::createVBOAndVAO() { |
| 229 | |
| 230 | // Create the VBO for the vertices data |
| 231 | mVBOVertices.create(); |
| 232 | mVBOVertices.bind(); |
| 233 | size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3); |
| 234 | mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW); |
| 235 | mVBOVertices.unbind(); |
| 236 | |
| 237 | // Create the VBO for the normals data |
| 238 | mVBONormals.create(); |
| 239 | mVBONormals.bind(); |
| 240 | size_t sizeNormals = mNormals.size() * sizeof(openglframework::Vector3); |
| 241 | mVBONormals.copyDataIntoVBO(sizeNormals, getNormalsPointer(), GL_STATIC_DRAW); |
| 242 | mVBONormals.unbind(); |
| 243 | |
| 244 | if (hasTexture()) { |
| 245 | // Create the VBO for the texture co data |
| 246 | mVBOTextureCoords.create(); |
| 247 | mVBOTextureCoords.bind(); |
| 248 | size_t sizeTextureCoords = mUVs.size() * sizeof(openglframework::Vector2); |
| 249 | mVBOTextureCoords.copyDataIntoVBO(sizeTextureCoords, getUVTextureCoordinatesPointer(), GL_STATIC_DRAW); |
| 250 | mVBOTextureCoords.unbind(); |
| 251 | } |
| 252 | |
| 253 | // Create th VBO for the indices data |
| 254 | mVBOIndices.create(); |
| 255 | mVBOIndices.bind(); |
| 256 | size_t sizeIndices = mIndices[0].size() * sizeof(unsigned int); |
| 257 | mVBOIndices.copyDataIntoVBO(sizeIndices, getIndicesPointer(), GL_STATIC_DRAW); |
| 258 | mVBOIndices.unbind(); |
| 259 | |
| 260 | // Create the VAO for both VBOs |
| 261 | mVAO.create(); |
| 262 | mVAO.bind(); |
| 263 | |
| 264 | // Bind the VBO of vertices |
| 265 | mVBOVertices.bind(); |
| 266 | |
| 267 | // Bind the VBO of normals |
| 268 | mVBONormals.bind(); |
| 269 | |
| 270 | if (hasTexture()) { |
| 271 | // Bind the VBO of texture coords |
| 272 | mVBOTextureCoords.bind(); |
| 273 | } |
| 274 | |
| 275 | // Bind the VBO of indices |
| 276 | mVBOIndices.bind(); |
| 277 | |
| 278 | // Unbind the VAO |
| 279 | mVAO.unbind(); |
| 280 | } |
nothing calls this directly
no test coverage detected