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