summaryrefslogtreecommitdiff
path: root/src/mesa/tnl/t_imm_api.c
blob: 64cf7b82f6625f7f0f5bb777c8030ea539c1e6f2 (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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365

/*
 * Mesa 3-D graphics library
 * Version:  3.3
 *
 * Copyright (C) 1999-2000  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.
 *
 * Author:
 *   Keith Whitwell <keith@precisioninsight.com>
 */



#include "glheader.h"
#include "context.h"
#include "dlist.h"
#include "enums.h"
#include "light.h"
#include "mem.h"
#include "state.h"
#include "colormac.h"
#include "macros.h"

#include "t_context.h"
#include "t_imm_api.h"
#include "t_imm_elt.h"
#include "t_imm_exec.h"
#include "t_imm_dlist.h"


/* A cassette is full or flushed on a statechange.  
 */
void _tnl_flush_immediate( struct immediate *IM )
{
   GLcontext *ctx = IM->backref;

   if (ctx->CompileFlag) 
      _tnl_compile_cassette( ctx, IM );
   else 
      _tnl_execute_cassette( ctx, IM );
}


void _tnl_flush_vertices( GLcontext *ctx, GLuint flags )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);

   if (IM->Flag[IM->Start])
      if ((flags & FLUSH_UPDATE_CURRENT) || IM->Count > IM->Start)
	 _tnl_flush_immediate( IM );
}


static void
_tnl_begin( GLcontext *ctx, GLenum p )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);
   GLuint inflags, state;

   if (MESA_VERBOSE&VERBOSE_API)
      fprintf(stderr, "glBegin(IM %d) %s\n", IM->id, _mesa_lookup_enum_by_nr(p));
   
   if (ctx->NewState)
      _mesa_update_state(ctx);
       
   /* if only a very few slots left, might as well flush now
    */
   if (IM->Count > IMM_MAXDATA-8) {	      
      _tnl_flush_immediate( IM );
      IM = TNL_CURRENT_IM(ctx);
   }

   /* Check for and flush buffered vertices from internal operations.
    */
   if (IM->SavedBeginState) {
      _tnl_flush_immediate( IM );
      IM = TNL_CURRENT_IM(ctx);
      IM->BeginState = IM->SavedBeginState;
      IM->SavedBeginState = 0;
   }

   state = IM->BeginState;
   inflags = state & (VERT_BEGIN_0|VERT_BEGIN_1);
   state |= inflags << 2;	/* set error conditions */

   if (inflags != (VERT_BEGIN_0|VERT_BEGIN_1))
   {
      GLuint count = IM->Count;
      GLuint last = IM->LastPrimitive;

      ASSERT(IM->Primitive[IM->LastPrimitive] & PRIM_LAST);

      state |= (VERT_BEGIN_0|VERT_BEGIN_1);
      IM->Flag[count] |= VERT_BEGIN; 
      IM->Primitive[IM->LastPrimitive] &= ~PRIM_LAST;
      IM->Primitive[count] = p | PRIM_BEGIN | PRIM_LAST;
      IM->PrimitiveLength[IM->LastPrimitive] = count - IM->LastPrimitive;
      IM->LastPrimitive = count;

      /* Not quite right.  Need to use the fallback '_aa_ArrayElement'
       * when not known to be inside begin/end and arrays are unlocked.
       */
      if (IM->FlushElt) {
	 _tnl_translate_array_elts( ctx, IM, last, count );
	 IM->FlushElt = 0;
      }
   }

   ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
   IM->BeginState = state;
}



static void
_tnl_Begin( GLenum mode )
{
   GET_CURRENT_CONTEXT(ctx);

   if (mode > GL_POLYGON) {
      _mesa_compile_error( ctx, GL_INVALID_ENUM, "glBegin" );
      return;		     
   }

   _tnl_begin(ctx, mode);

   /* If compiling update SavePrimitive now.  
    *
    * In compile_and_exec mode, exec_primitive will be updated when
    * the cassette is finished.
    *
    * If not compiling, update exec_primitive now.
    */
   if (ctx->CompileFlag) {
      if (ctx->Driver.CurrentSavePrimitive == PRIM_UNKNOWN) 
	 ctx->Driver.CurrentSavePrimitive = PRIM_INSIDE_UNKNOWN_PRIM;
      else if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END)
	 ctx->Driver.CurrentSavePrimitive = mode; 
      }
   else if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END)
      ctx->Driver.CurrentExecPrimitive = mode;
}


