Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VBO.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 
20 #ifndef OMNI_VISUAL_VBO_H
21 #define OMNI_VISUAL_VBO_H
22 
23 #include <QOpenGLContext>
24 #include <omni/visual/util.h>
25 
26 namespace omni {
27  namespace visual {
28  /// A small Vertex Buffer Object class
29  struct VBO
30  {
31  VBO();
32 
33  /// Destructor. Frees VBO if necessary
34  ~VBO();
35 
36  /// Generate a new VBO and get the associated ID
37  void gen();
38 
39  /// Free the existing buffer generates a new one
40  void freeAndGen();
41 
42  /// Copy static vertex array onto GPU
43  template<typename BUF>
44  void bufferStaticArray(BUF const& _buf) {
45  withCurrentContext([&](QOpenGLFunctions& _) {
46  _.glBindBuffer(GL_ARRAY_BUFFER, id());
47  {
48  _.glBufferData(GL_ARRAY_BUFFER,
49  _buf.size() * sizeof(typename BUF::value_type),
50  _buf.data(),
51  GL_STATIC_DRAW);
52  }
53  _.glBindBuffer(GL_ARRAY_BUFFER, 0);
54  });
55  }
56 
57  /// Copy static index array onto GPU
58  template<typename BUF>
59  void bufferStaticElementArray(BUF const& _buf) {
60  withCurrentContext([&](QOpenGLFunctions& _) {
61  _.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id());
62  {
63  _.glBufferData(GL_ELEMENT_ARRAY_BUFFER,
64  _buf.size() * sizeof(typename BUF::value_type),
65  _buf.data(),
66  GL_STATIC_DRAW);
67  }
68  _.glBindBuffer(GL_ARRAY_BUFFER, 0);
69  });
70  }
71 
72  /// Free VBO via glDeleteBuffers
73  void free();
74 
75  /// Return buffer id
76  GLuint id() const;
77 
78  private:
79  GLuint id_ = 0;
80  };
81  }
82 }
83 
84 #endif /* OMNI_VISUAL_VBO_H */
A small Vertex Buffer Object class.
Definition: VBO.h:29
void freeAndGen()
Free the existing buffer generates a new one.
Definition: VBO.cpp:47
void bufferStaticElementArray(BUF const &_buf)
Copy static index array onto GPU.
Definition: VBO.h:59
void free()
Free VBO via glDeleteBuffers.
Definition: VBO.cpp:56
~VBO()
Destructor. Frees VBO if necessary.
Definition: VBO.cpp:33
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
GLuint id() const
Return buffer id.
Definition: VBO.cpp:65
GLuint id_
Definition: VBO.h:79
VBO()
Definition: VBO.cpp:28
void gen()
Generate a new VBO and get the associated ID.
Definition: VBO.cpp:38
void bufferStaticArray(BUF const &_buf)
Copy static vertex array onto GPU.
Definition: VBO.h:44