hx3d  1
2D/3D Simple Game Framework
buffer.inl.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 namespace hx3d {
22 namespace graphics {
23 namespace buffers {
24 
25 template <class T>
26 Buffer<T>::Buffer() {
27  glGenBuffers(1, &_buf);
28 }
29 
30 template <class T>
31 Buffer<T>::~Buffer() {
32  glDeleteBuffers(1, &_buf);
33 }
34 
35 template <class T>
36 GLuint Buffer<T>::getId() {
37  return _buf;
38 }
39 
40 template <class T>
41 void Buffer<T>::set(const std::vector<T>& values) {
42  _vector.clear();
43  _vector.resize(values.size());
44 
45  std::copy(values.begin(), values.end(), _vector.begin());
46 }
47 
48 template <class T>
49 void Buffer<T>::add(const std::vector<T>& values) {
50  size_t prevSize = _vector.size();
51  _vector.resize(prevSize + values.size());
52 
53  std::copy(values.begin(), values.end(), _vector.begin() + prevSize);
54 }
55 
56 template <class T>
58  return _vector.data();
59 }
60 
61 template <class T>
62 unsigned int Buffer<T>::size() {
63  return _vector.size();
64 }
65 
66 template <class T>
67 std::vector<T>& Buffer<T>::getVector() {
68  return _vector;
69 }
70 
71 template <class T>
72 T Buffer<T>::getValue(const unsigned int i) {
73  return _vector[i];
74 }
75 
76 template <class T>
77 void Buffer<T>::setValue(const unsigned int i, const T value) {
78  _vector[i] = value;
79 }
80 
81 template <class T>
83  _vector.clear();
84 }
85 
86 } /* buffers */
87 } /* graphics */
88 } /* hx3d */
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
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
void set(const std::vector< T > &values)
Set the buffer values.
Definition: buffer.inl.hpp:41
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