GLboolean
_tnl_hard_begin( GLcontext *ctx, GLenum p )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);
   GLuint count, last;
   
   if (ctx->NewState)
      _mesa_update_state(ctx);
       
   /* If not compiling, treat as a normal begin().
    */
   if (!ctx->CompileFlag) {
      _tnl_begin( ctx, p );

      /* Set this for the duration:
       */
      ctx->Driver.CurrentExecPrimitive = p;
      return GL_TRUE;
   }
       
   if (IM->Count > IMM_MAXDATA-8) {	      
      _tnl_flush_immediate( IM );
      IM = TNL_CURRENT_IM(ctx);
   }
 
   switch (IM->BeginState & (VERT_BEGIN_0|VERT_BEGIN_1)) {
   case VERT_BEGIN_0|VERT_BEGIN_1:
      /* This is an immediate known to be inside a begin/end object.
       */
      IM->BeginState |= (VERT_ERROR_1|VERT_ERROR_0);
      return GL_FALSE;
      
   case VERT_BEGIN_0:
   case VERT_BEGIN_1:
      /* This is a display-list immediate in an unknown begin/end
       * state.  Assert it is empty and conviert it to a 'hard' one.  
       */
      ASSERT (IM->SavedBeginState == 0);
      
/*        ASSERT (ctx->Driver.CurrentSavePrimitive >= GL_POLYGON+1); */

      /* Push current beginstate, to be restored later.  Don't worry
       * about raising errors.
       */
      IM->SavedBeginState = IM->BeginState;
      
      /* FALLTHROUGH */
   case 0: 
      /* Unless we have fallen through, this is an immediate known to 
       * be outside begin/end objects.
       */
      
      IM->BeginState |= VERT_BEGIN_0|VERT_BEGIN_1;
	 

      count = IM->Count;
      last = IM->LastPrimitive;

      ASSERT(IM->Primitive[IM->LastPrimitive] & PRIM_LAST);

      IM->Flag[count] |= VERT_BEGIN; 
      IM->Primitive[last] &= ~PRIM_LAST;
      IM->Primitive[count] = p | PRIM_BEGIN | PRIM_LAST;
      IM->PrimitiveLength[last] = count - last;
      IM->LastPrimitive = count;
      
      ASSERT (!IM->FlushElt);

      /* This is necessary as this immediate will not be flushed in
       * _tnl_end() -- we leave it active, hoping to pick up more
       * vertices before the next state change.
       */
      ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;

      return GL_TRUE;
      
   default:
      ASSERT (0);
      return GL_TRUE;      
   }
}



/* Need to do this to get the correct begin/end error behaviour from
 * functions like ColorPointerEXT which are still active in
 * SAVE_AND_EXEC modes.  
 */
void
_tnl_save_Begin( GLenum mode )
{
   GET_CURRENT_CONTEXT(ctx);
  
    if (mode > GL_POLYGON) {
      _mesa_compile_error( ctx, GL_INVALID_ENUM, "glBegin" );
      return;		     
   }

   if (ctx->ExecuteFlag) {
      /* Preserve vtxfmt invarient:
       */
      if (ctx->NewState)
	 _mesa_update_state( ctx );

      /* Slot in geomexec: No need to call setdispatch as we know
       * CurrentDispatch is Save.
       */
      ASSERT(ctx->CurrentDispatch == ctx->Save);
   }

   _tnl_begin( ctx, mode );
}




/* Note the continuation of a partially completed primitive.  For
 * driver t&l fallbacks between begin/end primitives.  Has basically
 * the same effects as a primitive wrapping onto a second immediate
 * struct.
 *
 * ==> Can actually call this from _tnl_wakeup_exec, taking mode from
 *     ctx->Driver.CurrentExecPrimitive.
 */
#if 0
void _tnl_fallback_begin( GLcontext *ctx, GLenum mode )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);
   ASSERT( IM->Count == IM->Start );
   ASSERT( IM->Flag[IM->Start] == 0 );
   ASSERT( mode < GL_POLYGON+1 );
   _tnl_begin( ctx, mode );
   IM->Primitive[IM->Start] &= ~PRIM_BEGIN;
}
#endif


/* Both streams now outside begin/end.
 *
 * Leave SavedBeginState untouched -- attempt to gather several
 * rects/arrays together in a single immediate struct.
 */
void
_tnl_end( GLcontext *ctx )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);
   GLuint state = IM->BeginState;
   GLuint inflags = (~state) & (VERT_BEGIN_0|VERT_BEGIN_1);

   state |= inflags << 2;	/* errors */

   if (inflags != (VERT_BEGIN_0|VERT_BEGIN_1))
   {
      GLuint count = IM->Count;
      GLuint last = IM->LastPrimitive;

      ASSERT(IM->Primitive[IM->LastPrimitive] & PRIM_LAST);

      state &= ~(VERT_BEGIN_0|VERT_BEGIN_1); /* update state */
      IM->Flag[count] |= VERT_END;
      IM->Primitive[last] |= PRIM_END;
      IM->Primitive[last] &= ~PRIM_LAST;
      IM->PrimitiveLength[last] = count - last;
      IM->Primitive[count] = (GL_POLYGON+1) | PRIM_LAST;
      IM->LastPrimitive = count;

      if (IM->FlushElt) {
	 _tnl_translate_array_elts( ctx, IM, last, count );
	 IM->FlushElt = 0;
      }
      
/*        ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; */
   }

   IM->BeginState = state;      

   if (!ctx->CompileFlag)
      ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;


   /* You can set this flag to get the old 'flush_vb on glEnd()'
    * behaviour.
    */
   if ((MESA_DEBUG_FLAGS&DEBUG_ALWAYS_FLUSH))
      _tnl_flush_immediate( IM );
}

static void
_tnl_End(void)
{
   GET_CURRENT_CONTEXT(ctx);
   _tnl_end( ctx );

   /* Need to keep save primitive uptodate in COMPILE and
    * COMPILE_AND_EXEC modes, need to keep exec primitive uptodate
    * otherwise.
    */
   if (ctx->CompileFlag) 
      ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
}


