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_ATTRIBUTE_H__
|
|
35 #define __VERTEX_ATTRIBUTE_H__
|
|
36
|
|
37 #ifdef __cplusplus
|
|
38 extern "C" {
|
|
39 #endif
|
|
40
|
|
41 #include "opengl.h"
|
|
42 #include "vector.h"
|
|
43
|
|
44
|
|
45 /**
|
|
46 * @file vertex-attribute.h
|
|
47 * @author Nicolas Rougier (Nicolas.Rougier@inria.fr)
|
|
48 *
|
|
49 * @defgroup vertex-attribut Vertex attribute
|
|
50 *
|
|
51 * Besides the required vertex position, vertices can have several other
|
|
52 * numeric attributes. Each is specified in the format string with a letter,
|
|
53 * the number of components and the data type.
|
|
54 *
|
|
55 * Each of the attributes is described in the table below with the set of valid
|
|
56 * format strings written as a regular expression (for example, "v[234][if]"
|
|
57 * means "v2f", "v3i", "v4f", etc. are all valid formats).
|
|
58 *
|
|
59 * Some attributes have a "recommended" format string, which is the most
|
|
60 * efficient form for the video driver as it requires less conversion.
|
|
61 *
|
|
62 * <table>
|
|
63 * <tr>
|
|
64 * <th>Attribute</th>
|
|
65 * <th>Formats</th>
|
|
66 * <th>Recommended</th>
|
|
67 * </tr>
|
|
68 * <tr>
|
|
69 * <td>Vertex position</td>
|
|
70 * <td>"v[234][sifd]"</td>
|
|
71 * <td>"v[234]f"</td>
|
|
72 * </tr>
|
|
73 * <tr>
|
|
74 * <td> Color </td>
|
|
75 * <td> "c[34][bBsSiIfd]" </td>
|
|
76 * <td> "c[34]B" </td>
|
|
77 * </tr>
|
|
78 * <tr>
|
|
79 * <td> Edge flag </td>
|
|
80 * <td> "e1[bB]" </td>
|
|
81 * <td> </td>
|
|
82 * </tr>
|
|
83 * <tr>
|
|
84 * <td> Fog coordinate </td>
|
|
85 * <td> "f[1234][bBsSiIfd]"</td>
|
|
86 * <td> </td>
|
|
87 * </tr>
|
|
88 * <tr>
|
|
89 * <td> Normal </td>
|
|
90 * <td> "n3[bsifd]" </td>
|
|
91 * <td> "n3f" </td>
|
|
92 * </tr>
|
|
93 * <tr>
|
|
94 * <td> Secondary color </td>
|
|
95 * <td> "s[34][bBsSiIfd]" </td>
|
|
96 * <td> "s[34]B" </td>
|
|
97 * </tr>
|
|
98 * <tr>
|
|
99 * <td> Texture coordinate </td>
|
|
100 * <td> "t[234][sifd]" </td>
|
|
101 * <td> "t[234]f" </td>
|
|
102 * </tr>
|
|
103 * <tr>
|
|
104 * <td> Generic attribute </td>
|
|
105 * <td> "[0-15]g(n)?[1234][bBsSiIfd]" </td>
|
|
106 * <td> </td>
|
|
107 * </tr>
|
|
108 * </table>
|
|
109 *
|
|
110 * The possible data types that can be specified in the format string are described below.
|
|
111 *
|
|
112 * <table>
|
|
113 * <tr>
|
|
114 * <th> Format </th>
|
|
115 * <th> Type </th>
|
|
116 * <th> GL Type </th>
|
|
117 * </tr>
|
|
118 * <tr>
|
|
119 * <td> "b" </td>
|
|
120 * <td> Signed byte </td>
|
|
121 * <td> GL_BYTE </td>
|
|
122 * </tr>
|
|
123 * <tr>
|
|
124 * <td> "B" </td>
|
|
125 * <td> Unsigned byte </td>
|
|
126 * <td> GL_UNSIGNED_BYTE </td>
|
|
127 * </tr>
|
|
128 * <tr>
|
|
129 * <td> "s" </td>
|
|
130 * <td> Signed short </td>
|
|
131 * <td> GL_SHORT </td>
|
|
132 * </tr>
|
|
133 * <tr>
|
|
134 * <td> "S" </td>
|
|
135 * <td> Unsigned short </td>
|
|
136 * <td> GL_UNSIGNED_SHORT </td>
|
|
137 * </tr>
|
|
138 * <tr>
|
|
139 * <td> "i" </td>
|
|
140 * <td> Signed int </td>
|
|
141 * <td> GL_INT </td>
|
|
142 * </tr>
|
|
143 * <tr>
|
|
144 * <td> "I" </td>
|
|
145 * <td> Unsigned int </td>
|
|
146 * <td> GL_UNSIGNED_INT </td>
|
|
147 * </tr>
|
|
148 * <tr>
|
|
149 * <td> "f" </td>
|
|
150 * <td> Float </td>
|
|
151 * <td> GL_FLOAT </td>
|
|
152 * </tr>
|
|
153 * <tr>
|
|
154 * <td> "d" </td>
|
|
155 * <td> Double </td>
|
|
156 * <td> GL_DOUBLE T </td>
|
|
157 * </tr>
|
|
158 * </table>
|
|
159 *
|
|
160 * The following attributes are normalised to the range [0, 1]. The value is
|
|
161 * used as-is if the data type is floating-point. If the data type is byte,
|
|
162 * short or int, the value is divided by the maximum value representable by
|
|
163 * that type. For example, unsigned bytes are divided by 255 to get the
|
|
164 * normalised value.
|
|
165 *
|
|
166 * - Color
|
|
167 * - Secondary color
|
|
168 * - Generic attributes with the "n" format given.
|
|
169 *
|
|
170 * Up to 16 generic attributes can be specified per vertex, and can be used by
|
|
171 * shader programs for any purpose (they are ignored in the fixed-function
|
|
172 * pipeline). For the other attributes, consult the OpenGL programming guide
|
|
173 * for details on their effects.
|
|
174 *
|
|
175 * When using the draw and related functions, attribute data is specified
|
|
176 * alongside the vertex position data. The following example reproduces the two
|
|
177 * points from the previous page, except that the first point is blue and the
|
|
178 * second green:
|
|
179 *
|
|
180 * It is an error to provide more than one set of data for any attribute, or to
|
|
181 * mismatch the size of the initial data with the number of vertices specified
|
|
182 * in the first argument.
|
|
183 *
|
|
184 * @{
|
|
185 */
|
|
186
|
|
187
|
|
188 /**
|
|
189 * Maximum number of attributes per vertex
|
|
190 *
|
|
191 * @private
|
|
192 */
|
|
193 #define MAX_VERTEX_ATTRIBUTE 16
|
|
194
|
|
195
|
|
196 /**
|
|
197 * Generic vertex attribute.
|
|
198 */
|
|
199 typedef struct
|
|
200 {
|
|
201 /**
|
|
202 * atribute name
|
|
203 */
|
|
204 GLchar * name;
|
|
205
|
|
206 /**
|
|
207 * index of the generic vertex attribute to be modified.
|
|
208 */
|
|
209 GLuint index;
|
|
210
|
|
211 /**
|
|
212 * Number of components per generic vertex attribute.
|
|
213 *
|
|
214 * Must be 1, 2, 3, or 4. The initial value is 4.
|
|
215 */
|
|
216 GLint size;
|
|
217
|
|
218 /**
|
|
219 * data type of each component in the array.
|
|
220 *
|
|
221 * Symbolic constants GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,
|
|
222 * GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, or GL_DOUBLE are
|
|
223 * accepted. The initial value is GL_FLOAT.
|
|
224 */
|
|
225 GLenum type;
|
|
226
|
|
227 /**
|
|
228 * whether fixed-point data values should be normalized (GL_TRUE) or
|
|
229 * converted directly as fixed-point values (GL_FALSE) when they are
|
|
230 * accessed.
|
|
231 */
|
|
232 GLboolean normalized;
|
|
233
|
|
234 /**
|
|
235 * byte offset between consecutive generic vertex attributes.
|
|
236 *
|
|
237 * If stride is 0, the generic vertex attributes are understood to be
|
|
238 * tightly packed in the array. The initial value is 0.
|
|
239 */
|
|
240 GLsizei stride;
|
|
241
|
|
242 /**
|
|
243 * pointer to the first component of the first attribute element in the
|
|
244 * array.
|
|
245 */
|
|
246 GLvoid * pointer;
|
|
247
|
|
248 /**
|
|
249 * pointer to the function that enable this attribute.
|
|
250 */
|
|
251 void ( * enable )(void *);
|
|
252
|
|
253 } vertex_attribute_t;
|
|
254
|
|
255
|
|
256
|
|
257 /**
|
|
258 * Create an attribute from the given parameters.
|
|
259 *
|
|
260 * @param size number of component
|
|
261 * @param type data type
|
|
262 * @param normalized Whether fixed-point data values should be normalized
|
|
263 (GL_TRUE) or converted directly as fixed-point values
|
|
264 (GL_FALSE) when they are accessed.
|
|
265 * @param stride byte offset between consecutive attributes.
|
|
266 * @param pointer pointer to the first component of the first attribute
|
|
267 * element in the array.
|
|
268 * @return a new initialized vertex attribute.
|
|
269 *
|
|
270 * @private
|
|
271 */
|
|
272 vertex_attribute_t *
|
|
273 vertex_attribute_new( GLchar * name,
|
|
274 GLint size,
|
|
275 GLenum type,
|
|
276 GLboolean normalized,
|
|
277 GLsizei stride,
|
|
278 GLvoid *pointer );
|
|
279
|
|
280
|
|
281
|
|
282 /**
|
|
283 * Delete a vertex attribute.
|
|
284 *
|
|
285 * @param self a vertex attribute
|
|
286 *
|
|
287 */
|
|
288 void
|
|
289 vertex_attribute_delete( vertex_attribute_t * self );
|
|
290
|
|
291
|
|
292 /**
|
|
293 * Create an attribute from the given description.
|
|
294 *
|
|
295 * @param format Format string specifies the format of a vertex attribute.
|
|
296 * @return an initialized vertex attribute
|
|
297 *
|
|
298 * @private
|
|
299 */
|
|
300 vertex_attribute_t *
|
|
301 vertex_attribute_parse( char *format );
|
|
302
|
|
303 /**
|
|
304 * Enable a vertex attribute.
|
|
305 *
|
|
306 * @param attr a vertex attribute
|
|
307 *
|
|
308 * @private
|
|
309 */
|
|
310 void
|
|
311 vertex_attribute_enable( vertex_attribute_t *attr );
|
|
312
|
|
313
|
|
314 /** @} */
|
|
315
|
|
316 #ifdef __cplusplus
|
|
317 }
|
|
318 #endif
|
|
319
|
|
320 #endif /* __VERTEX_ATTRIBUTE_H__ */
|