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