summaryrefslogtreecommitdiff
path: root/src/mesa/tnl/t_vtx_api.c
blob: b957f336691811ee8dd8628ffd687d0fc028edde (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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/* $XFree86$ */
/**************************************************************************

Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.

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
on the rights to use, copy, modify, merge, publish, distribute, sub
license, 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 (including the next
paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL
TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS 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 "mtypes.h"
#include "colormac.h"
#include "simple_list.h"
#include "vtxfmt.h"

#include "tnl_vtx_api.h"

/* Fallback versions of all the entrypoints for situations where
 * codegen isn't available.  This is slowed significantly by all the
 * gumph necessary to get to the tnl pointer.
 */


/* MultiTexcoord ends up with both of these branches, unfortunately
 * (it may get its own version of the macro after size-tracking is
 * working). 
 *
 * Errors (VertexAttribNV when ATTR>15) are handled at a higher level.  
 */
#define ATTRF( ATTR, N, A, B, C, D )				\
{								\
   GET_CURRENT_CONTEXT( ctx );					\
   TNLcontext *tnl = TNL_CONTEXT(ctx);				\
								\
   if ((ATTR) == 0) {						\
      int i;							\
								\
      if (N>0) tnl->vbptr[0].f = A;				\
      if (N>1) tnl->vbptr[1].f = B;				\
      if (N>2) tnl->vbptr[2].f = C;				\
      if (N>3) tnl->vbptr[3].f = D;				\
								\
      for (i = N; i < tnl->vertex_size; i++)			\
	 *tnl->vbptr[i].i = tnl->vertex[i].i;			\
								\
      tnl->vbptr += tnl->vertex_size;				\
								\
      if (--tnl->counter == 0)					\
	 tnl->notify();						\
   }								\
   else {					\
      GLfloat *dest = tnl->attrptr[ATTR];			\
      if (N>0) dest[0] = A;					\
      if (N>1) dest[1] = B;					\
      if (N>2) dest[2] = C;					\
      if (N>3) dest[3] = D;					\
   }								\
}

#define ATTR4F( ATTR, A, B, C, D )  ATTRF( ATTR, 4, A, B, C, D )
#define ATTR3F( ATTR, A, B, C, D )  ATTRF( ATTR, 3, A, B, C, 1 )
#define ATTR2F( ATTR, A, B, C, D )  ATTRF( ATTR, 2, A, B, 0, 1 )
#define ATTR1F( ATTR, A, B, C, D )  ATTRF( ATTR, 1, A, 0, 0, 1 )

#define ATTR3UB( ATTR, A, B, C )		\
   ATTR3F( ATTR,				\
	   UBYTE_TO_FLOAT(A),			\
	   UBYTE_TO_FLOAT(B),			\
	   UBYTE_TO_FLOAT(C))


#define ATTR4UB( ATTR, A, B, C, D )		\
   ATTR4F( ATTR,				\
	   UBYTE_TO_FLOAT(A),			\
	   UBYTE_TO_FLOAT(B),			\
	   UBYTE_TO_FLOAT(C),			\
	   UBYTE_TO_FLOAT(D))


/* Vertex
 */
static void tnl_Vertex2f( GLfloat x, GLfloat y )
{
   ATTR2F( VERT_ATTRIB_POS, x, y ); 
}

static void tnl_Vertex2fv( const GLfloat *v )
{
   ATTR2F( VERT_ATTRIB_POS, v[0], v[1] ); 
}

static void tnl_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
{
   ATTR3F( VERT_ATTRIB_POS, x, y, z ); 
}

static void tnl_Vertex3fv( const GLfloat *v )
{
   ATTR3F( VERT_ATTRIB_POS, v[0], v[1], v[2] ); 
}

static void tnl_Vertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
{
   ATTR4F( VERT_ATTRIB_POS, x, y, z, w ); 
}

static void tnl_Vertex4fv( const GLfloat *v )
{
   ATTR4F( VERT_ATTRIB_POS, v[0], v[1], v[2], v[3] ); 
}


/* Color
 */
static void tnl_Color3ub( GLubyte r, GLubyte g, GLubyte b )
{
   ATTR3UB( VERT_ATTRIB_COLOR0, r, g, b );
}

static void tnl_Color3ubv( const GLubyte *v )
{
   ATTR3UB( VERT_ATTRIB_COLOR0, v[0], v[1], v[2] );
}

static void tnl_Color4ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
   ATTR4UB( VERT_ATTRIB_COLOR0, r, g, b, a );
}

