/
buffer.h
245 lines (200 loc) · 11.8 KB
/
buffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#define GLM_FORCE_RADIANS
#include <GL/gl.h>
#include <glm/glm.hpp>
#pragma once
namespace EZGraphics {
/* ------------------------------------------- */
/** supported buffer types: Array is a standard array buffer and ElemArray is an element array (index buffer) */
typedef enum { Array, ElemArray } BufType;
/* ------------------------------------------- */
/** wrapper class for OpenGL Buffer objects */
class Buffer {
private:
GLuint handle; /** OpenGL name of the buffer object */
BufType tp; /** type of the buffer (array or element) */
GLenum type; /** type of entries - this is an OpenGL constant such as GL_INT */
int components; /** components per entry - can be 1,2,3 or 4, e.g. 3 if entries are 3D vectors */
void on();
void off();
GLenum getType() const { return type; }
GLuint getHandle() const { return handle; }
protected:
Buffer ( const int cs, const int size, const GLubyte * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLbyte * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLuint * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLint * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLshort * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLushort * const data = NULL, const BufType t = Array );
Buffer ( const int cs, const int size, const GLfloat * const data = NULL, const BufType t = Array );
public:
/**
Generates an error - use only pointers to Buffer objects for best results
*/
Buffer ( const Buffer &a );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLubyte * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLbyte * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLshort * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLushort * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLint * const data, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::ivec2 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::ivec3 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::ivec4 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLuint * const data, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::uvec2 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::uvec3 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::uvec4 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const GLfloat * const data, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::vec2 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::vec3 * const data = NULL, const BufType t = Array );
/**
Constructs a buffer object; sends data to it if non-NULL pointer is provided as the data parameter
\param size is the number of entries (typically, vertices in the model)
\param data is the pointer to data to be sent to the buffer; if data==NULL (default), no data is sent
\param t is the buffer type; default value is Array (meaning array buffer)
*/
Buffer ( const int size, const glm::vec4 * const data = NULL, const BufType t = Array );
/** deletes the buffer */
~Buffer();
/** will generate an error */
Buffer & operator= ( const Buffer & rhs );
/**
sets the vertex attribute index for data stored in the buffer
\param aix is the index of the attribute; has to match the location qualifier in the vertex shader
*/
void setIndex ( int aix ) const;
/**
Use buffer as shader storage
\param index is the index of the shader storage buffer; has to match the binding qualifier of the buffer in the shaders
*/
void useAsShaderStorage ( GLuint index );
friend class VertexArray;
friend class TFProgram;
};
/* ------------------------------------------- */
/** a wrapper for index buffers (or element array buffers) */
class IndexBuffer : public Buffer {
public:
/** constructs the index buffer; sends data to it if non-NULL pointer is provided as the second argument
\param size is the number of entries in the buffer
\param data is the pointer to data to be sent to it
*/
IndexBuffer ( const int size, const GLubyte * const data = NULL );
/** constructs the index buffer; sends data to it if non-NULL pointer is provided as the second argument
\param size is the number of entries in the buffer
\param data is the pointer to data to be sent to it
*/
IndexBuffer ( const int size, const GLuint * const data = NULL );
/** constructs the index buffer; sends data to it if non-NULL pointer is provided as the second argument
\param size is the number of entries in the buffer
\param data is the pointer to data to be sent to it
*/
IndexBuffer ( const int size, const GLushort * const data = NULL );
/** constructs the index buffer; sends data to it if non-NULL pointer is provided as the second argument
\param size is the number of entries in the buffer
\param data is the pointer to data to be sent to it
The resulting buffer has 2*size scalar entries
*/
IndexBuffer ( const int size, const glm::uvec2 * const data = NULL );
/** constructs the index buffer; sends data to it if non-NULL pointer is provided as the second argument
\param size is the number of entries in the buffer
\param data is the pointer to data to be sent to it
Note that the resulting buffer has 3*size scalar entries for this variant of the constructor
*/
IndexBuffer ( const int size, const glm::uvec3 * const data = NULL );
/** will generate an error - use only pointers to IndexBuffer objects for best results */
IndexBuffer ( const IndexBuffer & );
/** will generate an error - use only pointers to IndexBuffer objects for best results */
IndexBuffer & operator= ( const IndexBuffer & );
};
/* ------------------------------------------- */
};