#define COLOR( IM, r, g, b, a )			\
{						\
   GLuint count = IM->Count;			\
   IM->Flag[count] |= VERT_RGBA;		\
   IM->Color[count][0] = r;			\
   IM->Color[count][1] = g;			\
   IM->Color[count][2] = b;			\
   IM->Color[count][3] = a;			\
}

#define COLORV( IM, v )				\
{						\
   GLuint count = IM->Count;			\
   IM->Flag[count] |= VERT_RGBA;		\
   COPY_CHAN4(IM->Color[count], v);		\
}


static void
_tnl_Color3f( GLfloat red, GLfloat green, GLfloat blue )
{
   GLchan col[4];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], red);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], green);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], blue);
   col[3] = CHAN_MAX;
   COLORV( IM, col );
}


static void
_tnl_Color3ub( GLubyte red, GLubyte green, GLubyte blue )
{
#if CHAN_BITS == 8
   GET_IMMEDIATE;
   COLOR( IM, red, green, blue, CHAN_MAX );
#else
   GET_IMMEDIATE;
   COLOR(IM,
         UBYTE_TO_CHAN(red),
         UBYTE_TO_CHAN(green),
         UBYTE_TO_CHAN(blue),
         CHAN_MAX);
#endif
}




static void
_tnl_Color4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
{
   GLchan col[4];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], red);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], green);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], blue);
   UNCLAMPED_FLOAT_TO_CHAN(col[3], alpha);
   COLORV( IM, col );
}

static void
_tnl_Color4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
{
   GET_IMMEDIATE;
   COLOR(IM,
         UBYTE_TO_CHAN(red),
         UBYTE_TO_CHAN(green),
         UBYTE_TO_CHAN(blue),
         UBYTE_TO_CHAN(alpha));
}


static void
_tnl_Color3fv( const GLfloat *v )
{
   GLchan col[4];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], v[0]);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], v[1]);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], v[2]);
   col[3] = CHAN_MAX;
   COLORV( IM, col );
}



static void
_tnl_Color3ubv( const GLubyte *v )
{
   GET_IMMEDIATE;
   COLOR(IM,
         UBYTE_TO_CHAN(v[0]),
         UBYTE_TO_CHAN(v[1]),
         UBYTE_TO_CHAN(v[2]),
         CHAN_MAX );
}

static void
_tnl_Color4fv( const GLfloat *v )
{
   GLchan col[4];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], v[0]);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], v[1]);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], v[2]);
   UNCLAMPED_FLOAT_TO_CHAN(col[3], v[3]);
   COLORV( IM, col );
}



static void
_tnl_Color4ubv( const GLubyte *v)
{
   GET_IMMEDIATE;
   COLOR(IM,
         UBYTE_TO_CHAN(v[0]),
         UBYTE_TO_CHAN(v[1]),
         UBYTE_TO_CHAN(v[2]),
         UBYTE_TO_CHAN(v[3]));
}




#define SECONDARY_COLOR( IM, r, g, b )		\
{						\
   GLuint count = IM->Count;			\
   IM->Flag[count] |= VERT_SPEC_RGB;		\
   IM->SecondaryColor[count][0] = r;		\
   IM->SecondaryColor[count][1] = g;		\
   IM->SecondaryColor[count][2] = b;		\
}

#define SECONDARY_COLORV( IM, v )		\
{						\
   GLuint count = IM->Count;			\
   IM->Flag[count] |= VERT_SPEC_RGB;		\
   IM->SecondaryColor[count][0] = v[0];		\
   IM->SecondaryColor[count][1] = v[1];		\
   IM->SecondaryColor[count][2] = v[2];		\
}




static void
_tnl_SecondaryColor3fEXT( GLfloat red, GLfloat green, GLfloat blue )
{
   GLchan col[3];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], red);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], green);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], blue);
   SECONDARY_COLORV( IM, col );
}



static void
_tnl_SecondaryColor3ubEXT( GLubyte red, GLubyte green, GLubyte blue )
{
   GET_IMMEDIATE;
   SECONDARY_COLOR(IM,
                   UBYTE_TO_CHAN(red),
                   UBYTE_TO_CHAN(green),
                   UBYTE_TO_CHAN(blue));
}




static void
_tnl_SecondaryColor3fvEXT( const GLfloat *v )
{
   GLchan col[3];
   GET_IMMEDIATE;
   UNCLAMPED_FLOAT_TO_CHAN(col[0], v[0]);
   UNCLAMPED_FLOAT_TO_CHAN(col[1], v[1]);
   UNCLAMPED_FLOAT_TO_CHAN(col[2], v[2]);
   SECONDARY_COLORV( IM, col );
}



static void
_tnl_SecondaryColor3ubvEXT( const GLubyte *v )
{
   GET_IMMEDIATE;
   SECONDARY_COLOR(IM,
                   UBYTE_TO_CHAN(v[0]),
                   UBYTE_TO_CHAN(v[1]),
                   UBYTE_TO_CHAN(v[2]));
}




static void
_tnl_EdgeFlag( GLboolean flag )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->EdgeFlag[count] = flag;
   IM->Flag[count] |= VERT_EDGE;
}


