Clean-up/renaming of the per-vertex attribute bits, specifically, the
[mesa.git] / src / mesa / tnl / t_imm_elt.c
1 /* $Id: t_imm_elt.c,v 1.16 2002/01/22 14:35:16 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 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_BIT_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 #if 00
601 static void _tnl_trans_elt_1f(GLfloat *to,
602 const struct gl_client_array *from,
603 GLuint *flags,
604 GLuint *elts,
605 GLuint match,
606 GLuint start,
607 GLuint n )
608 {
609 _tnl_trans_elt_1f_tab[TYPE_IDX(from->Type)]( to,
610 from->Ptr,
611 from->StrideB,
612 flags,
613 elts,
614 match,
615 start,
616 n );
617
618 }
619 #endif
620
621 static void _tnl_trans_elt_1ui(GLuint *to,
622 const struct gl_client_array *from,
623 GLuint *flags,
624 GLuint *elts,
625 GLuint match,
626 GLuint start,
627 GLuint n )
628 {
629 _tnl_trans_elt_1ui_tab[TYPE_IDX(from->Type)]( to,
630 from->Ptr,
631 from->StrideB,
632 flags,
633 elts,
634 match,
635 start,
636 n );
637
638 }
639
640
641 static void _tnl_trans_elt_1ub(GLubyte *to,
642 const struct gl_client_array *from,
643 GLuint *flags,
644 GLuint *elts,
645 GLuint match,
646 GLuint start,
647 GLuint n )
648 {
649 _tnl_trans_elt_1ub_tab[TYPE_IDX(from->Type)]( to,
650 from->Ptr,
651 from->StrideB,
652 flags,
653 elts,
654 match,
655 start,
656 n );
657
658 }
659
660
661 #if 0
662 static void _tnl_trans_elt_4ub(GLubyte (*to)[4],
663 const struct gl_client_array *from,
664 GLuint *flags,
665 GLuint *elts,
666 GLuint match,
667 GLuint start,
668 GLuint n )
669 {
670 _tnl_trans_elt_4ub_tab[from->Size][TYPE_IDX(from->Type)]( to,
671 from->Ptr,
672 from->StrideB,
673 flags,
674 elts,
675 match,
676 start,
677 n );
678
679 }
680 #endif
681
682 #if 0
683 static void _tnl_trans_elt_4us(GLushort (*to)[4],
684 const struct gl_client_array *from,
685 GLuint *flags,
686 GLuint *elts,
687 GLuint match,
688 GLuint start,
689 GLuint n )
690 {
691 _tnl_trans_elt_4us_tab[from->Size][TYPE_IDX(from->Type)]( to,
692 from->Ptr,
693 from->StrideB,
694 flags,
695 elts,
696 match,
697 start,
698 n );
699
700 }
701 #endif
702
703 static void _tnl_trans_elt_4f(GLfloat (*to)[4],
704 const struct gl_client_array *from,
705 GLuint *flags,
706 GLuint *elts,
707 GLuint match,
708 GLuint start,
709 GLuint n )
710 {
711 _tnl_trans_elt_4f_tab[from->Size][TYPE_IDX(from->Type)]( to,
712 from->Ptr,
713 from->StrideB,
714 flags,
715 elts,
716 match,
717 start,
718 n );
719
720 }
721
722
723
724 #if 0
725 static void _tnl_trans_elt_3f(GLfloat (*to)[3],
726 const struct gl_client_array *from,
727 GLuint *flags,
728 GLuint *elts,
729 GLuint match,
730 GLuint start,
731 GLuint n )
732 {
733 _tnl_trans_elt_3f_tab[TYPE_IDX(from->Type)]( to,
734 from->Ptr,
735 from->StrideB,
736 flags,
737 elts,
738 match,
739 start,
740 n );
741 }
742 #endif
743
744
745
746 /* Batch function to translate away all the array elements in the
747 * input buffer prior to transform. Done only the first time a vertex
748 * buffer is executed or compiled.
749 *
750 * KW: Have to do this after each glEnd if arrays aren't locked.
751 */
752 void _tnl_translate_array_elts( GLcontext *ctx, struct immediate *IM,
753 GLuint start, GLuint count )
754 {
755 GLuint *flags = IM->Flag;
756 GLuint *elts = IM->Elt;
757 GLuint translate = ctx->Array._Enabled;
758 GLuint i;
759
760 if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
761 fprintf(stderr, "exec_array_elements %d .. %d\n", start, count);
762
763 if (translate & VERT_BIT_POS) {
764 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_POS],
765 &ctx->Array.Vertex,
766 flags, elts, (VERT_BIT_ELT|VERT_BIT_POS),
767 start, count);
768
769 if (ctx->Array.Vertex.Size == 4)
770 translate |= VERT_BITS_OBJ_234;
771 else if (ctx->Array.Vertex.Size == 3)
772 translate |= VERT_BITS_OBJ_23;
773 }
774
775
776 if (translate & VERT_BIT_NORMAL)
777 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_NORMAL],
778 &ctx->Array.Normal,
779 flags, elts, (VERT_BIT_ELT|VERT_BIT_NORMAL),
780 start, count);
781
782 if (translate & VERT_BIT_EDGEFLAG)
783 _tnl_trans_elt_1ub( IM->EdgeFlag,
784 &ctx->Array.EdgeFlag,
785 flags, elts, (VERT_BIT_ELT|VERT_BIT_EDGEFLAG),
786 start, count);
787
788 if (translate & VERT_BIT_COLOR0) {
789 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_COLOR0],
790 &ctx->Array.Color,
791 flags, elts, (VERT_BIT_ELT|VERT_BIT_COLOR0),
792 start, count);
793 }
794
795 if (translate & VERT_BIT_COLOR1) {
796 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_COLOR1],
797 &ctx->Array.SecondaryColor,
798 flags, elts, (VERT_BIT_ELT|VERT_BIT_COLOR1),
799 start, count);
800 }
801
802 if (translate & VERT_BIT_FOG)
803 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_FOG],
804 &ctx->Array.FogCoord,
805 flags, elts, (VERT_BIT_ELT|VERT_BIT_FOG),
806 start, count);
807
808 if (translate & VERT_BIT_INDEX)
809 _tnl_trans_elt_1ui( IM->Index,
810 &ctx->Array.Index,
811 flags, elts, (VERT_BIT_ELT|VERT_BIT_INDEX),
812 start, count);
813
814 if (translate & VERT_BITS_TEX_ANY) {
815 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
816 if (translate & VERT_BIT_TEX(i)) {
817 _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_TEX0 + i],
818 &ctx->Array.TexCoord[i],
819 flags, elts, (VERT_BIT_ELT|VERT_BIT_TEX(i)),
820 start, count);
821
822 if (ctx->Array.TexCoord[i].Size == 4)
823 IM->TexSize |= TEX_SIZE_4(i);
824 else if (ctx->Array.TexCoord[i].Size == 3)
825 IM->TexSize |= TEX_SIZE_3(i);
826 }
827 }
828
829 for (i = start ; i < count ; i++)
830 if (flags[i] & VERT_BIT_ELT) flags[i] |= translate;
831
832 IM->FlushElt = 0;
833 }