static void tnl_Color4ubv( const GLubyte *v )
{
   ATTR4UB( VERT_ATTRIB_COLOR0, v[0], v[1], v[2], v[3] );
}

static void tnl_Color3f( GLfloat r, GLfloat g, GLfloat b )
{
   ATTR3F( VERT_ATTRIB_COLOR0, r, g, b );
}

static void tnl_Color3fv( const GLfloat *v )
{
   ATTR3F( VERT_ATTRIB_COLOR0, v[0], v[1], v[2] );
}

static void tnl_Color4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
{
   ATTR4F( VERT_ATTRIB_COLOR0, r, g, b, a );
}

static void tnl_Color4fv( const GLfloat *v )
{
   ATTR4F( VERT_ATTRIB_COLOR0, v[0], v[1], v[2], v[3] );
}


/* Secondary Color
 */
static void tnl_SecondaryColor3ubEXT( GLubyte r, GLubyte g, GLubyte b )
{
   ATTR3UB( VERT_ATTRIB_COLOR1, r, g, b );
}

static void tnl_SecondaryColor3ubvEXT( const GLubyte *v )
{
   ATTR3UB( VERT_ATTRIB_COLOR1, v[0], v[1], v[2] );
}

static void tnl_SecondaryColor3fEXT( GLfloat r, GLfloat g, GLfloat b )
{
   ATTR3F( VERT_ATTRIB_COLOR1, r, g, b );
}

static void tnl_SecondaryColor3fvEXT( const GLfloat *v )
{
   ATTR3F( VERT_ATTRIB_COLOR1, v[0], v[1], v[2] );
}



/* Fog Coord
 */
static void tnl_FogCoordfEXT( GLfloat f )
{
   ATTR1F( VERT_ATTRIB_FOG, f );
}

static void tnl_FogCoordfvEXT( const GLfloat *v )
{
   ATTR1F( VERT_ATTRIB_FOG, v[0] );
}



/* Normal
 */
static void tnl_Normal3f( GLfloat n0, GLfloat n1, GLfloat n2 )
{
   ATTR3F( VERT_ATTRIB_NORMAL, n0, n1, n2 );
}

static void tnl_Normal3fv( const GLfloat *v )
{
   ATTR3F( VERT_ATTRIB_COLOR1, v[0], v[1], v[2] );
}


/* TexCoord
 */
static void tnl_TexCoord1f( GLfloat s )
{
   ATTR1F( VERT_ATTRIB_TEX0, s );
}

static void tnl_TexCoord1fv( const GLfloat *v )
{
   ATTR1F( VERT_ATTRIB_TEX0, v[0] );
}

static void tnl_TexCoord2f( GLfloat s, GLfloat t )
{
   ATTR2F( VERT_ATTRIB_TEX0, s, t );
}

static void tnl_TexCoord2fv( const GLfloat *v )
{
   ATTR2F( VERT_ATTRIB_TEX0, v[0], v[1] );
}

static void tnl_TexCoord3f( GLfloat s, GLfloat t, GLfloat r )
{
   ATTR3F( VERT_ATTRIB_TEX0, s, t, r );
}

static void tnl_TexCoord3fv( const GLfloat *v )
{
   ATTR3F( VERT_ATTRIB_TEX0, v[0], v[1], v[2] );
}

