summaryrefslogtreecommitdiff
path: root/src/mesa/tnl/t_imm_elt.c
blob: fdecef61af091660f3094967bf9478e1ef226869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/*
 * Mesa 3-D graphics library
 * Version:  5.1
 *
 * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Keith Whitwell <keith@tungstengraphics.com>
 */

#include "glheader.h"
#include "colormac.h"
#include "context.h"
#include "imports.h"
#include "mtypes.h"

#include "math/m_translate.h"

#include "t_context.h"
#include "t_imm_elt.h"



typedef void (*trans_elt_1ui_func)(GLuint *to,
				   CONST void *ptr,
				   GLuint stride,
				   const GLuint *flags,
				   const GLuint *elts,
				   GLuint match,
				   GLuint start,
				   GLuint n );

typedef void (*trans_elt_1ub_func)(GLubyte *to,
				   CONST void *ptr,
				   GLuint stride,
				   const GLuint *flags,
				   const GLuint *elts,
				   GLuint match,
				   GLuint start,
				   GLuint n );

typedef void (*trans_elt_4f_func)(GLfloat (*to)[4],
				  CONST void *ptr,
				  GLuint stride,
				  const GLuint *flags,
				  const GLuint *elts,
				  GLuint match,
				  GLuint start,
				  GLuint n );



static trans_elt_1ui_func _tnl_trans_elt_1ui_tab[MAX_TYPES];
static trans_elt_1ub_func _tnl_trans_elt_1ub_tab[MAX_TYPES];
static trans_elt_4f_func  _tnl_trans_elt_4f_tab[5][MAX_TYPES];
static trans_elt_4f_func  _tnl_trans_elt_4fc_tab[5][MAX_TYPES];


#define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])



/* Code specific to array element implementation.  There is a small
 * subtlety in the bits CHECK() tests, and the way bits are set in
 * glArrayElement which ensures that if, eg, in the case that the
 * vertex array is disabled and normal array is enabled, and we get
 * either sequence:
 *
 * ArrayElement()    OR   Normal()
 * Normal()               ArrayElement()
 * Vertex()               Vertex()
 *
 * That the correct value for normal is used.
 */
#define TAB(x) _tnl_trans_elt##x##_tab
#define ARGS   const GLuint *flags, const GLuint *elts, GLuint match, \
               GLuint start, GLuint n
#define SRC_START  0
#define DST_START  start
#define CHECK  if ((flags[i]&match) == VERT_BIT_ELT)
#define NEXT_F  (void)1
#define NEXT_F2 f = first + elts[i] * stride;


/* GL_BYTE
 */
#define SRC GLbyte
#define SRC_IDX TYPE_IDX(GL_BYTE)
#define TRX_4F(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_4FC(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub, f,n)  ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))


#define SZ 4
#define INIT init_trans_4_GLbyte_elt
#define DEST_4F trans_4_GLbyte_4f_elt
#define DEST_4FC trans_4_GLbyte_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLbyte_elt
#define DEST_4F trans_3_GLbyte_4f_elt
#define DEST_4FC trans_3_GLbyte_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLbyte_elt
#define DEST_4F trans_2_GLbyte_4f_elt
#define DEST_4FC trans_2_GLbyte_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLbyte_elt
#define DEST_4F trans_1_GLbyte_4f_elt
#define DEST_4FC trans_1_GLbyte_4fc_elt
#define DEST_1UB trans_1_GLbyte_1ub_elt
#define DEST_1UI trans_1_GLbyte_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI
#undef SRC_IDX

/* GL_UNSIGNED_BYTE
 */
#define SRC GLubyte
#define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
#define TRX_4F(f,n)	     UBYTE_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_4FC(f,n)	     UBYTE_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub, f,n)	     ub = PTR_ELT(f,n)
#define TRX_UI(f,n)          (GLuint)PTR_ELT(f,n)

/* 4ub->4ub handled in special case below.
 */
#define SZ 4
#define INIT init_trans_4_GLubyte_elt
#define DEST_4F trans_4_GLubyte_4f_elt
#define DEST_4FC trans_4_GLubyte_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLubyte_elt
#define DEST_4F trans_3_GLubyte_4f_elt
#define DEST_4FC trans_3_GLubyte_4fc_elt
#include "math/m_trans_tmp.h"


