Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VertexVBO.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OMNI_VISUAL_VERTEXVBO_H_
20 #define OMNI_VISUAL_VERTEXVBO_H_
21 
22 #include <vector>
23 #include <omni/visual/VBO.h>
25 #include <omni/geometry/Vertex.h>
26 
27 namespace omni {
28  namespace visual {
29  /// Utility class for storing and drawing VBO data
30  class VertexVBO {
31  public:
32  /// Vertex buffer type
33  typedef std::vector<Vertex>vertex_buffer_type;
34 
35  /// Index buffer type
36  typedef std::vector<uint32_t>index_buffer_type;
37 
38  VertexVBO();
39 
40  VertexVBO(vertex_buffer_type const& _vertices,
41  index_buffer_type const& _indices);
42 
43 
44  /// Copy buffers to GPU
45  void buffer(
46  vertex_buffer_type const& _vertices,
47  index_buffer_type const& _indices);
48 
49  /// Bind buffer for drawing
50  void bind() const;
51 
52  /// Draw buffer as triangles
53  void draw() const;
54 
55  /// Draw specific indices from buffer as triangles
56  void draw(uint32_t _numIndices,
57  GLuint _drawType = GL_TRIANGLES) const;
58 
59  /// Unbind buffer
60  void unbind() const;
61 
62  template<typename ... ARGS>
63  void bindAndDraw(ARGS&& ... _args) const {
64  bind();
65  draw(_args ...);
66  unbind();
67  }
68 
69  /// Return number of indices in this buffer
70  size_t numIndices() const;
71 
72  /// Number of triangles = number of indices / 3
73  inline size_t numTriangles() const {
74  return numIndices() / 3;
75  }
76 
77  /// Return vertex vertex buffer object
78  VBO const& vertexVbo() const;
79 
80  /// Return index vertex buffer object
81  VBO const& indexVbo() const;
82 
83  private:
84  size_t numIndices_ = 0;
85  std::unique_ptr<VBO> vertexVbo_, indexVbo_;
86  };
87  }
88 }
89 
90 
91 #endif /* OMNI_VISUAL_VERTEXVBO_H_ */
void unbind() const
Unbind buffer.
Definition: VertexVBO.cpp:90
std::unique_ptr< VBO > indexVbo_
Definition: VertexVBO.h:85
A small Vertex Buffer Object class.
Definition: VBO.h:29
VertexVBO()
Definition: VertexVBO.cpp:26
std::vector< uint32_t > index_buffer_type
Index buffer type.
Definition: VertexVBO.h:36
VBO const & indexVbo() const
Return index vertex buffer object.
Definition: VertexVBO.cpp:110
size_t numTriangles() const
Number of triangles = number of indices / 3.
Definition: VertexVBO.h:73
void draw() const
Draw buffer as triangles.
Definition: VertexVBO.cpp:72
void bind() const
Bind buffer for drawing.
Definition: VertexVBO.cpp:60
void bindAndDraw(ARGS &&..._args) const
Definition: VertexVBO.h:63
size_t numIndices() const
Return number of indices in this buffer.
Definition: VertexVBO.cpp:102
std::unique_ptr< VBO > vertexVbo_
Definition: VertexVBO.h:85
Utility class for storing and drawing VBO data.
Definition: VertexVBO.h:30
std::vector< Vertex > vertex_buffer_type
Vertex buffer type.
Definition: VertexVBO.h:33
VBO const & vertexVbo() const
Return vertex vertex buffer object.
Definition: VertexVBO.cpp:106
void buffer(vertex_buffer_type const &_vertices, index_buffer_type const &_indices)
Copy buffers to GPU.
Definition: VertexVBO.cpp:33
size_t numIndices_
Definition: VertexVBO.h:84