vertex program check-in
[mesa.git] / src / mesa / tnl / t_imm_elt.c
1 /* $Id: t_imm_elt.c,v 1.13 2001/12/14 02:51:45 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #include "glheader.h"
31 #include "colormac.h"
32 #include "mem.h"
33 #include "mmath.h"
34 #include "mtypes.h"
35
36 #include "math/m_translate.h"
37
38 #include "t_context.h"
39 #include "t_imm_elt.h"
40
41
42
43 typedef void (*trans_elt_1f_func)(GLfloat *to,
44 CONST void *ptr,
45 GLuint stride,
46 GLuint *flags,
47 GLuint *elts,
48 GLuint match,
49 GLuint start,
50 GLuint n );
51
52 typedef void (*trans_elt_1ui_func)(GLuint *to,
53 CONST void *ptr,
54 GLuint stride,
55 GLuint *flags,
56 GLuint *elts,
57 GLuint match,
58 GLuint start,
59 GLuint n );
60
61 typedef void (*trans_elt_1ub_func)(GLubyte *to,
62 CONST void *ptr,
63 GLuint stride,
64 GLuint *flags,
65 GLuint *elts,
66 GLuint match,
67 GLuint start,
68 GLuint n );
69
70 typedef void (*trans_elt_4ub_func)(GLubyte (*to)[4],
71 CONST void *ptr,
72 GLuint stride,
73 GLuint *flags,
74 GLuint *elts,
75 GLuint match,
76 GLuint start,
77 GLuint n );
78
79 typedef void (*trans_elt_4us_func)(GLushort (*to)[4],
80 CONST void *ptr,
81 GLuint stride,
82 GLuint *flags,
83 GLuint *elts,
84 GLuint match,
85 GLuint start,
86 GLuint n );
87
88 typedef void (*trans_elt_4f_func)(GLfloat (*to)[4],
89 CONST void *ptr,
90 GLuint stride,
91 GLuint *flags,
92 GLuint *elts,
93 GLuint match,
94 GLuint start,
95 GLuint n );
96
97 typedef void (*trans_elt_3f_func)(GLfloat (*to)[3],
98 CONST void *ptr,
99 GLuint stride,
100 GLuint *flags,
101 GLuint *elts,
102 GLuint match,
103 GLuint start,
104 GLuint n );
105
106
107
108
109 static trans_elt_1f_func _tnl_trans_elt_1f_tab[MAX_TYPES];
110 static trans_elt_1ui_func _tnl_trans_elt_1ui_tab[MAX_TYPES];
111 static trans_elt_1ub_func _tnl_trans_elt_1ub_tab[MAX_TYPES];
112 static trans_elt_3f_func _tnl_trans_elt_3f_tab[MAX_TYPES];
113 static trans_elt_4ub_func _tnl_trans_elt_4ub_tab[5][MAX_TYPES];
114 static trans_elt_4us_func _tnl_trans_elt_4us_tab[5][MAX_TYPES];
115 static trans_elt_4f_func _tnl_trans_elt_4f_tab[5][MAX_TYPES];
116
117
118 #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
119
120
121
122
123
124 /* Code specific to array element implementation. There is a small
125 * subtlety in the bits CHECK() tests, and the way bits are set in
126 * glArrayElement which ensures that if, eg, in the case that the
127 * vertex array is disabled and normal array is enabled, and we get
128 * either sequence:
129 *
130 * ArrayElement() OR Normal()
131 * Normal() ArrayElement()
132 * Vertex() Vertex()
133 *
134 * That the correct value for normal is used.
135 */
136 #define TAB(x) _tnl_trans_elt##x##_tab
137 #define ARGS GLuint *flags, GLuint *elts, GLuint match, \
138 GLuint start, GLuint n
139 #define SRC_START 0
140 #define DST_START start
141 #define CHECK if ((flags[i]&match) == VERT_ELT)
142 #define NEXT_F (void)1
143 #define NEXT_F2 f = first + elts[i] * stride;
144
145
146 /* GL_BYTE
147 */
148 #define SRC GLbyte
149 #define SRC_IDX TYPE_IDX(GL_BYTE)
150 #define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
151 #define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
152 #define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
153 #define TRX_US(us, f,n) us = BYTE_TO_USHORT( PTR_ELT(f,n) )
154 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
155
156
157 #define SZ 4
158 #define INIT init_trans_4_GLbyte_elt
159 #define DEST_4F trans_4_GLbyte_4f_elt
160 #define DEST_4UB trans_4_GLbyte_4ub_elt
161 #define DEST_4US trans_4_GLbyte_4us_elt
162 #include "math/m_trans_tmp.h"
163
164 #define SZ 3
165 #define INIT init_trans_3_GLbyte_elt
166 #define DEST_4F trans_3_GLbyte_4f_elt
167 #define DEST_4UB trans_3_GLbyte_4ub_elt
168 #define DEST_4US trans_3_GLbyte_4us_elt
169 #define DEST_3F trans_3_GLbyte_3f_elt
170 #include "math/m_trans_tmp.h"
171
172 #define SZ 2
173 #define INIT init_trans_2_GLbyte_elt
174 #define DEST_4F trans_2_GLbyte_4f_elt
175 #include "math/m_trans_tmp.h"
176
177 #define SZ 1
178 #define INIT init_trans_1_GLbyte_elt
179 #define DEST_4F trans_1_GLbyte_4f_elt
180 #define DEST_1UB trans_1_GLbyte_1ub_elt
181 #define DEST_1UI trans_1_GLbyte_1ui_elt
182 #include "math/m_trans_tmp.h"
183
184 #undef SRC
185 #undef TRX_3F
186 #undef TRX_4F
187 #undef TRX_UB
188 #undef TRX_US
189 #undef TRX_UI
190 #undef SRC_IDX
191
192 /* GL_UNSIGNED_BYTE
193 */
194 #define SRC GLubyte
195 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
196 #define TRX_3F(f,n) UBYTE_TO_FLOAT( PTR_ELT(f,n) )
197 #define TRX_4F(f,n) UBYTE_TO_FLOAT( PTR_ELT(f,n) )
198 #define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
199 #define TRX_US(us, f,n) us = PTR_ELT(f,n)
200 #define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
201
202 /* 4ub->4ub handled in special case below.
203 */
204 #define SZ 4
205 #define INIT init_trans_4_GLubyte_elt
206 #define DEST_4F trans_4_GLubyte_4f_elt
207 #define DEST_4US trans_4_GLubyte_4us_elt
208 #include "math/m_trans_tmp.h"
209
210 #define SZ 3
211 #define INIT init_trans_3_GLubyte_elt
212 #define DEST_4F trans_3_GLubyte_4f_elt
213 #define DEST_3F trans_3_GLubyte_3f_elt
214 #define DEST_4UB trans_3_GLubyte_4ub_elt
215 #define DEST_4US trans_3_GLubyte_4us_elt
216 #include "math/m_trans_tmp.h"
217
218
219 #define SZ 1
220 #define INIT init_trans_1_GLubyte_elt
221 #define DEST_1UI trans_1_GLubyte_1ui_elt
222 #define DEST_1UB trans_1_GLubyte_1ub_elt
223 #include "math/m_trans_tmp.h"
224
225 #undef SRC
226 #undef SRC_IDX
227 #undef TRX_3F
228 #undef TRX_4F
229 #undef TRX_UB
230 #undef TRX_US
231 #undef TRX_UI
232
233
234 /* GL_SHORT
235 */
236 #define SRC GLshort
237 #define SRC_IDX TYPE_IDX(GL_SHORT)
238 #define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
239 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
240 #define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
241 #define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
242 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
243
244
245 #define SZ 4
246 #define INIT init_trans_4_GLshort_elt
247 #define DEST_4F trans_4_GLshort_4f_elt
248 #define DEST_4UB trans_4_GLshort_4ub_elt
249 #define DEST_4US trans_4_GLshort_4us_elt
250 #include "math/m_trans_tmp.h"
251
252 #define SZ 3
253 #define INIT init_trans_3_GLshort_elt
254 #define DEST_4F trans_3_GLshort_4f_elt
255 #define DEST_4UB trans_3_GLshort_4ub_elt
256 #define DEST_4US trans_3_GLshort_4us_elt
257 #define DEST_3F trans_3_GLshort_3f_elt
258 #include "math/m_trans_tmp.h"
259
260 #define SZ 2
261 #define INIT init_trans_2_GLshort_elt
262 #define DEST_4F trans_2_GLshort_4f_elt
263 #include "math/m_trans_tmp.h"
264
265 #define SZ 1
266 #define INIT init_trans_1_GLshort_elt
267 #define DEST_4F trans_1_GLshort_4f_elt
268 #define DEST_1UB trans_1_GLshort_1ub_elt
269 #define DEST_1UI trans_1_GLshort_1ui_elt
270 #include "math/m_trans_tmp.h"
271
272
273 #undef SRC
274 #undef SRC_IDX
275 #undef TRX_3F
276 #undef TRX_4F
277 #undef TRX_UB
278 #undef TRX_US
279 #undef TRX_UI
280
281
282 /* GL_UNSIGNED_SHORT
283 */
284 #define SRC GLushort
285 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
286 #define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
287 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
288 #define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
289 #define TRX_US(us,f,n) us = PTR_ELT(f,n)
290 #define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
291
292
293 #define SZ 4
294 #define INIT init_trans_4_GLushort_elt
295 #define DEST_4F trans_4_GLushort_4f_elt
296 #define DEST_4UB trans_4_GLushort_4ub_elt
297 #define DEST_4US trans_4_GLushort_4us_elt
298 #include "math/m_trans_tmp.h"
299
300 #define SZ 3
301 #define INIT init_trans_3_GLushort_elt
302 #define DEST_4F trans_3_GLushort_4f_elt
303 #define DEST_4UB trans_3_GLushort_4ub_elt
304 #define DEST_4US trans_3_GLushort_4us_elt
305 #define DEST_3F trans_3_GLushort_3f_elt
306 #include "math/m_trans_tmp.h"
307
308 #define SZ 2
309 #define INIT init_trans_2_GLushort_elt
310 #define DEST_4F trans_2_GLushort_4f_elt
311 #include "math/m_trans_tmp.h"
312
313 #define SZ 1
314 #define INIT init_trans_1_GLushort_elt
315 #define DEST_4F trans_1_GLushort_4f_elt
316 #define DEST_1UB trans_1_GLushort_1ub_elt
317 #define DEST_1UI trans_1_GLushort_1ui_elt
318 #include "math/m_trans_tmp.h"
319
320 #undef SRC
321 #undef SRC_IDX
322 #undef TRX_3F
323 #undef TRX_4F
324 #undef TRX_UB
325 #undef TRX_US
326 #undef TRX_UI
327
328
329 /* GL_INT
330 */
331 #define SRC GLint
332 #define SRC_IDX TYPE_IDX(GL_INT)
333 #define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
334 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
335 #define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
336 #define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
337 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
338
339
340 #define SZ 4
341 #define INIT init_trans_4_GLint_elt
342 #define DEST_4F trans_4_GLint_4f_elt
343 #define DEST_4UB trans_4_GLint_4ub_elt
344 #define DEST_4US trans_4_GLint_4us_elt
345 #include "math/m_trans_tmp.h"
346
347 #define SZ 3
348 #define INIT init_trans_3_GLint_elt
349 #define DEST_4F trans_3_GLint_4f_elt
350 #define DEST_4UB trans_3_GLint_4ub_elt
351 #define DEST_4US trans_3_GLint_4us_elt
352 #define DEST_3F trans_3_GLint_3f_elt
353 #include "math/m_trans_tmp.h"
354
355 #define SZ 2
356 #define INIT init_trans_2_GLint_elt
357 #define DEST_4F trans_2_GLint_4f_elt
358 #include "math/m_trans_tmp.h"
359
360 #define SZ 1
361 #define INIT init_trans_1_GLint_elt
362 #define DEST_4F trans_1_GLint_4f_elt
363 #define DEST_1UB trans_1_GLint_1ub_elt
364 #define DEST_1UI trans_1_GLint_1ui_elt
365 #include "math/m_trans_tmp.h"
366
367
368 #undef SRC
369 #undef SRC_IDX
370 #undef TRX_3F
371 #undef TRX_4F
372 #undef TRX_UB
373 #undef TRX_US
374 #undef TRX_UI
375
376
377 /* GL_UNSIGNED_INT
378 */
379 #define SRC GLuint
380 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
381 #define TRX_3F(f,n) UINT_TO_FLOAT( PTR_ELT(f,n) )
382 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
383 #define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
384 #define TRX_US(us, f,n) us = (GLushort) (PTR_ELT(f,n) >> 16)
385 #define TRX_UI(f,n) PTR_ELT(f,n)
386
387
388 #define SZ 4
389 #define INIT init_trans_4_GLuint_elt
390 #define DEST_4F trans_4_GLuint_4f_elt
391 #define DEST_4UB trans_4_GLuint_4ub_elt
392 #define DEST_4US trans_4_GLuint_4us_elt
393 #include "math/m_trans_tmp.h"
394
395 #define SZ 3
396 #define INIT init_trans_3_GLuint_elt
397 #define DEST_4F trans_3_GLuint_4f_elt
398 #define DEST_4UB trans_3_GLuint_4ub_elt
399 #define DEST_4US trans_3_GLuint_4us_elt
400 #define DEST_3F trans_3_GLuint_3f_elt
401 #include "math/m_trans_tmp.h"
402
403 #define SZ 2
404 #define INIT init_trans_2_GLuint_elt
405 #define DEST_4F trans_2_GLuint_4f_elt
406 #include "math/m_trans_tmp.h"
407
408 #define SZ 1
409 #define INIT init_trans_1_GLuint_elt
410 #define DEST_4F trans_1_GLuint_4f_elt
411 #define DEST_1UB trans_1_GLuint_1ub_elt
412 #define DEST_1UI trans_1_GLuint_1ui_elt
413 #include "math/m_trans_tmp.h"
414
415 #undef SRC
416 #undef SRC_IDX
417 #undef TRX_3F
418 #undef TRX_4F
419 #undef TRX_UB
420 #undef TRX_US
421 #undef TRX_UI
422
423
424 /* GL_DOUBLE
425 */
426 #define SRC GLdouble
427 #define SRC_IDX TYPE_IDX(GL_DOUBLE)
428 #define TRX_3F(f,n) (GLfloat) PTR_ELT(f,n)
429 #define TRX_4F(f,n) (GLfloat) PTR_ELT(f,n)
430 #define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
431 #define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
432 #define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
433 #define TRX_1F(f,n) (GLfloat) PTR_ELT(f,n)
434
435
436 #define SZ 4
437 #define INIT init_trans_4_GLdouble_elt
438 #define DEST_4F trans_4_GLdouble_4f_elt
439 #define DEST_4UB trans_4_GLdouble_4ub_elt
440 #define DEST_4US trans_4_GLdouble_4us_elt
441 #include "math/m_trans_tmp.h"
442
443 #define SZ 3
444 #define INIT init_trans_3_GLdouble_elt
445 #define DEST_4F trans_3_GLdouble_4f_elt
446 #define DEST_4UB trans_3_GLdouble_4ub_elt
447 #define DEST_4US trans_3_GLdouble_4us_elt
448 #define DEST_3F trans_3_GLdouble_3f_elt
449 #include "math/m_trans_tmp.h"
450
451 #define SZ 2
452 #define INIT init_trans_2_GLdouble_elt
453 #define DEST_4F trans_2_GLdouble_4f_elt
454 #include "math/m_trans_tmp.h"
455
456 #define SZ 1
457 #define INIT init_trans_1_GLdouble_elt
458 #define DEST_4F trans_1_GLdouble_4f_elt
459 #define DEST_1UB trans_1_GLdouble_1ub_elt
460 #define DEST_1UI trans_1_GLdouble_1ui_elt
461 #define DEST_1F trans_1_GLdouble_1f_elt
462 #include "math/m_trans_tmp.h"
463
464 #undef SRC
465 #undef SRC_IDX
466
467 /* GL_FLOAT
468 */
469 #define SRC GLfloat
470 #define SRC_IDX TYPE_IDX(GL_FLOAT)
471 #define SZ 4
472 #define INIT init_trans_4_GLfloat_elt
473 #define DEST_4UB trans_4_GLfloat_4ub_elt
474 #define DEST_4US trans_4_GLfloat_4us_elt
475 #define DEST_4F trans_4_GLfloat_4f_elt
476 #include "math/m_trans_tmp.h"
477
478 #define SZ 3
479 #define INIT init_trans_3_GLfloat_elt
480 #define DEST_4F trans_3_GLfloat_4f_elt
481 #define DEST_4UB trans_3_GLfloat_4ub_elt
482 #define DEST_4US trans_3_GLfloat_4us_elt
483 #define DEST_3F trans_3_GLfloat_3f_elt
484 #include "math/m_trans_tmp.h"
485
486 #define SZ 2
487 #define INIT init_trans_2_GLfloat_elt
488 #define DEST_4F trans_2_GLfloat_4f_elt
489 #include "math/m_trans_tmp.h"
490
491 #define SZ 1
492 #define INIT init_trans_1_GLfloat_elt
493 #define DEST_4F trans_1_GLfloat_3f_elt
494 #define DEST_1UB trans_1_GLfloat_1ub_elt
495 #define DEST_1UI trans_1_GLfloat_1ui_elt
496 #define DEST_1F trans_1_GLfloat_1f_elt
497 #include "math/m_trans_tmp.h"
498
499 #undef SRC
500 #undef SRC_IDX
501 #undef TRX_3F
502 #undef TRX_4F
503 #undef TRX_UB
504 #undef TRX_US
505 #undef TRX_UI
506
507
508 static void trans_4_GLubyte_4ub(GLubyte (*t)[4],
509 CONST void *Ptr,
510 GLuint stride,
511 ARGS )
512 {
513 const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
514 const GLubyte *first = f;
515 GLuint i;
516 (void) start;
517 if (((((long) f | (long) stride)) & 3L) == 0L) {
518 /* Aligned.
519 */
520 for (i = DST_START ; i < n ; i++, NEXT_F) {
521 CHECK {
522 NEXT_F2;
523 COPY_4UBV( t[i], f );
524 }
525 }
526 } else {
527 for (i = DST_START ; i < n ; i++, NEXT_F) {
528 CHECK {
529 NEXT_F2;
530 t[i][0] = f[0];
531 t[i][1] = f[1];
532 t[i][2] = f[2];
533 t[i][3] = f[3];
534 }
535 }
536 }
537 }
538
539
540 static void init_translate_elt(void)
541 {
542 MEMSET( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
543 MEMSET( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
544 MEMSET( TAB(_3f), 0, sizeof(TAB(_3f)) );
545 MEMSET( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
546 MEMSET( TAB(_4us), 0, sizeof(TAB(_4us)) );
547 MEMSET( TAB(_4f), 0, sizeof(TAB(_4f)) );
548
549 TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub;
550
551 init_trans_4_GLbyte_elt();
552 init_trans_3_GLbyte_elt();
553 init_trans_2_GLbyte_elt();
554 init_trans_1_GLbyte_elt();
555 init_trans_1_GLubyte_elt();
556 init_trans_3_GLubyte_elt();
557 init_trans_4_GLubyte_elt();
558 init_trans_4_GLshort_elt();
559 init_trans_3_GLshort_elt();
560 init_trans_2_GLshort_elt();
561 init_trans_1_GLshort_elt();
562 init_trans_4_GLushort_elt();
563 init_trans_3_GLushort_elt();
564 init_trans_2_GLushort_elt();
565 init_trans_1_GLushort_elt();
566 init_trans_4_GLint_elt();
567 init_trans_3_GLint_elt();
568 init_trans_2_GLint_elt();
569 init_trans_1_GLint_elt();
570 init_trans_4_GLuint_elt();
571 init_trans_3_GLuint_elt();
572 init_trans_2_GLuint_elt();
573 init_trans_1_GLuint_elt();
574 init_trans_4_GLdouble_elt();
575 init_trans_3_GLdouble_elt();
576 init_trans_2_GLdouble_elt();
577 init_trans_1_GLdouble_elt();
578 init_trans_4_GLfloat_elt();
579 init_trans_3_GLfloat_elt();
580 init_trans_2_GLfloat_elt();
581 init_trans_1_GLfloat_elt();
582 }
583
584
585 #undef TAB
586 #undef CLASS
587 #undef ARGS
588 #undef CHECK
589 #undef START
590
591
592
593
594 void _tnl_imm_elt_init( void )
595 {
596 init_translate_elt();
597 }
598
599
600 static void _tnl_trans_elt_1f(GLfloat *to,
601 const struct gl_client_array *from,
602 GLuint *flags,
603 GLuint *elts,
604 GLuint match,
605 GLuint start,
606 GLuint n )
607 {
608 _tnl_trans_elt_1f_tab[TYPE_IDX(from->Type)]( to,
609 from->Ptr,
610 from->StrideB,
611 flags,
612 elts,
613 match,
614 start,
615 n );
616
617 }
618
619 static void _tnl_trans_elt_1ui(GLuint *to,
620 const struct gl_client_array *from,
621 GLuint *flags,
622 GLuint *elts,
623 GLuint match,
624 GLuint start,
625 GLuint n )
626 {
627 _tnl_trans_elt_1ui_tab[TYPE_IDX(from->Type)]( to,
628 from->Ptr,
629 from->StrideB,
630 flags,
631 elts,
632 match,
633 start,
634 n );
635
636 }
637
638
639 static void _tnl_trans_elt_1ub(GLubyte *to,
640 const struct gl_client_array *from,
641 GLuint *flags,
642 GLuint *elts,
643 GLuint match,
644 GLuint start,
645 GLuint n )
646 {
647 _tnl_trans_elt_1ub_tab[TYPE_IDX(from->Type)]( to,
648 from->Ptr,
649 from->StrideB,
650 flags,
651 elts,
652 match,
653 start,
654 n );
655
656 }
657
658
659 #if 0
660 static void _tnl_trans_elt_4ub(GLubyte (*to)[4],
661 const struct gl_client_array *from,
662 GLuint *flags,
663 GLuint *elts,
664 GLuint match,
665 GLuint start,
666 GLuint n )
667 {
668 _tnl_trans_elt_4ub_tab[from->Size][TYPE_IDX(from->Type)]( to,
669 from->Ptr,
670 from->StrideB,
671 flags,
672 elts,
673 match,
674 start,
675 n );
676
677 }
678 #endif
679
680 #if 0
681 static void _tnl_trans_elt_4us(GLushort (*to)[4],
682 const struct gl_client_array *from,
683 GLuint *flags,
684 GLuint *elts,
685 GLuint match,
686 GLuint start,
687 GLuint n )
688 {
689 _tnl_trans_elt_4us_tab[from->Size][TYPE_IDX(from->Type)]( to,
690 from->Ptr,
691 from->StrideB,
692 flags,
693 elts,
694 match,
695 start,
696 n );
697
698 }
699 #endif
700
701 static void _tnl_trans_elt_4f(GLfloat (*to)[4],
702 const struct gl_client_array *from,
703 GLuint *flags,
704 GLuint *elts,
705 GLuint match,
706 GLuint start,
707 GLuint n )
708 {
709 _tnl_trans_elt_4f_tab[from->Size][TYPE_IDX(from->Type)]( to,
710 from->Ptr,
711 from->StrideB,
712 flags,
713 elts,
714 match,
715 start,
716 n );
717
718 }
719
720
721
722 static void _tnl_trans_elt_3f(GLfloat (*to)[3],
723 const struct gl_client_array *from,
724 GLuint *flags,
725 GLuint *elts,
726 GLuint match,
727 GLuint start,
728 GLuint n )
729 {
730 _tnl_trans_elt_3f_tab[TYPE_IDX(from->Type)]( to,
731 from->Ptr,
732 from->StrideB,
733 flags,
734 elts,
735 match,
736 start,
737 n );
738 }
739
740
741
742
743 /* Batch function to translate away all the array elements in the
744 * input buffer prior to transform. Done only the first time a vertex
745 * buffer is executed or compiled.
746 *
747 * KW: Have to do this after each glEnd if arrays aren't locked.
748 */
749 void _tnl_translate_array_elts( GLcontext *ctx, struct immediate *IM,
750 GLuint start, GLuint count )
751 {
752 GLuint *flags = IM->Flag;
753 GLuint *elts = IM->Elt;
754 GLuint translate = ctx->Array._Enabled;
755 GLuint i;
756
757 if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
758 fprintf(stderr, "exec_array_elements %d .. %d\n", start, count);
759
760 if (translate & VERT_OBJ_BIT) {
761 _tnl_trans_elt_4f( IM->Obj,
762 &ctx->Array.Vertex,
763 flags, elts, (VERT_ELT|VERT_OBJ_BIT),
764 start, count);
765
766 if (ctx->Array.Vertex.Size == 4)
767 translate |= VERT_OBJ_234;
768 else if (ctx->Array.Vertex.Size == 3)
769 translate |= VERT_OBJ_23;
770 }
771
772
773 if (translate & VERT_NORMAL_BIT)
774 _tnl_trans_elt_3f( IM->Normal,
775 &ctx->Array.Normal,
776 flags, elts, (VERT_ELT|VERT_NORMAL_BIT),
777 start, count);
778
779 if (translate & VERT_EDGEFLAG_BIT)
780 _tnl_trans_elt_1ub( IM->EdgeFlag,
781 &ctx->Array.EdgeFlag,
782 flags, elts, (VERT_ELT|VERT_EDGEFLAG_BIT),
783 start, count);
784
785 if (translate & VERT_COLOR0_BIT) {
786 _tnl_trans_elt_4f( IM->Color,
787 &ctx->Array.Color,
788 flags, elts, (VERT_ELT|VERT_COLOR0_BIT),
789 start, count);
790 }
791
792 if (translate & VERT_COLOR1_BIT) {
793 _tnl_trans_elt_4f( IM->SecondaryColor,
794 &ctx->Array.SecondaryColor,
795 flags, elts, (VERT_ELT|VERT_COLOR1_BIT),
796 start, count);
797 }
798
799 if (translate & VERT_FOG_BIT)
800 _tnl_trans_elt_1f( IM->FogCoord,
801 &ctx->Array.FogCoord,
802 flags, elts, (VERT_ELT|VERT_FOG_BIT),
803 start, count);
804
805 if (translate & VERT_INDEX_BIT)
806 _tnl_trans_elt_1ui( IM->Index,
807 &ctx->Array.Index,
808 flags, elts, (VERT_ELT|VERT_INDEX_BIT),
809 start, count);
810
811 if (translate & VERT_TEX_ANY) {
812 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
813 if (translate & VERT_TEX(i)) {
814 _tnl_trans_elt_4f( IM->TexCoord[i],
815 &ctx->Array.TexCoord[i],
816 flags, elts, (VERT_ELT|VERT_TEX(i)),
817 start, count);
818
819 if (ctx->Array.TexCoord[i].Size == 4)
820 IM->TexSize |= TEX_SIZE_4(i);
821 else if (ctx->Array.TexCoord[i].Size == 3)
822 IM->TexSize |= TEX_SIZE_3(i);
823 }
824 }
825
826 for (i = start ; i < count ; i++)
827 if (flags[i] & VERT_ELT) flags[i] |= translate;
828
829 IM->FlushElt = 0;
830 }