|
|
|
@ -11,15 +11,12 @@ MeshView::MeshView(const MeshProcessor &mesh_processor, QOpenGLShaderProgram &pr
|
|
|
|
|
n_vertices(mesh_processor.mesh.n_vertices()),
|
|
|
|
|
mesh_processor(mesh_processor) {
|
|
|
|
|
const MyMesh &mesh = mesh_processor.mesh;
|
|
|
|
|
QVector<GLfloat> vertices(n_vertices * 6);
|
|
|
|
|
QVector<GLfloat> vertices(n_vertices * 3);
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
for (const VertexHandle it : mesh.vertices()) {
|
|
|
|
|
vertices[6*i + 0] = mesh.point(it)[0];
|
|
|
|
|
vertices[6*i + 1] = mesh.point(it)[1];
|
|
|
|
|
vertices[6*i + 2] = mesh.point(it)[2];
|
|
|
|
|
vertices[6*i + 3] = mesh.color.red();
|
|
|
|
|
vertices[6*i + 4] = mesh.color.green();
|
|
|
|
|
vertices[6*i + 5] = mesh.color.blue();
|
|
|
|
|
vertices[3*i + 0] = mesh.point(it)[0];
|
|
|
|
|
vertices[3*i + 1] = mesh.point(it)[1];
|
|
|
|
|
vertices[3*i + 2] = mesh.point(it)[2];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
QVector<GLuint> indices(n_faces * 3);
|
|
|
|
@ -39,15 +36,13 @@ MeshView::MeshView(const MeshProcessor &mesh_processor, QOpenGLShaderProgram &pr
|
|
|
|
|
vertex_buffer.create();
|
|
|
|
|
vertex_buffer.bind();
|
|
|
|
|
vertex_buffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
|
|
|
|
|
vertex_buffer.allocate(vertices.constData(), n_vertices * 6 * sizeof (GLfloat));
|
|
|
|
|
vertex_buffer.allocate(vertices.constData(), n_vertices * 3 * sizeof (GLfloat));
|
|
|
|
|
index_buffer.create();
|
|
|
|
|
index_buffer.bind();
|
|
|
|
|
index_buffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
|
|
|
|
|
index_buffer.allocate(indices.constData(), n_faces * 3 * sizeof (GLuint));
|
|
|
|
|
program.setAttributeBuffer("pos", GL_FLOAT, 0, 3, 6 * sizeof (GLfloat));
|
|
|
|
|
program.setAttributeBuffer("pos", GL_FLOAT, 0, 3);
|
|
|
|
|
program.enableAttributeArray("pos");
|
|
|
|
|
program.setAttributeBuffer("col", GL_FLOAT, 3 * sizeof (GLfloat), 3, 6 * sizeof (GLfloat));
|
|
|
|
|
program.enableAttributeArray("col");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -70,6 +65,7 @@ void MeshView::paint(QOpenGLShaderProgram &program) {
|
|
|
|
|
qFatal("Failed to get OpenGL 2.1 functions");
|
|
|
|
|
|
|
|
|
|
program.setUniformValue("model", mesh.transform);
|
|
|
|
|
program.setUniformValue("col", mesh.color.redF(), mesh.color.greenF(), mesh.color.blueF());
|
|
|
|
|
|
|
|
|
|
{QOpenGLVertexArrayObject::Binder binder(&vao);
|
|
|
|
|
/* Mesh */
|
|
|
|
|