static void tnl_TexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q )
{
   ATTR4F( VERT_ATTRIB_TEX0, s, t, r, q );
}

static void tnl_TexCoord4fv( const GLfloat *v )
{
   ATTR4F( VERT_ATTRIB_TEX0, v[0], v[1], v[2], v[3] );
}


/* Miscellaneous: 
 *
 * These don't alias NV attributes, but still need similar treatment.
 * Basically these are attributes with numbers greater than 16.
 */
static void tnl_EdgeFlag( GLboolean flag )
{
   GLfloat f = flag ? 1 : 0;
   ATTR1F( VERT_ATTRIB_EDGEFLAG, f);
}

static void tnl_EdgeFlagv( const GLboolean *flag )
{
   GLfloat f = flag[0] ? 1 : 0;
   ATTR1F( VERT_ATTRIB_EDGEFLAG, f);
}

static void tnl_Indexi( GLint idx )
{
   ATTR1F( VERT_ATTRIB_INDEX, idx );
}

static void tnl_Indexiv( const GLint *idx )
{
   ATTR1F( VERT_ATTRIB_INDEX, idx );
}

/* Use dispatch switching to build 'ranges' of eval vertices for each
 * type, avoiding need for flags.  (Make
 * evalcoords/evalpoints/vertices/attr0 mutually exclusive)
 */
static void _tnl_EvalCoord1f( GLfloat u )
{
   ATTR1F( VERT_ATTRIB_POS, u );
}

static void _tnl_EvalCoord1fv( const GLfloat *v )
{
   ATTR1F( VERT_ATTRIB_POS, v[0] );
}

static void _tnl_EvalCoord2f( GLfloat u, GLfloat v )
{
   ATTR2F( VERT_ATTRIB_POS, u, v );
}

static void _tnl_EvalCoord2fv( const GLfloat *v )
{
   ATTR2F( VERT_ATTRIB_POS, v[0], v[1] );
}



/* Second level dispatch table for MultiTexCoord, Material and 
 * VertexAttribNV.
 *
 * Need this because we want to track things like vertex attribute
 * sizes, presence/otherwise of attribs in recorded vertices, etc, by
 * manipulating the state of dispatch tables.  Need therefore a
 * dispatch slot for each value of 'index' or 'unit' in VertexAttribNV
 * and MultiTexCoordARB.  Also need a mechnism for keeping this data
 * consistent with what's coming in via the Vertex/Normal/etc api
 * above (where aliasing exists with the traditional entrypoints).
 * Note that MultiTexCoordARB aliases with TexCoord when unit==0.
 *
 * Need presence tracking for material components, too, but not size
 * tracking or help with aliasing.  Could move material to seperate
 * dispatch without the "*4" below, or even do the checks every time.
 */
struct attr_dispatch_tab {
   void (*tab[32*4])( void );
   void (*swapped[32*4])( void );
   int swapcount;
   int installed_sizes[32];
};

#define DISPATCH_ATTR1F( ATTR, N,  ) 
   tnl->vb.attr_dispatch 

/* Result at the back end after second dispatch -- could further
 * specialize for attr zero -- maybe just in the codegen version.
 */
static void tnl_Attr1f( GLint attr, GLfloat s )
{
   ATTR1F( attr, s );
}

static void tnl_Attr1fv( GLint attr, const GLfloat *v )
{
   ATTR1F( attr, v[0] );
}

static void tnl_Attr2f( GLint attr, GLfloat s, GLfloat t )
{
   ATTR2F( attr, s, t );
}

static void tnl_Attr2fv( GLint attr, const GLfloat *v )
{
   ATTR2F( attr, v[0], v[1] );
}

static void tnl_Attr3f( GLint attr, GLfloat s, GLfloat t, GLfloat r )
{
   ATTR3F( attr, s, t, r );
}