static void
_tnl_EdgeFlagv( const GLboolean *flag )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->EdgeFlag[count] = *flag;
   IM->Flag[count] |= VERT_EDGE;
}


static void
_tnl_FogCoordfEXT( GLfloat f )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->FogCoord[count] = f;
   IM->Flag[count] |= VERT_FOG_COORD;
}

static void
_tnl_FogCoordfvEXT( const GLfloat *v )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->FogCoord[count] = v[0];
   IM->Flag[count] |= VERT_FOG_COORD;
}


static void
_tnl_Indexi( GLint c )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->Index[count] = c;
   IM->Flag[count] |= VERT_INDEX;
}


static void
_tnl_Indexiv( const GLint *c )
{
   GLuint count;
   GET_IMMEDIATE;
   count = IM->Count;
   IM->Index[count] = *c;
   IM->Flag[count] |= VERT_INDEX;
}


#define NORMAL( x, y, z )			\
{						\
   GLuint count;				\
   GLfloat *normal;				\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_NORM;		\
   normal = IM->Normal[count];			\
   ASSIGN_3V(normal, x,y,z);			\
}

#if defined(USE_IEEE)
#define NORMALF( x, y, z )					\
{								\
   GLuint count;						\
   GLint *normal;						\
   GET_IMMEDIATE;						\
   count = IM->Count;						\
   IM->Flag[count] |= VERT_NORM;				\
   normal = (GLint *)IM->Normal[count];				\
   ASSIGN_3V(normal, *(int*)&(x), *(int*)&(y), *(int*)&(z));	\
}
#else
#define NORMALF NORMAL
#endif

static void
_tnl_Normal3f( GLfloat nx, GLfloat ny, GLfloat nz )
{
   NORMALF(nx, ny, nz);
}


static void
_tnl_Normal3fv( const GLfloat *v )
{
   NORMALF( v[0], v[1], v[2] );
}



#define TEXCOORD1(s)				\
{						\
   GLuint count;				\
   GLfloat *tc;					\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_TEX0;		\
   tc = IM->TexCoord0[count];			\
   ASSIGN_4V(tc,s,0,0,1);			\
}

#define TEXCOORD2(s,t)				\
{						\
   GLuint count;				\
   GLfloat *tc;					\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_TEX0;		\
   tc = IM->TexCoord0[count];			\
   ASSIGN_4V(tc, s,t,0,1);		        \
}

#define TEXCOORD3(s,t,u)			\
{						\
   GLuint count;				\
   GLfloat *tc;					\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_TEX0;		\
   IM->TexSize |= TEX_0_SIZE_3;		\
   tc = IM->TexCoord0[count];			\
   ASSIGN_4V(tc, s,t,u,1);			\
}

#define TEXCOORD4(s,t,u,v)			\
{						\
   GLuint count;				\
   GLfloat *tc;					\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_TEX0;		\
   IM->TexSize |= TEX_0_SIZE_4;		\
   tc = IM->TexCoord0[count];			\
   ASSIGN_4V(tc, s,t,u,v);			\
}

#if defined(USE_IEEE)
#define TEXCOORD2F(s,t)				\
{						\
   GLuint count;				\
   GLint *tc;					\
   GET_IMMEDIATE;				\
   count = IM->Count;				\
   IM->Flag[count] |= VERT_TEX0;		\
   tc = (GLint *)IM->TexCoord0[count];		\
   tc[0] = *(GLint *)&(s);			\
   tc[1] = *(GLint *)&(t);			\
   tc[2] = 0;					\
   tc[3] = IEEE_ONE;				\
}
#else
#define TEXCOORD2F TEXCOORD2
#endif

static void
_tnl_TexCoord1f( GLfloat s )
{
   TEXCOORD1(s);
}


static void
_tnl_TexCoord2f( GLfloat s, GLfloat t )
{
   TEXCOORD2F(s,t); 
}


static void
_tnl_TexCoord3f( GLfloat s, GLfloat t, GLfloat r )
{
   TEXCOORD3(s,t,r);
}

static void
_tnl_TexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q )
{
   TEXCOORD4(s,t,r,q)
}

static void
_tnl_TexCoord1fv( const GLfloat *v )
{
   TEXCOORD1(v[0]);
}

static void
_tnl_TexCoord2fv( const GLfloat *v )
{
   TEXCOORD2F(v[0],v[1]);
}

static void
_tnl_TexCoord3fv( const GLfloat *v )
{
   TEXCOORD3(v[0],v[1],v[2]);
}

static void
_tnl_TexCoord4fv( const GLfloat *v )
{
   TEXCOORD4(v[0],v[1],v[2],v[3]);
}



/* KW: Run into bad problems in vertex copying if we don't fully pad
 *     the incoming vertices.
 */
#define VERTEX2(IM, x,y)			\
{						\
   GLuint count = IM->Count++;			\
   GLfloat *dest = IM->Obj[count];		\
   IM->Flag[count] |= VERT_OBJ;			\
   ASSIGN_4V(dest, x, y, 0, 1);			\
/*     ASSERT(IM->Flag[IM->Count]==0);		 */\
   if (count == IMM_MAXDATA - 1)		\
      _tnl_flush_immediate( IM );		\
}

