MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
mesh_renderer.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include "ogl/opengl.h"
11#include "ogl/mesh_renderer.h"
12
14
15void
16MeshRenderer::set_mesh (mve::TriangleMesh::ConstPtr mesh)
17{
18 if (mesh == nullptr)
19 throw std::invalid_argument("Got null mesh");
20
21 /* Clean previous content. */
22 this->reset_vertex_array();
23
24 mve::TriangleMesh::VertexList const& verts(mesh->get_vertices());
25 mve::TriangleMesh::FaceList const& faces(mesh->get_faces());
26 mve::TriangleMesh::NormalList const& vnormals(mesh->get_vertex_normals());
27 mve::TriangleMesh::ColorList const& vcolors(mesh->get_vertex_colors());
28 mve::TriangleMesh::TexCoordList const& vtexuv(mesh->get_vertex_texcoords());
29
30 /* Init vertex VBO. */
31 {
32 VertexBuffer::Ptr vbo = VertexBuffer::create();
33 vbo->set_data(&verts[0][0], (GLsizei)verts.size(), 3);
34 this->set_vertex_vbo(vbo);
35 }
36
37 /* Init index VBO if faces are given. */
38 if (!faces.empty())
39 {
41 vbo->set_indices(&faces[0], (GLsizei)faces.size());
42 this->set_index_vbo(vbo);
43 }
44
45 /* Init normal VBO if normals are given. */
46 if (!vnormals.empty())
47 {
49 vbo->set_data(&vnormals[0][0], (GLsizei)vnormals.size(), 3);
50 this->add_vbo(vbo, OGL_ATTRIB_NORMAL);
51 }
52
53 /* Init color VBO if colors are given. */
54 if (!vcolors.empty())
55 {
57 vbo->set_data(&vcolors[0][0], (GLsizei)vcolors.size(), 4);
58 this->add_vbo(vbo, OGL_ATTRIB_COLOR);
59 }
60
61 /* Init UV VBO if texture coordinates are given. */
62 if (!vtexuv.empty())
63 {
65 vbo->set_data(&vtexuv[0][0], (GLsizei)vtexuv.size(), 2);
66 this->add_vbo(vbo, OGL_ATTRIB_TEXCOORD);
67 }
68}
69
std::vector< math::Vec3f > VertexList
Definition mesh.h:33
std::vector< math::Vec4f > ColorList
Definition mesh.h:34
std::vector< math::Vec3f > NormalList
Definition mesh.h:95
std::vector< math::Vec2f > TexCoordList
Definition mesh.h:96
std::vector< VertexID > FaceList
Definition mesh.h:97
std::shared_ptr< TriangleMesh const > ConstPtr
Definition mesh.h:93
static Ptr create(void)
std::shared_ptr< VertexBuffer > Ptr
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13
#define OGL_ATTRIB_NORMAL
#define OGL_ATTRIB_COLOR
#define OGL_ATTRIB_TEXCOORD