static void tnl_Attr3fv( GLint attr, const GLfloat *v )
{
   ATTR3F( attr, v[0], v[1], v[2] );
}

static void tnl_Attr4f( GLint attr, GLfloat s, GLfloat t, GLfloat r, GLfloat q )
{
   ATTR4F( attr, s, t, r, q );
}

static void tnl_Attr4fv( GLint attr, const GLfloat *v )
{
   ATTR4F( attr, v[0], v[1], v[2], v[3] );
}


/* MultiTexcoord:  Send through second level dispatch.
 */
static void tnl_MultiTexCoord1fARB( GLenum target, GLfloat s  )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR1F( attr, s );
}

static void tnl_MultiTexCoord1fvARB( GLenum target, const GLfloat *v )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR1F( attr, v[0] );
}

static void tnl_MultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR2F( attr, s, t );
}

static void tnl_MultiTexCoord2fvARB( GLenum target, const GLfloat *v )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR2F( attr, v[0], v[1] );
}

static void tnl_MultiTexCoord3fARB( GLenum target, GLfloat s, GLfloat t,
				    GLfloat r)
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR3F( attr, s, t, r );
}

static void tnl_MultiTexCoord3fvARB( GLenum target, const GLfloat *v )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR3F( attr, v[0], v[1], v[2] );
}

static void tnl_MultiTexCoord4fARB( GLenum target, GLfloat s, GLfloat t,
				    GLfloat r, GLfloat q )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR4F( attr, s, t, r, q );
}

static void tnl_MultiTexCoord4fvARB( GLenum target, const GLfloat *v )
{
   GLuint attr = (target - GL_TEXTURE0_ARB) + VERT_ATTRIB_TEX0;
   if (attr < MAX_VERT_ATTRS)
      DISPATCH_ATTR4F( attr, v[0], v[1], v[2], v[3] );
}


/* NV_vertex_program:
 *
 * Check for errors & reroute through second dispatch layer to get
 * size tracking per-attribute.
 */
static void tnl_VertexAttrib1fNV( GLuint index, GLfloat s )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR1F( index, s );
   else
      DISPATCH_ERROR; 
}

static void tnl_VertexAttrib1fvNV( GLuint index, const GLfloat *v )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR1F( index, v[0] );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib2fNV( GLuint index, GLfloat s, GLfloat t )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR2F( index, s, t );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib2fvNV( GLuint index, const GLfloat *v )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR2F( index, v[0], v[1] );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib3fNV( GLuint index, GLfloat s, GLfloat t, 
				  GLfloat r )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR3F( index, s, t, r );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib3fvNV( GLuint index, const GLfloat *v )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR3F( index, v[0], v[1], v[2] );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib4fNV( GLuint index, GLfloat s, GLfloat t,
				  GLfloat r, GLfloat q )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR4F( index, s, t, r, q );
   else
      DISPATCH_ERROR;
}

static void tnl_VertexAttrib4fvNV( GLuint index, const GLfloat *v )
{
   if (index < MAX_VERT_ATTRS)
      DISPATCH_ATTR4F( index, v[0], v[1], v[2], v[3] );
   else
      DISPATCH_ERROR;
}







/* Materials:  
 * 
 * These are treated as per-vertex attributes, at indices above where
 * the NV_vertex_program leaves off.  There are a lot of good things
 * about treating materials this way.  
 *
 * *** Need a dispatch step (like VertexAttribute GLint attr, and MultiTexCoord)
 * *** to expand vertex size, etc.  Use the same second level dispatch
 * *** (keyed by attr number) as above.
 */
#define MAT( ATTR, face, params )		\
do {						\
   if (face != GL_BACK)				\
      DISPATCH_ATTRF( ATTR, N, params );	\
   if (face != GL_FRONT)			\
      DISPATCH_ATTRF( ATTR+7, N, params );	\
} while (0)