#define VERTEX3(IM,x,y,z)			\
{						\
   GLuint count = IM->Count++;			\
   GLfloat *dest = IM->Obj[count];		\
   IM->Flag[count] |= VERT_OBJ_23;		\
   ASSIGN_4V(dest, x, y, z, 1);			\
/*     ASSERT(IM->Flag[IM->Count]==0); */		\
   if (count == IMM_MAXDATA - 1)		\
      _tnl_flush_immediate( IM );		\
}

#define VERTEX4(IM, x,y,z,w)			\
{						\
   GLuint count = IM->Count++;			\
   GLfloat *dest = IM->Obj[count];		\
   IM->Flag[count] |= VERT_OBJ_234;		\
   ASSIGN_4V(dest, x, y, z, w);			\
   if (count == IMM_MAXDATA - 1)			\
      _tnl_flush_immediate( IM );		\
}

#if defined(USE_IEEE)
#define VERTEX2F(IM, x, y)			\
{						\
   GLuint count = IM->Count++;			\
   GLint *dest = (GLint *)IM->Obj[count];	\
   IM->Flag[count] |= VERT_OBJ; 		\
   dest[0] = *(GLint *)&(x);			\
   dest[1] = *(GLint *)&(y);			\
   dest[2] = 0;					\
   dest[3] = IEEE_ONE;				\
/*     ASSERT(IM->Flag[IM->Count]==0); */		\
   if (count == IMM_MAXDATA - 1)			\
      _tnl_flush_immediate( IM );		\
}
#else
#define VERTEX2F VERTEX2
#endif

#if defined(USE_IEEE)
#define VERTEX3F(IM, x, y, z)			\
{						\
   GLuint count = IM->Count++;			\
   GLint *dest = (GLint *)IM->Obj[count];	\
   IM->Flag[count] |= VERT_OBJ_23;		\
   dest[0] = *(GLint *)&(x);			\
   dest[1] = *(GLint *)&(y);			\
   dest[2] = *(GLint *)&(z);			\
   dest[3] = IEEE_ONE;				\
/*     ASSERT(IM->Flag[IM->Count]==0);	 */	\
   if (count == IMM_MAXDATA - 1)			\
      _tnl_flush_immediate( IM );		\
}
#else
#define VERTEX3F VERTEX3
#endif

#if defined(USE_IEEE)
#define VERTEX4F(IM, x, y, z, w)		\
{						\
   GLuint count = IM->Count++;			\
   GLint *dest = (GLint *)IM->Obj[count];	\
   IM->Flag[count] |= VERT_OBJ_234;		\
   dest[0] = *(GLint *)&(x);			\
   dest[1] = *(GLint *)&(y);			\
   dest[2] = *(GLint *)&(z);			\
   dest[3] = *(GLint *)&(w);			\
   if (count == IMM_MAXDATA - 1)			\
      _tnl_flush_immediate( IM );		\
}
#else
#define VERTEX4F VERTEX4
#endif



static void
_tnl_Vertex2f( GLfloat x, GLfloat y )
{
   GET_IMMEDIATE;
   VERTEX2F( IM, x, y );
}

static void
_tnl_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
{
   GET_IMMEDIATE;
   VERTEX3F( IM, x, y, z ); 
}
static void
_tnl_Vertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
{
   GET_IMMEDIATE;
   VERTEX4F( IM, x, y, z, w );
}

static void
_tnl_Vertex2fv( const GLfloat *v )
{
   GET_IMMEDIATE;
   VERTEX2F( IM, v[0], v[1] );
}

static void
_tnl_Vertex3fv( const GLfloat *v )
{
   GET_IMMEDIATE;
   VERTEX3F( IM, v[0], v[1], v[2] );
}

static void
_tnl_Vertex4fv( const GLfloat *v )
{
   GET_IMMEDIATE;
   VERTEX4F( IM, v[0], v[1], v[2], v[3] );
}




/*
 * GL_ARB_multitexture
 *
 * Note: the multitexture spec says that specifying an invalid target
 * has undefined results and does not have to generate an error.  Just
 * don't crash.  We no-op on invalid targets.
 */

#define MAX_TARGET (GL_TEXTURE0_ARB + MAX_TEXTURE_UNITS)

#define MULTI_TEXCOORD1(target, s)			\
{							\
   GET_IMMEDIATE;					\
   GLuint texunit = target - GL_TEXTURE0_ARB;		\
   if (texunit < IM->MaxTextureUnits) {			\
      GLuint count = IM->Count;				\
      GLfloat *tc = IM->TexCoord[texunit][count];	\
      ASSIGN_4V(tc, s, 0.0F, 0.0F, 1.0F);		\
      IM->Flag[count] |= VERT_TEX(texunit);		\
   }							\
}

#define MULTI_TEXCOORD2(target, s, t)			\
{							\
   GET_IMMEDIATE;					\
   GLuint texunit = target - GL_TEXTURE0_ARB;		\
   if (texunit < IM->MaxTextureUnits) {			\
      GLuint count = IM->Count;				\
      GLfloat *tc = IM->TexCoord[texunit][count];	\
      ASSIGN_4V(tc, s, t, 0.0F, 1.0F);			\
      IM->Flag[count] |= VERT_TEX(texunit);		\
   }							\
}