#define SZ 1
#define INIT init_trans_1_GLubyte_elt
#define DEST_4F  trans_1_GLubyte_4f_elt
#define DEST_4FC  trans_1_GLubyte_4fc_elt
#define DEST_1UB trans_1_GLubyte_1ub_elt
#define DEST_1UI trans_1_GLubyte_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI


/* GL_SHORT
 */
#define SRC GLshort
#define SRC_IDX TYPE_IDX(GL_SHORT)
#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
#define TRX_4FC(f,n)   SHORT_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub, f,n)  ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))


#define SZ  4
#define INIT init_trans_4_GLshort_elt
#define DEST_4F trans_4_GLshort_4f_elt
#define DEST_4FC trans_4_GLshort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLshort_elt
#define DEST_4F trans_3_GLshort_4f_elt
#define DEST_4FC trans_3_GLshort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLshort_elt
#define DEST_4F trans_2_GLshort_4f_elt
#define DEST_4FC trans_2_GLshort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLshort_elt
#define DEST_4F trans_1_GLshort_4f_elt
#define DEST_4FC trans_1_GLshort_4fc_elt
#define DEST_1UB trans_1_GLshort_1ub_elt
#define DEST_1UI trans_1_GLshort_1ui_elt
#include "math/m_trans_tmp.h"


#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI


/* GL_UNSIGNED_SHORT
 */
#define SRC GLushort
#define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
#define TRX_4FC(f,n)   USHORT_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub,f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 8)
#define TRX_UI(f,n)  (GLuint)   PTR_ELT(f,n)


#define SZ 4
#define INIT init_trans_4_GLushort_elt
#define DEST_4F trans_4_GLushort_4f_elt
#define DEST_4FC trans_4_GLushort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLushort_elt
#define DEST_4F trans_3_GLushort_4f_elt
#define DEST_4FC trans_3_GLushort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLushort_elt
#define DEST_4F trans_2_GLushort_4f_elt
#define DEST_4FC trans_2_GLushort_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLushort_elt
#define DEST_4F trans_1_GLushort_4f_elt
#define DEST_4FC trans_1_GLushort_4fc_elt
#define DEST_1UB trans_1_GLushort_1ub_elt
#define DEST_1UI trans_1_GLushort_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI


/* GL_INT
 */
#define SRC GLint
#define SRC_IDX TYPE_IDX(GL_INT)
#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
#define TRX_4FC(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub, f,n)  ub = INT_TO_UBYTE(PTR_ELT(f,n))
#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))


#define SZ 4
#define INIT init_trans_4_GLint_elt
#define DEST_4F trans_4_GLint_4f_elt
#define DEST_4FC trans_4_GLint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLint_elt
#define DEST_4F trans_3_GLint_4f_elt
#define DEST_4FC trans_3_GLint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLint_elt
#define DEST_4F trans_2_GLint_4f_elt
#define DEST_4FC trans_2_GLint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLint_elt
#define DEST_4F trans_1_GLint_4f_elt
#define DEST_4FC trans_1_GLint_4fc_elt
#define DEST_1UB trans_1_GLint_1ub_elt
#define DEST_1UI trans_1_GLint_1ui_elt
#include "math/m_trans_tmp.h"


#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI


/* GL_UNSIGNED_INT
 */
#define SRC GLuint
#define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
#define TRX_4FC(f,n)   UINT_TO_FLOAT( PTR_ELT(f,n) )
#define TRX_UB(ub, f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 24)
#define TRX_UI(f,n)		PTR_ELT(f,n)


#define SZ 4
#define INIT init_trans_4_GLuint_elt
#define DEST_4F trans_4_GLuint_4f_elt
#define DEST_4FC trans_4_GLuint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLuint_elt
#define DEST_4F trans_3_GLuint_4f_elt
#define DEST_4FC trans_3_GLuint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLuint_elt
#define DEST_4F trans_2_GLuint_4f_elt
#define DEST_4FC trans_2_GLuint_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLuint_elt
#define DEST_4F trans_1_GLuint_4f_elt
#define DEST_4FC trans_1_GLuint_4fc_elt
#define DEST_1UB trans_1_GLuint_1ub_elt
#define DEST_1UI trans_1_GLuint_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI


/* GL_DOUBLE
 */
#define SRC GLdouble
#define SRC_IDX TYPE_IDX(GL_DOUBLE)
#define TRX_4F(f,n)    (GLfloat) PTR_ELT(f,n)
#define TRX_4FC(f,n)    (GLfloat) PTR_ELT(f,n)
#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
#define TRX_UI(f,n)    (GLuint) (GLint) PTR_ELT(f,n)
#define TRX_1F(f,n)    (GLfloat) PTR_ELT(f,n)


#define SZ 4
#define INIT init_trans_4_GLdouble_elt
#define DEST_4F trans_4_GLdouble_4f_elt
#define DEST_4FC trans_4_GLdouble_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLdouble_elt
#define DEST_4F trans_3_GLdouble_4f_elt
#define DEST_4FC trans_3_GLdouble_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLdouble_elt
#define DEST_4F trans_2_GLdouble_4f_elt
#define DEST_4FC trans_2_GLdouble_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLdouble_elt
#define DEST_4F trans_1_GLdouble_4f_elt
#define DEST_4FC trans_1_GLdouble_4fc_elt
#define DEST_1UB trans_1_GLdouble_1ub_elt
#define DEST_1UI trans_1_GLdouble_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI

/* GL_FLOAT
 */
#define SRC GLfloat
#define SRC_IDX TYPE_IDX(GL_FLOAT)
#define TRX_4F(f,n)    (GLfloat) PTR_ELT(f,n)
#define TRX_4FC(f,n)    (GLfloat) PTR_ELT(f,n)
#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
#define TRX_UI(f,n)    (GLuint) (GLint) PTR_ELT(f,n)
#define TRX_1F(f,n)    (GLfloat) PTR_ELT(f,n)


#define SZ 4
#define INIT init_trans_4_GLfloat_elt
#define DEST_4F  trans_4_GLfloat_4f_elt
#define DEST_4FC  trans_4_GLfloat_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 3
#define INIT init_trans_3_GLfloat_elt
#define DEST_4F  trans_3_GLfloat_4f_elt
#define DEST_4FC  trans_3_GLfloat_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 2
#define INIT init_trans_2_GLfloat_elt
#define DEST_4F trans_2_GLfloat_4f_elt
#define DEST_4FC trans_2_GLfloat_4fc_elt
#include "math/m_trans_tmp.h"

#define SZ 1
#define INIT init_trans_1_GLfloat_elt
#define DEST_4F  trans_1_GLfloat_4f_elt
#define DEST_4FC  trans_1_GLfloat_4fc_elt
#define DEST_1UB trans_1_GLfloat_1ub_elt
#define DEST_1UI trans_1_GLfloat_1ui_elt
#include "math/m_trans_tmp.h"

#undef SRC
#undef SRC_IDX
#undef TRX_4F
#undef TRX_4FC
#undef TRX_UB
#undef TRX_UI




static void init_translate_elt(void)
{
   MEMSET( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
   MEMSET( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
   MEMSET( TAB(_4f),  0, sizeof(TAB(_4f)) );
   MEMSET( TAB(_4fc),  0, sizeof(TAB(_4fc)) );

   init_trans_4_GLbyte_elt();
   init_trans_3_GLbyte_elt();
   init_trans_2_GLbyte_elt();
   init_trans_1_GLbyte_elt();
   init_trans_1_GLubyte_elt();
   init_trans_3_GLubyte_elt();
   init_trans_4_GLubyte_elt();
   init_trans_4_GLshort_elt();
   init_trans_3_GLshort_elt();
   init_trans_2_GLshort_elt();
   init_trans_1_GLshort_elt();
   init_trans_4_GLushort_elt();
   init_trans_3_GLushort_elt();
   init_trans_2_GLushort_elt();
   init_trans_1_GLushort_elt();
   init_trans_4_GLint_elt();
   init_trans_3_GLint_elt();
   init_trans_2_GLint_elt();
   init_trans_1_GLint_elt();
   init_trans_4_GLuint_elt();
   init_trans_3_GLuint_elt();
   init_trans_2_GLuint_elt();
   init_trans_1_GLuint_elt();
   init_trans_4_GLdouble_elt();
   init_trans_3_GLdouble_elt();
   init_trans_2_GLdouble_elt();
   init_trans_1_GLdouble_elt();
   init_trans_4_GLfloat_elt();
   init_trans_3_GLfloat_elt();
   init_trans_2_GLfloat_elt();
   init_trans_1_GLfloat_elt();
}


#undef TAB
#undef CLASS
#undef ARGS
#undef CHECK
#ifdef START
#undef START
#endif



void _tnl_imm_elt_init( void )
{
   init_translate_elt();
}


static void _tnl_trans_elt_1ui(GLuint *to,
			const struct gl_client_array *from,
			const GLuint *flags,
			const GLuint *elts,
			GLuint match,
			GLuint start,
			GLuint n )
{
   GLubyte *fromData = ADD_POINTERS( from->Ptr, from->BufferObj->Data );
   _tnl_trans_elt_1ui_tab[TYPE_IDX(from->Type)]( to,
                                                 fromData,
                                                 from->StrideB,
                                                 flags,
                                                 elts,
                                                 match,
                                                 start,
                                                 n );

}


static void _tnl_trans_elt_1ub(GLubyte *to,
			const struct gl_client_array *from,
			const GLuint *flags,
			const GLuint *elts,
			GLuint match,
			GLuint start,
			GLuint n )
{
   GLubyte *fromData = ADD_POINTERS( from->Ptr, from->BufferObj->Data );
   _tnl_trans_elt_1ub_tab[TYPE_IDX(from->Type)]( to,
                                                 fromData,
                                                 from->StrideB,
                                                 flags,
                                                 elts,
                                                 match,
                                                 start,
                                                 n );

}

static void _tnl_trans_elt_4f(GLfloat (*to)[4],
                              const struct gl_client_array *from,
                              const GLuint *flags,
                              const GLuint *elts,
                              GLuint match,
                              GLuint start,
                              GLuint n )
{
   GLubyte *fromData = ADD_POINTERS( from->Ptr, from->BufferObj->Data );
   _tnl_trans_elt_4f_tab[from->Size][TYPE_IDX(from->Type)]( to,
					      fromData,
					      from->StrideB,
					      flags,
					      elts,
					      match,
					      start,
					      n );

}


static void _tnl_trans_elt_4fc(GLfloat (*to)[4],
			       const struct gl_client_array *from,
			       const GLuint *flags,
			       const GLuint *elts,
			       GLuint match,
			       GLuint start,
			       GLuint n )
{
   GLubyte *fromData = ADD_POINTERS( from->Ptr, from->BufferObj->Data );
   _tnl_trans_elt_4fc_tab[from->Size][TYPE_IDX(from->Type)]( to,
					      fromData,
					      from->StrideB,
					      flags,
					      elts,
					      match,
					      start,
					      n );

}




/* Batch function to translate away all the array elements in the
 * input buffer prior to transform.  Done only the first time a vertex
 * buffer is executed or compiled.
 *
 * KW: Have to do this after each glEnd if arrays aren't locked.
 */
void _tnl_translate_array_elts( GLcontext *ctx, struct immediate *IM,
				GLuint start, GLuint count )
{
   GLuint *flags = IM->Flag;
   const GLuint *elts = IM->Elt;
   GLuint translate = ctx->Array._Enabled;
   GLuint translateConventional;
   GLuint attr;

   if (MESA_VERBOSE & VERBOSE_IMMEDIATE)
      _mesa_debug(ctx, "exec_array_elements %d .. %d\n", start, count);

   /* XXX It would be nice to replace this code with a loop over the vertex
    * attributes but there's a fair number of special cases.
    */

   /* Allocate destination attribute arrays if needed */
   ASSERT(IM->Attrib[VERT_ATTRIB_POS]);
   for (attr = 1; attr < VERT_ATTRIB_MAX; attr++) {
      if ((translate & (1 << attr)) && !IM->Attrib[attr]) {
         IM->Attrib[attr] = _mesa_malloc(IMM_SIZE * 4 * sizeof(GLfloat));
         if (!IM->Attrib[attr]) {
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "vertex processing2");
            return;
         }
      }
   }

   translateConventional = translate;

   /*
    * When vertex program mode is enabled, the generic vertex attribute arrays
    * have priority over the conventional arrays.  Process those arrays now.
    * When we're done here, translateConventional will indicate which
    * conventional arrays still have to be translated when we're done.
    */
   if (ctx->VertexProgram.Enabled) {
      for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
         const GLuint attrBit = 1 << attr;
         if ((translate & attrBit) && ctx->Array.VertexAttrib[attr].Enabled) {
            _tnl_trans_elt_4f( IM->Attrib[attr],
                               &ctx->Array.VertexAttrib[attr],
                               flags, elts, (VERT_BIT_ELT | attrBit),
                               start, count);
            /* special case stuff */
            if (attr == VERT_ATTRIB_POS) {
               if (ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Size == 4)
                  translate |= VERT_BITS_OBJ_234;
               else if (ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Size == 3)
                  translate |= VERT_BITS_OBJ_23;
            }
            else if (attr >= VERT_ATTRIB_TEX0 && attr <= VERT_ATTRIB_TEX7) {
               if (ctx->Array.VertexAttrib[attr].Size == 4)
                  IM->TexSize |= TEX_SIZE_4(attr - VERT_ATTRIB_TEX0);
               else if (ctx->Array.VertexAttrib[attr].Size == 3)
                  IM->TexSize |= TEX_SIZE_3(attr - VERT_ATTRIB_TEX0);
            }
            /* override the conventional array */
            translateConventional &= ~attrBit;
         }
      }
   }

   /*
    * Check which conventional arrays are needed.
    */
   if (translateConventional & VERT_BIT_POS) {
      _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_POS],
                         &ctx->Array.Vertex,
                         flags, elts, (VERT_BIT_ELT|VERT_BIT_POS),
                         start, count);

      if (ctx->Array.Vertex.Size == 4)
         translate |= VERT_BITS_OBJ_234;
      else if (ctx->Array.Vertex.Size == 3)
         translate |= VERT_BITS_OBJ_23;
   }

   if (translateConventional & VERT_BIT_NORMAL) {
      _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_NORMAL],
                         &ctx->Array.Normal,
                         flags, elts, (VERT_BIT_ELT|VERT_BIT_NORMAL),
                         start, count);
   }

   if (translateConventional & VERT_BIT_COLOR0) {
      _tnl_trans_elt_4fc( IM->Attrib[VERT_ATTRIB_COLOR0],
			  &ctx->Array.Color,
			  flags, elts, (VERT_BIT_ELT|VERT_BIT_COLOR0),
			  start, count);
   }

   if (translateConventional & VERT_BIT_COLOR1) {
      _tnl_trans_elt_4fc( IM->Attrib[VERT_ATTRIB_COLOR1],
			  &ctx->Array.SecondaryColor,
			  flags, elts, (VERT_BIT_ELT|VERT_BIT_COLOR1),
			  start, count);
   }

   if (translateConventional & VERT_BIT_FOG) {
      _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_FOG],
                         &ctx->Array.FogCoord,
                         flags, elts, (VERT_BIT_ELT|VERT_BIT_FOG),
                         start, count);
   }

   if (translateConventional & VERT_BITS_TEX_ANY) {
      GLuint i;
      for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
	 if (translateConventional & VERT_BIT_TEX(i)) {
            _tnl_trans_elt_4f( IM->Attrib[VERT_ATTRIB_TEX0 + i],
                               &ctx->Array.TexCoord[i],
                               flags, elts, (VERT_BIT_ELT|VERT_BIT_TEX(i)),
                               start, count);

            if (ctx->Array.TexCoord[i].Size == 4)
               IM->TexSize |= TEX_SIZE_4(i);
            else if (ctx->Array.TexCoord[i].Size == 3)
               IM->TexSize |= TEX_SIZE_3(i);
	 }
   }

   if (translate & VERT_BIT_INDEX)
      _tnl_trans_elt_1ui( IM->Index,
			  &ctx->Array.Index,
			  flags, elts, (VERT_BIT_ELT|VERT_BIT_INDEX),
			  start, count);

   if (translate & VERT_BIT_EDGEFLAG)
      _tnl_trans_elt_1ub( IM->EdgeFlag,
			  &ctx->Array.EdgeFlag,
			  flags, elts, (VERT_BIT_ELT|VERT_BIT_EDGEFLAG),
			  start, count);

   {
      GLuint i;
      for (i = start ; i < count ; i++)
         if (flags[i] & VERT_BIT_ELT)
            flags[i] |= translate;
   }

   IM->FlushElt = 0;
}