remove ^M chars, disable shading language extensions
[mesa.git] / src / mesa / main / api_arrayelt.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 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 "context.h"
32 #include "glapi.h"
33 #include "imports.h"
34 #include "macros.h"
35 #include "mtypes.h"
36 #include "glapioffsets.h"
37 #include "dispatch.h"
38
39 typedef void (GLAPIENTRY *array_func)( const void * );
40
41 typedef struct {
42 const struct gl_client_array *array;
43 int offset;
44 } AEarray;
45
46 typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
47
48 typedef struct {
49 const struct gl_client_array *array;
50 attrib_func func;
51 GLuint index;
52 } AEattrib;
53
54 typedef struct {
55 AEarray arrays[32];
56 AEattrib attribs[VERT_ATTRIB_MAX + 1];
57 GLuint NewState;
58 } AEcontext;
59
60 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
61
62
63 /*
64 * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
65 * in the range [0, 7]. Luckily these type tokens are sequentially
66 * numbered in gl.h, except for GL_DOUBLE.
67 */
68 #define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
69
70 static const int ColorFuncs[2][8] = {
71 {
72 _gloffset_Color3bv,
73 _gloffset_Color3ubv,
74 _gloffset_Color3sv,
75 _gloffset_Color3usv,
76 _gloffset_Color3iv,
77 _gloffset_Color3uiv,
78 _gloffset_Color3fv,
79 _gloffset_Color3dv,
80 },
81 {
82 _gloffset_Color4bv,
83 _gloffset_Color4ubv,
84 _gloffset_Color4sv,
85 _gloffset_Color4usv,
86 _gloffset_Color4iv,
87 _gloffset_Color4uiv,
88 _gloffset_Color4fv,
89 _gloffset_Color4dv,
90 },
91 };
92
93 static const int VertexFuncs[3][8] = {
94 {
95 -1,
96 -1,
97 _gloffset_Vertex2sv,
98 -1,
99 _gloffset_Vertex2iv,
100 -1,
101 _gloffset_Vertex2fv,
102 _gloffset_Vertex2dv,
103 },
104 {
105 -1,
106 -1,
107 _gloffset_Vertex3sv,
108 -1,
109 _gloffset_Vertex3iv,
110 -1,
111 _gloffset_Vertex3fv,
112 _gloffset_Vertex3dv,
113 },
114 {
115 -1,
116 -1,
117 _gloffset_Vertex4sv,
118 -1,
119 _gloffset_Vertex4iv,
120 -1,
121 _gloffset_Vertex4fv,
122 _gloffset_Vertex4dv,
123 },
124 };
125
126 static const int IndexFuncs[8] = {
127 -1,
128 _gloffset_Indexubv,
129 _gloffset_Indexsv,
130 -1,
131 _gloffset_Indexiv,
132 -1,
133 _gloffset_Indexfv,
134 _gloffset_Indexdv,
135 };
136
137 static const int NormalFuncs[8] = {
138 _gloffset_Normal3bv,
139 -1,
140 _gloffset_Normal3sv,
141 -1,
142 _gloffset_Normal3iv,
143 -1,
144 _gloffset_Normal3fv,
145 _gloffset_Normal3dv,
146 };
147
148 static const int SecondaryColorFuncs[8] = {
149 _gloffset_SecondaryColor3bvEXT,
150 _gloffset_SecondaryColor3ubvEXT,
151 _gloffset_SecondaryColor3svEXT,
152 _gloffset_SecondaryColor3usvEXT,
153 _gloffset_SecondaryColor3ivEXT,
154 _gloffset_SecondaryColor3uivEXT,
155 _gloffset_SecondaryColor3fvEXT,
156 _gloffset_SecondaryColor3dvEXT,
157 };
158
159 static const int FogCoordFuncs[8] = {
160 -1,
161 -1,
162 -1,
163 -1,
164 -1,
165 -1,
166 _gloffset_FogCoordfvEXT,
167 _gloffset_FogCoorddvEXT
168 };
169
170 /**********************************************************************/
171
172 /* GL_BYTE attributes */
173
174 static void GLAPIENTRY VertexAttrib1NbvNV(GLuint index, const GLbyte *v)
175 {
176 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
177 }
178
179 static void GLAPIENTRY VertexAttrib1bvNV(GLuint index, const GLbyte *v)
180 {
181 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
182 }
183
184 static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v)
185 {
186 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
187 }
188
189 static void GLAPIENTRY VertexAttrib2bvNV(GLuint index, const GLbyte *v)
190 {
191 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
192 }
193
194 static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v)
195 {
196 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
197 BYTE_TO_FLOAT(v[1]),
198 BYTE_TO_FLOAT(v[2])));
199 }
200
201 static void GLAPIENTRY VertexAttrib3bvNV(GLuint index, const GLbyte *v)
202 {
203 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
204 }
205
206 static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v)
207 {
208 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
209 BYTE_TO_FLOAT(v[1]),
210 BYTE_TO_FLOAT(v[2]),
211 BYTE_TO_FLOAT(v[3])));
212 }
213
214 static void GLAPIENTRY VertexAttrib4bvNV(GLuint index, const GLbyte *v)
215 {
216 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
217 }
218
219 /* GL_UNSIGNED_BYTE attributes */
220
221 static void GLAPIENTRY VertexAttrib1NubvNV(GLuint index, const GLubyte *v)
222 {
223 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
224 }
225
226 static void GLAPIENTRY VertexAttrib1ubvNV(GLuint index, const GLubyte *v)
227 {
228 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
229 }
230
231 static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v)
232 {
233 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
234 UBYTE_TO_FLOAT(v[1])));
235 }
236
237 static void GLAPIENTRY VertexAttrib2ubvNV(GLuint index, const GLubyte *v)
238 {
239 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
240 }
241
242 static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v)
243 {
244 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
245 UBYTE_TO_FLOAT(v[1]),
246 UBYTE_TO_FLOAT(v[2])));
247 }
248 static void GLAPIENTRY VertexAttrib3ubvNV(GLuint index, const GLubyte *v)
249 {
250 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
251 }
252
253 static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v)
254 {
255 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
256 UBYTE_TO_FLOAT(v[1]),
257 UBYTE_TO_FLOAT(v[2]),
258 UBYTE_TO_FLOAT(v[3])));
259 }
260
261 static void GLAPIENTRY VertexAttrib4ubvNV(GLuint index, const GLubyte *v)
262 {
263 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
264 }
265
266 /* GL_SHORT attributes */
267
268 static void GLAPIENTRY VertexAttrib1NsvNV(GLuint index, const GLshort *v)
269 {
270 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
271 }
272
273 static void GLAPIENTRY VertexAttrib1svNV(GLuint index, const GLshort *v)
274 {
275 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
276 }
277
278 static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v)
279 {
280 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
281 SHORT_TO_FLOAT(v[1])));
282 }
283
284 static void GLAPIENTRY VertexAttrib2svNV(GLuint index, const GLshort *v)
285 {
286 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
287 }
288
289 static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v)
290 {
291 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
292 SHORT_TO_FLOAT(v[1]),
293 SHORT_TO_FLOAT(v[2])));
294 }
295
296 static void GLAPIENTRY VertexAttrib3svNV(GLuint index, const GLshort *v)
297 {
298 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
299 }
300
301 static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v)
302 {
303 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
304 SHORT_TO_FLOAT(v[1]),
305 SHORT_TO_FLOAT(v[2]),
306 SHORT_TO_FLOAT(v[3])));
307 }
308
309 static void GLAPIENTRY VertexAttrib4svNV(GLuint index, const GLshort *v)
310 {
311 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
312 }
313
314 /* GL_UNSIGNED_SHORT attributes */
315
316 static void GLAPIENTRY VertexAttrib1NusvNV(GLuint index, const GLushort *v)
317 {
318 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
319 }
320
321 static void GLAPIENTRY VertexAttrib1usvNV(GLuint index, const GLushort *v)
322 {
323 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
324 }
325
326 static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v)
327 {
328 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
329 USHORT_TO_FLOAT(v[1])));
330 }
331
332 static void GLAPIENTRY VertexAttrib2usvNV(GLuint index, const GLushort *v)
333 {
334 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
335 }
336
337 static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v)
338 {
339 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
340 USHORT_TO_FLOAT(v[1]),
341 USHORT_TO_FLOAT(v[2])));
342 }
343
344 static void GLAPIENTRY VertexAttrib3usvNV(GLuint index, const GLushort *v)
345 {
346 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
347 }
348
349 static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v)
350 {
351 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
352 USHORT_TO_FLOAT(v[1]),
353 USHORT_TO_FLOAT(v[2]),
354 USHORT_TO_FLOAT(v[3])));
355 }
356
357 static void GLAPIENTRY VertexAttrib4usvNV(GLuint index, const GLushort *v)
358 {
359 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
360 }
361
362 /* GL_INT attributes */
363
364 static void GLAPIENTRY VertexAttrib1NivNV(GLuint index, const GLint *v)
365 {
366 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
367 }
368
369 static void GLAPIENTRY VertexAttrib1ivNV(GLuint index, const GLint *v)
370 {
371 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
372 }
373
374 static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v)
375 {
376 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
377 INT_TO_FLOAT(v[1])));
378 }
379
380 static void GLAPIENTRY VertexAttrib2ivNV(GLuint index, const GLint *v)
381 {
382 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
383 }
384
385 static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v)
386 {
387 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
388 INT_TO_FLOAT(v[1]),
389 INT_TO_FLOAT(v[2])));
390 }
391
392 static void GLAPIENTRY VertexAttrib3ivNV(GLuint index, const GLint *v)
393 {
394 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
395 }
396
397 static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v)
398 {
399 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
400 INT_TO_FLOAT(v[1]),
401 INT_TO_FLOAT(v[2]),
402 INT_TO_FLOAT(v[3])));
403 }
404
405 static void GLAPIENTRY VertexAttrib4ivNV(GLuint index, const GLint *v)
406 {
407 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
408 }
409
410 /* GL_UNSIGNED_INT attributes */
411
412 static void GLAPIENTRY VertexAttrib1NuivNV(GLuint index, const GLuint *v)
413 {
414 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
415 }
416
417 static void GLAPIENTRY VertexAttrib1uivNV(GLuint index, const GLuint *v)
418 {
419 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
420 }
421
422 static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v)
423 {
424 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
425 UINT_TO_FLOAT(v[1])));
426 }
427
428 static void GLAPIENTRY VertexAttrib2uivNV(GLuint index, const GLuint *v)
429 {
430 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
431 }
432
433 static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v)
434 {
435 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
436 UINT_TO_FLOAT(v[1]),
437 UINT_TO_FLOAT(v[2])));
438 }
439
440 static void GLAPIENTRY VertexAttrib3uivNV(GLuint index, const GLuint *v)
441 {
442 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
443 }
444
445 static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v)
446 {
447 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
448 UINT_TO_FLOAT(v[1]),
449 UINT_TO_FLOAT(v[2]),
450 UINT_TO_FLOAT(v[3])));
451 }
452
453 static void GLAPIENTRY VertexAttrib4uivNV(GLuint index, const GLuint *v)
454 {
455 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
456 }
457
458 /* GL_FLOAT attributes */
459
460 static void GLAPIENTRY VertexAttrib1fvNV(GLuint index, const GLfloat *v)
461 {
462 CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index, v));
463 }
464
465 static void GLAPIENTRY VertexAttrib2fvNV(GLuint index, const GLfloat *v)
466 {
467 CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index, v));
468 }
469
470 static void GLAPIENTRY VertexAttrib3fvNV(GLuint index, const GLfloat *v)
471 {
472 CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index, v));
473 }
474
475 static void GLAPIENTRY VertexAttrib4fvNV(GLuint index, const GLfloat *v)
476 {
477 CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index, v));
478 }
479
480 /* GL_DOUBLE attributes */
481
482 static void GLAPIENTRY VertexAttrib1dvNV(GLuint index, const GLdouble *v)
483 {
484 CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index, v));
485 }
486
487 static void GLAPIENTRY VertexAttrib2dvNV(GLuint index, const GLdouble *v)
488 {
489 CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index, v));
490 }
491
492 static void GLAPIENTRY VertexAttrib3dvNV(GLuint index, const GLdouble *v)
493 {
494 CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index, v));
495 }
496
497 static void GLAPIENTRY VertexAttrib4dvNV(GLuint index, const GLdouble *v)
498 {
499 CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index, v));
500 }
501
502
503 /*
504 * Array [size][type] of VertexAttrib functions
505 */
506 static attrib_func AttribFuncsNV[2][4][8] = {
507 {
508 /* non-normalized */
509 {
510 /* size 1 */
511 (attrib_func) VertexAttrib1bvNV,
512 (attrib_func) VertexAttrib1ubvNV,
513 (attrib_func) VertexAttrib1svNV,
514 (attrib_func) VertexAttrib1usvNV,
515 (attrib_func) VertexAttrib1ivNV,
516 (attrib_func) VertexAttrib1uivNV,
517 (attrib_func) VertexAttrib1fvNV,
518 (attrib_func) VertexAttrib1dvNV
519 },
520 {
521 /* size 2 */
522 (attrib_func) VertexAttrib2bvNV,
523 (attrib_func) VertexAttrib2ubvNV,
524 (attrib_func) VertexAttrib2svNV,
525 (attrib_func) VertexAttrib2usvNV,
526 (attrib_func) VertexAttrib2ivNV,
527 (attrib_func) VertexAttrib2uivNV,
528 (attrib_func) VertexAttrib2fvNV,
529 (attrib_func) VertexAttrib2dvNV
530 },
531 {
532 /* size 3 */
533 (attrib_func) VertexAttrib3bvNV,
534 (attrib_func) VertexAttrib3ubvNV,
535 (attrib_func) VertexAttrib3svNV,
536 (attrib_func) VertexAttrib3usvNV,
537 (attrib_func) VertexAttrib3ivNV,
538 (attrib_func) VertexAttrib3uivNV,
539 (attrib_func) VertexAttrib3fvNV,
540 (attrib_func) VertexAttrib3dvNV
541 },
542 {
543 /* size 4 */
544 (attrib_func) VertexAttrib4bvNV,
545 (attrib_func) VertexAttrib4ubvNV,
546 (attrib_func) VertexAttrib4svNV,
547 (attrib_func) VertexAttrib4usvNV,
548 (attrib_func) VertexAttrib4ivNV,
549 (attrib_func) VertexAttrib4uivNV,
550 (attrib_func) VertexAttrib4fvNV,
551 (attrib_func) VertexAttrib4dvNV
552 }
553 },
554 {
555 /* normalized (except for float/double) */
556 {
557 /* size 1 */
558 (attrib_func) VertexAttrib1NbvNV,
559 (attrib_func) VertexAttrib1NubvNV,
560 (attrib_func) VertexAttrib1NsvNV,
561 (attrib_func) VertexAttrib1NusvNV,
562 (attrib_func) VertexAttrib1NivNV,
563 (attrib_func) VertexAttrib1NuivNV,
564 (attrib_func) VertexAttrib1fvNV,
565 (attrib_func) VertexAttrib1dvNV
566 },
567 {
568 /* size 2 */
569 (attrib_func) VertexAttrib2NbvNV,
570 (attrib_func) VertexAttrib2NubvNV,
571 (attrib_func) VertexAttrib2NsvNV,
572 (attrib_func) VertexAttrib2NusvNV,
573 (attrib_func) VertexAttrib2NivNV,
574 (attrib_func) VertexAttrib2NuivNV,
575 (attrib_func) VertexAttrib2fvNV,
576 (attrib_func) VertexAttrib2dvNV
577 },
578 {
579 /* size 3 */
580 (attrib_func) VertexAttrib3NbvNV,
581 (attrib_func) VertexAttrib3NubvNV,
582 (attrib_func) VertexAttrib3NsvNV,
583 (attrib_func) VertexAttrib3NusvNV,
584 (attrib_func) VertexAttrib3NivNV,
585 (attrib_func) VertexAttrib3NuivNV,
586 (attrib_func) VertexAttrib3fvNV,
587 (attrib_func) VertexAttrib3dvNV
588 },
589 {
590 /* size 4 */
591 (attrib_func) VertexAttrib4NbvNV,
592 (attrib_func) VertexAttrib4NubvNV,
593 (attrib_func) VertexAttrib4NsvNV,
594 (attrib_func) VertexAttrib4NusvNV,
595 (attrib_func) VertexAttrib4NivNV,
596 (attrib_func) VertexAttrib4NuivNV,
597 (attrib_func) VertexAttrib4fvNV,
598 (attrib_func) VertexAttrib4dvNV
599 }
600 }
601 };
602
603 /**********************************************************************/
604
605
606 GLboolean _ae_create_context( GLcontext *ctx )
607 {
608 if (ctx->aelt_context)
609 return GL_TRUE;
610
611 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
612 if (!ctx->aelt_context)
613 return GL_FALSE;
614
615 AE_CONTEXT(ctx)->NewState = ~0;
616 return GL_TRUE;
617 }
618
619
620 void _ae_destroy_context( GLcontext *ctx )
621 {
622 if ( AE_CONTEXT( ctx ) ) {
623 FREE( ctx->aelt_context );
624 ctx->aelt_context = NULL;
625 }
626 }
627
628
629 /**
630 * Make a list of per-vertex functions to call for each glArrayElement call.
631 * These functions access the array data (i.e. glVertex, glColor, glNormal,
632 * etc).
633 * Note: this may be called during display list construction.
634 */
635 static void _ae_update_state( GLcontext *ctx )
636 {
637 AEcontext *actx = AE_CONTEXT(ctx);
638 AEarray *aa = actx->arrays;
639 AEattrib *at = actx->attribs;
640 GLuint i;
641
642 /* conventional vertex arrays */
643 if (ctx->Array.Index.Enabled) {
644 aa->array = &ctx->Array.Index;
645 aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
646 aa++;
647 }
648 if (ctx->Array.EdgeFlag.Enabled) {
649 aa->array = &ctx->Array.EdgeFlag;
650 aa->offset = _gloffset_EdgeFlagv;
651 aa++;
652 }
653 if (ctx->Array.Normal.Enabled) {
654 aa->array = &ctx->Array.Normal;
655 aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
656 aa++;
657 }
658 if (ctx->Array.Color.Enabled) {
659 aa->array = &ctx->Array.Color;
660 aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
661 aa++;
662 }
663 if (ctx->Array.SecondaryColor.Enabled) {
664 aa->array = &ctx->Array.SecondaryColor;
665 aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
666 aa++;
667 }
668 if (ctx->Array.FogCoord.Enabled) {
669 aa->array = &ctx->Array.FogCoord;
670 aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
671 aa++;
672 }
673 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
674 if (ctx->Array.TexCoord[i].Enabled) {
675 /* NOTE: we use generic glVertexAttrib functions here.
676 * If we ever de-alias conventional/generic vertex attribs this
677 * will have to change.
678 */
679 struct gl_client_array *attribArray = &ctx->Array.TexCoord[i];
680 at->array = attribArray;
681 at->func = AttribFuncsNV[at->array->Normalized][at->array->Size-1][TYPE_IDX(at->array->Type)];
682 at->index = VERT_ATTRIB_TEX0 + i;
683 at++;
684 }
685 }
686
687 /* generic vertex attribute arrays */
688 for (i = 1; i < VERT_ATTRIB_MAX; i++) { /* skip zero! */
689 if (ctx->Array.VertexAttrib[i].Enabled) {
690 struct gl_client_array *attribArray = &ctx->Array.VertexAttrib[i];
691 at->array = attribArray;
692 /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
693 * function pointer here (for float arrays) since the pointer may
694 * change from one execution of _ae_loopback_array_elt() to
695 * the next. Doing so caused UT to break.
696 */
697 at->func = AttribFuncsNV[at->array->Normalized][at->array->Size-1][TYPE_IDX(at->array->Type)];
698 at->index = i;
699 at++;
700 }
701 }
702
703 /* finally, vertex position */
704 if (ctx->Array.VertexAttrib[0].Enabled) {
705 /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
706 * issued as the last (proviking) attribute).
707 */
708 aa->array = &ctx->Array.VertexAttrib[0];
709 assert(aa->array->Size >= 2); /* XXX fix someday? */
710 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
711 aa++;
712 }
713 else if (ctx->Array.Vertex.Enabled) {
714 aa->array = &ctx->Array.Vertex;
715 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
716 aa++;
717 }
718
719 ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
720 ASSERT(aa - actx->arrays < 32);
721 at->func = NULL; /* terminate the list */
722 aa->offset = -1; /* terminate the list */
723
724 actx->NewState = 0;
725 }
726
727
728 /**
729 * Called via glArrayElement() and glDrawArrays().
730 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
731 * for all enabled vertex arrays (for elt-th element).
732 * Note: this may be called during display list construction.
733 */
734 void GLAPIENTRY _ae_loopback_array_elt( GLint elt )
735 {
736 GET_CURRENT_CONTEXT(ctx);
737 const AEcontext *actx = AE_CONTEXT(ctx);
738 const AEarray *aa;
739 const AEattrib *at;
740 const struct _glapi_table * const disp = GET_DISPATCH();
741
742
743 if (actx->NewState)
744 _ae_update_state( ctx );
745
746 /* generic attributes */
747 for (at = actx->attribs; at->func; at++) {
748 const GLubyte *src = at->array->BufferObj->Data
749 + (uintptr_t) at->array->Ptr
750 + elt * at->array->StrideB;
751 at->func( at->index, src );
752 }
753
754 /* conventional arrays */
755 for (aa = actx->arrays; aa->offset != -1 ; aa++) {
756 const GLubyte *src = aa->array->BufferObj->Data
757 + (uintptr_t) aa->array->Ptr
758 + elt * aa->array->StrideB;
759 CALL_by_offset( disp, (array_func), aa->offset,
760 ((const void *) src) );
761 }
762 }
763
764
765 void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
766 {
767 AE_CONTEXT(ctx)->NewState |= new_state;
768 }