MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
vertex_array.h
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#ifndef OGL_VERTEX_ARRAY_HEADER
11#define OGL_VERTEX_ARRAY_HEADER
12
13#include <utility>
14#include <vector>
15#include <string>
16#include <memory>
17
18#include "ogl/defines.h"
19#include "ogl/opengl.h"
20#include "ogl/check_gl_error.h"
21#include "ogl/shader_program.h"
22#include "ogl/vertex_buffer.h"
23
25
35{
36public:
37 typedef std::shared_ptr<VertexArray> Ptr;
38 typedef std::shared_ptr<VertexArray const> ConstPtr;
39
40 typedef std::pair<VertexBuffer::Ptr, std::string> BoundVBO;
41 typedef std::vector<BoundVBO> VBOList;
42
43public:
44 virtual ~VertexArray (void);
45 static Ptr create (void);
46
48 void set_primitive (GLuint primitive);
49
51 void set_shader (ShaderProgram::Ptr shader);
52
54 void set_vertex_vbo (VertexBuffer::Ptr vbo);
55
57 void set_index_vbo (VertexBuffer::Ptr vbo);
58
60 void add_vbo (VertexBuffer::Ptr vbo, std::string const& name);
61
63 void remove_vbo (std::string const& name);
64
66 void reset_vertex_array (void);
67
69 void draw (void);
70
71protected:
72 VertexArray (void);
73 void assign_attrib (BoundVBO const& bound_vbo);
74
75private:
76 GLuint vao_id;
77 GLuint primitive;
78 ShaderProgram::Ptr shader;
79
80 /* Vertex VBO, Index VBO and generic VBOs. */
81 VertexBuffer::Ptr vert_vbo;
82 VertexBuffer::Ptr index_vbo;
83 VBOList vbo_list;
84};
85
86/* ---------------------------------------------------------------- */
87
88inline
89VertexArray::VertexArray (void)
90{
91 glGenVertexArrays(1, &this->vao_id);
93 this->primitive = GL_TRIANGLES;
94}
95
96inline
97VertexArray::~VertexArray (void)
98{
99 glDeleteVertexArrays(1, &this->vao_id);
101}
102
103inline VertexArray::Ptr
104VertexArray::create (void)
105{
106 return Ptr(new VertexArray);
107}
108
109inline void
110VertexArray::set_primitive (GLuint primitive)
111{
112 this->primitive = primitive;
113}
114
115inline void
116VertexArray::set_vertex_vbo (VertexBuffer::Ptr vbo)
117{
118 this->vert_vbo = vbo;
119}
120
121inline void
122VertexArray::set_index_vbo (VertexBuffer::Ptr vbo)
123{
124 this->index_vbo = vbo;
125}
126
127inline void
128VertexArray::add_vbo (VertexBuffer::Ptr vbo, std::string const& name)
129{
130 this->vbo_list.push_back(std::make_pair(vbo, name));
131}
132
133inline void
134VertexArray::reset_vertex_array(void)
135{
136 this->vert_vbo.reset();
137 this->index_vbo.reset();
138 this->vbo_list.clear();
139 //this->shader.reset();
140 glDeleteVertexArrays(1, &this->vao_id);
142 glGenVertexArrays(1, &this->vao_id);
144}
145
146inline void
147VertexArray::set_shader (ShaderProgram::Ptr shader)
148{
149 this->shader = shader;
150}
151
153
154#endif /* OGL_VERTEX_ARRAY_HEADER */
std::shared_ptr< ShaderProgram > Ptr
OpenGL vertex array object abstraction.
std::pair< VertexBuffer::Ptr, std::string > BoundVBO
std::shared_ptr< VertexArray > Ptr
std::shared_ptr< VertexArray const > ConstPtr
std::vector< BoundVBO > VBOList
std::shared_ptr< VertexBuffer > Ptr
void check_gl_error()
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13