#define MULTI_TEXCOORD3(target, s, t, u)		\
{							\
   GET_IMMEDIATE;					\
   GLuint texunit = target - GL_TEXTURE0_ARB;		\
   if (texunit < IM->MaxTextureUnits) {			\
      GLuint count = IM->Count;				\
      GLfloat *tc = IM->TexCoord[texunit][count];	\
      ASSIGN_4V(tc, s, t, u, 1.0F);			\
      IM->Flag[count] |= VERT_TEX(texunit);		\
      IM->TexSize |= TEX_SIZE_3(texunit);		\
   }							\
}

#define MULTI_TEXCOORD4(target, s, t, u, v)		\
{							\
   GET_IMMEDIATE;					\
   GLuint texunit = target - GL_TEXTURE0_ARB;		\
   if (texunit < IM->MaxTextureUnits) {			\
      GLuint count = IM->Count;				\
      GLfloat *tc = IM->TexCoord[texunit][count];	\
      ASSIGN_4V(tc, s, t, u, v);			\
      IM->Flag[count] |= VERT_TEX(texunit);		\
      IM->TexSize |= TEX_SIZE_4(texunit);		\
   }							\
}

#if defined(USE_IEEE)
#define MULTI_TEXCOORD2F(target, s, t)				\
{								\
   GET_IMMEDIATE;						\
   GLuint texunit = target - GL_TEXTURE0_ARB;			\
   if (texunit < IM->MaxTextureUnits) {				\
      GLuint count = IM->Count;					\
      GLint *tc = (GLint *)IM->TexCoord[texunit][count];	\
      IM->Flag[count] |= VERT_TEX(texunit);			\
      tc[0] = *(int *)&(s);					\
      tc[1] = *(int *)&(t);					\
      tc[2] = 0;						\
      tc[3] = IEEE_ONE;						\
   }								\
}
#else
#define MULTI_TEXCOORD2F MULTI_TEXCOORD2
#endif

static void
_tnl_MultiTexCoord1fARB(GLenum target, GLfloat s)
{
   MULTI_TEXCOORD1( target, s );
}

static void
_tnl_MultiTexCoord1fvARB(GLenum target, const GLfloat *v)
{
   MULTI_TEXCOORD1( target, v[0] );
}

static void
_tnl_MultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t)
{
   MULTI_TEXCOORD2F( target, s, t );
}

static void
_tnl_MultiTexCoord2fvARB(GLenum target, const GLfloat *v)
{
   MULTI_TEXCOORD2F( target, v[0], v[1] );
}

static void
_tnl_MultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r)
{
   MULTI_TEXCOORD3( target, s, t, r );
}

static void
_tnl_MultiTexCoord3fvARB(GLenum target, const GLfloat *v)
{
   MULTI_TEXCOORD3( target, v[0], v[1], v[2] );
}

static void
_tnl_MultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
{
   MULTI_TEXCOORD4( target, s, t, r, q );
}

static void
_tnl_MultiTexCoord4fvARB(GLenum target, const GLfloat *v)
{
   MULTI_TEXCOORD4( target, v[0], v[1], v[2], v[3] );
}



/* KW: Because the eval values don't become 'current', fixup will flow
 *     through these vertices, and then evaluation will write on top
 *     of the fixup results.  
 *
 *     Note: using Obj to hold eval coord data. 
 */
#define EVALCOORD1(IM, x)				\
{							\
   GLuint count = IM->Count++;				\
   IM->Flag[count] |= VERT_EVAL_C1;			\
   ASSIGN_4V(IM->Obj[count], x, 0, 0, 1);		\
   if (count == IMM_MAXDATA-1)				\
      _tnl_flush_immediate( IM );			\
}

#define EVALCOORD2(IM, x, y)				\
{							\
   GLuint count = IM->Count++;				\
   IM->Flag[count] |= VERT_EVAL_C2;			\
   ASSIGN_4V(IM->Obj[count], x, y, 0, 1);		\
   if (count == IMM_MAXDATA-1)				\
      _tnl_flush_immediate( IM );			\
}

#define EVALPOINT1(IM, x)				\
{							\
   GLuint count = IM->Count++;				\
   IM->Flag[count] |= VERT_EVAL_P1;			\
   ASSIGN_4V(IM->Obj[count], x, 0, 0, 1);		\
   if (count == IMM_MAXDATA-1)				\
      _tnl_flush_immediate( IM );			\
}
 
#define EVALPOINT2(IM, x, y)				\
{							\
   GLuint count = IM->Count++;				\
   IM->Flag[count] |= VERT_EVAL_P2;			\
   ASSIGN_4V(IM->Obj[count], x, y, 0, 1);		\
   if (count == IMM_MAXDATA-1)				\
      _tnl_flush_immediate( IM );			\
}

static void
_tnl_EvalCoord1f( GLfloat u )
{
   GET_IMMEDIATE;
   EVALCOORD1( IM, u );
}

static void
_tnl_EvalCoord1fv( const GLfloat *u )
{
   GET_IMMEDIATE;
   EVALCOORD1( IM, (GLfloat) *u );
}

static void
_tnl_EvalCoord2f( GLfloat u, GLfloat v )
{
   GET_IMMEDIATE;
   EVALCOORD2( IM, u, v );
}

