hx3d  1
2D/3D Simple Game Framework
buffer.hpp
1 /*
2  Base buffer.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_GRAPHICS_BUFFERS_BUFFER
22 #define HX3D_GRAPHICS_BUFFERS_BUFFER
23 
24 #include <vector>
25 
26 #include "hx3d/graphics/gl.hpp"
27 
28 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
29 
30 namespace hx3d {
31 namespace graphics {
32 
36 namespace buffers {
37 
41 template <class T>
42 class Buffer {
43 
44 public:
45  Buffer();
46  virtual ~Buffer();
47 
53  void set(const std::vector<T>& values);
54 
60  void add(const std::vector<T>& values);
61 
67  T* data();
68 
74  GLuint getId();
75 
81  unsigned int size();
82 
88  std::vector<T>& getVector();
89 
97  T getValue(unsigned int i);
98 
105  void setValue(const unsigned int i, const T value);
106 
110  void clear();
111 
112 protected:
114  std::vector<T> _vector;
116  GLuint _buf;
117 };
118 
119 } /* buffers */
120 } /* graphics */
121 } /* hx3d */
122 
123 #include "hx3d/graphics/buffers/_inline/buffer.inl.hpp"
124 
125 #endif
GLuint getId()
Get the buffer ID.
Definition: buffer.inl.hpp:36
void add(const std::vector< T > &values)
Add buffer values.
Definition: buffer.inl.hpp:49
std::vector< T > _vector
Data.
Definition: buffer.hpp:114
hx3d framework namespace
Definition: audio.hpp:26
void clear()
Clear all values.
Definition: buffer.inl.hpp:82
void setValue(const unsigned int i, const T value)
Set a value.
Definition: buffer.inl.hpp:77
OpenGL data buffer.
Definition: buffer.hpp:42
std::vector< T > & getVector()
Get the vector.
Definition: buffer.inl.hpp:67
T * data()
Get the buffer values.
Definition: buffer.inl.hpp:57
T getValue(unsigned int i)
Get a value.
Definition: buffer.inl.hpp:72
unsigned int size()
Get the buffer size.
Definition: buffer.inl.hpp:62
GLuint _buf
Internal ID.
Definition: buffer.hpp:116