/* NOTE: Have to remove/dealwith colormaterial crossovers, probably
 * later on - in the meantime just store everything.
 */
static void _tnl_Materialfv( GLenum face, GLenum pname, 
			       const GLfloat *params )
{
   switch (pname) {
   case GL_EMISSION:
      MAT( VERT_ATTRIB_FRONT_EMMISSION, 4, face, params );
      break;
   case GL_AMBIENT:
      MAT( VERT_ATTRIB_FRONT_AMBIENT, 4, face, params );
      break;
   case GL_DIFFUSE:
      MAT( VERT_ATTRIB_FRONT_DIFFUSE, 4, face, params );
      break;
   case GL_SPECULAR:
      MAT( VERT_ATTRIB_FRONT_SPECULAR, 4, face, params );
      break;
   case GL_SHININESS:
      MAT( VERT_ATTRIB_FRONT_SHININESS, 1, face, params );
      break;
   case GL_COLOR_INDEXES:
      MAT( VERT_ATTRIB_FRONT_EMMISSION, 3, face, params );
      break;
   case GL_AMBIENT_AND_DIFFUSE:
      MAT( VERT_ATTRIB_FRONT_AMBIENT, 4, face, params );
      MAT( VERT_ATTRIB_FRONT_DIFFUSE, 4, face, params );
      break;
   default:
      _mesa_error( ctx, GL_INVALID_ENUM, where );
      return;
   }
}




/* Codegen support
 */
static struct dynfn *lookup( struct dynfn *l, int key )
{
   struct dynfn *f;

   foreach( f, l ) {
      if (f->key == key) 
	 return f;
   }

   return 0;
}

/* Vertex descriptor
 */
struct _tnl_vertex_descriptor {
   GLuint attr_bits[4];
};


/* Can't use the loopback template for this:
 */
#define CHOOSE(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 )			\
static void choose_##FN ARGS1						\
{									\
   int key = tnl->vertex_format & (MASK|ACTIVE);			\
   struct dynfn *dfn = lookup( &tnl->dfn_cache.FN, key );		\
									\
   if (dfn == 0)							\
      dfn = tnl->codegen.FN( &vb, key );				\
   else if (MESA_VERBOSE & DEBUG_CODEGEN)				\
      fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ );		\
									\
   if (dfn)								\
      tnl->context->Exec->FN = (FNTYPE)(dfn->code);			\
   else {								\
      if (MESA_VERBOSE & DEBUG_CODEGEN)					\
	 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ );	\
      tnl->context->Exec->FN = tnl_##FN;				\
   }									\
									\
   tnl->context->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;		\
   tnl->context->Exec->FN ARGS2;					\
}