static void
_tnl_EvalCoord2fv( const GLfloat *u )
{
   GET_IMMEDIATE;
   EVALCOORD2( IM, u[0], u[1] );
}


static void
_tnl_EvalPoint1( GLint i )
{
   GET_IMMEDIATE;
   EVALPOINT1( IM, i );
}


static void
_tnl_EvalPoint2( GLint i, GLint j )
{
   GET_IMMEDIATE;
   EVALPOINT2( IM, i, j );
}


/* Need to use the default array-elt outside begin/end for strict
 * conformance.
 */
#define ARRAY_ELT( IM, i )			\
{						\
   GLuint count = IM->Count;			\
   IM->Elt[count] = i;				\
   IM->Flag[count] &= IM->ArrayEltFlags;	\
   IM->Flag[count] |= VERT_ELT;			\
   IM->FlushElt |= IM->ArrayEltFlush;		\
   IM->Count += IM->ArrayEltIncr;		\
   if (IM->Count == IMM_MAXDATA)			\
      _tnl_flush_immediate( IM );		\
}


static void
_tnl_ArrayElement( GLint i )
{
   GET_IMMEDIATE;
   ARRAY_ELT( IM, i );
}


/* Internal functions.  These are safe to use providing either: 
 * 
 *    - It is determined that a display list is not being compiled, or
 *    if so that these commands won't be compiled into the list (see
 *    t_eval.c for an example).  
 *
 *    - _tnl_hard_begin() is used instead of _tnl_[bB]egin, and tested
 *    for a GL_TRUE return value.  See _tnl_Rectf, below.
 */
void
_tnl_eval_coord1f( GLcontext *CC, GLfloat u )
{
   struct immediate *i = TNL_CURRENT_IM(CC);
   EVALCOORD1( i, u );
}

void
_tnl_eval_coord2f( GLcontext *CC, GLfloat u, GLfloat v )
{
   struct immediate *i = TNL_CURRENT_IM(CC);
   EVALCOORD2( i, u, v );
}

void
_tnl_array_element( GLcontext *CC, GLint i )
{
   struct immediate *im = TNL_CURRENT_IM(CC);
   ARRAY_ELT( im, i );
}

void
_tnl_vertex2f( GLcontext *ctx, GLfloat x, GLfloat y )
{
   struct immediate *im = TNL_CURRENT_IM(ctx);
   VERTEX2( im, x, y );
}





/* Execute a glRectf() function.  _tnl_hard_begin() ensures the check
 * on outside_begin_end is executed even in compiled lists.  These
 * vertices can now participate in the same VB as regular ones, even
 * in most display lists.
 */
static void
_tnl_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
{
   GET_CURRENT_CONTEXT(ctx);

   if (_tnl_hard_begin( ctx, GL_QUADS )) {
      _tnl_vertex2f( ctx, x1, y1 );
      _tnl_vertex2f( ctx, x2, y1 );
      _tnl_vertex2f( ctx, x2, y2 );
      _tnl_vertex2f( ctx, x1, y2 );
      _tnl_end( ctx );
   }
}

static void
_tnl_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
{
   GET_CURRENT_CONTEXT(ctx);
   struct immediate *IM = TNL_CURRENT_IM(ctx);
   GLuint count = IM->Count;
   struct gl_material *mat;
   GLuint bitmask = _mesa_material_bitmask(ctx, face, pname, ~0, "Materialfv");

   if (bitmask == 0)
      return;

   if (!(IM->Flag[count] & VERT_MATERIAL)) {
      if (!IM->Material) {
	 IM->Material = (GLmaterial (*)[2]) MALLOC( sizeof(GLmaterial) *
						    IMM_SIZE * 2 );
	 IM->MaterialMask = (GLuint *) MALLOC( sizeof(GLuint) * IMM_SIZE ); 
      }
      else if (IM->MaterialOrMask & ~bitmask) {
	 _mesa_copy_material_pairs( IM->Material[count], 
				 IM->Material[IM->LastMaterial],
				 IM->MaterialOrMask & ~bitmask );
      }

      IM->Flag[count] |= VERT_MATERIAL;
      IM->LastMaterial = count;
      IM->MaterialMask[count] = 0;
   }
   
   IM->MaterialOrMask |= bitmask;
   IM->MaterialMask[count] |= bitmask;
   mat = IM->Material[count];

   if (bitmask & FRONT_AMBIENT_BIT) {
      COPY_4FV( mat[0].Ambient, params );
   }
   if (bitmask & BACK_AMBIENT_BIT) {
      COPY_4FV( mat[1].Ambient, params );
   }
   if (bitmask & FRONT_DIFFUSE_BIT) {
      COPY_4FV( mat[0].Diffuse, params );
   }
   if (bitmask & BACK_DIFFUSE_BIT) {
      COPY_4FV( mat[1].Diffuse, params );
   }
   if (bitmask & FRONT_SPECULAR_BIT) {
      COPY_4FV( mat[0].Specular, params );
   }
   if (bitmask & BACK_SPECULAR_BIT) {
      COPY_4FV( mat[1].Specular, params );
   }
   if (bitmask & FRONT_EMISSION_BIT) {
      COPY_4FV( mat[0].Emission, params );
   }
   if (bitmask & BACK_EMISSION_BIT) {
      COPY_4FV( mat[1].Emission, params );
   }
   if (bitmask & FRONT_SHININESS_BIT) {
      GLfloat shininess = CLAMP( params[0], 0.0F, 128.0F );
      mat[0].Shininess = shininess;
   }
   if (bitmask & BACK_SHININESS_BIT) {
      GLfloat shininess = CLAMP( params[0], 0.0F, 128.0F );
      mat[1].Shininess = shininess;
   }
   if (bitmask & FRONT_INDEXES_BIT) {
      mat[0].AmbientIndex = params[0];
      mat[0].DiffuseIndex = params[1];
      mat[0].SpecularIndex = params[2];
   }
   if (bitmask & BACK_INDEXES_BIT) {
      mat[1].AmbientIndex = params[0];
      mat[1].DiffuseIndex = params[1];
      mat[1].SpecularIndex = params[2];
   }
}

