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

Method createVBOAndVAO

testbed/common/AABB.cpp:131–203  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

129// Create the Vertex Buffer Objects used to render to box with OpenGL.
130/// We create two VBOs (one for vertices and one for indices)
131void AABB::createVBOAndVAO() {
132
133 std::vector<openglframework::Vector3> vertices;
134 std::vector<openglframework::Vector3> normals;
135 std::vector<unsigned int> indices;
136
137 // Vertices
138 vertices.push_back(openglframework::Vector3(-0.5, -0.5, 0.5));
139 vertices.push_back(openglframework::Vector3(0.5, -0.5, 0.5));
140 vertices.push_back(openglframework::Vector3(0.5, 0.5, 0.5));
141 vertices.push_back(openglframework::Vector3(-0.5, 0.5, 0.5));
142 vertices.push_back(openglframework::Vector3(0.5, -0.5, -0.5));
143 vertices.push_back(openglframework::Vector3(0.5, 0.5, -0.5));
144 vertices.push_back(openglframework::Vector3(-0.5, 0.5, -0.5));
145 vertices.push_back(openglframework::Vector3(-0.5, -0.5, -0.5));
146
147 // Normals
148 normals.push_back(openglframework::Vector3(1, -1, 1));
149 normals.push_back(openglframework::Vector3(1, 1, 1));
150 normals.push_back(openglframework::Vector3(-1, 1, 1));
151 normals.push_back(openglframework::Vector3(-1, -1, 1));
152 normals.push_back(openglframework::Vector3(1, -1, -1));
153 normals.push_back(openglframework::Vector3(1, 1, -1));
154 normals.push_back(openglframework::Vector3(-1, 1, -1));
155 normals.push_back(openglframework::Vector3(-1, -1, -1));
156
157 // Indices
158 indices.push_back(0); indices.push_back(1); indices.push_back(1); indices.push_back(2);
159 indices.push_back(2); indices.push_back(3); indices.push_back(3); indices.push_back(0);
160
161 indices.push_back(4); indices.push_back(5); indices.push_back(5); indices.push_back(6);
162 indices.push_back(6); indices.push_back(7); indices.push_back(7); indices.push_back(4);
163
164 indices.push_back(1); indices.push_back(4); indices.push_back(2); indices.push_back(5);
165 indices.push_back(0); indices.push_back(7); indices.push_back(3); indices.push_back(6);
166
167 // Create the VBO for the vertices data
168 mVBOVertices.create();
169 mVBOVertices.bind();
170 GLsizei sizeVertices = static_cast<GLsizei>(vertices.size() * sizeof(openglframework::Vector3));
171 mVBOVertices.copyDataIntoVBO(sizeVertices, &(vertices[0]), GL_STATIC_DRAW);
172 mVBOVertices.unbind();
173
174 // Create the VBO for the normals data
175 mVBONormals.create();
176 mVBONormals.bind();
177 GLsizei sizeNormals = static_cast<GLsizei>(normals.size() * sizeof(openglframework::Vector3));
178 mVBONormals.copyDataIntoVBO(sizeNormals, &(normals[0]), GL_STATIC_DRAW);
179 mVBONormals.unbind();
180
181 // Create th VBO for the indices data
182 mVBOIndices.create();
183 mVBOIndices.bind();
184 GLsizei sizeIndices = static_cast<GLsizei>(indices.size() * sizeof(unsigned int));
185 mVBOIndices.copyDataIntoVBO(sizeIndices, &(indices[0]), GL_STATIC_DRAW);
186 mVBOIndices.unbind();
187
188 // Create the VAO for both VBOs

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected