0
|
1 /* ============================================================================
|
|
2 * Freetype GL - A C OpenGL Freetype engine
|
|
3 * Platform: Any
|
|
4 * WWW: http://code.google.com/p/freetype-gl/
|
|
5 * ----------------------------------------------------------------------------
|
|
6 * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
|
|
7 *
|
|
8 * Redistribution and use in source and binary forms, with or without
|
|
9 * modification, are permitted provided that the following conditions are met:
|
|
10 *
|
|
11 * 1. Redistributions of source code must retain the above copyright notice,
|
|
12 * this list of conditions and the following disclaimer.
|
|
13 *
|
|
14 * 2. Redistributions in binary form must reproduce the above copyright
|
|
15 * notice, this list of conditions and the following disclaimer in the
|
|
16 * documentation and/or other materials provided with the distribution.
|
|
17 *
|
|
18 * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
|
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
21 * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28 *
|
|
29 * The views and conclusions contained in the software and documentation are
|
|
30 * those of the authors and should not be interpreted as representing official
|
|
31 * policies, either expressed or implied, of Nicolas P. Rougier.
|
|
32 * ============================================================================
|
|
33 */
|
|
34 #ifndef __VERTEX_BUFFER_H__
|
|
35 #define __VERTEX_BUFFER_H__
|
|
36
|
|
37 #ifdef __cplusplus
|
|
38 extern "C" {
|
|
39 #endif
|
|
40
|
|
41 #include "opengl.h"
|
|
42 #include "vector.h"
|
|
43 #include "vertex-attribute.h"
|
|
44
|
|
45
|
|
46 /**
|
|
47 * @file vertex-buffer.h
|
|
48 * @author Nicolas Rougier (Nicolas.Rougier@inria.fr)
|
|
49 * @date April, 2012
|
|
50 *
|
|
51 * @defgroup vertex-buffer Vertex buffer
|
|
52 *
|
|
53 * @{
|
|
54 */
|
|
55
|
|
56
|
|
57 /**
|
|
58 * Generic vertex buffer.
|
|
59 */
|
|
60 typedef struct
|
|
61 {
|
|
62 /** Format of the vertex buffer. */
|
|
63 char * format;
|
|
64
|
|
65 /** Vector of vertices. */
|
|
66 vector_t * vertices;
|
|
67
|
|
68 /** GL identity of the vertices buffer. */
|
|
69 GLuint vertices_id;
|
|
70
|
|
71 /** Vector of indices. */
|
|
72 vector_t * indices;
|
|
73
|
|
74 /** GL identity of the indices buffer. */
|
|
75 GLuint indices_id;
|
|
76
|
|
77 /** Current size of the vertices buffer in GPU */
|
|
78 size_t GPU_vsize;
|
|
79
|
|
80 /** Current size of the indices buffer in GPU*/
|
|
81 size_t GPU_isize;
|
|
82
|
|
83 /** GL primitives to render. */
|
|
84 GLenum mode;
|
|
85
|
|
86 /** Whether the vertex buffer needs to be uploaded to GPU memory. */
|
|
87 char state;
|
|
88
|
|
89 /** Individual items */
|
|
90 vector_t * items;
|
|
91
|
|
92 /** Array of attributes. */
|
|
93 vertex_attribute_t *attributes[MAX_VERTEX_ATTRIBUTE];
|
|
94 } vertex_buffer_t;
|
|
95
|
|
96
|
|
97 /**
|
|
98 * Creates an empty vertex buffer.
|
|
99 *
|
|
100 * @param format a string describing vertex format.
|
|
101 * @return an empty vertex buffer.
|
|
102 */
|
|
103 vertex_buffer_t *
|
|
104 vertex_buffer_new( const char *format );
|
|
105
|
|
106
|
|
107 /**
|
|
108 * Deletes vertex buffer and releases GPU memory.
|
|
109 *
|
|
110 * @param self a vertex buffer
|
|
111 */
|
|
112 void
|
|
113 vertex_buffer_delete( vertex_buffer_t * self );
|
|
114
|
|
115
|
|
116 /**
|
|
117 * Returns the number of items in the vertex buffer
|
|
118 *
|
|
119 * @param self a vertex buffer
|
|
120 * @return number of items
|
|
121 */
|
|
122 size_t
|
|
123 vertex_buffer_size( const vertex_buffer_t *self );
|
|
124
|
|
125
|
|
126 /**
|
|
127 * Returns vertex format
|
|
128 *
|
|
129 * @param self a vertex buffer
|
|
130 * @return vertex format
|
|
131 */
|
|
132 const char *
|
|
133 vertex_buffer_format( const vertex_buffer_t *self );
|
|
134
|
|
135
|
|
136 /**
|
|
137 * Print information about a vertex buffer
|
|
138 *
|
|
139 * @param self a vertex buffer
|
|
140 */
|
|
141 void
|
|
142 vertex_buffer_print( vertex_buffer_t * self );
|
|
143
|
|
144
|
|
145 /**
|
|
146 * Prepare vertex buffer for render.
|
|
147 *
|
|
148 * @param self a vertex buffer
|
|
149 * @param mode render mode
|
|
150 */
|
|
151 void
|
|
152 vertex_buffer_render_setup ( vertex_buffer_t *self,
|
|
153 GLenum mode );
|
|
154
|
|
155
|
|
156 /**
|
|
157 * Finish rendering by setting back modified states
|
|
158 *
|
|
159 * @param self a vertex buffer
|
|
160 */
|
|
161 void
|
|
162 vertex_buffer_render_finish ( vertex_buffer_t *self );
|
|
163
|
|
164
|
|
165 /**
|
|
166 * Render vertex buffer.
|
|
167 *
|
|
168 * @param self a vertex buffer
|
|
169 * @param mode render mode
|
|
170 */
|
|
171 void
|
|
172 vertex_buffer_render ( vertex_buffer_t *self,
|
|
173 GLenum mode );
|
|
174
|
|
175
|
|
176 /**
|
|
177 * Render a specified item from the vertex buffer.
|
|
178 *
|
|
179 * @param self a vertex buffer
|
|
180 * @param index index of the item to be rendered
|
|
181 */
|
|
182 void
|
|
183 vertex_buffer_render_item ( vertex_buffer_t *self,
|
|
184 size_t index );
|
|
185
|
|
186
|
|
187 /**
|
|
188 * Upload buffer to GPU memory.
|
|
189 *
|
|
190 * @param self a vertex buffer
|
|
191 */
|
|
192 void
|
|
193 vertex_buffer_upload( vertex_buffer_t *self );
|
|
194
|
|
195
|
|
196 /**
|
|
197 * Clear all items.
|
|
198 *
|
|
199 * @param self a vertex buffer
|
|
200 */
|
|
201 void
|
|
202 vertex_buffer_clear( vertex_buffer_t *self );
|
|
203
|
|
204
|
|
205 /**
|
|
206 * Appends indices at the end of the buffer.
|
|
207 *
|
|
208 * @param self a vertex buffer
|
|
209 * @param indices indices to be appended
|
|
210 * @param icount number of indices to be appended
|
|
211 *
|
|
212 * @private
|
|
213 */
|
|
214 void
|
|
215 vertex_buffer_push_back_indices ( vertex_buffer_t *self,
|
|
216 const GLuint * indices,
|
|
217 const size_t icount );
|
|
218
|
|
219
|
|
220 /**
|
|
221 * Appends vertices at the end of the buffer.
|
|
222 *
|
|
223 * @note Internal use
|
|
224 *
|
|
225 * @param self a vertex buffer
|
|
226 * @param vertices vertices to be appended
|
|
227 * @param vcount number of vertices to be appended
|
|
228 *
|
|
229 * @private
|
|
230 */
|
|
231 void
|
|
232 vertex_buffer_push_back_vertices ( vertex_buffer_t *self,
|
|
233 const void * vertices,
|
|
234 const size_t vcount );
|
|
235
|
|
236
|
|
237 /**
|
|
238 * Insert indices in the buffer.
|
|
239 *
|
|
240 * @param self a vertex buffer
|
|
241 * @param index location before which to insert indices
|
|
242 * @param indices indices to be appended
|
|
243 * @param icount number of indices to be appended
|
|
244 *
|
|
245 * @private
|
|
246 */
|
|
247 void
|
|
248 vertex_buffer_insert_indices ( vertex_buffer_t *self,
|
|
249 const size_t index,
|
|
250 const GLuint *indices,
|
|
251 const size_t icount );
|
|
252
|
|
253
|
|
254 /**
|
|
255 * Insert vertices in the buffer.
|
|
256 *
|
|
257 * @param self a vertex buffer
|
|
258 * @param index location before which to insert vertices
|
|
259 * @param vertices vertices to be appended
|
|
260 * @param vcount number of vertices to be appended
|
|
261 *
|
|
262 * @private
|
|
263 */
|
|
264 void
|
|
265 vertex_buffer_insert_vertices ( vertex_buffer_t *self,
|
|
266 const size_t index,
|
|
267 const void *vertices,
|
|
268 const size_t vcount );
|
|
269
|
|
270 /**
|
|
271 * Erase indices in the buffer.
|
|
272 *
|
|
273 * @param self a vertex buffer
|
|
274 * @param first the index of the first index to be erased
|
|
275 * @param last the index of the last index to be erased
|
|
276 *
|
|
277 * @private
|
|
278 */
|
|
279 void
|
|
280 vertex_buffer_erase_indices ( vertex_buffer_t *self,
|
|
281 const size_t first,
|
|
282 const size_t last );
|
|
283
|
|
284 /**
|
|
285 * Erase vertices in the buffer.
|
|
286 *
|
|
287 * @param self a vertex buffer
|
|
288 * @param first the index of the first vertex to be erased
|
|
289 * @param last the index of the last vertex to be erased
|
|
290 *
|
|
291 * @private
|
|
292 */
|
|
293 void
|
|
294 vertex_buffer_erase_vertices ( vertex_buffer_t *self,
|
|
295 const size_t first,
|
|
296 const size_t last );
|
|
297
|
|
298
|
|
299 /**
|
|
300 * Append a new item to the collection.
|
|
301 *
|
|
302 * @param self a vertex buffer
|
|
303 * @param vcount number of vertices
|
|
304 * @param vertices raw vertices data
|
|
305 * @param icount number of indices
|
|
306 * @param indices raw indices data
|
|
307 */
|
|
308 size_t
|
|
309 vertex_buffer_push_back( vertex_buffer_t * self,
|
|
310 const void * vertices, const size_t vcount,
|
|
311 const GLuint * indices, const size_t icount );
|
|
312
|
|
313
|
|
314 /**
|
|
315 * Insert a new item into the vertex buffer.
|
|
316 *
|
|
317 * @param self a vertex buffer
|
|
318 * @param index location before which to insert item
|
|
319 * @param vertices raw vertices data
|
|
320 * @param vcount number of vertices
|
|
321 * @param indices raw indices data
|
|
322 * @param icount number of indices
|
|
323 */
|
|
324 size_t
|
|
325 vertex_buffer_insert( vertex_buffer_t * self,
|
|
326 size_t index,
|
|
327 const void * vertices, const size_t vcount,
|
|
328 const GLuint * indices, const size_t icount );
|
|
329
|
|
330 /**
|
|
331 * Erase an item from the vertex buffer.
|
|
332 *
|
|
333 * @param self a vertex buffer
|
|
334 * @param index index of the item to be deleted
|
|
335 */
|
|
336 void
|
|
337 vertex_buffer_erase( vertex_buffer_t * self,
|
|
338 const size_t index );
|
|
339
|
|
340 /** @} */
|
|
341
|
|
342 #ifdef __cplusplus
|
|
343 }
|
|
344 #endif
|
|
345
|
|
346 #endif /* __VERTEX_BUFFER_H__ */
|