void _tnl_imm_vtxfmt_init( GLcontext *ctx )
{
   GLvertexformat *vfmt = &(TNL_CONTEXT(ctx)->vtxfmt);

   /* All begin/end operations are handled by this vertex format:
    */
   vfmt->ArrayElement = _tnl_ArrayElement;
   vfmt->Begin = _tnl_Begin;
   vfmt->Color3f = _tnl_Color3f;
   vfmt->Color3fv = _tnl_Color3fv;
   vfmt->Color3ub = _tnl_Color3ub;
   vfmt->Color3ubv = _tnl_Color3ubv;
   vfmt->Color4f = _tnl_Color4f;
   vfmt->Color4fv = _tnl_Color4fv;
   vfmt->Color4ub = _tnl_Color4ub;
   vfmt->Color4ubv = _tnl_Color4ubv;
   vfmt->EdgeFlag = _tnl_EdgeFlag;
   vfmt->EdgeFlagv = _tnl_EdgeFlagv;
   vfmt->End = _tnl_End;
   vfmt->EvalCoord1f = _tnl_EvalCoord1f;
   vfmt->EvalCoord1fv = _tnl_EvalCoord1fv;
   vfmt->EvalCoord2f = _tnl_EvalCoord2f;
   vfmt->EvalCoord2fv = _tnl_EvalCoord2fv;
   vfmt->EvalPoint1 = _tnl_EvalPoint1;
   vfmt->EvalPoint2 = _tnl_EvalPoint2;
   vfmt->FogCoordfEXT = _tnl_FogCoordfEXT;
   vfmt->FogCoordfvEXT = _tnl_FogCoordfvEXT;
   vfmt->Indexi = _tnl_Indexi;
   vfmt->Indexiv = _tnl_Indexiv;
   vfmt->Materialfv = _tnl_Materialfv;
   vfmt->MultiTexCoord1fARB = _tnl_MultiTexCoord1fARB;
   vfmt->MultiTexCoord1fvARB = _tnl_MultiTexCoord1fvARB;
   vfmt->MultiTexCoord2fARB = _tnl_MultiTexCoord2fARB;
   vfmt->MultiTexCoord2fvARB = _tnl_MultiTexCoord2fvARB;
   vfmt->MultiTexCoord3fARB = _tnl_MultiTexCoord3fARB;
   vfmt->MultiTexCoord3fvARB = _tnl_MultiTexCoord3fvARB;
   vfmt->MultiTexCoord4fARB = _tnl_MultiTexCoord4fARB;
   vfmt->MultiTexCoord4fvARB = _tnl_MultiTexCoord4fvARB;
   vfmt->Normal3f = _tnl_Normal3f;
   vfmt->Normal3fv = _tnl_Normal3fv;
   vfmt->SecondaryColor3fEXT = _tnl_SecondaryColor3fEXT;
   vfmt->SecondaryColor3fvEXT = _tnl_SecondaryColor3fvEXT;
   vfmt->SecondaryColor3ubEXT = _tnl_SecondaryColor3ubEXT;
   vfmt->SecondaryColor3ubvEXT = _tnl_SecondaryColor3ubvEXT;
   vfmt->TexCoord1f = _tnl_TexCoord1f;
   vfmt->TexCoord1fv = _tnl_TexCoord1fv;
   vfmt->TexCoord2f = _tnl_TexCoord2f;
   vfmt->TexCoord2fv = _tnl_TexCoord2fv;
   vfmt->TexCoord3f = _tnl_TexCoord3f;
   vfmt->TexCoord3fv = _tnl_TexCoord3fv;
   vfmt->TexCoord4f = _tnl_TexCoord4f;
   vfmt->TexCoord4fv = _tnl_TexCoord4fv;
   vfmt->Vertex2f = _tnl_Vertex2f;
   vfmt->Vertex2fv = _tnl_Vertex2fv;
   vfmt->Vertex3f = _tnl_Vertex3f;
   vfmt->Vertex3fv = _tnl_Vertex3fv;
   vfmt->Vertex4f = _tnl_Vertex4f;
   vfmt->Vertex4fv = _tnl_Vertex4fv;

   /* Outside begin/end functions (from t_varray.c, t_eval.c, ...): 
    */
   vfmt->Rectf = _tnl_Rectf;

   /* Just use the core function:
    */
   vfmt->CallList = _mesa_CallList; 

   vfmt->prefer_float_colors = GL_FALSE;
}