CHOOSE(Normal3f, p3f, 3, VERT_ATTRIB_NORMAL, 
       (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
CHOOSE(Normal3fv, pfv, 3, VERT_ATTRIB_NORMAL, 
       (const GLfloat *v), (v))

CHOOSE(Color4ub, p4ub, 4, VERT_ATTRIB_COLOR0,
	(GLubyte a,GLubyte b, GLubyte c, GLubyte d), (a,b,c,d))
CHOOSE(Color4ubv, pubv, 4, VERT_ATTRIB_COLOR0, 
	(const GLubyte *v), (v))
CHOOSE(Color3ub, p3ub, 3, VERT_ATTRIB_COLOR0, 
	(GLubyte a,GLubyte b, GLubyte c), (a,b,c))
CHOOSE(Color3ubv, pubv, 3, VERT_ATTRIB_COLOR0, 
	(const GLubyte *v), (v))

CHOOSE(Color4f, p4f, 4, VERT_ATTRIB_COLOR0, 
	(GLfloat a,GLfloat b, GLfloat c, GLfloat d), (a,b,c,d))
CHOOSE(Color4fv, pfv, 4, VERT_ATTRIB_COLOR0, 
	(const GLfloat *v), (v))
CHOOSE(Color3f, p3f, 3, VERT_ATTRIB_COLOR0,
	(GLfloat a,GLfloat b, GLfloat c), (a,b,c))
CHOOSE(Color3fv, pfv, 3, VERT_ATTRIB_COLOR0,
	(const GLfloat *v), (v))


CHOOSE(SecondaryColor3ubEXT, p3ub, VERT_ATTRIB_COLOR1, 
	(GLubyte a,GLubyte b, GLubyte c), (a,b,c))
CHOOSE(SecondaryColor3ubvEXT, pubv, VERT_ATTRIB_COLOR1, 
	(const GLubyte *v), (v))
CHOOSE(SecondaryColor3fEXT, p3f, VERT_ATTRIB_COLOR1,
	(GLfloat a,GLfloat b, GLfloat c), (a,b,c))
CHOOSE(SecondaryColor3fvEXT, pfv, VERT_ATTRIB_COLOR1,
	(const GLfloat *v), (v))

CHOOSE(TexCoord2f, p2f, VERT_ATTRIB_TEX0, 
       (GLfloat a,GLfloat b), (a,b))
CHOOSE(TexCoord2fv, pfv, VERT_ATTRIB_TEX0, 
       (const GLfloat *v), (v))
CHOOSE(TexCoord1f, p1f, VERT_ATTRIB_TEX0, 
       (GLfloat a), (a))
CHOOSE(TexCoord1fv, pfv, VERT_ATTRIB_TEX0, 
       (const GLfloat *v), (v))

CHOOSE(MultiTexCoord2fARB, pe2f, VERT_ATTRIB_TEX0,
	 (GLenum u,GLfloat a,GLfloat b), (u,a,b))
CHOOSE(MultiTexCoord2fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
	(GLenum u,const GLfloat *v), (u,v))
CHOOSE(MultiTexCoord1fARB, pe1f, MASK_ST_ALL, ACTIVE_ST_ALL,
	 (GLenum u,GLfloat a), (u,a))
CHOOSE(MultiTexCoord1fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
	(GLenum u,const GLfloat *v), (u,v))

CHOOSE(Vertex3f, p3f, VERT_ATTRIB_POS, 
       (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
CHOOSE(Vertex3fv, pfv, VERT_ATTRIB_POS, 
       (const GLfloat *v), (v))
CHOOSE(Vertex2f, p2f, VERT_ATTRIB_POS, 
       (GLfloat a,GLfloat b), (a,b))
CHOOSE(Vertex2fv, pfv, VERT_ATTRIB_POS, 
       (const GLfloat *v), (v))





void _tnl_InitVtxfmtChoosers( GLvertexformat *vfmt )
{
   vfmt->Color3f = choose_Color3f;
   vfmt->Color3fv = choose_Color3fv;
   vfmt->Color3ub = choose_Color3ub;
   vfmt->Color3ubv = choose_Color3ubv;
   vfmt->Color4f = choose_Color4f;
   vfmt->Color4fv = choose_Color4fv;
   vfmt->Color4ub = choose_Color4ub;
   vfmt->Color4ubv = choose_Color4ubv;
   vfmt->SecondaryColor3fEXT = choose_SecondaryColor3fEXT;
   vfmt->SecondaryColor3fvEXT = choose_SecondaryColor3fvEXT;
   vfmt->SecondaryColor3ubEXT = choose_SecondaryColor3ubEXT;
   vfmt->SecondaryColor3ubvEXT = choose_SecondaryColor3ubvEXT;
   vfmt->MultiTexCoord1fARB = dd_MultiTexCoord1fARB;
   vfmt->MultiTexCoord1fvARB = dd_MultiTexCoord1fvARB;
   vfmt->MultiTexCoord2fARB = dd_MultiTexCoord2fARB;
   vfmt->MultiTexCoord2fvARB = dd_MultiTexCoord2fvARB;
   vfmt->MultiTexCoord3fARB = dd_MultiTexCoord3fARB;
   vfmt->MultiTexCoord3fvARB = dd_MultiTexCoord3fvARB;
   vfmt->MultiTexCoord4fARB = dd_MultiTexCoord4fARB;
   vfmt->MultiTexCoord4fvARB = dd_MultiTexCoord4fvARB;
   vfmt->Normal3f = choose_Normal3f;
   vfmt->Normal3fv = choose_Normal3fv;
   vfmt->TexCoord1f = choose_TexCoord1f;
   vfmt->TexCoord1fv = choose_TexCoord1fv;
   vfmt->TexCoord2f = choose_TexCoord2f;
   vfmt->TexCoord2fv = choose_TexCoord2fv;
   vfmt->TexCoord3f = choose_TexCoord3f;
   vfmt->TexCoord3fv = choose_TexCoord3fv;
   vfmt->TexCoord4f = choose_TexCoord4f;
   vfmt->TexCoord4fv = choose_TexCoord4fv;
   vfmt->Vertex2f = choose_Vertex2f;
   vfmt->Vertex2fv = choose_Vertex2fv;
   vfmt->Vertex3f = choose_Vertex3f;
   vfmt->Vertex3fv = choose_Vertex3fv;
   vfmt->Vertex4f = choose_Vertex4f;
   vfmt->Vertex4fv = choose_Vertex4fv;
   vfmt->FogCoordfvEXT = choose_FogCoordfvEXT;
   vfmt->FogCoordfEXT = choose_FogCoordfEXT;
   vfmt->EdgeFlag = choose_EdgeFlag;
   vfmt->EdgeFlagv = choose_EdgeFlagv;
   vfmt->Indexi = choose_Indexi;
   vfmt->Indexiv = choose_Indexiv;
   vfmt->EvalCoord1f = choose_EvalCoord1f;
   vfmt->EvalCoord1fv = choose_EvalCoord1fv;
   vfmt->EvalCoord2f = choose_EvalCoord2f;
   vfmt->EvalCoord2fv = choose_EvalCoord2fv;
   vfmt->Materialfv = dd_Materialfv;
}


static struct dynfn *codegen_noop( struct _vb *vb, int key )
{
   (void) vb; (void) key;
   return 0;
}

void _tnl_InitCodegen( struct dfn_generators *gen )
{
   /* Generate an attribute or vertex command.
    */
   gen->Attr1f = codegen_noop;
   gen->Attr1fv = codegen_noop;
   gen->Attr2f = codegen_noop;
   gen->Attr2fv = codegen_noop;
   gen->Attr3f = codegen_noop;
   gen->Attr3fv = codegen_noop;
   gen->Attr4f = codegen_noop;
   gen->Attr4fv = codegen_noop;
   
   /* Index is never zero for these...
    */
   gen->Attr3ub = codegen_noop;
   gen->Attr3ubv = codegen_noop;
   gen->Attr4ub = codegen_noop;
   gen->Attr4ubv = codegen_noop;

   /* As above, but deal with the extra (redundant by now) index
    * argument to the generated function.
    */
   gen->NVAttr1f = codegen_noop;
   gen->NVAttr1fv = codegen_noop;
   gen->NVAttr2f = codegen_noop;
   gen->NVAttr2fv = codegen_noop;
   gen->NVAttr3f = codegen_noop;
   gen->NVAttr3fv = codegen_noop;
   gen->NVAttr4f = codegen_noop;
   gen->NVAttr4fv = codegen_noop;


   if (!getenv("MESA_NO_CODEGEN")) {
#if defined(USE_X86_ASM)
      _tnl_InitX86Codegen( gen );
#endif

#if defined(USE_SSE_ASM)
      _tnl_InitSSECodegen( gen );
#endif

#if defined(USE_3DNOW_ASM)
#endif

#if defined(USE_SPARC_ASM)
#endif
   }
}