-
Notifications
You must be signed in to change notification settings - Fork 3
/
glmesh.cpp
37 lines (29 loc) · 968 Bytes
/
glmesh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "glmesh.h"
#include "mesh.h"
GLMesh::GLMesh(const Mesh* const mesh)
: vertices(QOpenGLBuffer::VertexBuffer), indices(QOpenGLBuffer::IndexBuffer)
{
initializeOpenGLFunctions();
vertices.create();
indices.create();
vertices.setUsagePattern(QOpenGLBuffer::StaticDraw);
indices.setUsagePattern(QOpenGLBuffer::StaticDraw);
vertices.bind();
vertices.allocate(mesh->vertices.data(),
mesh->vertices.size() * sizeof(float));
vertices.release();
indices.bind();
indices.allocate(mesh->indices.data(),
mesh->indices.size() * sizeof(uint32_t));
indices.release();
}
void GLMesh::draw(GLuint vp)
{
vertices.bind();
indices.bind();
glVertexAttribPointer(vp, 3, GL_FLOAT, false, 3*sizeof(float), NULL);
glDrawElements(GL_TRIANGLES, indices.size() / sizeof(uint32_t),
GL_UNSIGNED_INT, NULL);
vertices.release();
indices.release();
}