Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / main / api_arrayelt.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /* Author:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29 #include "glheader.h"
30 #include "api_arrayelt.h"
31 #include "bufferobj.h"
32 #include "context.h"
33 #include "imports.h"
34 #include "macros.h"
35 #include "glapi/glapioffsets.h"
36 #include "glapi/dispatch.h"
37
38 typedef void (GLAPIENTRY *array_func)( const void * );
39
40 typedef struct {
41 const struct gl_client_array *array;
42 int offset;
43 } AEarray;
44
45 typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
46
47 typedef struct {
48 const struct gl_client_array *array;
49 attrib_func func;
50 GLuint index;
51 } AEattrib;
52
53 typedef struct {
54 AEarray arrays[32];
55 AEattrib attribs[VERT_ATTRIB_MAX + 1];
56 GLuint NewState;
57
58 struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
59 GLuint nr_vbos;
60 GLboolean mapped_vbos;
61
62 } AEcontext;
63
64 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
65
66
67 /*
68 * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
69 * in the range [0, 7]. Luckily these type tokens are sequentially
70 * numbered in gl.h, except for GL_DOUBLE.
71 */
72 #define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
73
74
75 #if FEATURE_arrayelt
76
77
78 static const int ColorFuncs[2][8] = {
79 {
80 _gloffset_Color3bv,
81 _gloffset_Color3ubv,
82 _gloffset_Color3sv,
83 _gloffset_Color3usv,
84 _gloffset_Color3iv,
85 _gloffset_Color3uiv,
86 _gloffset_Color3fv,
87 _gloffset_Color3dv,
88 },
89 {
90 _gloffset_Color4bv,
91 _gloffset_Color4ubv,
92 _gloffset_Color4sv,
93 _gloffset_Color4usv,
94 _gloffset_Color4iv,
95 _gloffset_Color4uiv,
96 _gloffset_Color4fv,
97 _gloffset_Color4dv,
98 },
99 };
100
101 static const int VertexFuncs[3][8] = {
102 {
103 -1,
104 -1,
105 _gloffset_Vertex2sv,
106 -1,
107 _gloffset_Vertex2iv,
108 -1,
109 _gloffset_Vertex2fv,
110 _gloffset_Vertex2dv,
111 },
112 {
113 -1,
114 -1,
115 _gloffset_Vertex3sv,
116 -1,
117 _gloffset_Vertex3iv,
118 -1,
119 _gloffset_Vertex3fv,
120 _gloffset_Vertex3dv,
121 },
122 {
123 -1,
124 -1,
125 _gloffset_Vertex4sv,
126 -1,
127 _gloffset_Vertex4iv,
128 -1,
129 _gloffset_Vertex4fv,
130 _gloffset_Vertex4dv,
131 },
132 };
133
134 static const int IndexFuncs[8] = {
135 -1,
136 _gloffset_Indexubv,
137 _gloffset_Indexsv,
138 -1,
139 _gloffset_Indexiv,
140 -1,
141 _gloffset_Indexfv,
142 _gloffset_Indexdv,
143 };
144
145 static const int NormalFuncs[8] = {
146 _gloffset_Normal3bv,
147 -1,
148 _gloffset_Normal3sv,
149 -1,
150 _gloffset_Normal3iv,
151 -1,
152 _gloffset_Normal3fv,
153 _gloffset_Normal3dv,
154 };
155
156 /* Note: _gloffset_* for these may not be a compile-time constant. */
157 static int SecondaryColorFuncs[8];
158 static int FogCoordFuncs[8];
159
160
161 /**
162 ** GL_NV_vertex_program
163 **/
164
165 /* GL_BYTE attributes */
166
167 static void GLAPIENTRY VertexAttrib1NbvNV(GLuint index, const GLbyte *v)
168 {
169 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
170 }
171
172 static void GLAPIENTRY VertexAttrib1bvNV(GLuint index, const GLbyte *v)
173 {
174 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
175 }
176
177 static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v)
178 {
179 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
180 }
181
182 static void GLAPIENTRY VertexAttrib2bvNV(GLuint index, const GLbyte *v)
183 {
184 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
185 }
186
187 static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v)
188 {
189 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
190 BYTE_TO_FLOAT(v[1]),
191 BYTE_TO_FLOAT(v[2])));
192 }
193
194 static void GLAPIENTRY VertexAttrib3bvNV(GLuint index, const GLbyte *v)
195 {
196 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
197 }
198
199 static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v)
200 {
201 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
202 BYTE_TO_FLOAT(v[1]),
203 BYTE_TO_FLOAT(v[2]),
204 BYTE_TO_FLOAT(v[3])));
205 }
206
207 static void GLAPIENTRY VertexAttrib4bvNV(GLuint index, const GLbyte *v)
208 {
209 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
210 }
211
212 /* GL_UNSIGNED_BYTE attributes */
213
214 static void GLAPIENTRY VertexAttrib1NubvNV(GLuint index, const GLubyte *v)
215 {
216 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
217 }
218
219 static void GLAPIENTRY VertexAttrib1ubvNV(GLuint index, const GLubyte *v)
220 {
221 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
222 }
223
224 static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v)
225 {
226 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
227 UBYTE_TO_FLOAT(v[1])));
228 }
229
230 static void GLAPIENTRY VertexAttrib2ubvNV(GLuint index, const GLubyte *v)
231 {
232 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
233 }
234
235 static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v)
236 {
237 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
238 UBYTE_TO_FLOAT(v[1]),
239 UBYTE_TO_FLOAT(v[2])));
240 }
241 static void GLAPIENTRY VertexAttrib3ubvNV(GLuint index, const GLubyte *v)
242 {
243 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
244 }
245
246 static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v)
247 {
248 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
249 UBYTE_TO_FLOAT(v[1]),
250 UBYTE_TO_FLOAT(v[2]),
251 UBYTE_TO_FLOAT(v[3])));
252 }
253
254 static void GLAPIENTRY VertexAttrib4ubvNV(GLuint index, const GLubyte *v)
255 {
256 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
257 }
258
259 /* GL_SHORT attributes */
260
261 static void GLAPIENTRY VertexAttrib1NsvNV(GLuint index, const GLshort *v)
262 {
263 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
264 }
265
266 static void GLAPIENTRY VertexAttrib1svNV(GLuint index, const GLshort *v)
267 {
268 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
269 }
270
271 static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v)
272 {
273 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
274 SHORT_TO_FLOAT(v[1])));
275 }
276
277 static void GLAPIENTRY VertexAttrib2svNV(GLuint index, const GLshort *v)
278 {
279 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
280 }
281
282 static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v)
283 {
284 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
285 SHORT_TO_FLOAT(v[1]),
286 SHORT_TO_FLOAT(v[2])));
287 }
288
289 static void GLAPIENTRY VertexAttrib3svNV(GLuint index, const GLshort *v)
290 {
291 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
292 }
293
294 static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v)
295 {
296 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
297 SHORT_TO_FLOAT(v[1]),
298 SHORT_TO_FLOAT(v[2]),
299 SHORT_TO_FLOAT(v[3])));
300 }
301
302 static void GLAPIENTRY VertexAttrib4svNV(GLuint index, const GLshort *v)
303 {
304 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
305 }
306
307 /* GL_UNSIGNED_SHORT attributes */
308
309 static void GLAPIENTRY VertexAttrib1NusvNV(GLuint index, const GLushort *v)
310 {
311 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
312 }
313
314 static void GLAPIENTRY VertexAttrib1usvNV(GLuint index, const GLushort *v)
315 {
316 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
317 }
318
319 static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v)
320 {
321 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
322 USHORT_TO_FLOAT(v[1])));
323 }
324
325 static void GLAPIENTRY VertexAttrib2usvNV(GLuint index, const GLushort *v)
326 {
327 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
328 }
329
330 static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v)
331 {
332 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
333 USHORT_TO_FLOAT(v[1]),
334 USHORT_TO_FLOAT(v[2])));
335 }
336
337 static void GLAPIENTRY VertexAttrib3usvNV(GLuint index, const GLushort *v)
338 {
339 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
340 }
341
342 static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v)
343 {
344 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
345 USHORT_TO_FLOAT(v[1]),
346 USHORT_TO_FLOAT(v[2]),
347 USHORT_TO_FLOAT(v[3])));
348 }
349
350 static void GLAPIENTRY VertexAttrib4usvNV(GLuint index, const GLushort *v)
351 {
352 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
353 }
354
355 /* GL_INT attributes */
356
357 static void GLAPIENTRY VertexAttrib1NivNV(GLuint index, const GLint *v)
358 {
359 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
360 }
361
362 static void GLAPIENTRY VertexAttrib1ivNV(GLuint index, const GLint *v)
363 {
364 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
365 }
366
367 static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v)
368 {
369 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
370 INT_TO_FLOAT(v[1])));
371 }
372
373 static void GLAPIENTRY VertexAttrib2ivNV(GLuint index, const GLint *v)
374 {
375 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
376 }
377
378 static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v)
379 {
380 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
381 INT_TO_FLOAT(v[1]),
382 INT_TO_FLOAT(v[2])));
383 }
384
385 static void GLAPIENTRY VertexAttrib3ivNV(GLuint index, const GLint *v)
386 {
387 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
388 }
389
390 static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v)
391 {
392 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
393 INT_TO_FLOAT(v[1]),
394 INT_TO_FLOAT(v[2]),
395 INT_TO_FLOAT(v[3])));
396 }
397
398 static void GLAPIENTRY VertexAttrib4ivNV(GLuint index, const GLint *v)
399 {
400 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
401 }
402
403 /* GL_UNSIGNED_INT attributes */
404
405 static void GLAPIENTRY VertexAttrib1NuivNV(GLuint index, const GLuint *v)
406 {
407 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
408 }
409
410 static void GLAPIENTRY VertexAttrib1uivNV(GLuint index, const GLuint *v)
411 {
412 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
413 }
414
415 static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v)
416 {
417 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
418 UINT_TO_FLOAT(v[1])));
419 }
420
421 static void GLAPIENTRY VertexAttrib2uivNV(GLuint index, const GLuint *v)
422 {
423 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
424 }
425
426 static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v)
427 {
428 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
429 UINT_TO_FLOAT(v[1]),
430 UINT_TO_FLOAT(v[2])));
431 }
432
433 static void GLAPIENTRY VertexAttrib3uivNV(GLuint index, const GLuint *v)
434 {
435 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
436 }
437
438 static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v)
439 {
440 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
441 UINT_TO_FLOAT(v[1]),
442 UINT_TO_FLOAT(v[2]),
443 UINT_TO_FLOAT(v[3])));
444 }
445
446 static void GLAPIENTRY VertexAttrib4uivNV(GLuint index, const GLuint *v)
447 {
448 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
449 }
450
451 /* GL_FLOAT attributes */
452
453 static void GLAPIENTRY VertexAttrib1fvNV(GLuint index, const GLfloat *v)
454 {
455 CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index, v));
456 }
457
458 static void GLAPIENTRY VertexAttrib2fvNV(GLuint index, const GLfloat *v)
459 {
460 CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index, v));
461 }
462
463 static void GLAPIENTRY VertexAttrib3fvNV(GLuint index, const GLfloat *v)
464 {
465 CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index, v));
466 }
467
468 static void GLAPIENTRY VertexAttrib4fvNV(GLuint index, const GLfloat *v)
469 {
470 CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index, v));
471 }
472
473 /* GL_DOUBLE attributes */
474
475 static void GLAPIENTRY VertexAttrib1dvNV(GLuint index, const GLdouble *v)
476 {
477 CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index, v));
478 }
479
480 static void GLAPIENTRY VertexAttrib2dvNV(GLuint index, const GLdouble *v)
481 {
482 CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index, v));
483 }
484
485 static void GLAPIENTRY VertexAttrib3dvNV(GLuint index, const GLdouble *v)
486 {
487 CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index, v));
488 }
489
490 static void GLAPIENTRY VertexAttrib4dvNV(GLuint index, const GLdouble *v)
491 {
492 CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index, v));
493 }
494
495
496 /*
497 * Array [size][type] of VertexAttrib functions
498 */
499 static attrib_func AttribFuncsNV[2][4][8] = {
500 {
501 /* non-normalized */
502 {
503 /* size 1 */
504 (attrib_func) VertexAttrib1bvNV,
505 (attrib_func) VertexAttrib1ubvNV,
506 (attrib_func) VertexAttrib1svNV,
507 (attrib_func) VertexAttrib1usvNV,
508 (attrib_func) VertexAttrib1ivNV,
509 (attrib_func) VertexAttrib1uivNV,
510 (attrib_func) VertexAttrib1fvNV,
511 (attrib_func) VertexAttrib1dvNV
512 },
513 {
514 /* size 2 */
515 (attrib_func) VertexAttrib2bvNV,
516 (attrib_func) VertexAttrib2ubvNV,
517 (attrib_func) VertexAttrib2svNV,
518 (attrib_func) VertexAttrib2usvNV,
519 (attrib_func) VertexAttrib2ivNV,
520 (attrib_func) VertexAttrib2uivNV,
521 (attrib_func) VertexAttrib2fvNV,
522 (attrib_func) VertexAttrib2dvNV
523 },
524 {
525 /* size 3 */
526 (attrib_func) VertexAttrib3bvNV,
527 (attrib_func) VertexAttrib3ubvNV,
528 (attrib_func) VertexAttrib3svNV,
529 (attrib_func) VertexAttrib3usvNV,
530 (attrib_func) VertexAttrib3ivNV,
531 (attrib_func) VertexAttrib3uivNV,
532 (attrib_func) VertexAttrib3fvNV,
533 (attrib_func) VertexAttrib3dvNV
534 },
535 {
536 /* size 4 */
537 (attrib_func) VertexAttrib4bvNV,
538 (attrib_func) VertexAttrib4ubvNV,
539 (attrib_func) VertexAttrib4svNV,
540 (attrib_func) VertexAttrib4usvNV,
541 (attrib_func) VertexAttrib4ivNV,
542 (attrib_func) VertexAttrib4uivNV,
543 (attrib_func) VertexAttrib4fvNV,
544 (attrib_func) VertexAttrib4dvNV
545 }
546 },
547 {
548 /* normalized (except for float/double) */
549 {
550 /* size 1 */
551 (attrib_func) VertexAttrib1NbvNV,
552 (attrib_func) VertexAttrib1NubvNV,
553 (attrib_func) VertexAttrib1NsvNV,
554 (attrib_func) VertexAttrib1NusvNV,
555 (attrib_func) VertexAttrib1NivNV,
556 (attrib_func) VertexAttrib1NuivNV,
557 (attrib_func) VertexAttrib1fvNV,
558 (attrib_func) VertexAttrib1dvNV
559 },
560 {
561 /* size 2 */
562 (attrib_func) VertexAttrib2NbvNV,
563 (attrib_func) VertexAttrib2NubvNV,
564 (attrib_func) VertexAttrib2NsvNV,
565 (attrib_func) VertexAttrib2NusvNV,
566 (attrib_func) VertexAttrib2NivNV,
567 (attrib_func) VertexAttrib2NuivNV,
568 (attrib_func) VertexAttrib2fvNV,
569 (attrib_func) VertexAttrib2dvNV
570 },
571 {
572 /* size 3 */
573 (attrib_func) VertexAttrib3NbvNV,
574 (attrib_func) VertexAttrib3NubvNV,
575 (attrib_func) VertexAttrib3NsvNV,
576 (attrib_func) VertexAttrib3NusvNV,
577 (attrib_func) VertexAttrib3NivNV,
578 (attrib_func) VertexAttrib3NuivNV,
579 (attrib_func) VertexAttrib3fvNV,
580 (attrib_func) VertexAttrib3dvNV
581 },
582 {
583 /* size 4 */
584 (attrib_func) VertexAttrib4NbvNV,
585 (attrib_func) VertexAttrib4NubvNV,
586 (attrib_func) VertexAttrib4NsvNV,
587 (attrib_func) VertexAttrib4NusvNV,
588 (attrib_func) VertexAttrib4NivNV,
589 (attrib_func) VertexAttrib4NuivNV,
590 (attrib_func) VertexAttrib4fvNV,
591 (attrib_func) VertexAttrib4dvNV
592 }
593 }
594 };
595
596
597 /**
598 ** GL_ARB_vertex_program
599 **/
600
601 /* GL_BYTE attributes */
602
603 static void GLAPIENTRY VertexAttrib1NbvARB(GLuint index, const GLbyte *v)
604 {
605 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
606 }
607
608 static void GLAPIENTRY VertexAttrib1bvARB(GLuint index, const GLbyte *v)
609 {
610 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
611 }
612
613 static void GLAPIENTRY VertexAttrib2NbvARB(GLuint index, const GLbyte *v)
614 {
615 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
616 }
617
618 static void GLAPIENTRY VertexAttrib2bvARB(GLuint index, const GLbyte *v)
619 {
620 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
621 }
622
623 static void GLAPIENTRY VertexAttrib3NbvARB(GLuint index, const GLbyte *v)
624 {
625 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
626 BYTE_TO_FLOAT(v[1]),
627 BYTE_TO_FLOAT(v[2])));
628 }
629
630 static void GLAPIENTRY VertexAttrib3bvARB(GLuint index, const GLbyte *v)
631 {
632 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
633 }
634
635 static void GLAPIENTRY VertexAttrib4NbvARB(GLuint index, const GLbyte *v)
636 {
637 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
638 BYTE_TO_FLOAT(v[1]),
639 BYTE_TO_FLOAT(v[2]),
640 BYTE_TO_FLOAT(v[3])));
641 }
642
643 static void GLAPIENTRY VertexAttrib4bvARB(GLuint index, const GLbyte *v)
644 {
645 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
646 }
647
648 /* GL_UNSIGNED_BYTE attributes */
649
650 static void GLAPIENTRY VertexAttrib1NubvARB(GLuint index, const GLubyte *v)
651 {
652 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
653 }
654
655 static void GLAPIENTRY VertexAttrib1ubvARB(GLuint index, const GLubyte *v)
656 {
657 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
658 }
659
660 static void GLAPIENTRY VertexAttrib2NubvARB(GLuint index, const GLubyte *v)
661 {
662 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
663 UBYTE_TO_FLOAT(v[1])));
664 }
665
666 static void GLAPIENTRY VertexAttrib2ubvARB(GLuint index, const GLubyte *v)
667 {
668 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
669 }
670
671 static void GLAPIENTRY VertexAttrib3NubvARB(GLuint index, const GLubyte *v)
672 {
673 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
674 UBYTE_TO_FLOAT(v[1]),
675 UBYTE_TO_FLOAT(v[2])));
676 }
677 static void GLAPIENTRY VertexAttrib3ubvARB(GLuint index, const GLubyte *v)
678 {
679 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
680 }
681
682 static void GLAPIENTRY VertexAttrib4NubvARB(GLuint index, const GLubyte *v)
683 {
684 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
685 UBYTE_TO_FLOAT(v[1]),
686 UBYTE_TO_FLOAT(v[2]),
687 UBYTE_TO_FLOAT(v[3])));
688 }
689
690 static void GLAPIENTRY VertexAttrib4ubvARB(GLuint index, const GLubyte *v)
691 {
692 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
693 }
694
695 /* GL_SHORT attributes */
696
697 static void GLAPIENTRY VertexAttrib1NsvARB(GLuint index, const GLshort *v)
698 {
699 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
700 }
701
702 static void GLAPIENTRY VertexAttrib1svARB(GLuint index, const GLshort *v)
703 {
704 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
705 }
706
707 static void GLAPIENTRY VertexAttrib2NsvARB(GLuint index, const GLshort *v)
708 {
709 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
710 SHORT_TO_FLOAT(v[1])));
711 }
712
713 static void GLAPIENTRY VertexAttrib2svARB(GLuint index, const GLshort *v)
714 {
715 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
716 }
717
718 static void GLAPIENTRY VertexAttrib3NsvARB(GLuint index, const GLshort *v)
719 {
720 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
721 SHORT_TO_FLOAT(v[1]),
722 SHORT_TO_FLOAT(v[2])));
723 }
724
725 static void GLAPIENTRY VertexAttrib3svARB(GLuint index, const GLshort *v)
726 {
727 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
728 }
729
730 static void GLAPIENTRY VertexAttrib4NsvARB(GLuint index, const GLshort *v)
731 {
732 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
733 SHORT_TO_FLOAT(v[1]),
734 SHORT_TO_FLOAT(v[2]),
735 SHORT_TO_FLOAT(v[3])));
736 }
737
738 static void GLAPIENTRY VertexAttrib4svARB(GLuint index, const GLshort *v)
739 {
740 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
741 }
742
743 /* GL_UNSIGNED_SHORT attributes */
744
745 static void GLAPIENTRY VertexAttrib1NusvARB(GLuint index, const GLushort *v)
746 {
747 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
748 }
749
750 static void GLAPIENTRY VertexAttrib1usvARB(GLuint index, const GLushort *v)
751 {
752 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
753 }
754
755 static void GLAPIENTRY VertexAttrib2NusvARB(GLuint index, const GLushort *v)
756 {
757 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
758 USHORT_TO_FLOAT(v[1])));
759 }
760
761 static void GLAPIENTRY VertexAttrib2usvARB(GLuint index, const GLushort *v)
762 {
763 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
764 }
765
766 static void GLAPIENTRY VertexAttrib3NusvARB(GLuint index, const GLushort *v)
767 {
768 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
769 USHORT_TO_FLOAT(v[1]),
770 USHORT_TO_FLOAT(v[2])));
771 }
772
773 static void GLAPIENTRY VertexAttrib3usvARB(GLuint index, const GLushort *v)
774 {
775 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
776 }
777
778 static void GLAPIENTRY VertexAttrib4NusvARB(GLuint index, const GLushort *v)
779 {
780 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
781 USHORT_TO_FLOAT(v[1]),
782 USHORT_TO_FLOAT(v[2]),
783 USHORT_TO_FLOAT(v[3])));
784 }
785
786 static void GLAPIENTRY VertexAttrib4usvARB(GLuint index, const GLushort *v)
787 {
788 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
789 }
790
791 /* GL_INT attributes */
792
793 static void GLAPIENTRY VertexAttrib1NivARB(GLuint index, const GLint *v)
794 {
795 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
796 }
797
798 static void GLAPIENTRY VertexAttrib1ivARB(GLuint index, const GLint *v)
799 {
800 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
801 }
802
803 static void GLAPIENTRY VertexAttrib2NivARB(GLuint index, const GLint *v)
804 {
805 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
806 INT_TO_FLOAT(v[1])));
807 }
808
809 static void GLAPIENTRY VertexAttrib2ivARB(GLuint index, const GLint *v)
810 {
811 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
812 }
813
814 static void GLAPIENTRY VertexAttrib3NivARB(GLuint index, const GLint *v)
815 {
816 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
817 INT_TO_FLOAT(v[1]),
818 INT_TO_FLOAT(v[2])));
819 }
820
821 static void GLAPIENTRY VertexAttrib3ivARB(GLuint index, const GLint *v)
822 {
823 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
824 }
825
826 static void GLAPIENTRY VertexAttrib4NivARB(GLuint index, const GLint *v)
827 {
828 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
829 INT_TO_FLOAT(v[1]),
830 INT_TO_FLOAT(v[2]),
831 INT_TO_FLOAT(v[3])));
832 }
833
834 static void GLAPIENTRY VertexAttrib4ivARB(GLuint index, const GLint *v)
835 {
836 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
837 }
838
839 /* GL_UNSIGNED_INT attributes */
840
841 static void GLAPIENTRY VertexAttrib1NuivARB(GLuint index, const GLuint *v)
842 {
843 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
844 }
845
846 static void GLAPIENTRY VertexAttrib1uivARB(GLuint index, const GLuint *v)
847 {
848 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
849 }
850
851 static void GLAPIENTRY VertexAttrib2NuivARB(GLuint index, const GLuint *v)
852 {
853 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
854 UINT_TO_FLOAT(v[1])));
855 }
856
857 static void GLAPIENTRY VertexAttrib2uivARB(GLuint index, const GLuint *v)
858 {
859 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
860 }
861
862 static void GLAPIENTRY VertexAttrib3NuivARB(GLuint index, const GLuint *v)
863 {
864 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
865 UINT_TO_FLOAT(v[1]),
866 UINT_TO_FLOAT(v[2])));
867 }
868
869 static void GLAPIENTRY VertexAttrib3uivARB(GLuint index, const GLuint *v)
870 {
871 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
872 }
873
874 static void GLAPIENTRY VertexAttrib4NuivARB(GLuint index, const GLuint *v)
875 {
876 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
877 UINT_TO_FLOAT(v[1]),
878 UINT_TO_FLOAT(v[2]),
879 UINT_TO_FLOAT(v[3])));
880 }
881
882 static void GLAPIENTRY VertexAttrib4uivARB(GLuint index, const GLuint *v)
883 {
884 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
885 }
886
887 /* GL_FLOAT attributes */
888
889 static void GLAPIENTRY VertexAttrib1fvARB(GLuint index, const GLfloat *v)
890 {
891 CALL_VertexAttrib1fvARB(GET_DISPATCH(), (index, v));
892 }
893
894 static void GLAPIENTRY VertexAttrib2fvARB(GLuint index, const GLfloat *v)
895 {
896 CALL_VertexAttrib2fvARB(GET_DISPATCH(), (index, v));
897 }
898
899 static void GLAPIENTRY VertexAttrib3fvARB(GLuint index, const GLfloat *v)
900 {
901 CALL_VertexAttrib3fvARB(GET_DISPATCH(), (index, v));
902 }
903
904 static void GLAPIENTRY VertexAttrib4fvARB(GLuint index, const GLfloat *v)
905 {
906 CALL_VertexAttrib4fvARB(GET_DISPATCH(), (index, v));
907 }
908
909 /* GL_DOUBLE attributes */
910
911 static void GLAPIENTRY VertexAttrib1dvARB(GLuint index, const GLdouble *v)
912 {
913 CALL_VertexAttrib1dvARB(GET_DISPATCH(), (index, v));
914 }
915
916 static void GLAPIENTRY VertexAttrib2dvARB(GLuint index, const GLdouble *v)
917 {
918 CALL_VertexAttrib2dvARB(GET_DISPATCH(), (index, v));
919 }
920
921 static void GLAPIENTRY VertexAttrib3dvARB(GLuint index, const GLdouble *v)
922 {
923 CALL_VertexAttrib3dvARB(GET_DISPATCH(), (index, v));
924 }
925
926 static void GLAPIENTRY VertexAttrib4dvARB(GLuint index, const GLdouble *v)
927 {
928 CALL_VertexAttrib4dvARB(GET_DISPATCH(), (index, v));
929 }
930
931
932 /*
933 * Array [size][type] of VertexAttrib functions
934 */
935 static attrib_func AttribFuncsARB[2][4][8] = {
936 {
937 /* non-normalized */
938 {
939 /* size 1 */
940 (attrib_func) VertexAttrib1bvARB,
941 (attrib_func) VertexAttrib1ubvARB,
942 (attrib_func) VertexAttrib1svARB,
943 (attrib_func) VertexAttrib1usvARB,
944 (attrib_func) VertexAttrib1ivARB,
945 (attrib_func) VertexAttrib1uivARB,
946 (attrib_func) VertexAttrib1fvARB,
947 (attrib_func) VertexAttrib1dvARB
948 },
949 {
950 /* size 2 */
951 (attrib_func) VertexAttrib2bvARB,
952 (attrib_func) VertexAttrib2ubvARB,
953 (attrib_func) VertexAttrib2svARB,
954 (attrib_func) VertexAttrib2usvARB,
955 (attrib_func) VertexAttrib2ivARB,
956 (attrib_func) VertexAttrib2uivARB,
957 (attrib_func) VertexAttrib2fvARB,
958 (attrib_func) VertexAttrib2dvARB
959 },
960 {
961 /* size 3 */
962 (attrib_func) VertexAttrib3bvARB,
963 (attrib_func) VertexAttrib3ubvARB,
964 (attrib_func) VertexAttrib3svARB,
965 (attrib_func) VertexAttrib3usvARB,
966 (attrib_func) VertexAttrib3ivARB,
967 (attrib_func) VertexAttrib3uivARB,
968 (attrib_func) VertexAttrib3fvARB,
969 (attrib_func) VertexAttrib3dvARB
970 },
971 {
972 /* size 4 */
973 (attrib_func) VertexAttrib4bvARB,
974 (attrib_func) VertexAttrib4ubvARB,
975 (attrib_func) VertexAttrib4svARB,
976 (attrib_func) VertexAttrib4usvARB,
977 (attrib_func) VertexAttrib4ivARB,
978 (attrib_func) VertexAttrib4uivARB,
979 (attrib_func) VertexAttrib4fvARB,
980 (attrib_func) VertexAttrib4dvARB
981 }
982 },
983 {
984 /* normalized (except for float/double) */
985 {
986 /* size 1 */
987 (attrib_func) VertexAttrib1NbvARB,
988 (attrib_func) VertexAttrib1NubvARB,
989 (attrib_func) VertexAttrib1NsvARB,
990 (attrib_func) VertexAttrib1NusvARB,
991 (attrib_func) VertexAttrib1NivARB,
992 (attrib_func) VertexAttrib1NuivARB,
993 (attrib_func) VertexAttrib1fvARB,
994 (attrib_func) VertexAttrib1dvARB
995 },
996 {
997 /* size 2 */
998 (attrib_func) VertexAttrib2NbvARB,
999 (attrib_func) VertexAttrib2NubvARB,
1000 (attrib_func) VertexAttrib2NsvARB,
1001 (attrib_func) VertexAttrib2NusvARB,
1002 (attrib_func) VertexAttrib2NivARB,
1003 (attrib_func) VertexAttrib2NuivARB,
1004 (attrib_func) VertexAttrib2fvARB,
1005 (attrib_func) VertexAttrib2dvARB
1006 },
1007 {
1008 /* size 3 */
1009 (attrib_func) VertexAttrib3NbvARB,
1010 (attrib_func) VertexAttrib3NubvARB,
1011 (attrib_func) VertexAttrib3NsvARB,
1012 (attrib_func) VertexAttrib3NusvARB,
1013 (attrib_func) VertexAttrib3NivARB,
1014 (attrib_func) VertexAttrib3NuivARB,
1015 (attrib_func) VertexAttrib3fvARB,
1016 (attrib_func) VertexAttrib3dvARB
1017 },
1018 {
1019 /* size 4 */
1020 (attrib_func) VertexAttrib4NbvARB,
1021 (attrib_func) VertexAttrib4NubvARB,
1022 (attrib_func) VertexAttrib4NsvARB,
1023 (attrib_func) VertexAttrib4NusvARB,
1024 (attrib_func) VertexAttrib4NivARB,
1025 (attrib_func) VertexAttrib4NuivARB,
1026 (attrib_func) VertexAttrib4fvARB,
1027 (attrib_func) VertexAttrib4dvARB
1028 }
1029 }
1030 };
1031
1032 /**********************************************************************/
1033
1034
1035 GLboolean _ae_create_context( GLcontext *ctx )
1036 {
1037 if (ctx->aelt_context)
1038 return GL_TRUE;
1039
1040 /* These _gloffset_* values may not be compile-time constants */
1041 SecondaryColorFuncs[0] = _gloffset_SecondaryColor3bvEXT;
1042 SecondaryColorFuncs[1] = _gloffset_SecondaryColor3ubvEXT;
1043 SecondaryColorFuncs[2] = _gloffset_SecondaryColor3svEXT;
1044 SecondaryColorFuncs[3] = _gloffset_SecondaryColor3usvEXT;
1045 SecondaryColorFuncs[4] = _gloffset_SecondaryColor3ivEXT;
1046 SecondaryColorFuncs[5] = _gloffset_SecondaryColor3uivEXT;
1047 SecondaryColorFuncs[6] = _gloffset_SecondaryColor3fvEXT;
1048 SecondaryColorFuncs[7] = _gloffset_SecondaryColor3dvEXT;
1049
1050 FogCoordFuncs[0] = -1;
1051 FogCoordFuncs[1] = -1;
1052 FogCoordFuncs[2] = -1;
1053 FogCoordFuncs[3] = -1;
1054 FogCoordFuncs[4] = -1;
1055 FogCoordFuncs[5] = -1;
1056 FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
1057 FogCoordFuncs[7] = _gloffset_FogCoorddvEXT;
1058
1059 ctx->aelt_context = CALLOC( sizeof(AEcontext) );
1060 if (!ctx->aelt_context)
1061 return GL_FALSE;
1062
1063 AE_CONTEXT(ctx)->NewState = ~0;
1064 return GL_TRUE;
1065 }
1066
1067
1068 void _ae_destroy_context( GLcontext *ctx )
1069 {
1070 if ( AE_CONTEXT( ctx ) ) {
1071 FREE( ctx->aelt_context );
1072 ctx->aelt_context = NULL;
1073 }
1074 }
1075
1076 static void check_vbo( AEcontext *actx,
1077 struct gl_buffer_object *vbo )
1078 {
1079 if (_mesa_is_bufferobj(vbo) && !_mesa_bufferobj_mapped(vbo)) {
1080 GLuint i;
1081 for (i = 0; i < actx->nr_vbos; i++)
1082 if (actx->vbo[i] == vbo)
1083 return;
1084 assert(actx->nr_vbos < VERT_ATTRIB_MAX);
1085 actx->vbo[actx->nr_vbos++] = vbo;
1086 }
1087 }
1088
1089
1090 /**
1091 * Make a list of per-vertex functions to call for each glArrayElement call.
1092 * These functions access the array data (i.e. glVertex, glColor, glNormal,
1093 * etc).
1094 * Note: this may be called during display list construction.
1095 */
1096 static void _ae_update_state( GLcontext *ctx )
1097 {
1098 AEcontext *actx = AE_CONTEXT(ctx);
1099 AEarray *aa = actx->arrays;
1100 AEattrib *at = actx->attribs;
1101 GLuint i;
1102 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
1103
1104 actx->nr_vbos = 0;
1105
1106 /* conventional vertex arrays */
1107 if (arrayObj->Index.Enabled) {
1108 aa->array = &arrayObj->Index;
1109 aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
1110 check_vbo(actx, aa->array->BufferObj);
1111 aa++;
1112 }
1113 if (arrayObj->EdgeFlag.Enabled) {
1114 aa->array = &arrayObj->EdgeFlag;
1115 aa->offset = _gloffset_EdgeFlagv;
1116 check_vbo(actx, aa->array->BufferObj);
1117 aa++;
1118 }
1119 if (arrayObj->Normal.Enabled) {
1120 aa->array = &arrayObj->Normal;
1121 aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
1122 check_vbo(actx, aa->array->BufferObj);
1123 aa++;
1124 }
1125 if (arrayObj->Color.Enabled) {
1126 aa->array = &arrayObj->Color;
1127 aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
1128 check_vbo(actx, aa->array->BufferObj);
1129 aa++;
1130 }
1131 if (arrayObj->SecondaryColor.Enabled) {
1132 aa->array = &arrayObj->SecondaryColor;
1133 aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
1134 check_vbo(actx, aa->array->BufferObj);
1135 aa++;
1136 }
1137 if (arrayObj->FogCoord.Enabled) {
1138 aa->array = &arrayObj->FogCoord;
1139 aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
1140 check_vbo(actx, aa->array->BufferObj);
1141 aa++;
1142 }
1143 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
1144 struct gl_client_array *attribArray = &arrayObj->TexCoord[i];
1145 if (attribArray->Enabled) {
1146 /* NOTE: we use generic glVertexAttribNV functions here.
1147 * If we ever remove GL_NV_vertex_program this will have to change.
1148 */
1149 at->array = attribArray;
1150 ASSERT(!at->array->Normalized);
1151 at->func = AttribFuncsNV[at->array->Normalized]
1152 [at->array->Size-1]
1153 [TYPE_IDX(at->array->Type)];
1154 at->index = VERT_ATTRIB_TEX0 + i;
1155 check_vbo(actx, at->array->BufferObj);
1156 at++;
1157 }
1158 }
1159
1160 /* generic vertex attribute arrays */
1161 for (i = 1; i < Elements(arrayObj->VertexAttrib); i++) { /* skip zero! */
1162 struct gl_client_array *attribArray = &arrayObj->VertexAttrib[i];
1163 if (attribArray->Enabled) {
1164 at->array = attribArray;
1165 /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
1166 * function pointer here (for float arrays) since the pointer may
1167 * change from one execution of _ae_ArrayElement() to
1168 * the next. Doing so caused UT to break.
1169 */
1170 if (ctx->VertexProgram._Enabled
1171 && ctx->VertexProgram.Current->IsNVProgram) {
1172 at->func = AttribFuncsNV[at->array->Normalized]
1173 [at->array->Size-1]
1174 [TYPE_IDX(at->array->Type)];
1175 }
1176 else {
1177 at->func = AttribFuncsARB[at->array->Normalized]
1178 [at->array->Size-1]
1179 [TYPE_IDX(at->array->Type)];
1180 }
1181 at->index = i;
1182 check_vbo(actx, at->array->BufferObj);
1183 at++;
1184 }
1185 }
1186
1187 /* finally, vertex position */
1188 if (arrayObj->VertexAttrib[0].Enabled) {
1189 /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
1190 * issued as the last (provoking) attribute).
1191 */
1192 aa->array = &arrayObj->VertexAttrib[0];
1193 assert(aa->array->Size >= 2); /* XXX fix someday? */
1194 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1195 check_vbo(actx, aa->array->BufferObj);
1196 aa++;
1197 }
1198 else if (arrayObj->Vertex.Enabled) {
1199 aa->array = &arrayObj->Vertex;
1200 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1201 check_vbo(actx, aa->array->BufferObj);
1202 aa++;
1203 }
1204
1205 check_vbo(actx, ctx->Array.ElementArrayBufferObj);
1206
1207 ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
1208 ASSERT(aa - actx->arrays < 32);
1209 at->func = NULL; /* terminate the list */
1210 aa->offset = -1; /* terminate the list */
1211
1212 actx->NewState = 0;
1213 }
1214
1215 void _ae_map_vbos( GLcontext *ctx )
1216 {
1217 AEcontext *actx = AE_CONTEXT(ctx);
1218 GLuint i;
1219
1220 if (actx->mapped_vbos)
1221 return;
1222
1223 if (actx->NewState)
1224 _ae_update_state(ctx);
1225
1226 for (i = 0; i < actx->nr_vbos; i++)
1227 ctx->Driver.MapBuffer(ctx,
1228 GL_ARRAY_BUFFER_ARB,
1229 GL_DYNAMIC_DRAW_ARB,
1230 actx->vbo[i]);
1231
1232 if (actx->nr_vbos)
1233 actx->mapped_vbos = GL_TRUE;
1234 }
1235
1236 void _ae_unmap_vbos( GLcontext *ctx )
1237 {
1238 AEcontext *actx = AE_CONTEXT(ctx);
1239 GLuint i;
1240
1241 if (!actx->mapped_vbos)
1242 return;
1243
1244 assert (!actx->NewState);
1245
1246 for (i = 0; i < actx->nr_vbos; i++)
1247 ctx->Driver.UnmapBuffer(ctx,
1248 GL_ARRAY_BUFFER_ARB,
1249 actx->vbo[i]);
1250
1251 actx->mapped_vbos = GL_FALSE;
1252 }
1253
1254
1255 /**
1256 * Called via glArrayElement() and glDrawArrays().
1257 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
1258 * for all enabled vertex arrays (for elt-th element).
1259 * Note: this may be called during display list construction.
1260 */
1261 void GLAPIENTRY _ae_ArrayElement( GLint elt )
1262 {
1263 GET_CURRENT_CONTEXT(ctx);
1264 const AEcontext *actx = AE_CONTEXT(ctx);
1265 const AEarray *aa;
1266 const AEattrib *at;
1267 const struct _glapi_table * const disp = GET_DISPATCH();
1268 GLboolean do_map;
1269
1270 if (actx->NewState) {
1271 assert(!actx->mapped_vbos);
1272 _ae_update_state( ctx );
1273 }
1274
1275 do_map = actx->nr_vbos && !actx->mapped_vbos;
1276
1277 /*
1278 */
1279 if (do_map)
1280 _ae_map_vbos(ctx);
1281
1282 /* generic attributes */
1283 for (at = actx->attribs; at->func; at++) {
1284 const GLubyte *src
1285 = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr)
1286 + elt * at->array->StrideB;
1287 at->func( at->index, src );
1288 }
1289
1290 /* conventional arrays */
1291 for (aa = actx->arrays; aa->offset != -1 ; aa++) {
1292 const GLubyte *src
1293 = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr)
1294 + elt * aa->array->StrideB;
1295 CALL_by_offset( disp, (array_func), aa->offset,
1296 ((const void *) src) );
1297 }
1298
1299 if (do_map)
1300 _ae_unmap_vbos(ctx);
1301 }
1302
1303
1304 void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
1305 {
1306 AEcontext *actx = AE_CONTEXT(ctx);
1307
1308
1309 /* Only interested in this subset of mesa state. Need to prune
1310 * this down as both tnl/ and the drivers can raise statechanges
1311 * for arcane reasons in the middle of seemingly atomic operations
1312 * like DrawElements, over which we'd like to keep a known set of
1313 * arrays and vbo's mapped.
1314 *
1315 * Luckily, neither the drivers nor tnl muck with the state that
1316 * concerns us here:
1317 */
1318 new_state &= _NEW_ARRAY | _NEW_PROGRAM;
1319 if (new_state) {
1320 assert(!actx->mapped_vbos);
1321 actx->NewState |= new_state;
1322 }
1323 }
1324
1325
1326 void _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
1327 const GLvertexformat *vfmt)
1328 {
1329 SET_ArrayElement(disp, vfmt->ArrayElement);
1330 }
1331
1332
1333 #endif /* FEATURE_arrayelt */