dlist.c revision 94a6ec8f0c8a25aeeb5880e2285ae6042cfb99db
1/* $Id: dlist.c,v 1.76 2001/09/18 16:16:21 kschultz Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  3.5
6 *
7 * Copyright (C) 1999-2001  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
27
28#ifdef PC_HEADER
29#include "all.h"
30#else
31#include "glheader.h"
32#include "api_loopback.h"
33#include "attrib.h"
34#include "blend.h"
35#include "buffers.h"
36#include "clip.h"
37#include "colormac.h"
38#include "colortab.h"
39#include "context.h"
40#include "convolve.h"
41#include "depth.h"
42#include "dlist.h"
43#include "enable.h"
44#include "enums.h"
45#include "eval.h"
46#include "extensions.h"
47#include "feedback.h"
48#include "get.h"
49#include "glapi.h"
50#include "hash.h"
51#include "histogram.h"
52#include "image.h"
53#include "light.h"
54#include "lines.h"
55#include "dlist.h"
56#include "macros.h"
57#include "matrix.h"
58#include "mem.h"
59#include "pixel.h"
60#include "points.h"
61#include "polygon.h"
62#include "state.h"
63#include "texobj.h"
64#include "teximage.h"
65#include "texstate.h"
66#include "mtypes.h"
67#include "varray.h"
68
69#include "math/m_matrix.h"
70#include "math/m_xform.h"
71
72#endif
73
74
75
76/*
77Functions which aren't compiled but executed immediately:
78	glIsList
79	glGenLists
80	glDeleteLists
81	glEndList  --- BUT:  call ctx->Driver.EndList at end of list execution?
82	glFeedbackBuffer
83	glSelectBuffer
84	glRenderMode
85	glReadPixels
86	glPixelStore
87	glFlush
88	glFinish
89	glIsEnabled
90	glGet*
91
92Functions which cause errors if called while compiling a display list:
93	glNewList
94*/
95
96
97
98/*
99 * Display list instructions are stored as sequences of "nodes".  Nodes
100 * are allocated in blocks.  Each block has BLOCK_SIZE nodes.  Blocks
101 * are linked together with a pointer.
102 */
103
104
105/* How many nodes to allocate at a time:
106 * - reduced now that we hold vertices etc. elsewhere.
107 */
108#define BLOCK_SIZE 256
109
110
111/*
112 * Display list opcodes.
113 *
114 * The fact that these identifiers are assigned consecutive
115 * integer values starting at 0 is very important, see InstSize array usage)
116 *
117 */
118typedef enum {
119	OPCODE_ACCUM,
120	OPCODE_ALPHA_FUNC,
121        OPCODE_BIND_TEXTURE,
122	OPCODE_BITMAP,
123	OPCODE_BLEND_COLOR,
124	OPCODE_BLEND_EQUATION,
125	OPCODE_BLEND_FUNC,
126	OPCODE_BLEND_FUNC_SEPARATE,
127        OPCODE_CALL_LIST,
128        OPCODE_CALL_LIST_OFFSET,
129	OPCODE_CLEAR,
130	OPCODE_CLEAR_ACCUM,
131	OPCODE_CLEAR_COLOR,
132	OPCODE_CLEAR_DEPTH,
133	OPCODE_CLEAR_INDEX,
134	OPCODE_CLEAR_STENCIL,
135        OPCODE_CLIP_PLANE,
136	OPCODE_COLOR_MASK,
137	OPCODE_COLOR_MATERIAL,
138	OPCODE_COLOR_TABLE,
139	OPCODE_COLOR_TABLE_PARAMETER_FV,
140	OPCODE_COLOR_TABLE_PARAMETER_IV,
141	OPCODE_COLOR_SUB_TABLE,
142        OPCODE_CONVOLUTION_FILTER_1D,
143        OPCODE_CONVOLUTION_FILTER_2D,
144        OPCODE_CONVOLUTION_PARAMETER_I,
145        OPCODE_CONVOLUTION_PARAMETER_IV,
146        OPCODE_CONVOLUTION_PARAMETER_F,
147        OPCODE_CONVOLUTION_PARAMETER_FV,
148        OPCODE_COPY_COLOR_SUB_TABLE,
149        OPCODE_COPY_COLOR_TABLE,
150	OPCODE_COPY_PIXELS,
151        OPCODE_COPY_TEX_IMAGE1D,
152        OPCODE_COPY_TEX_IMAGE2D,
153        OPCODE_COPY_TEX_SUB_IMAGE1D,
154        OPCODE_COPY_TEX_SUB_IMAGE2D,
155        OPCODE_COPY_TEX_SUB_IMAGE3D,
156	OPCODE_CULL_FACE,
157	OPCODE_DEPTH_FUNC,
158	OPCODE_DEPTH_MASK,
159	OPCODE_DEPTH_RANGE,
160	OPCODE_DISABLE,
161	OPCODE_DRAW_BUFFER,
162	OPCODE_DRAW_PIXELS,
163	OPCODE_ENABLE,
164	OPCODE_EVALMESH1,
165	OPCODE_EVALMESH2,
166	OPCODE_FOG,
167	OPCODE_FRONT_FACE,
168	OPCODE_FRUSTUM,
169	OPCODE_HINT,
170	OPCODE_HISTOGRAM,
171	OPCODE_INDEX_MASK,
172	OPCODE_INIT_NAMES,
173	OPCODE_LIGHT,
174	OPCODE_LIGHT_MODEL,
175	OPCODE_LINE_STIPPLE,
176	OPCODE_LINE_WIDTH,
177	OPCODE_LIST_BASE,
178	OPCODE_LOAD_IDENTITY,
179	OPCODE_LOAD_MATRIX,
180	OPCODE_LOAD_NAME,
181	OPCODE_LOGIC_OP,
182	OPCODE_MAP1,
183	OPCODE_MAP2,
184	OPCODE_MAPGRID1,
185	OPCODE_MAPGRID2,
186	OPCODE_MATRIX_MODE,
187        OPCODE_MIN_MAX,
188	OPCODE_MULT_MATRIX,
189	OPCODE_ORTHO,
190	OPCODE_PASSTHROUGH,
191	OPCODE_PIXEL_MAP,
192	OPCODE_PIXEL_TRANSFER,
193	OPCODE_PIXEL_ZOOM,
194	OPCODE_POINT_SIZE,
195        OPCODE_POINT_PARAMETERS,
196	OPCODE_POLYGON_MODE,
197        OPCODE_POLYGON_STIPPLE,
198	OPCODE_POLYGON_OFFSET,
199	OPCODE_POP_ATTRIB,
200	OPCODE_POP_MATRIX,
201	OPCODE_POP_NAME,
202	OPCODE_PRIORITIZE_TEXTURE,
203	OPCODE_PUSH_ATTRIB,
204	OPCODE_PUSH_MATRIX,
205	OPCODE_PUSH_NAME,
206	OPCODE_RASTER_POS,
207	OPCODE_READ_BUFFER,
208        OPCODE_RESET_HISTOGRAM,
209        OPCODE_RESET_MIN_MAX,
210        OPCODE_ROTATE,
211        OPCODE_SCALE,
212	OPCODE_SCISSOR,
213	OPCODE_SELECT_TEXTURE_SGIS,
214	OPCODE_SELECT_TEXTURE_COORD_SET,
215	OPCODE_SHADE_MODEL,
216	OPCODE_STENCIL_FUNC,
217	OPCODE_STENCIL_MASK,
218	OPCODE_STENCIL_OP,
219        OPCODE_TEXENV,
220        OPCODE_TEXGEN,
221        OPCODE_TEXPARAMETER,
222	OPCODE_TEX_IMAGE1D,
223	OPCODE_TEX_IMAGE2D,
224	OPCODE_TEX_IMAGE3D,
225	OPCODE_TEX_SUB_IMAGE1D,
226	OPCODE_TEX_SUB_IMAGE2D,
227	OPCODE_TEX_SUB_IMAGE3D,
228        OPCODE_TRANSLATE,
229	OPCODE_VIEWPORT,
230	OPCODE_WINDOW_POS,
231        /* GL_ARB_multitexture */
232        OPCODE_ACTIVE_TEXTURE,
233        /* GL_SGIX/SGIS_pixel_texture */
234        OPCODE_PIXEL_TEXGEN_SGIX,
235        OPCODE_PIXEL_TEXGEN_PARAMETER_SGIS,
236        /* GL_ARB_texture_compression */
237        OPCODE_COMPRESSED_TEX_IMAGE_1D,
238        OPCODE_COMPRESSED_TEX_IMAGE_2D,
239        OPCODE_COMPRESSED_TEX_IMAGE_3D,
240        OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D,
241        OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D,
242        OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D,
243        /* GL_ARB_multisample */
244        OPCODE_SAMPLE_COVERAGE,
245	/* The following three are meta instructions */
246	OPCODE_ERROR,	        /* raise compiled-in error */
247	OPCODE_CONTINUE,
248	OPCODE_END_OF_LIST,
249	OPCODE_DRV_0
250} OpCode;
251
252
253/*
254 * Each instruction in the display list is stored as a sequence of
255 * contiguous nodes in memory.
256 * Each node is the union of a variety of datatypes.
257 */
258union node {
259	OpCode		opcode;
260	GLboolean	b;
261	GLbitfield	bf;
262	GLubyte		ub;
263	GLshort		s;
264	GLushort	us;
265	GLint		i;
266	GLuint		ui;
267	GLenum		e;
268	GLfloat		f;
269	GLvoid		*data;
270	void		*next;	/* If prev node's opcode==OPCODE_CONTINUE */
271};
272
273
274
275/* Number of nodes of storage needed for each instruction.  Sizes for
276 * dynamically allocated opcodes are stored in the context struct.
277 */
278static GLuint InstSize[ OPCODE_END_OF_LIST+1 ];
279
280void mesa_print_display_list( GLuint list );
281
282
283/**********************************************************************/
284/*****                           Private                          *****/
285/**********************************************************************/
286
287
288
289
290
291/*
292 * Make an empty display list.  This is used by glGenLists() to
293 * reserver display list IDs.
294 */
295static Node *make_empty_list( void )
296{
297   Node *n = (Node *) MALLOC( sizeof(Node) );
298   n[0].opcode = OPCODE_END_OF_LIST;
299   return n;
300}
301
302
303
304/*
305 * Destroy all nodes in a display list.
306 * Input:  list - display list number
307 */
308void _mesa_destroy_list( GLcontext *ctx, GLuint list )
309{
310   Node *n, *block;
311   GLboolean done;
312
313   if (list==0)
314      return;
315
316   block = (Node *) _mesa_HashLookup(ctx->Shared->DisplayList, list);
317   n = block;
318
319   done = block ? GL_FALSE : GL_TRUE;
320   while (!done) {
321
322      /* check for extension opcodes first */
323
324      GLint i = (GLint) n[0].opcode - (GLint) OPCODE_DRV_0;
325      if (i >= 0 && i < (GLint) ctx->listext.nr_opcodes) {
326	 ctx->listext.opcode[i].destroy(ctx, &n[1]);
327	 n += ctx->listext.opcode[i].size;
328      }
329      else {
330	 switch (n[0].opcode) {
331	 case OPCODE_MAP1:
332            FREE(n[6].data);
333	    n += InstSize[n[0].opcode];
334	    break;
335	 case OPCODE_MAP2:
336            FREE(n[10].data);
337	    n += InstSize[n[0].opcode];
338	    break;
339	 case OPCODE_DRAW_PIXELS:
340	    FREE( n[5].data );
341	    n += InstSize[n[0].opcode];
342	    break;
343	 case OPCODE_BITMAP:
344	    FREE( n[7].data );
345	    n += InstSize[n[0].opcode];
346	    break;
347         case OPCODE_COLOR_TABLE:
348            FREE( n[6].data );
349            n += InstSize[n[0].opcode];
350            break;
351         case OPCODE_COLOR_SUB_TABLE:
352            FREE( n[6].data );
353            n += InstSize[n[0].opcode];
354            break;
355         case OPCODE_CONVOLUTION_FILTER_1D:
356            FREE( n[6].data );
357            n += InstSize[n[0].opcode];
358            break;
359         case OPCODE_CONVOLUTION_FILTER_2D:
360            FREE( n[7].data );
361            n += InstSize[n[0].opcode];
362            break;
363         case OPCODE_POLYGON_STIPPLE:
364            FREE( n[1].data );
365	    n += InstSize[n[0].opcode];
366            break;
367	 case OPCODE_TEX_IMAGE1D:
368            FREE(n[8].data);
369            n += InstSize[n[0].opcode];
370	    break;
371	 case OPCODE_TEX_IMAGE2D:
372            FREE( n[9]. data );
373            n += InstSize[n[0].opcode];
374	    break;
375	 case OPCODE_TEX_IMAGE3D:
376            FREE( n[10]. data );
377            n += InstSize[n[0].opcode];
378	    break;
379         case OPCODE_TEX_SUB_IMAGE1D:
380            FREE(n[7].data);
381            n += InstSize[n[0].opcode];
382            break;
383         case OPCODE_TEX_SUB_IMAGE2D:
384            FREE(n[9].data);
385            n += InstSize[n[0].opcode];
386            break;
387         case OPCODE_TEX_SUB_IMAGE3D:
388            FREE(n[11].data);
389            n += InstSize[n[0].opcode];
390            break;
391         case OPCODE_COMPRESSED_TEX_IMAGE_1D:
392            FREE(n[7].data);
393            n += InstSize[n[0].opcode];
394            break;
395         case OPCODE_COMPRESSED_TEX_IMAGE_2D:
396            FREE(n[8].data);
397            n += InstSize[n[0].opcode];
398            break;
399         case OPCODE_COMPRESSED_TEX_IMAGE_3D:
400            FREE(n[9].data);
401            n += InstSize[n[0].opcode];
402            break;
403         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D:
404            FREE(n[7].data);
405            n += InstSize[n[0].opcode];
406            break;
407         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D:
408            FREE(n[9].data);
409            n += InstSize[n[0].opcode];
410            break;
411         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D:
412            FREE(n[11].data);
413            n += InstSize[n[0].opcode];
414            break;
415	 case OPCODE_CONTINUE:
416	    n = (Node *) n[1].next;
417	    FREE( block );
418	    block = n;
419	    break;
420	 case OPCODE_END_OF_LIST:
421	    FREE( block );
422	    done = GL_TRUE;
423	    break;
424	 default:
425	    /* Most frequent case */
426	    n += InstSize[n[0].opcode];
427	    break;
428	 }
429      }
430   }
431
432   _mesa_HashRemove(ctx->Shared->DisplayList, list);
433}
434
435
436
437/*
438 * Translate the nth element of list from type to GLuint.
439 */
440static GLuint translate_id( GLsizei n, GLenum type, const GLvoid *list )
441{
442   GLbyte *bptr;
443   GLubyte *ubptr;
444   GLshort *sptr;
445   GLushort *usptr;
446   GLint *iptr;
447   GLuint *uiptr;
448   GLfloat *fptr;
449
450   switch (type) {
451      case GL_BYTE:
452         bptr = (GLbyte *) list;
453         return (GLuint) *(bptr+n);
454      case GL_UNSIGNED_BYTE:
455         ubptr = (GLubyte *) list;
456         return (GLuint) *(ubptr+n);
457      case GL_SHORT:
458         sptr = (GLshort *) list;
459         return (GLuint) *(sptr+n);
460      case GL_UNSIGNED_SHORT:
461         usptr = (GLushort *) list;
462         return (GLuint) *(usptr+n);
463      case GL_INT:
464         iptr = (GLint *) list;
465         return (GLuint) *(iptr+n);
466      case GL_UNSIGNED_INT:
467         uiptr = (GLuint *) list;
468         return (GLuint) *(uiptr+n);
469      case GL_FLOAT:
470         fptr = (GLfloat *) list;
471         return (GLuint) *(fptr+n);
472      case GL_2_BYTES:
473         ubptr = ((GLubyte *) list) + 2*n;
474         return (GLuint) *ubptr * 256 + (GLuint) *(ubptr+1);
475      case GL_3_BYTES:
476         ubptr = ((GLubyte *) list) + 3*n;
477         return (GLuint) *ubptr * 65536
478              + (GLuint) *(ubptr+1) * 256
479              + (GLuint) *(ubptr+2);
480      case GL_4_BYTES:
481         ubptr = ((GLubyte *) list) + 4*n;
482         return (GLuint) *ubptr * 16777216
483              + (GLuint) *(ubptr+1) * 65536
484              + (GLuint) *(ubptr+2) * 256
485              + (GLuint) *(ubptr+3);
486      default:
487         return 0;
488   }
489}
490
491
492
493
494/**********************************************************************/
495/*****                        Public                              *****/
496/**********************************************************************/
497
498void _mesa_init_lists( void )
499{
500   static int init_flag = 0;
501
502   if (init_flag==0) {
503      InstSize[OPCODE_ACCUM] = 3;
504      InstSize[OPCODE_ALPHA_FUNC] = 3;
505      InstSize[OPCODE_BIND_TEXTURE] = 3;
506      InstSize[OPCODE_BITMAP] = 8;
507      InstSize[OPCODE_BLEND_COLOR] = 5;
508      InstSize[OPCODE_BLEND_EQUATION] = 2;
509      InstSize[OPCODE_BLEND_FUNC] = 3;
510      InstSize[OPCODE_BLEND_FUNC_SEPARATE] = 5;
511      InstSize[OPCODE_CALL_LIST] = 2;
512      InstSize[OPCODE_CALL_LIST_OFFSET] = 2;
513      InstSize[OPCODE_CLEAR] = 2;
514      InstSize[OPCODE_CLEAR_ACCUM] = 5;
515      InstSize[OPCODE_CLEAR_COLOR] = 5;
516      InstSize[OPCODE_CLEAR_DEPTH] = 2;
517      InstSize[OPCODE_CLEAR_INDEX] = 2;
518      InstSize[OPCODE_CLEAR_STENCIL] = 2;
519      InstSize[OPCODE_CLIP_PLANE] = 6;
520      InstSize[OPCODE_COLOR_MASK] = 5;
521      InstSize[OPCODE_COLOR_MATERIAL] = 3;
522      InstSize[OPCODE_COLOR_TABLE] = 7;
523      InstSize[OPCODE_COLOR_TABLE_PARAMETER_FV] = 7;
524      InstSize[OPCODE_COLOR_TABLE_PARAMETER_IV] = 7;
525      InstSize[OPCODE_COLOR_SUB_TABLE] = 7;
526      InstSize[OPCODE_CONVOLUTION_FILTER_1D] = 7;
527      InstSize[OPCODE_CONVOLUTION_FILTER_2D] = 8;
528      InstSize[OPCODE_CONVOLUTION_PARAMETER_I] = 4;
529      InstSize[OPCODE_CONVOLUTION_PARAMETER_IV] = 7;
530      InstSize[OPCODE_CONVOLUTION_PARAMETER_F] = 4;
531      InstSize[OPCODE_CONVOLUTION_PARAMETER_FV] = 7;
532      InstSize[OPCODE_COPY_PIXELS] = 6;
533      InstSize[OPCODE_COPY_COLOR_SUB_TABLE] = 6;
534      InstSize[OPCODE_COPY_COLOR_TABLE] = 6;
535      InstSize[OPCODE_COPY_TEX_IMAGE1D] = 8;
536      InstSize[OPCODE_COPY_TEX_IMAGE2D] = 9;
537      InstSize[OPCODE_COPY_TEX_SUB_IMAGE1D] = 7;
538      InstSize[OPCODE_COPY_TEX_SUB_IMAGE2D] = 9;
539      InstSize[OPCODE_COPY_TEX_SUB_IMAGE3D] = 10;
540      InstSize[OPCODE_CULL_FACE] = 2;
541      InstSize[OPCODE_DEPTH_FUNC] = 2;
542      InstSize[OPCODE_DEPTH_MASK] = 2;
543      InstSize[OPCODE_DEPTH_RANGE] = 3;
544      InstSize[OPCODE_DISABLE] = 2;
545      InstSize[OPCODE_DRAW_BUFFER] = 2;
546      InstSize[OPCODE_DRAW_PIXELS] = 6;
547      InstSize[OPCODE_ENABLE] = 2;
548      InstSize[OPCODE_EVALMESH1] = 4;
549      InstSize[OPCODE_EVALMESH2] = 6;
550      InstSize[OPCODE_FOG] = 6;
551      InstSize[OPCODE_FRONT_FACE] = 2;
552      InstSize[OPCODE_FRUSTUM] = 7;
553      InstSize[OPCODE_HINT] = 3;
554      InstSize[OPCODE_HISTOGRAM] = 5;
555      InstSize[OPCODE_INDEX_MASK] = 2;
556      InstSize[OPCODE_INIT_NAMES] = 1;
557      InstSize[OPCODE_LIGHT] = 7;
558      InstSize[OPCODE_LIGHT_MODEL] = 6;
559      InstSize[OPCODE_LINE_STIPPLE] = 3;
560      InstSize[OPCODE_LINE_WIDTH] = 2;
561      InstSize[OPCODE_LIST_BASE] = 2;
562      InstSize[OPCODE_LOAD_IDENTITY] = 1;
563      InstSize[OPCODE_LOAD_MATRIX] = 17;
564      InstSize[OPCODE_LOAD_NAME] = 2;
565      InstSize[OPCODE_LOGIC_OP] = 2;
566      InstSize[OPCODE_MAP1] = 7;
567      InstSize[OPCODE_MAP2] = 11;
568      InstSize[OPCODE_MAPGRID1] = 4;
569      InstSize[OPCODE_MAPGRID2] = 7;
570      InstSize[OPCODE_MATRIX_MODE] = 2;
571      InstSize[OPCODE_MIN_MAX] = 4;
572      InstSize[OPCODE_MULT_MATRIX] = 17;
573      InstSize[OPCODE_ORTHO] = 7;
574      InstSize[OPCODE_PASSTHROUGH] = 2;
575      InstSize[OPCODE_PIXEL_MAP] = 4;
576      InstSize[OPCODE_PIXEL_TRANSFER] = 3;
577      InstSize[OPCODE_PIXEL_ZOOM] = 3;
578      InstSize[OPCODE_POINT_SIZE] = 2;
579      InstSize[OPCODE_POINT_PARAMETERS] = 5;
580      InstSize[OPCODE_POLYGON_MODE] = 3;
581      InstSize[OPCODE_POLYGON_STIPPLE] = 2;
582      InstSize[OPCODE_POLYGON_OFFSET] = 3;
583      InstSize[OPCODE_POP_ATTRIB] = 1;
584      InstSize[OPCODE_POP_MATRIX] = 1;
585      InstSize[OPCODE_POP_NAME] = 1;
586      InstSize[OPCODE_PRIORITIZE_TEXTURE] = 3;
587      InstSize[OPCODE_PUSH_ATTRIB] = 2;
588      InstSize[OPCODE_PUSH_MATRIX] = 1;
589      InstSize[OPCODE_PUSH_NAME] = 2;
590      InstSize[OPCODE_RASTER_POS] = 5;
591      InstSize[OPCODE_READ_BUFFER] = 2;
592      InstSize[OPCODE_RESET_HISTOGRAM] = 2;
593      InstSize[OPCODE_RESET_MIN_MAX] = 2;
594      InstSize[OPCODE_ROTATE] = 5;
595      InstSize[OPCODE_SCALE] = 4;
596      InstSize[OPCODE_SCISSOR] = 5;
597      InstSize[OPCODE_STENCIL_FUNC] = 4;
598      InstSize[OPCODE_STENCIL_MASK] = 2;
599      InstSize[OPCODE_STENCIL_OP] = 4;
600      InstSize[OPCODE_SHADE_MODEL] = 2;
601      InstSize[OPCODE_TEXENV] = 7;
602      InstSize[OPCODE_TEXGEN] = 7;
603      InstSize[OPCODE_TEXPARAMETER] = 7;
604      InstSize[OPCODE_TEX_IMAGE1D] = 9;
605      InstSize[OPCODE_TEX_IMAGE2D] = 10;
606      InstSize[OPCODE_TEX_IMAGE3D] = 11;
607      InstSize[OPCODE_TEX_SUB_IMAGE1D] = 8;
608      InstSize[OPCODE_TEX_SUB_IMAGE2D] = 10;
609      InstSize[OPCODE_TEX_SUB_IMAGE3D] = 12;
610      InstSize[OPCODE_TRANSLATE] = 4;
611      InstSize[OPCODE_VIEWPORT] = 5;
612      InstSize[OPCODE_WINDOW_POS] = 5;
613      InstSize[OPCODE_CONTINUE] = 2;
614      InstSize[OPCODE_ERROR] = 3;
615      InstSize[OPCODE_END_OF_LIST] = 1;
616      /* GL_SGIX/SGIS_pixel_texture */
617      InstSize[OPCODE_PIXEL_TEXGEN_SGIX] = 2;
618      InstSize[OPCODE_PIXEL_TEXGEN_PARAMETER_SGIS] = 3;
619      /* GL_ARB_texture_compression */
620      InstSize[OPCODE_COMPRESSED_TEX_IMAGE_1D] = 8;
621      InstSize[OPCODE_COMPRESSED_TEX_IMAGE_2D] = 9;
622      InstSize[OPCODE_COMPRESSED_TEX_IMAGE_3D] = 10;
623      InstSize[OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D] = 8;
624      InstSize[OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D] = 10;
625      InstSize[OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D] = 12;
626      /* GL_ARB_multisample */
627      InstSize[OPCODE_SAMPLE_COVERAGE] = 3;
628      /* GL_ARB_multitexture */
629      InstSize[OPCODE_ACTIVE_TEXTURE] = 2;
630   }
631   init_flag = 1;
632}
633
634
635/*
636 * Allocate space for a display list instruction.
637 * Input:  opcode - type of instruction
638 *         argcount - size in bytes of data required.
639 * Return: pointer to the usable data area (not including the internal
640 *         opcode).
641 */
642void *
643_mesa_alloc_instruction( GLcontext *ctx, int opcode, GLint sz )
644{
645   Node *n, *newblock;
646   GLuint count = 1 + (sz + sizeof(Node) - 1) / sizeof(Node);
647
648#ifdef DEBUG
649   if (opcode < (int) OPCODE_DRV_0) {
650      assert( count == InstSize[opcode] );
651   }
652#endif
653
654   if (ctx->CurrentPos + count + 2 > BLOCK_SIZE) {
655      /* This block is full.  Allocate a new block and chain to it */
656      n = ctx->CurrentBlock + ctx->CurrentPos;
657      n[0].opcode = OPCODE_CONTINUE;
658      newblock = (Node *) MALLOC( sizeof(Node) * BLOCK_SIZE );
659      if (!newblock) {
660         _mesa_error( ctx, GL_OUT_OF_MEMORY, "Building display list" );
661         return NULL;
662      }
663      n[1].next = (Node *) newblock;
664      ctx->CurrentBlock = newblock;
665      ctx->CurrentPos = 0;
666   }
667
668   n = ctx->CurrentBlock + ctx->CurrentPos;
669   ctx->CurrentPos += count;
670
671   n[0].opcode = (OpCode) opcode;
672
673   return (void *)&n[1];
674}
675
676
677/* Allow modules and drivers to get their own opcodes.
678 */
679int
680_mesa_alloc_opcode( GLcontext *ctx,
681		    GLuint sz,
682		    void (*execute)( GLcontext *, void * ),
683		    void (*destroy)( GLcontext *, void * ),
684		    void (*print)( GLcontext *, void * ) )
685{
686   if (ctx->listext.nr_opcodes < GL_MAX_EXT_OPCODES) {
687      GLuint i = ctx->listext.nr_opcodes++;
688      ctx->listext.opcode[i].size = 1 + (sz + sizeof(Node) - 1)/sizeof(Node);
689      ctx->listext.opcode[i].execute = execute;
690      ctx->listext.opcode[i].destroy = destroy;
691      ctx->listext.opcode[i].print = print;
692      return i + OPCODE_DRV_0;
693   }
694   return -1;
695}
696
697
698
699/* Mimic the old behaviour of alloc_instruction:
700 *   - sz is in units of sizeof(Node)
701 *   - return value a pointer to sizeof(Node) before the actual
702 *     usable data area.
703 */
704#define ALLOC_INSTRUCTION(ctx, opcode, sz) \
705        ((Node *)_mesa_alloc_instruction(ctx, opcode, sz*sizeof(Node)) - 1)
706
707
708
709/*
710 * Display List compilation functions
711 */
712static void save_Accum( GLenum op, GLfloat value )
713{
714   GET_CURRENT_CONTEXT(ctx);
715   Node *n;
716   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
717   n = ALLOC_INSTRUCTION( ctx, OPCODE_ACCUM, 2 );
718   if (n) {
719      n[1].e = op;
720      n[2].f = value;
721   }
722   if (ctx->ExecuteFlag) {
723      (*ctx->Exec->Accum)( op, value );
724   }
725}
726
727
728static void save_AlphaFunc( GLenum func, GLclampf ref )
729{
730   GET_CURRENT_CONTEXT(ctx);
731   Node *n;
732   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
733   n = ALLOC_INSTRUCTION( ctx, OPCODE_ALPHA_FUNC, 2 );
734   if (n) {
735      n[1].e = func;
736      n[2].f = (GLfloat) ref;
737   }
738   if (ctx->ExecuteFlag) {
739      (*ctx->Exec->AlphaFunc)( func, ref );
740   }
741}
742
743
744static void save_BindTexture( GLenum target, GLuint texture )
745{
746   GET_CURRENT_CONTEXT(ctx);
747   Node *n;
748   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
749   n = ALLOC_INSTRUCTION( ctx, OPCODE_BIND_TEXTURE, 2 );
750   if (n) {
751      n[1].e = target;
752      n[2].ui = texture;
753   }
754   if (ctx->ExecuteFlag) {
755      (*ctx->Exec->BindTexture)( target, texture );
756   }
757}
758
759
760static void save_Bitmap( GLsizei width, GLsizei height,
761                         GLfloat xorig, GLfloat yorig,
762                         GLfloat xmove, GLfloat ymove,
763                         const GLubyte *pixels )
764{
765   GET_CURRENT_CONTEXT(ctx);
766   GLvoid *image = _mesa_unpack_bitmap( width, height, pixels, &ctx->Unpack );
767   Node *n;
768   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
769   n = ALLOC_INSTRUCTION( ctx, OPCODE_BITMAP, 7 );
770   if (n) {
771      n[1].i = (GLint) width;
772      n[2].i = (GLint) height;
773      n[3].f = xorig;
774      n[4].f = yorig;
775      n[5].f = xmove;
776      n[6].f = ymove;
777      n[7].data = image;
778   }
779   else if (image) {
780      FREE(image);
781   }
782   if (ctx->ExecuteFlag) {
783      (*ctx->Exec->Bitmap)( width, height,
784                           xorig, yorig, xmove, ymove, pixels );
785   }
786}
787
788
789static void save_BlendEquation( GLenum mode )
790{
791   GET_CURRENT_CONTEXT(ctx);
792   Node *n;
793   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
794   n = ALLOC_INSTRUCTION( ctx, OPCODE_BLEND_EQUATION, 1 );
795   if (n) {
796      n[1].e = mode;
797   }
798   if (ctx->ExecuteFlag) {
799      (*ctx->Exec->BlendEquation)( mode );
800   }
801}
802
803
804static void save_BlendFunc( GLenum sfactor, GLenum dfactor )
805{
806   GET_CURRENT_CONTEXT(ctx);
807   Node *n;
808   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
809   n = ALLOC_INSTRUCTION( ctx, OPCODE_BLEND_FUNC, 2 );
810   if (n) {
811      n[1].e = sfactor;
812      n[2].e = dfactor;
813   }
814   if (ctx->ExecuteFlag) {
815      (*ctx->Exec->BlendFunc)( sfactor, dfactor );
816   }
817}
818
819
820static void save_BlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB,
821                                      GLenum sfactorA, GLenum dfactorA)
822{
823   GET_CURRENT_CONTEXT(ctx);
824   Node *n;
825   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
826   n = ALLOC_INSTRUCTION( ctx, OPCODE_BLEND_FUNC_SEPARATE, 4 );
827   if (n) {
828      n[1].e = sfactorRGB;
829      n[2].e = dfactorRGB;
830      n[3].e = sfactorA;
831      n[4].e = dfactorA;
832   }
833   if (ctx->ExecuteFlag) {
834      (*ctx->Exec->BlendFuncSeparateEXT)( sfactorRGB, dfactorRGB,
835                                          sfactorA, dfactorA);
836   }
837}
838
839
840static void save_BlendColor( GLfloat red, GLfloat green,
841                             GLfloat blue, GLfloat alpha )
842{
843   GET_CURRENT_CONTEXT(ctx);
844   Node *n;
845   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
846   n = ALLOC_INSTRUCTION( ctx, OPCODE_BLEND_COLOR, 4 );
847   if (n) {
848      n[1].f = red;
849      n[2].f = green;
850      n[3].f = blue;
851      n[4].f = alpha;
852   }
853   if (ctx->ExecuteFlag) {
854      (*ctx->Exec->BlendColor)( red, green, blue, alpha );
855   }
856}
857
858
859void _mesa_save_CallList( GLuint list )
860{
861   GET_CURRENT_CONTEXT(ctx);
862   Node *n;
863   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
864   FLUSH_CURRENT(ctx, 0);
865
866   n = ALLOC_INSTRUCTION( ctx, OPCODE_CALL_LIST, 1 );
867   if (n) {
868      n[1].ui = list;
869   }
870   if (ctx->ExecuteFlag) {
871      (*ctx->Exec->CallList)( list );
872   }
873}
874
875
876void _mesa_save_CallLists( GLsizei n, GLenum type, const GLvoid *lists )
877{
878   GET_CURRENT_CONTEXT(ctx);
879   GLint i;
880   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
881   FLUSH_CURRENT(ctx, 0);
882
883   for (i=0;i<n;i++) {
884      GLuint list = translate_id( i, type, lists );
885      Node *n = ALLOC_INSTRUCTION( ctx, OPCODE_CALL_LIST_OFFSET, 1 );
886      if (n) {
887         n[1].ui = list;
888      }
889   }
890   if (ctx->ExecuteFlag) {
891      (*ctx->Exec->CallLists)( n, type, lists );
892   }
893}
894
895
896static void save_Clear( GLbitfield mask )
897{
898   GET_CURRENT_CONTEXT(ctx);
899   Node *n;
900   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
901   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR, 1 );
902   if (n) {
903      n[1].bf = mask;
904   }
905   if (ctx->ExecuteFlag) {
906      (*ctx->Exec->Clear)( mask );
907   }
908}
909
910
911static void save_ClearAccum( GLfloat red, GLfloat green,
912                             GLfloat blue, GLfloat alpha )
913{
914   GET_CURRENT_CONTEXT(ctx);
915   Node *n;
916   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
917   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR_ACCUM, 4 );
918   if (n) {
919      n[1].f = red;
920      n[2].f = green;
921      n[3].f = blue;
922      n[4].f = alpha;
923   }
924   if (ctx->ExecuteFlag) {
925      (*ctx->Exec->ClearAccum)( red, green, blue, alpha );
926   }
927}
928
929
930static void save_ClearColor( GLclampf red, GLclampf green,
931                             GLclampf blue, GLclampf alpha )
932{
933   GET_CURRENT_CONTEXT(ctx);
934   Node *n;
935   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
936   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR_COLOR, 4 );
937   if (n) {
938      n[1].f = red;
939      n[2].f = green;
940      n[3].f = blue;
941      n[4].f = alpha;
942   }
943   if (ctx->ExecuteFlag) {
944      (*ctx->Exec->ClearColor)( red, green, blue, alpha );
945   }
946}
947
948
949static void save_ClearDepth( GLclampd depth )
950{
951   GET_CURRENT_CONTEXT(ctx);
952   Node *n;
953   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
954   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR_DEPTH, 1 );
955   if (n) {
956      n[1].f = (GLfloat) depth;
957   }
958   if (ctx->ExecuteFlag) {
959      (*ctx->Exec->ClearDepth)( depth );
960   }
961}
962
963
964static void save_ClearIndex( GLfloat c )
965{
966   GET_CURRENT_CONTEXT(ctx);
967   Node *n;
968   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
969   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR_INDEX, 1 );
970   if (n) {
971      n[1].f = c;
972   }
973   if (ctx->ExecuteFlag) {
974      (*ctx->Exec->ClearIndex)( c );
975   }
976}
977
978
979static void save_ClearStencil( GLint s )
980{
981   GET_CURRENT_CONTEXT(ctx);
982   Node *n;
983   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
984   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLEAR_STENCIL, 1 );
985   if (n) {
986      n[1].i = s;
987   }
988   if (ctx->ExecuteFlag) {
989      (*ctx->Exec->ClearStencil)( s );
990   }
991}
992
993
994static void save_ClipPlane( GLenum plane, const GLdouble *equ )
995{
996   GET_CURRENT_CONTEXT(ctx);
997   Node *n;
998   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
999   n = ALLOC_INSTRUCTION( ctx, OPCODE_CLIP_PLANE, 5 );
1000   if (n) {
1001      n[1].e = plane;
1002      n[2].f = (GLfloat) equ[0];
1003      n[3].f = (GLfloat) equ[1];
1004      n[4].f = (GLfloat) equ[2];
1005      n[5].f = (GLfloat) equ[3];
1006   }
1007   if (ctx->ExecuteFlag) {
1008      (*ctx->Exec->ClipPlane)( plane, equ );
1009   }
1010}
1011
1012
1013
1014static void save_ColorMask( GLboolean red, GLboolean green,
1015                            GLboolean blue, GLboolean alpha )
1016{
1017   GET_CURRENT_CONTEXT(ctx);
1018   Node *n;
1019   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1020   n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_MASK, 4 );
1021   if (n) {
1022      n[1].b = red;
1023      n[2].b = green;
1024      n[3].b = blue;
1025      n[4].b = alpha;
1026   }
1027   if (ctx->ExecuteFlag) {
1028      (*ctx->Exec->ColorMask)( red, green, blue, alpha );
1029   }
1030}
1031
1032
1033static void save_ColorMaterial( GLenum face, GLenum mode )
1034{
1035   GET_CURRENT_CONTEXT(ctx);
1036   Node *n;
1037   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1038   FLUSH_CURRENT(ctx, 0);
1039
1040   n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_MATERIAL, 2 );
1041   if (n) {
1042      n[1].e = face;
1043      n[2].e = mode;
1044   }
1045   if (ctx->ExecuteFlag) {
1046      (*ctx->Exec->ColorMaterial)( face, mode );
1047   }
1048}
1049
1050
1051static void save_ColorTable( GLenum target, GLenum internalFormat,
1052                             GLsizei width, GLenum format, GLenum type,
1053                             const GLvoid *table )
1054{
1055   GET_CURRENT_CONTEXT(ctx);
1056   if (target == GL_PROXY_TEXTURE_1D ||
1057       target == GL_PROXY_TEXTURE_2D ||
1058       target == GL_PROXY_TEXTURE_3D ||
1059       target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
1060      /* execute immediately */
1061      (*ctx->Exec->ColorTable)( target, internalFormat, width,
1062                                format, type, table );
1063   }
1064   else {
1065      GLvoid *image = _mesa_unpack_image(width, 1, 1, format, type, table,
1066                                         &ctx->Unpack);
1067      Node *n;
1068      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1069      n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_TABLE, 6 );
1070      if (n) {
1071         n[1].e = target;
1072         n[2].e = internalFormat;
1073         n[3].i = width;
1074         n[4].e = format;
1075         n[5].e = type;
1076         n[6].data = image;
1077      }
1078      else if (image) {
1079         FREE(image);
1080      }
1081      if (ctx->ExecuteFlag) {
1082         (*ctx->Exec->ColorTable)( target, internalFormat, width,
1083                                   format, type, table );
1084      }
1085   }
1086}
1087
1088
1089
1090static void
1091save_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1092{
1093   GET_CURRENT_CONTEXT(ctx);
1094   Node *n;
1095
1096   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1097
1098   n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_TABLE_PARAMETER_FV, 6 );
1099   if (n) {
1100      n[1].e = target;
1101      n[2].e = pname;
1102      n[3].f = params[0];
1103      if (pname == GL_COLOR_TABLE_SGI ||
1104          pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1105          pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
1106         n[4].f = params[1];
1107         n[5].f = params[2];
1108         n[6].f = params[3];
1109      }
1110   }
1111
1112   if (ctx->ExecuteFlag) {
1113      (*ctx->Exec->ColorTableParameterfv)( target, pname, params );
1114   }
1115}
1116
1117
1118static void
1119save_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
1120{
1121   GET_CURRENT_CONTEXT(ctx);
1122   Node *n;
1123
1124   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1125
1126   n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_TABLE_PARAMETER_IV, 6 );
1127   if (n) {
1128      n[1].e = target;
1129      n[2].e = pname;
1130      n[3].i = params[0];
1131      if (pname == GL_COLOR_TABLE_SGI ||
1132          pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1133          pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
1134         n[4].i = params[1];
1135         n[5].i = params[2];
1136         n[6].i = params[3];
1137      }
1138   }
1139
1140   if (ctx->ExecuteFlag) {
1141      (*ctx->Exec->ColorTableParameteriv)( target, pname, params );
1142   }
1143}
1144
1145
1146
1147static void save_ColorSubTable( GLenum target, GLsizei start, GLsizei count,
1148                                GLenum format, GLenum type,
1149                                const GLvoid *table)
1150{
1151   GET_CURRENT_CONTEXT(ctx);
1152   GLvoid *image = _mesa_unpack_image(count, 1, 1, format, type, table,
1153                                      &ctx->Unpack);
1154   Node *n;
1155   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1156   n = ALLOC_INSTRUCTION( ctx, OPCODE_COLOR_SUB_TABLE, 6 );
1157   if (n) {
1158      n[1].e = target;
1159      n[2].i = start;
1160      n[3].i = count;
1161      n[4].e = format;
1162      n[5].e = type;
1163      n[6].data = image;
1164   }
1165   else if (image) {
1166      FREE(image);
1167   }
1168   if (ctx->ExecuteFlag) {
1169      (*ctx->Exec->ColorSubTable)(target, start, count, format, type, table);
1170   }
1171}
1172
1173
1174static void
1175save_CopyColorSubTable(GLenum target, GLsizei start,
1176                       GLint x, GLint y, GLsizei width)
1177{
1178   GET_CURRENT_CONTEXT(ctx);
1179   Node *n;
1180
1181   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1182   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_COLOR_SUB_TABLE, 5 );
1183   if (n) {
1184      n[1].e = target;
1185      n[2].i = start;
1186      n[3].i = x;
1187      n[4].i = y;
1188      n[5].i = width;
1189   }
1190   if (ctx->ExecuteFlag) {
1191      (*ctx->Exec->CopyColorSubTable)(target, start, x, y, width);
1192   }
1193}
1194
1195
1196static void
1197save_CopyColorTable(GLenum target, GLenum internalformat,
1198                    GLint x, GLint y, GLsizei width)
1199{
1200   GET_CURRENT_CONTEXT(ctx);
1201   Node *n;
1202
1203   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1204   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_COLOR_TABLE, 5 );
1205   if (n) {
1206      n[1].e = target;
1207      n[2].e = internalformat;
1208      n[3].i = x;
1209      n[4].i = y;
1210      n[5].i = width;
1211   }
1212   if (ctx->ExecuteFlag) {
1213      (*ctx->Exec->CopyColorTable)(target, internalformat, x, y, width);
1214   }
1215}
1216
1217
1218static void
1219save_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width,
1220                         GLenum format, GLenum type, const GLvoid *filter)
1221{
1222   GET_CURRENT_CONTEXT(ctx);
1223   GLvoid *image = _mesa_unpack_image(width, 1, 1, format, type, filter,
1224                                      &ctx->Unpack);
1225   Node *n;
1226   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1227   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_FILTER_1D, 6 );
1228   if (n) {
1229      n[1].e = target;
1230      n[2].e = internalFormat;
1231      n[3].i = width;
1232      n[4].e = format;
1233      n[5].e = type;
1234      n[6].data = image;
1235   }
1236   else if (image) {
1237      FREE(image);
1238   }
1239   if (ctx->ExecuteFlag) {
1240      (*ctx->Exec->ConvolutionFilter1D)( target, internalFormat, width,
1241                                         format, type, filter );
1242   }
1243}
1244
1245
1246static void
1247save_ConvolutionFilter2D(GLenum target, GLenum internalFormat,
1248                         GLsizei width, GLsizei height, GLenum format,
1249                         GLenum type, const GLvoid *filter)
1250{
1251   GET_CURRENT_CONTEXT(ctx);
1252   GLvoid *image = _mesa_unpack_image(width, height, 1, format, type, filter,
1253                                      &ctx->Unpack);
1254   Node *n;
1255   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1256   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_FILTER_2D, 7 );
1257   if (n) {
1258      n[1].e = target;
1259      n[2].e = internalFormat;
1260      n[3].i = width;
1261      n[4].i = height;
1262      n[5].e = format;
1263      n[6].e = type;
1264      n[7].data = image;
1265   }
1266   else if (image) {
1267      FREE(image);
1268   }
1269   if (ctx->ExecuteFlag) {
1270      (*ctx->Exec->ConvolutionFilter2D)( target, internalFormat, width, height,
1271                                         format, type, filter );
1272   }
1273}
1274
1275
1276static void
1277save_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
1278{
1279   GET_CURRENT_CONTEXT(ctx);
1280   Node *n;
1281   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1282   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_PARAMETER_I, 3 );
1283   if (n) {
1284      n[1].e = target;
1285      n[2].e = pname;
1286      n[3].i = param;
1287   }
1288   if (ctx->ExecuteFlag) {
1289      (*ctx->Exec->ConvolutionParameteri)( target, pname, param );
1290   }
1291}
1292
1293
1294static void
1295save_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
1296{
1297   GET_CURRENT_CONTEXT(ctx);
1298   Node *n;
1299   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1300   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_PARAMETER_IV, 6 );
1301   if (n) {
1302      n[1].e = target;
1303      n[2].e = pname;
1304      n[3].i = params[0];
1305      if (pname == GL_CONVOLUTION_BORDER_COLOR ||
1306          pname == GL_CONVOLUTION_FILTER_SCALE ||
1307          pname == GL_CONVOLUTION_FILTER_BIAS) {
1308         n[4].i = params[1];
1309         n[5].i = params[2];
1310         n[6].i = params[3];
1311      }
1312      else {
1313         n[4].i = n[5].i = n[6].i = 0;
1314      }
1315   }
1316   if (ctx->ExecuteFlag) {
1317      (*ctx->Exec->ConvolutionParameteriv)( target, pname, params );
1318   }
1319}
1320
1321
1322static void
1323save_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
1324{
1325   GET_CURRENT_CONTEXT(ctx);
1326   Node *n;
1327   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1328   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_PARAMETER_F, 3 );
1329   if (n) {
1330      n[1].e = target;
1331      n[2].e = pname;
1332      n[3].f = param;
1333   }
1334   if (ctx->ExecuteFlag) {
1335      (*ctx->Exec->ConvolutionParameterf)( target, pname, param );
1336   }
1337}
1338
1339
1340static void
1341save_ConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1342{
1343   GET_CURRENT_CONTEXT(ctx);
1344   Node *n;
1345   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1346   n = ALLOC_INSTRUCTION( ctx, OPCODE_CONVOLUTION_PARAMETER_FV, 6 );
1347   if (n) {
1348      n[1].e = target;
1349      n[2].e = pname;
1350      n[3].f = params[0];
1351      if (pname == GL_CONVOLUTION_BORDER_COLOR ||
1352          pname == GL_CONVOLUTION_FILTER_SCALE ||
1353          pname == GL_CONVOLUTION_FILTER_BIAS) {
1354         n[4].f = params[1];
1355         n[5].f = params[2];
1356         n[6].f = params[3];
1357      }
1358      else {
1359         n[4].f = n[5].f = n[6].f = 0.0F;
1360      }
1361   }
1362   if (ctx->ExecuteFlag) {
1363      (*ctx->Exec->ConvolutionParameterfv)( target, pname, params );
1364   }
1365}
1366
1367
1368static void
1369save_CopyPixels( GLint x, GLint y,
1370		 GLsizei width, GLsizei height, GLenum type )
1371{
1372   GET_CURRENT_CONTEXT(ctx);
1373   Node *n;
1374   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1375   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_PIXELS, 5 );
1376   if (n) {
1377      n[1].i = x;
1378      n[2].i = y;
1379      n[3].i = (GLint) width;
1380      n[4].i = (GLint) height;
1381      n[5].e = type;
1382   }
1383   if (ctx->ExecuteFlag) {
1384      (*ctx->Exec->CopyPixels)( x, y, width, height, type );
1385   }
1386}
1387
1388
1389
1390static void
1391save_CopyTexImage1D( GLenum target, GLint level, GLenum internalformat,
1392                     GLint x, GLint y, GLsizei width, GLint border )
1393{
1394   GET_CURRENT_CONTEXT(ctx);
1395   Node *n;
1396   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1397   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_TEX_IMAGE1D, 7 );
1398   if (n) {
1399      n[1].e = target;
1400      n[2].i = level;
1401      n[3].e = internalformat;
1402      n[4].i = x;
1403      n[5].i = y;
1404      n[6].i = width;
1405      n[7].i = border;
1406   }
1407   if (ctx->ExecuteFlag) {
1408      (*ctx->Exec->CopyTexImage1D)( target, level, internalformat,
1409                                   x, y, width, border );
1410   }
1411}
1412
1413
1414static void
1415save_CopyTexImage2D( GLenum target, GLint level,
1416                     GLenum internalformat,
1417                     GLint x, GLint y, GLsizei width,
1418                     GLsizei height, GLint border )
1419{
1420   GET_CURRENT_CONTEXT(ctx);
1421   Node *n;
1422   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1423   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_TEX_IMAGE2D, 8 );
1424   if (n) {
1425      n[1].e = target;
1426      n[2].i = level;
1427      n[3].e = internalformat;
1428      n[4].i = x;
1429      n[5].i = y;
1430      n[6].i = width;
1431      n[7].i = height;
1432      n[8].i = border;
1433   }
1434   if (ctx->ExecuteFlag) {
1435      (*ctx->Exec->CopyTexImage2D)( target, level, internalformat,
1436                                   x, y, width, height, border );
1437   }
1438}
1439
1440
1441
1442static void
1443save_CopyTexSubImage1D( GLenum target, GLint level,
1444                        GLint xoffset, GLint x, GLint y,
1445                        GLsizei width )
1446{
1447   GET_CURRENT_CONTEXT(ctx);
1448   Node *n;
1449   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1450   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_TEX_SUB_IMAGE1D, 6 );
1451   if (n) {
1452      n[1].e = target;
1453      n[2].i = level;
1454      n[3].i = xoffset;
1455      n[4].i = x;
1456      n[5].i = y;
1457      n[6].i = width;
1458   }
1459   if (ctx->ExecuteFlag) {
1460      (*ctx->Exec->CopyTexSubImage1D)( target, level, xoffset, x, y, width );
1461   }
1462}
1463
1464
1465static void
1466save_CopyTexSubImage2D( GLenum target, GLint level,
1467                        GLint xoffset, GLint yoffset,
1468                        GLint x, GLint y,
1469                        GLsizei width, GLint height )
1470{
1471   GET_CURRENT_CONTEXT(ctx);
1472   Node *n;
1473   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1474   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_TEX_SUB_IMAGE2D, 8 );
1475   if (n) {
1476      n[1].e = target;
1477      n[2].i = level;
1478      n[3].i = xoffset;
1479      n[4].i = yoffset;
1480      n[5].i = x;
1481      n[6].i = y;
1482      n[7].i = width;
1483      n[8].i = height;
1484   }
1485   if (ctx->ExecuteFlag) {
1486      (*ctx->Exec->CopyTexSubImage2D)( target, level, xoffset, yoffset,
1487                               x, y, width, height );
1488   }
1489}
1490
1491
1492static void
1493save_CopyTexSubImage3D( GLenum target, GLint level,
1494                        GLint xoffset, GLint yoffset, GLint zoffset,
1495                        GLint x, GLint y,
1496                        GLsizei width, GLint height )
1497{
1498   GET_CURRENT_CONTEXT(ctx);
1499   Node *n;
1500   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1501   n = ALLOC_INSTRUCTION( ctx, OPCODE_COPY_TEX_SUB_IMAGE3D, 9 );
1502   if (n) {
1503      n[1].e = target;
1504      n[2].i = level;
1505      n[3].i = xoffset;
1506      n[4].i = yoffset;
1507      n[5].i = zoffset;
1508      n[6].i = x;
1509      n[7].i = y;
1510      n[8].i = width;
1511      n[9].i = height;
1512   }
1513   if (ctx->ExecuteFlag) {
1514      (*ctx->Exec->CopyTexSubImage3D)( target, level,
1515                                      xoffset, yoffset, zoffset,
1516                                      x, y, width, height );
1517   }
1518}
1519
1520
1521static void save_CullFace( GLenum mode )
1522{
1523   GET_CURRENT_CONTEXT(ctx);
1524   Node *n;
1525   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1526   n = ALLOC_INSTRUCTION( ctx, OPCODE_CULL_FACE, 1 );
1527   if (n) {
1528      n[1].e = mode;
1529   }
1530   if (ctx->ExecuteFlag) {
1531      (*ctx->Exec->CullFace)( mode );
1532   }
1533}
1534
1535
1536static void save_DepthFunc( GLenum func )
1537{
1538   GET_CURRENT_CONTEXT(ctx);
1539   Node *n;
1540   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1541   n = ALLOC_INSTRUCTION( ctx, OPCODE_DEPTH_FUNC, 1 );
1542   if (n) {
1543      n[1].e = func;
1544   }
1545   if (ctx->ExecuteFlag) {
1546      (*ctx->Exec->DepthFunc)( func );
1547   }
1548}
1549
1550
1551static void save_DepthMask( GLboolean mask )
1552{
1553   GET_CURRENT_CONTEXT(ctx);
1554   Node *n;
1555   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1556   n = ALLOC_INSTRUCTION( ctx, OPCODE_DEPTH_MASK, 1 );
1557   if (n) {
1558      n[1].b = mask;
1559   }
1560   if (ctx->ExecuteFlag) {
1561      (*ctx->Exec->DepthMask)( mask );
1562   }
1563}
1564
1565
1566static void save_DepthRange( GLclampd nearval, GLclampd farval )
1567{
1568   GET_CURRENT_CONTEXT(ctx);
1569   Node *n;
1570   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1571   n = ALLOC_INSTRUCTION( ctx, OPCODE_DEPTH_RANGE, 2 );
1572   if (n) {
1573      n[1].f = (GLfloat) nearval;
1574      n[2].f = (GLfloat) farval;
1575   }
1576   if (ctx->ExecuteFlag) {
1577      (*ctx->Exec->DepthRange)( nearval, farval );
1578   }
1579}
1580
1581
1582static void save_Disable( GLenum cap )
1583{
1584   GET_CURRENT_CONTEXT(ctx);
1585   Node *n;
1586   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1587   n = ALLOC_INSTRUCTION( ctx, OPCODE_DISABLE, 1 );
1588   if (n) {
1589      n[1].e = cap;
1590   }
1591   if (ctx->ExecuteFlag) {
1592      (*ctx->Exec->Disable)( cap );
1593   }
1594}
1595
1596
1597static void save_DrawBuffer( GLenum mode )
1598{
1599   GET_CURRENT_CONTEXT(ctx);
1600   Node *n;
1601   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1602   n = ALLOC_INSTRUCTION( ctx, OPCODE_DRAW_BUFFER, 1 );
1603   if (n) {
1604      n[1].e = mode;
1605   }
1606   if (ctx->ExecuteFlag) {
1607      (*ctx->Exec->DrawBuffer)( mode );
1608   }
1609}
1610
1611
1612static void save_DrawPixels( GLsizei width, GLsizei height,
1613                             GLenum format, GLenum type,
1614                             const GLvoid *pixels )
1615{
1616   GET_CURRENT_CONTEXT(ctx);
1617   GLvoid *image = _mesa_unpack_image(width, height, 1, format, type,
1618                                      pixels, &ctx->Unpack);
1619   Node *n;
1620   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1621   n = ALLOC_INSTRUCTION( ctx, OPCODE_DRAW_PIXELS, 5 );
1622   if (n) {
1623      n[1].i = width;
1624      n[2].i = height;
1625      n[3].e = format;
1626      n[4].e = type;
1627      n[5].data = image;
1628   }
1629   else if (image) {
1630      FREE(image);
1631   }
1632   if (ctx->ExecuteFlag) {
1633      (*ctx->Exec->DrawPixels)( width, height, format, type, pixels );
1634   }
1635}
1636
1637
1638
1639static void save_Enable( GLenum cap )
1640{
1641   GET_CURRENT_CONTEXT(ctx);
1642   Node *n;
1643   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1644   n = ALLOC_INSTRUCTION( ctx, OPCODE_ENABLE, 1 );
1645   if (n) {
1646      n[1].e = cap;
1647   }
1648   if (ctx->ExecuteFlag) {
1649      (*ctx->Exec->Enable)( cap );
1650   }
1651}
1652
1653
1654
1655void _mesa_save_EvalMesh1( GLenum mode, GLint i1, GLint i2 )
1656{
1657   GET_CURRENT_CONTEXT(ctx);
1658   Node *n;
1659   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1660   n = ALLOC_INSTRUCTION( ctx, OPCODE_EVALMESH1, 3 );
1661   if (n) {
1662      n[1].e = mode;
1663      n[2].i = i1;
1664      n[3].i = i2;
1665   }
1666   if (ctx->ExecuteFlag) {
1667      (*ctx->Exec->EvalMesh1)( mode, i1, i2 );
1668   }
1669}
1670
1671
1672void _mesa_save_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
1673{
1674   GET_CURRENT_CONTEXT(ctx);
1675   Node *n;
1676   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1677   n = ALLOC_INSTRUCTION( ctx, OPCODE_EVALMESH2, 5 );
1678   if (n) {
1679      n[1].e = mode;
1680      n[2].i = i1;
1681      n[3].i = i2;
1682      n[4].i = j1;
1683      n[5].i = j2;
1684   }
1685   if (ctx->ExecuteFlag) {
1686      (*ctx->Exec->EvalMesh2)( mode, i1, i2, j1, j2 );
1687   }
1688}
1689
1690
1691
1692
1693static void save_Fogfv( GLenum pname, const GLfloat *params )
1694{
1695   GET_CURRENT_CONTEXT(ctx);
1696   Node *n;
1697   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1698   n = ALLOC_INSTRUCTION( ctx, OPCODE_FOG, 5 );
1699   if (n) {
1700      n[1].e = pname;
1701      n[2].f = params[0];
1702      n[3].f = params[1];
1703      n[4].f = params[2];
1704      n[5].f = params[3];
1705   }
1706   if (ctx->ExecuteFlag) {
1707      (*ctx->Exec->Fogfv)( pname, params );
1708   }
1709}
1710
1711
1712static void save_Fogf( GLenum pname, GLfloat param )
1713{
1714   save_Fogfv(pname, &param);
1715}
1716
1717
1718static void save_Fogiv(GLenum pname, const GLint *params )
1719{
1720   GLfloat p[4];
1721   switch (pname) {
1722      case GL_FOG_MODE:
1723      case GL_FOG_DENSITY:
1724      case GL_FOG_START:
1725      case GL_FOG_END:
1726      case GL_FOG_INDEX:
1727	 p[0] = (GLfloat) *params;
1728	 break;
1729      case GL_FOG_COLOR:
1730	 p[0] = INT_TO_FLOAT( params[0] );
1731	 p[1] = INT_TO_FLOAT( params[1] );
1732	 p[2] = INT_TO_FLOAT( params[2] );
1733	 p[3] = INT_TO_FLOAT( params[3] );
1734	 break;
1735      default:
1736         /* Error will be caught later in gl_Fogfv */
1737         ;
1738   }
1739   save_Fogfv(pname, p);
1740}
1741
1742
1743static void save_Fogi(GLenum pname, GLint param )
1744{
1745   save_Fogiv(pname, &param);
1746}
1747
1748
1749static void save_FrontFace( GLenum mode )
1750{
1751   GET_CURRENT_CONTEXT(ctx);
1752   Node *n;
1753   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1754   n = ALLOC_INSTRUCTION( ctx, OPCODE_FRONT_FACE, 1 );
1755   if (n) {
1756      n[1].e = mode;
1757   }
1758   if (ctx->ExecuteFlag) {
1759      (*ctx->Exec->FrontFace)( mode );
1760   }
1761}
1762
1763
1764static void save_Frustum( GLdouble left, GLdouble right,
1765                      GLdouble bottom, GLdouble top,
1766                      GLdouble nearval, GLdouble farval )
1767{
1768   GET_CURRENT_CONTEXT(ctx);
1769   Node *n;
1770   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1771   n = ALLOC_INSTRUCTION( ctx, OPCODE_FRUSTUM, 6 );
1772   if (n) {
1773      n[1].f = (GLfloat) left;
1774      n[2].f = (GLfloat) right;
1775      n[3].f = (GLfloat) bottom;
1776      n[4].f = (GLfloat) top;
1777      n[5].f = (GLfloat) nearval;
1778      n[6].f = (GLfloat) farval;
1779   }
1780   if (ctx->ExecuteFlag) {
1781      (*ctx->Exec->Frustum)( left, right, bottom, top, nearval, farval );
1782   }
1783}
1784
1785
1786static void save_Hint( GLenum target, GLenum mode )
1787{
1788   GET_CURRENT_CONTEXT(ctx);
1789   Node *n;
1790   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1791   n = ALLOC_INSTRUCTION( ctx, OPCODE_HINT, 2 );
1792   if (n) {
1793      n[1].e = target;
1794      n[2].e = mode;
1795   }
1796   if (ctx->ExecuteFlag) {
1797      (*ctx->Exec->Hint)( target, mode );
1798   }
1799}
1800
1801
1802static void
1803save_Histogram(GLenum target, GLsizei width, GLenum internalFormat, GLboolean sink)
1804{
1805   GET_CURRENT_CONTEXT(ctx);
1806   Node *n;
1807
1808   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1809   n = ALLOC_INSTRUCTION( ctx, OPCODE_HISTOGRAM, 4 );
1810   if (n) {
1811      n[1].e = target;
1812      n[2].i = width;
1813      n[3].e = internalFormat;
1814      n[4].b = sink;
1815   }
1816   if (ctx->ExecuteFlag) {
1817      (*ctx->Exec->Histogram)( target, width, internalFormat, sink );
1818   }
1819}
1820
1821
1822static void save_IndexMask( GLuint mask )
1823{
1824   GET_CURRENT_CONTEXT(ctx);
1825   Node *n;
1826   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1827   n = ALLOC_INSTRUCTION( ctx, OPCODE_INDEX_MASK, 1 );
1828   if (n) {
1829      n[1].ui = mask;
1830   }
1831   if (ctx->ExecuteFlag) {
1832      (*ctx->Exec->IndexMask)( mask );
1833   }
1834}
1835
1836
1837static void save_InitNames( void )
1838{
1839   GET_CURRENT_CONTEXT(ctx);
1840   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1841   (void) ALLOC_INSTRUCTION( ctx, OPCODE_INIT_NAMES, 0 );
1842   if (ctx->ExecuteFlag) {
1843      (*ctx->Exec->InitNames)();
1844   }
1845}
1846
1847
1848static void save_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
1849{
1850   GET_CURRENT_CONTEXT(ctx);
1851   Node *n;
1852   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1853   n = ALLOC_INSTRUCTION( ctx, OPCODE_LIGHT, 6 );
1854   if (OPCODE_LIGHT) {
1855      GLint i, nParams;
1856      n[1].e = light;
1857      n[2].e = pname;
1858      switch (pname) {
1859         case GL_AMBIENT:
1860            nParams = 4;
1861            break;
1862         case GL_DIFFUSE:
1863            nParams = 4;
1864            break;
1865         case GL_SPECULAR:
1866            nParams = 4;
1867            break;
1868         case GL_POSITION:
1869            nParams = 4;
1870            break;
1871         case GL_SPOT_DIRECTION:
1872            nParams = 3;
1873            break;
1874         case GL_SPOT_EXPONENT:
1875            nParams = 1;
1876            break;
1877         case GL_SPOT_CUTOFF:
1878            nParams = 1;
1879            break;
1880         case GL_CONSTANT_ATTENUATION:
1881            nParams = 1;
1882            break;
1883         case GL_LINEAR_ATTENUATION:
1884            nParams = 1;
1885            break;
1886         case GL_QUADRATIC_ATTENUATION:
1887            nParams = 1;
1888            break;
1889         default:
1890            nParams = 0;
1891      }
1892      for (i = 0; i < nParams; i++) {
1893	 n[3+i].f = params[i];
1894      }
1895   }
1896   if (ctx->ExecuteFlag) {
1897      (*ctx->Exec->Lightfv)( light, pname, params );
1898   }
1899}
1900
1901
1902static void save_Lightf( GLenum light, GLenum pname, GLfloat params )
1903{
1904   save_Lightfv(light, pname, &params);
1905}
1906
1907
1908static void save_Lightiv( GLenum light, GLenum pname, const GLint *params )
1909{
1910   GLfloat fparam[4];
1911   switch (pname) {
1912      case GL_AMBIENT:
1913      case GL_DIFFUSE:
1914      case GL_SPECULAR:
1915         fparam[0] = INT_TO_FLOAT( params[0] );
1916         fparam[1] = INT_TO_FLOAT( params[1] );
1917         fparam[2] = INT_TO_FLOAT( params[2] );
1918         fparam[3] = INT_TO_FLOAT( params[3] );
1919         break;
1920      case GL_POSITION:
1921         fparam[0] = (GLfloat) params[0];
1922         fparam[1] = (GLfloat) params[1];
1923         fparam[2] = (GLfloat) params[2];
1924         fparam[3] = (GLfloat) params[3];
1925         break;
1926      case GL_SPOT_DIRECTION:
1927         fparam[0] = (GLfloat) params[0];
1928         fparam[1] = (GLfloat) params[1];
1929         fparam[2] = (GLfloat) params[2];
1930         break;
1931      case GL_SPOT_EXPONENT:
1932      case GL_SPOT_CUTOFF:
1933      case GL_CONSTANT_ATTENUATION:
1934      case GL_LINEAR_ATTENUATION:
1935      case GL_QUADRATIC_ATTENUATION:
1936         fparam[0] = (GLfloat) params[0];
1937         break;
1938      default:
1939         /* error will be caught later in gl_Lightfv */
1940         ;
1941   }
1942   save_Lightfv( light, pname, fparam );
1943}
1944
1945
1946static void save_Lighti( GLenum light, GLenum pname, GLint param )
1947{
1948   save_Lightiv( light, pname, &param );
1949}
1950
1951
1952static void save_LightModelfv( GLenum pname, const GLfloat *params )
1953{
1954   GET_CURRENT_CONTEXT(ctx);
1955   Node *n;
1956   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1957   n = ALLOC_INSTRUCTION( ctx, OPCODE_LIGHT_MODEL, 5 );
1958   if (n) {
1959      n[1].e = pname;
1960      n[2].f = params[0];
1961      n[3].f = params[1];
1962      n[4].f = params[2];
1963      n[5].f = params[3];
1964   }
1965   if (ctx->ExecuteFlag) {
1966      (*ctx->Exec->LightModelfv)( pname, params );
1967   }
1968}
1969
1970
1971static void save_LightModelf( GLenum pname, GLfloat param )
1972{
1973   save_LightModelfv(pname, &param);
1974}
1975
1976
1977static void save_LightModeliv( GLenum pname, const GLint *params )
1978{
1979   GLfloat fparam[4];
1980   switch (pname) {
1981      case GL_LIGHT_MODEL_AMBIENT:
1982         fparam[0] = INT_TO_FLOAT( params[0] );
1983         fparam[1] = INT_TO_FLOAT( params[1] );
1984         fparam[2] = INT_TO_FLOAT( params[2] );
1985         fparam[3] = INT_TO_FLOAT( params[3] );
1986         break;
1987      case GL_LIGHT_MODEL_LOCAL_VIEWER:
1988      case GL_LIGHT_MODEL_TWO_SIDE:
1989      case GL_LIGHT_MODEL_COLOR_CONTROL:
1990         fparam[0] = (GLfloat) params[0];
1991         break;
1992      default:
1993         /* Error will be caught later in gl_LightModelfv */
1994         ;
1995   }
1996   save_LightModelfv(pname, fparam);
1997}
1998
1999
2000static void save_LightModeli( GLenum pname, GLint param )
2001{
2002   save_LightModeliv(pname, &param);
2003}
2004
2005
2006static void save_LineStipple( GLint factor, GLushort pattern )
2007{
2008   GET_CURRENT_CONTEXT(ctx);
2009   Node *n;
2010   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2011   n = ALLOC_INSTRUCTION( ctx, OPCODE_LINE_STIPPLE, 2 );
2012   if (n) {
2013      n[1].i = factor;
2014      n[2].us = pattern;
2015   }
2016   if (ctx->ExecuteFlag) {
2017      (*ctx->Exec->LineStipple)( factor, pattern );
2018   }
2019}
2020
2021
2022static void save_LineWidth( GLfloat width )
2023{
2024   GET_CURRENT_CONTEXT(ctx);
2025   Node *n;
2026   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2027   n = ALLOC_INSTRUCTION( ctx, OPCODE_LINE_WIDTH, 1 );
2028   if (n) {
2029      n[1].f = width;
2030   }
2031   if (ctx->ExecuteFlag) {
2032      (*ctx->Exec->LineWidth)( width );
2033   }
2034}
2035
2036
2037static void save_ListBase( GLuint base )
2038{
2039   GET_CURRENT_CONTEXT(ctx);
2040   Node *n;
2041   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2042   n = ALLOC_INSTRUCTION( ctx, OPCODE_LIST_BASE, 1 );
2043   if (n) {
2044      n[1].ui = base;
2045   }
2046   if (ctx->ExecuteFlag) {
2047      (*ctx->Exec->ListBase)( base );
2048   }
2049}
2050
2051
2052static void save_LoadIdentity( void )
2053{
2054   GET_CURRENT_CONTEXT(ctx);
2055   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2056   (void) ALLOC_INSTRUCTION( ctx, OPCODE_LOAD_IDENTITY, 0 );
2057   if (ctx->ExecuteFlag) {
2058      (*ctx->Exec->LoadIdentity)();
2059   }
2060}
2061
2062
2063static void save_LoadMatrixf( const GLfloat *m )
2064{
2065   GET_CURRENT_CONTEXT(ctx);
2066   Node *n;
2067   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2068   n = ALLOC_INSTRUCTION( ctx, OPCODE_LOAD_MATRIX, 16 );
2069   if (n) {
2070      GLuint i;
2071      for (i=0;i<16;i++) {
2072	 n[1+i].f = m[i];
2073      }
2074   }
2075   if (ctx->ExecuteFlag) {
2076      (*ctx->Exec->LoadMatrixf)( m );
2077   }
2078}
2079
2080
2081static void save_LoadMatrixd( const GLdouble *m )
2082{
2083   GLfloat f[16];
2084   GLint i;
2085   for (i = 0; i < 16; i++) {
2086      f[i] = (GLfloat) m[i];
2087   }
2088   save_LoadMatrixf(f);
2089}
2090
2091
2092static void save_LoadName( GLuint name )
2093{
2094   GET_CURRENT_CONTEXT(ctx);
2095   Node *n;
2096   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2097   n = ALLOC_INSTRUCTION( ctx, OPCODE_LOAD_NAME, 1 );
2098   if (n) {
2099      n[1].ui = name;
2100   }
2101   if (ctx->ExecuteFlag) {
2102      (*ctx->Exec->LoadName)( name );
2103   }
2104}
2105
2106
2107static void save_LogicOp( GLenum opcode )
2108{
2109   GET_CURRENT_CONTEXT(ctx);
2110   Node *n;
2111   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2112   n = ALLOC_INSTRUCTION( ctx, OPCODE_LOGIC_OP, 1 );
2113   if (n) {
2114      n[1].e = opcode;
2115   }
2116   if (ctx->ExecuteFlag) {
2117      (*ctx->Exec->LogicOp)( opcode );
2118   }
2119}
2120
2121
2122static void save_Map1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
2123                        GLint order, const GLdouble *points)
2124{
2125   GET_CURRENT_CONTEXT(ctx);
2126   Node *n;
2127   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2128   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAP1, 6 );
2129   if (n) {
2130      GLfloat *pnts = _mesa_copy_map_points1d( target, stride, order, points );
2131      n[1].e = target;
2132      n[2].f = (GLfloat) u1;
2133      n[3].f = (GLfloat) u2;
2134      n[4].i = _mesa_evaluator_components(target);  /* stride */
2135      n[5].i = order;
2136      n[6].data = (void *) pnts;
2137   }
2138   if (ctx->ExecuteFlag) {
2139      (*ctx->Exec->Map1d)( target, u1, u2, stride, order, points );
2140   }
2141}
2142
2143static void save_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
2144                        GLint order, const GLfloat *points)
2145{
2146   GET_CURRENT_CONTEXT(ctx);
2147   Node *n;
2148   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2149   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAP1, 6 );
2150   if (n) {
2151      GLfloat *pnts = _mesa_copy_map_points1f( target, stride, order, points );
2152      n[1].e = target;
2153      n[2].f = u1;
2154      n[3].f = u2;
2155      n[4].i = _mesa_evaluator_components(target);  /* stride */
2156      n[5].i = order;
2157      n[6].data = (void *) pnts;
2158   }
2159   if (ctx->ExecuteFlag) {
2160      (*ctx->Exec->Map1f)( target, u1, u2, stride, order, points );
2161   }
2162}
2163
2164
2165static void save_Map2d( GLenum target,
2166                        GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
2167                        GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
2168                        const GLdouble *points )
2169{
2170   GET_CURRENT_CONTEXT(ctx);
2171   Node *n;
2172   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2173   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAP2, 10 );
2174   if (n) {
2175      GLfloat *pnts = _mesa_copy_map_points2d( target, ustride, uorder,
2176                                            vstride, vorder, points );
2177      n[1].e = target;
2178      n[2].f = (GLfloat) u1;
2179      n[3].f = (GLfloat) u2;
2180      n[4].f = (GLfloat) v1;
2181      n[5].f = (GLfloat) v2;
2182      /* XXX verify these strides are correct */
2183      n[6].i = _mesa_evaluator_components(target) * vorder;  /*ustride*/
2184      n[7].i = _mesa_evaluator_components(target);           /*vstride*/
2185      n[8].i = uorder;
2186      n[9].i = vorder;
2187      n[10].data = (void *) pnts;
2188   }
2189   if (ctx->ExecuteFlag) {
2190      (*ctx->Exec->Map2d)( target,
2191                          u1, u2, ustride, uorder,
2192                          v1, v2, vstride, vorder, points );
2193   }
2194}
2195
2196
2197static void save_Map2f( GLenum target,
2198                        GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
2199                        GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
2200                        const GLfloat *points )
2201{
2202   GET_CURRENT_CONTEXT(ctx);
2203   Node *n;
2204   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2205   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAP2, 10 );
2206   if (n) {
2207      GLfloat *pnts = _mesa_copy_map_points2f( target, ustride, uorder,
2208                                            vstride, vorder, points );
2209      n[1].e = target;
2210      n[2].f = u1;
2211      n[3].f = u2;
2212      n[4].f = v1;
2213      n[5].f = v2;
2214      /* XXX verify these strides are correct */
2215      n[6].i = _mesa_evaluator_components(target) * vorder;  /*ustride*/
2216      n[7].i = _mesa_evaluator_components(target);           /*vstride*/
2217      n[8].i = uorder;
2218      n[9].i = vorder;
2219      n[10].data = (void *) pnts;
2220   }
2221   if (ctx->ExecuteFlag) {
2222      (*ctx->Exec->Map2f)( target, u1, u2, ustride, uorder,
2223                          v1, v2, vstride, vorder, points );
2224   }
2225}
2226
2227
2228static void save_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
2229{
2230   GET_CURRENT_CONTEXT(ctx);
2231   Node *n;
2232   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2233   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAPGRID1, 3 );
2234   if (n) {
2235      n[1].i = un;
2236      n[2].f = u1;
2237      n[3].f = u2;
2238   }
2239   if (ctx->ExecuteFlag) {
2240      (*ctx->Exec->MapGrid1f)( un, u1, u2 );
2241   }
2242}
2243
2244
2245static void save_MapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
2246{
2247   save_MapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
2248}
2249
2250
2251static void save_MapGrid2f( GLint un, GLfloat u1, GLfloat u2,
2252                            GLint vn, GLfloat v1, GLfloat v2 )
2253{
2254   GET_CURRENT_CONTEXT(ctx);
2255   Node *n;
2256   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2257   n = ALLOC_INSTRUCTION( ctx, OPCODE_MAPGRID2, 6 );
2258   if (n) {
2259      n[1].i = un;
2260      n[2].f = u1;
2261      n[3].f = u2;
2262      n[4].i = vn;
2263      n[5].f = v1;
2264      n[6].f = v2;
2265   }
2266   if (ctx->ExecuteFlag) {
2267      (*ctx->Exec->MapGrid2f)( un, u1, u2, vn, v1, v2 );
2268   }
2269}
2270
2271
2272
2273static void save_MapGrid2d( GLint un, GLdouble u1, GLdouble u2,
2274                            GLint vn, GLdouble v1, GLdouble v2 )
2275{
2276   save_MapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
2277		  vn, (GLfloat) v1, (GLfloat) v2);
2278}
2279
2280
2281static void save_MatrixMode( GLenum mode )
2282{
2283   GET_CURRENT_CONTEXT(ctx);
2284   Node *n;
2285   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2286   n = ALLOC_INSTRUCTION( ctx, OPCODE_MATRIX_MODE, 1 );
2287   if (n) {
2288      n[1].e = mode;
2289   }
2290   if (ctx->ExecuteFlag) {
2291      (*ctx->Exec->MatrixMode)( mode );
2292   }
2293}
2294
2295
2296static void
2297save_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
2298{
2299   GET_CURRENT_CONTEXT(ctx);
2300   Node *n;
2301
2302   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2303   n = ALLOC_INSTRUCTION( ctx, OPCODE_MIN_MAX, 3 );
2304   if (n) {
2305      n[1].e = target;
2306      n[2].e = internalFormat;
2307      n[3].b = sink;
2308   }
2309   if (ctx->ExecuteFlag) {
2310      (*ctx->Exec->Minmax)( target, internalFormat, sink );
2311   }
2312}
2313
2314
2315static void save_MultMatrixf( const GLfloat *m )
2316{
2317   GET_CURRENT_CONTEXT(ctx);
2318   Node *n;
2319   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2320   n = ALLOC_INSTRUCTION( ctx, OPCODE_MULT_MATRIX, 16 );
2321   if (n) {
2322      GLuint i;
2323      for (i=0;i<16;i++) {
2324	 n[1+i].f = m[i];
2325      }
2326   }
2327   if (ctx->ExecuteFlag) {
2328      (*ctx->Exec->MultMatrixf)( m );
2329   }
2330}
2331
2332
2333static void save_MultMatrixd( const GLdouble *m )
2334{
2335   GLfloat f[16];
2336   GLint i;
2337   for (i = 0; i < 16; i++) {
2338      f[i] = (GLfloat) m[i];
2339   }
2340   save_MultMatrixf(f);
2341}
2342
2343
2344static void save_NewList( GLuint list, GLenum mode )
2345{
2346   GET_CURRENT_CONTEXT(ctx);
2347   /* It's an error to call this function while building a display list */
2348   _mesa_error( ctx, GL_INVALID_OPERATION, "glNewList" );
2349   (void) list;
2350   (void) mode;
2351}
2352
2353
2354
2355static void save_Ortho( GLdouble left, GLdouble right,
2356                    GLdouble bottom, GLdouble top,
2357                    GLdouble nearval, GLdouble farval )
2358{
2359   GET_CURRENT_CONTEXT(ctx);
2360   Node *n;
2361   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2362   n = ALLOC_INSTRUCTION( ctx, OPCODE_ORTHO, 6 );
2363   if (n) {
2364      n[1].f = (GLfloat) left;
2365      n[2].f = (GLfloat) right;
2366      n[3].f = (GLfloat) bottom;
2367      n[4].f = (GLfloat) top;
2368      n[5].f = (GLfloat) nearval;
2369      n[6].f = (GLfloat) farval;
2370   }
2371   if (ctx->ExecuteFlag) {
2372      (*ctx->Exec->Ortho)( left, right, bottom, top, nearval, farval );
2373   }
2374}
2375
2376
2377static void
2378save_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
2379{
2380   GET_CURRENT_CONTEXT(ctx);
2381   Node *n;
2382   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2383   n = ALLOC_INSTRUCTION( ctx, OPCODE_PIXEL_MAP, 3 );
2384   if (n) {
2385      n[1].e = map;
2386      n[2].i = mapsize;
2387      n[3].data  = (void *) MALLOC( mapsize * sizeof(GLfloat) );
2388      MEMCPY( n[3].data, (void *) values, mapsize * sizeof(GLfloat) );
2389   }
2390   if (ctx->ExecuteFlag) {
2391      (*ctx->Exec->PixelMapfv)( map, mapsize, values );
2392   }
2393}
2394
2395
2396static void
2397save_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
2398{
2399   GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
2400   GLint i;
2401   if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
2402      for (i=0;i<mapsize;i++) {
2403         fvalues[i] = (GLfloat) values[i];
2404      }
2405   }
2406   else {
2407      for (i=0;i<mapsize;i++) {
2408         fvalues[i] = UINT_TO_FLOAT( values[i] );
2409      }
2410   }
2411   save_PixelMapfv(map, mapsize, fvalues);
2412}
2413
2414
2415static void
2416save_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
2417{
2418   GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
2419   GLint i;
2420   if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
2421      for (i=0;i<mapsize;i++) {
2422         fvalues[i] = (GLfloat) values[i];
2423      }
2424   }
2425   else {
2426      for (i=0;i<mapsize;i++) {
2427         fvalues[i] = USHORT_TO_FLOAT( values[i] );
2428      }
2429   }
2430   save_PixelMapfv(map, mapsize, fvalues);
2431}
2432
2433
2434static void
2435save_PixelTransferf( GLenum pname, GLfloat param )
2436{
2437   GET_CURRENT_CONTEXT(ctx);
2438   Node *n;
2439   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2440   n = ALLOC_INSTRUCTION( ctx, OPCODE_PIXEL_TRANSFER, 2 );
2441   if (n) {
2442      n[1].e = pname;
2443      n[2].f = param;
2444   }
2445   if (ctx->ExecuteFlag) {
2446      (*ctx->Exec->PixelTransferf)( pname, param );
2447   }
2448}
2449
2450
2451static void
2452save_PixelTransferi( GLenum pname, GLint param )
2453{
2454   save_PixelTransferf( pname, (GLfloat) param );
2455}
2456
2457
2458static void
2459save_PixelZoom( GLfloat xfactor, GLfloat yfactor )
2460{
2461   GET_CURRENT_CONTEXT(ctx);
2462   Node *n;
2463   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2464   n = ALLOC_INSTRUCTION( ctx, OPCODE_PIXEL_ZOOM, 2 );
2465   if (n) {
2466      n[1].f = xfactor;
2467      n[2].f = yfactor;
2468   }
2469   if (ctx->ExecuteFlag) {
2470      (*ctx->Exec->PixelZoom)( xfactor, yfactor );
2471   }
2472}
2473
2474
2475static void
2476save_PointParameterfvEXT( GLenum pname, const GLfloat *params )
2477{
2478   GET_CURRENT_CONTEXT(ctx);
2479   Node *n;
2480   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2481   n = ALLOC_INSTRUCTION( ctx, OPCODE_POINT_PARAMETERS, 4 );
2482   if (n) {
2483      n[1].e = pname;
2484      n[2].f = params[0];
2485      n[3].f = params[1];
2486      n[4].f = params[2];
2487   }
2488   if (ctx->ExecuteFlag) {
2489      (*ctx->Exec->PointParameterfvEXT)( pname, params );
2490   }
2491}
2492
2493
2494static void save_PointParameterfEXT( GLenum pname, GLfloat param )
2495{
2496   save_PointParameterfvEXT(pname, &param);
2497}
2498
2499
2500static void save_PointSize( GLfloat size )
2501{
2502   GET_CURRENT_CONTEXT(ctx);
2503   Node *n;
2504   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2505   n = ALLOC_INSTRUCTION( ctx, OPCODE_POINT_SIZE, 1 );
2506   if (n) {
2507      n[1].f = size;
2508   }
2509   if (ctx->ExecuteFlag) {
2510      (*ctx->Exec->PointSize)( size );
2511   }
2512}
2513
2514
2515static void save_PolygonMode( GLenum face, GLenum mode )
2516{
2517   GET_CURRENT_CONTEXT(ctx);
2518   Node *n;
2519   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2520   n = ALLOC_INSTRUCTION( ctx, OPCODE_POLYGON_MODE, 2 );
2521   if (n) {
2522      n[1].e = face;
2523      n[2].e = mode;
2524   }
2525   if (ctx->ExecuteFlag) {
2526      (*ctx->Exec->PolygonMode)( face, mode );
2527   }
2528}
2529
2530
2531/*
2532 * Polygon stipple must have been upacked already!
2533 */
2534static void save_PolygonStipple( const GLubyte *pattern )
2535{
2536   GET_CURRENT_CONTEXT(ctx);
2537   Node *n;
2538   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2539   n = ALLOC_INSTRUCTION( ctx, OPCODE_POLYGON_STIPPLE, 1 );
2540   if (n) {
2541      void *data;
2542      n[1].data = MALLOC( 32 * 4 );
2543      data = n[1].data;   /* This needed for Acorn compiler */
2544      MEMCPY( data, pattern, 32 * 4 );
2545   }
2546   if (ctx->ExecuteFlag) {
2547      (*ctx->Exec->PolygonStipple)( (GLubyte*) pattern );
2548   }
2549}
2550
2551
2552static void save_PolygonOffset( GLfloat factor, GLfloat units )
2553{
2554   GET_CURRENT_CONTEXT(ctx);
2555   Node *n;
2556   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2557   n = ALLOC_INSTRUCTION( ctx, OPCODE_POLYGON_OFFSET, 2 );
2558   if (n) {
2559      n[1].f = factor;
2560      n[2].f = units;
2561   }
2562   if (ctx->ExecuteFlag) {
2563      (*ctx->Exec->PolygonOffset)( factor, units );
2564   }
2565}
2566
2567
2568static void save_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
2569{
2570   GET_CURRENT_CONTEXT(ctx);
2571   save_PolygonOffset(factor, ctx->DepthMaxF * bias);
2572}
2573
2574
2575static void save_PopAttrib( void )
2576{
2577   GET_CURRENT_CONTEXT(ctx);
2578   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2579   (void) ALLOC_INSTRUCTION( ctx, OPCODE_POP_ATTRIB, 0 );
2580   if (ctx->ExecuteFlag) {
2581      (*ctx->Exec->PopAttrib)();
2582   }
2583}
2584
2585
2586static void save_PopMatrix( void )
2587{
2588   GET_CURRENT_CONTEXT(ctx);
2589   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2590   FLUSH_CURRENT(ctx, 0);
2591   (void) ALLOC_INSTRUCTION( ctx, OPCODE_POP_MATRIX, 0 );
2592   if (ctx->ExecuteFlag) {
2593      (*ctx->Exec->PopMatrix)();
2594   }
2595}
2596
2597
2598static void save_PopName( void )
2599{
2600   GET_CURRENT_CONTEXT(ctx);
2601   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2602   (void) ALLOC_INSTRUCTION( ctx, OPCODE_POP_NAME, 0 );
2603   if (ctx->ExecuteFlag) {
2604      (*ctx->Exec->PopName)();
2605   }
2606}
2607
2608
2609static void save_PrioritizeTextures( GLsizei num, const GLuint *textures,
2610                                     const GLclampf *priorities )
2611{
2612   GET_CURRENT_CONTEXT(ctx);
2613   GLint i;
2614   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2615
2616   for (i=0;i<num;i++) {
2617      Node *n;
2618      n = ALLOC_INSTRUCTION( ctx,  OPCODE_PRIORITIZE_TEXTURE, 2 );
2619      if (n) {
2620         n[1].ui = textures[i];
2621         n[2].f = priorities[i];
2622      }
2623   }
2624   if (ctx->ExecuteFlag) {
2625      (*ctx->Exec->PrioritizeTextures)( num, textures, priorities );
2626   }
2627}
2628
2629
2630static void save_PushAttrib( GLbitfield mask )
2631{
2632   GET_CURRENT_CONTEXT(ctx);
2633   Node *n;
2634   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2635   FLUSH_CURRENT(ctx, 0);
2636   n = ALLOC_INSTRUCTION( ctx, OPCODE_PUSH_ATTRIB, 1 );
2637   if (n) {
2638      n[1].bf = mask;
2639   }
2640   if (ctx->ExecuteFlag) {
2641      (*ctx->Exec->PushAttrib)( mask );
2642   }
2643}
2644
2645
2646static void save_PushMatrix( void )
2647{
2648   GET_CURRENT_CONTEXT(ctx);
2649   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2650   (void) ALLOC_INSTRUCTION( ctx, OPCODE_PUSH_MATRIX, 0 );
2651   if (ctx->ExecuteFlag) {
2652      (*ctx->Exec->PushMatrix)();
2653   }
2654}
2655
2656
2657static void save_PushName( GLuint name )
2658{
2659   GET_CURRENT_CONTEXT(ctx);
2660   Node *n;
2661   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2662   n = ALLOC_INSTRUCTION( ctx, OPCODE_PUSH_NAME, 1 );
2663   if (n) {
2664      n[1].ui = name;
2665   }
2666   if (ctx->ExecuteFlag) {
2667      (*ctx->Exec->PushName)( name );
2668   }
2669}
2670
2671
2672static void save_RasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
2673{
2674   GET_CURRENT_CONTEXT(ctx);
2675   Node *n;
2676   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2677   FLUSH_CURRENT(ctx, 0);
2678   n = ALLOC_INSTRUCTION( ctx, OPCODE_RASTER_POS, 4 );
2679   if (n) {
2680      n[1].f = x;
2681      n[2].f = y;
2682      n[3].f = z;
2683      n[4].f = w;
2684   }
2685   if (ctx->ExecuteFlag) {
2686      (*ctx->Exec->RasterPos4f)( x, y, z, w );
2687   }
2688}
2689
2690static void save_RasterPos2d(GLdouble x, GLdouble y)
2691{
2692   save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
2693}
2694
2695static void save_RasterPos2f(GLfloat x, GLfloat y)
2696{
2697   save_RasterPos4f(x, y, 0.0F, 1.0F);
2698}
2699
2700static void save_RasterPos2i(GLint x, GLint y)
2701{
2702   save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
2703}
2704
2705static void save_RasterPos2s(GLshort x, GLshort y)
2706{
2707   save_RasterPos4f(x, y, 0.0F, 1.0F);
2708}
2709
2710static void save_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
2711{
2712   save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
2713}
2714
2715static void save_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
2716{
2717   save_RasterPos4f(x, y, z, 1.0F);
2718}
2719
2720static void save_RasterPos3i(GLint x, GLint y, GLint z)
2721{
2722   save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
2723}
2724
2725static void save_RasterPos3s(GLshort x, GLshort y, GLshort z)
2726{
2727   save_RasterPos4f(x, y, z, 1.0F);
2728}
2729
2730static void save_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
2731{
2732   save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
2733}
2734
2735static void save_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
2736{
2737   save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
2738}
2739
2740static void save_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
2741{
2742   save_RasterPos4f(x, y, z, w);
2743}
2744
2745static void save_RasterPos2dv(const GLdouble *v)
2746{
2747   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
2748}
2749
2750static void save_RasterPos2fv(const GLfloat *v)
2751{
2752   save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
2753}
2754
2755static void save_RasterPos2iv(const GLint *v)
2756{
2757   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
2758}
2759
2760static void save_RasterPos2sv(const GLshort *v)
2761{
2762   save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
2763}
2764
2765static void save_RasterPos3dv(const GLdouble *v)
2766{
2767   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
2768}
2769
2770static void save_RasterPos3fv(const GLfloat *v)
2771{
2772   save_RasterPos4f(v[0], v[1], v[2], 1.0F);
2773}
2774
2775static void save_RasterPos3iv(const GLint *v)
2776{
2777   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
2778}
2779
2780static void save_RasterPos3sv(const GLshort *v)
2781{
2782   save_RasterPos4f(v[0], v[1], v[2], 1.0F);
2783}
2784
2785static void save_RasterPos4dv(const GLdouble *v)
2786{
2787   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
2788		    (GLfloat) v[2], (GLfloat) v[3]);
2789}
2790
2791static void save_RasterPos4fv(const GLfloat *v)
2792{
2793   save_RasterPos4f(v[0], v[1], v[2], v[3]);
2794}
2795
2796static void save_RasterPos4iv(const GLint *v)
2797{
2798   save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
2799		    (GLfloat) v[2], (GLfloat) v[3]);
2800}
2801
2802static void save_RasterPos4sv(const GLshort *v)
2803{
2804   save_RasterPos4f(v[0], v[1], v[2], v[3]);
2805}
2806
2807
2808static void save_PassThrough( GLfloat token )
2809{
2810   GET_CURRENT_CONTEXT(ctx);
2811   Node *n;
2812   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2813   n = ALLOC_INSTRUCTION( ctx, OPCODE_PASSTHROUGH, 1 );
2814   if (n) {
2815      n[1].f = token;
2816   }
2817   if (ctx->ExecuteFlag) {
2818      (*ctx->Exec->PassThrough)( token );
2819   }
2820}
2821
2822
2823static void save_ReadBuffer( GLenum mode )
2824{
2825   GET_CURRENT_CONTEXT(ctx);
2826   Node *n;
2827   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2828   n = ALLOC_INSTRUCTION( ctx, OPCODE_READ_BUFFER, 1 );
2829   if (n) {
2830      n[1].e = mode;
2831   }
2832   if (ctx->ExecuteFlag) {
2833      (*ctx->Exec->ReadBuffer)( mode );
2834   }
2835}
2836
2837
2838static void
2839save_ResetHistogram(GLenum target)
2840{
2841   GET_CURRENT_CONTEXT(ctx);
2842   Node *n;
2843   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2844   n = ALLOC_INSTRUCTION( ctx, OPCODE_RESET_HISTOGRAM, 1 );
2845   if (n) {
2846      n[1].e = target;
2847   }
2848   if (ctx->ExecuteFlag) {
2849      (*ctx->Exec->ResetHistogram)( target );
2850   }
2851}
2852
2853
2854static void
2855save_ResetMinmax(GLenum target)
2856{
2857   GET_CURRENT_CONTEXT(ctx);
2858   Node *n;
2859   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2860   n = ALLOC_INSTRUCTION( ctx, OPCODE_RESET_MIN_MAX, 1 );
2861   if (n) {
2862      n[1].e = target;
2863   }
2864   if (ctx->ExecuteFlag) {
2865      (*ctx->Exec->ResetMinmax)( target );
2866   }
2867}
2868
2869
2870static void save_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
2871{
2872   GET_CURRENT_CONTEXT(ctx);
2873   Node *n;
2874   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2875   n = ALLOC_INSTRUCTION( ctx, OPCODE_ROTATE, 4 );
2876   if (n) {
2877      n[1].f = angle;
2878      n[2].f = x;
2879      n[3].f = y;
2880      n[4].f = z;
2881   }
2882   if (ctx->ExecuteFlag) {
2883      (*ctx->Exec->Rotatef)( angle, x, y, z );
2884   }
2885}
2886
2887
2888static void save_Rotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z )
2889{
2890   save_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
2891}
2892
2893
2894static void save_Scalef( GLfloat x, GLfloat y, GLfloat z )
2895{
2896   GET_CURRENT_CONTEXT(ctx);
2897   Node *n;
2898   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2899   n = ALLOC_INSTRUCTION( ctx, OPCODE_SCALE, 3 );
2900   if (n) {
2901      n[1].f = x;
2902      n[2].f = y;
2903      n[3].f = z;
2904   }
2905   if (ctx->ExecuteFlag) {
2906      (*ctx->Exec->Scalef)( x, y, z );
2907   }
2908}
2909
2910
2911static void save_Scaled( GLdouble x, GLdouble y, GLdouble z )
2912{
2913   save_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
2914}
2915
2916
2917static void save_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
2918{
2919   GET_CURRENT_CONTEXT(ctx);
2920   Node *n;
2921   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2922   n = ALLOC_INSTRUCTION( ctx, OPCODE_SCISSOR, 4 );
2923   if (n) {
2924      n[1].i = x;
2925      n[2].i = y;
2926      n[3].i = width;
2927      n[4].i = height;
2928   }
2929   if (ctx->ExecuteFlag) {
2930      (*ctx->Exec->Scissor)( x, y, width, height );
2931   }
2932}
2933
2934
2935static void save_ShadeModel( GLenum mode )
2936{
2937   GET_CURRENT_CONTEXT(ctx);
2938   Node *n;
2939   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2940   n = ALLOC_INSTRUCTION( ctx, OPCODE_SHADE_MODEL, 1 );
2941   if (n) {
2942      n[1].e = mode;
2943   }
2944   if (ctx->ExecuteFlag) {
2945      (*ctx->Exec->ShadeModel)( mode );
2946   }
2947}
2948
2949
2950static void save_StencilFunc( GLenum func, GLint ref, GLuint mask )
2951{
2952   GET_CURRENT_CONTEXT(ctx);
2953   Node *n;
2954   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2955   n = ALLOC_INSTRUCTION( ctx, OPCODE_STENCIL_FUNC, 3 );
2956   if (n) {
2957      n[1].e = func;
2958      n[2].i = ref;
2959      n[3].ui = mask;
2960   }
2961   if (ctx->ExecuteFlag) {
2962      (*ctx->Exec->StencilFunc)( func, ref, mask );
2963   }
2964}
2965
2966
2967static void save_StencilMask( GLuint mask )
2968{
2969   GET_CURRENT_CONTEXT(ctx);
2970   Node *n;
2971   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2972   n = ALLOC_INSTRUCTION( ctx, OPCODE_STENCIL_MASK, 1 );
2973   if (n) {
2974      n[1].ui = mask;
2975   }
2976   if (ctx->ExecuteFlag) {
2977      (*ctx->Exec->StencilMask)( mask );
2978   }
2979}
2980
2981
2982static void save_StencilOp( GLenum fail, GLenum zfail, GLenum zpass )
2983{
2984   GET_CURRENT_CONTEXT(ctx);
2985   Node *n;
2986   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2987   n = ALLOC_INSTRUCTION( ctx, OPCODE_STENCIL_OP, 3 );
2988   if (n) {
2989      n[1].e = fail;
2990      n[2].e = zfail;
2991      n[3].e = zpass;
2992   }
2993   if (ctx->ExecuteFlag) {
2994      (*ctx->Exec->StencilOp)( fail, zfail, zpass );
2995   }
2996}
2997
2998
2999static void save_TexEnvfv( GLenum target, GLenum pname, const GLfloat *params )
3000{
3001   GET_CURRENT_CONTEXT(ctx);
3002   Node *n;
3003   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3004   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEXENV, 6 );
3005   if (n) {
3006      n[1].e = target;
3007      n[2].e = pname;
3008      n[3].f = params[0];
3009      n[4].f = params[1];
3010      n[5].f = params[2];
3011      n[6].f = params[3];
3012   }
3013   if (ctx->ExecuteFlag) {
3014      (*ctx->Exec->TexEnvfv)( target, pname, params );
3015   }
3016}
3017
3018
3019static void save_TexEnvf( GLenum target, GLenum pname, GLfloat param )
3020{
3021   save_TexEnvfv( target, pname, &param );
3022}
3023
3024
3025static void save_TexEnvi( GLenum target, GLenum pname, GLint param )
3026{
3027   GLfloat p[4];
3028   p[0] = (GLfloat) param;
3029   p[1] = p[2] = p[3] = 0.0;
3030   save_TexEnvfv( target, pname, p );
3031}
3032
3033
3034static void save_TexEnviv( GLenum target, GLenum pname, const GLint *param )
3035{
3036   GLfloat p[4];
3037   p[0] = INT_TO_FLOAT( param[0] );
3038   p[1] = INT_TO_FLOAT( param[1] );
3039   p[2] = INT_TO_FLOAT( param[2] );
3040   p[3] = INT_TO_FLOAT( param[3] );
3041   save_TexEnvfv( target, pname, p );
3042}
3043
3044
3045static void save_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
3046{
3047   GET_CURRENT_CONTEXT(ctx);
3048   Node *n;
3049   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3050   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEXGEN, 6 );
3051   if (n) {
3052      n[1].e = coord;
3053      n[2].e = pname;
3054      n[3].f = params[0];
3055      n[4].f = params[1];
3056      n[5].f = params[2];
3057      n[6].f = params[3];
3058   }
3059   if (ctx->ExecuteFlag) {
3060      (*ctx->Exec->TexGenfv)( coord, pname, params );
3061   }
3062}
3063
3064
3065static void save_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
3066{
3067   GLfloat p[4];
3068   p[0] = (GLfloat) params[0];
3069   p[1] = (GLfloat) params[1];
3070   p[2] = (GLfloat) params[2];
3071   p[3] = (GLfloat) params[3];
3072   save_TexGenfv(coord, pname, p);
3073}
3074
3075
3076static void save_TexGend(GLenum coord, GLenum pname, GLdouble param )
3077{
3078   GLfloat p = (GLfloat) param;
3079   save_TexGenfv( coord, pname, &p );
3080}
3081
3082
3083static void save_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
3084{
3085   GLfloat p[4];
3086   p[0] = (GLfloat) params[0];
3087   p[1] = (GLfloat) params[1];
3088   p[2] = (GLfloat) params[2];
3089   p[3] = (GLfloat) params[3];
3090   save_TexGenfv( coord, pname, p );
3091}
3092
3093
3094static void save_TexGenf( GLenum coord, GLenum pname, GLfloat param )
3095{
3096   save_TexGenfv(coord, pname, &param);
3097}
3098
3099
3100static void save_TexGeni( GLenum coord, GLenum pname, GLint param )
3101{
3102   save_TexGeniv( coord, pname, &param );
3103}
3104
3105
3106static void save_TexParameterfv( GLenum target,
3107                             GLenum pname, const GLfloat *params )
3108{
3109   GET_CURRENT_CONTEXT(ctx);
3110   Node *n;
3111   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3112   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEXPARAMETER, 6 );
3113   if (n) {
3114      n[1].e = target;
3115      n[2].e = pname;
3116      n[3].f = params[0];
3117      n[4].f = params[1];
3118      n[5].f = params[2];
3119      n[6].f = params[3];
3120   }
3121   if (ctx->ExecuteFlag) {
3122      (*ctx->Exec->TexParameterfv)( target, pname, params );
3123   }
3124}
3125
3126
3127static void save_TexParameterf( GLenum target, GLenum pname, GLfloat param )
3128{
3129   save_TexParameterfv(target, pname, &param);
3130}
3131
3132
3133static void save_TexParameteri( GLenum target, GLenum pname, const GLint param )
3134{
3135   GLfloat fparam[4];
3136   fparam[0] = (GLfloat) param;
3137   fparam[1] = fparam[2] = fparam[3] = 0.0;
3138   save_TexParameterfv(target, pname, fparam);
3139}
3140
3141
3142static void save_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
3143{
3144   GLfloat fparam[4];
3145   fparam[0] = (GLfloat) params[0];
3146   fparam[1] = fparam[2] = fparam[3] = 0.0;
3147   save_TexParameterfv(target, pname, fparam);
3148}
3149
3150
3151static void save_TexImage1D( GLenum target,
3152                             GLint level, GLint components,
3153                             GLsizei width, GLint border,
3154                             GLenum format, GLenum type,
3155                             const GLvoid *pixels )
3156{
3157   GET_CURRENT_CONTEXT(ctx);
3158   if (target == GL_PROXY_TEXTURE_1D) {
3159      /* don't compile, execute immediately */
3160      (*ctx->Exec->TexImage1D)( target, level, components, width,
3161                               border, format, type, pixels );
3162   }
3163   else {
3164      GLvoid *image = _mesa_unpack_image(width, 1, 1, format, type,
3165                                         pixels, &ctx->Unpack);
3166      Node *n;
3167      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3168      n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_IMAGE1D, 8 );
3169      if (n) {
3170         n[1].e = target;
3171         n[2].i = level;
3172         n[3].i = components;
3173         n[4].i = (GLint) width;
3174         n[5].i = border;
3175         n[6].e = format;
3176         n[7].e = type;
3177         n[8].data = image;
3178      }
3179      else if (image) {
3180         FREE(image);
3181      }
3182      if (ctx->ExecuteFlag) {
3183         (*ctx->Exec->TexImage1D)( target, level, components, width,
3184                                  border, format, type, pixels );
3185      }
3186   }
3187}
3188
3189
3190static void save_TexImage2D( GLenum target,
3191                             GLint level, GLint components,
3192                             GLsizei width, GLsizei height, GLint border,
3193                             GLenum format, GLenum type,
3194                             const GLvoid *pixels)
3195{
3196   GET_CURRENT_CONTEXT(ctx);
3197   if (target == GL_PROXY_TEXTURE_2D) {
3198      /* don't compile, execute immediately */
3199      (*ctx->Exec->TexImage2D)( target, level, components, width,
3200                               height, border, format, type, pixels );
3201   }
3202   else {
3203      GLvoid *image = _mesa_unpack_image(width, height, 1, format, type,
3204                                         pixels, &ctx->Unpack);
3205      Node *n;
3206      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3207      n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_IMAGE2D, 9 );
3208      if (n) {
3209         n[1].e = target;
3210         n[2].i = level;
3211         n[3].i = components;
3212         n[4].i = (GLint) width;
3213         n[5].i = (GLint) height;
3214         n[6].i = border;
3215         n[7].e = format;
3216         n[8].e = type;
3217         n[9].data = image;
3218      }
3219      else if (image) {
3220         FREE(image);
3221      }
3222      if (ctx->ExecuteFlag) {
3223         (*ctx->Exec->TexImage2D)( target, level, components, width,
3224                                  height, border, format, type, pixels );
3225      }
3226   }
3227}
3228
3229
3230static void save_TexImage3D( GLenum target,
3231                             GLint level, GLenum internalFormat,
3232                             GLsizei width, GLsizei height, GLsizei depth,
3233                             GLint border,
3234                             GLenum format, GLenum type,
3235                             const GLvoid *pixels )
3236{
3237   GET_CURRENT_CONTEXT(ctx);
3238   if (target == GL_PROXY_TEXTURE_3D) {
3239      /* don't compile, execute immediately */
3240      (*ctx->Exec->TexImage3D)( target, level, internalFormat, width,
3241                               height, depth, border, format, type, pixels );
3242   }
3243   else {
3244      Node *n;
3245      GLvoid *image = _mesa_unpack_image(width, height, depth, format, type,
3246                                         pixels, &ctx->Unpack);
3247      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3248      n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_IMAGE3D, 10 );
3249      if (n) {
3250         n[1].e = target;
3251         n[2].i = level;
3252         n[3].i = (GLint) internalFormat;
3253         n[4].i = (GLint) width;
3254         n[5].i = (GLint) height;
3255         n[6].i = (GLint) depth;
3256         n[7].i = border;
3257         n[8].e = format;
3258         n[9].e = type;
3259         n[10].data = image;
3260      }
3261      else if (image) {
3262         FREE(image);
3263      }
3264      if (ctx->ExecuteFlag) {
3265         (*ctx->Exec->TexImage3D)( target, level, internalFormat, width,
3266                                height, depth, border, format, type, pixels );
3267      }
3268   }
3269}
3270
3271
3272static void save_TexSubImage1D( GLenum target, GLint level, GLint xoffset,
3273                                GLsizei width, GLenum format, GLenum type,
3274                                const GLvoid *pixels )
3275{
3276   GET_CURRENT_CONTEXT(ctx);
3277   Node *n;
3278   GLvoid *image = _mesa_unpack_image(width, 1, 1, format, type,
3279                                      pixels, &ctx->Unpack);
3280   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3281   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_SUB_IMAGE1D, 7 );
3282   if (n) {
3283      n[1].e = target;
3284      n[2].i = level;
3285      n[3].i = xoffset;
3286      n[4].i = (GLint) width;
3287      n[5].e = format;
3288      n[6].e = type;
3289      n[7].data = image;
3290   }
3291   else if (image) {
3292      FREE(image);
3293   }
3294   if (ctx->ExecuteFlag) {
3295      (*ctx->Exec->TexSubImage1D)( target, level, xoffset, width,
3296                                  format, type, pixels );
3297   }
3298}
3299
3300
3301static void save_TexSubImage2D( GLenum target, GLint level,
3302                                GLint xoffset, GLint yoffset,
3303                                GLsizei width, GLsizei height,
3304                                GLenum format, GLenum type,
3305                                const GLvoid *pixels )
3306{
3307   GET_CURRENT_CONTEXT(ctx);
3308   Node *n;
3309   GLvoid *image = _mesa_unpack_image(width, height, 1, format, type,
3310                                      pixels, &ctx->Unpack);
3311   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3312   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_SUB_IMAGE2D, 9 );
3313   if (n) {
3314      n[1].e = target;
3315      n[2].i = level;
3316      n[3].i = xoffset;
3317      n[4].i = yoffset;
3318      n[5].i = (GLint) width;
3319      n[6].i = (GLint) height;
3320      n[7].e = format;
3321      n[8].e = type;
3322      n[9].data = image;
3323   }
3324   else if (image) {
3325      FREE(image);
3326   }
3327   if (ctx->ExecuteFlag) {
3328      (*ctx->Exec->TexSubImage2D)( target, level, xoffset, yoffset,
3329                           width, height, format, type, pixels );
3330   }
3331}
3332
3333
3334static void save_TexSubImage3D( GLenum target, GLint level,
3335                                GLint xoffset, GLint yoffset,GLint zoffset,
3336                                GLsizei width, GLsizei height, GLsizei depth,
3337                                GLenum format, GLenum type,
3338                                const GLvoid *pixels )
3339{
3340   GET_CURRENT_CONTEXT(ctx);
3341   Node *n;
3342   GLvoid *image = _mesa_unpack_image(width, height, depth, format, type,
3343                                      pixels, &ctx->Unpack);
3344   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3345   n = ALLOC_INSTRUCTION( ctx, OPCODE_TEX_SUB_IMAGE3D, 11 );
3346   if (n) {
3347      n[1].e = target;
3348      n[2].i = level;
3349      n[3].i = xoffset;
3350      n[4].i = yoffset;
3351      n[5].i = zoffset;
3352      n[6].i = (GLint) width;
3353      n[7].i = (GLint) height;
3354      n[8].i = (GLint) depth;
3355      n[9].e = format;
3356      n[10].e = type;
3357      n[11].data = image;
3358   }
3359   else if (image) {
3360      FREE(image);
3361   }
3362   if (ctx->ExecuteFlag) {
3363      (*ctx->Exec->TexSubImage3D)( target, level,
3364                                  xoffset, yoffset, zoffset,
3365                                  width, height, depth, format, type, pixels );
3366   }
3367}
3368
3369
3370static void save_Translatef( GLfloat x, GLfloat y, GLfloat z )
3371{
3372   GET_CURRENT_CONTEXT(ctx);
3373   Node *n;
3374   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3375   n = ALLOC_INSTRUCTION( ctx,  OPCODE_TRANSLATE, 3 );
3376   if (n) {
3377      n[1].f = x;
3378      n[2].f = y;
3379      n[3].f = z;
3380   }
3381   if (ctx->ExecuteFlag) {
3382      (*ctx->Exec->Translatef)( x, y, z );
3383   }
3384}
3385
3386
3387static void save_Translated( GLdouble x, GLdouble y, GLdouble z )
3388{
3389   save_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
3390}
3391
3392
3393
3394static void save_Viewport( GLint x, GLint y, GLsizei width, GLsizei height )
3395{
3396   GET_CURRENT_CONTEXT(ctx);
3397   Node *n;
3398   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3399   n = ALLOC_INSTRUCTION( ctx,  OPCODE_VIEWPORT, 4 );
3400   if (n) {
3401      n[1].i = x;
3402      n[2].i = y;
3403      n[3].i = (GLint) width;
3404      n[4].i = (GLint) height;
3405   }
3406   if (ctx->ExecuteFlag) {
3407      (*ctx->Exec->Viewport)( x, y, width, height );
3408   }
3409}
3410
3411
3412static void save_WindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
3413{
3414   GET_CURRENT_CONTEXT(ctx);
3415   Node *n;
3416   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3417   FLUSH_CURRENT(ctx, 0);
3418   n = ALLOC_INSTRUCTION( ctx,  OPCODE_WINDOW_POS, 4 );
3419   if (n) {
3420      n[1].f = x;
3421      n[2].f = y;
3422      n[3].f = z;
3423      n[4].f = w;
3424   }
3425   if (ctx->ExecuteFlag) {
3426      (*ctx->Exec->WindowPos4fMESA)( x, y, z, w );
3427   }
3428}
3429
3430static void save_WindowPos2dMESA(GLdouble x, GLdouble y)
3431{
3432   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
3433}
3434
3435static void save_WindowPos2fMESA(GLfloat x, GLfloat y)
3436{
3437   save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
3438}
3439
3440static void save_WindowPos2iMESA(GLint x, GLint y)
3441{
3442   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
3443}
3444
3445static void save_WindowPos2sMESA(GLshort x, GLshort y)
3446{
3447   save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
3448}
3449
3450static void save_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
3451{
3452   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
3453}
3454
3455static void save_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
3456{
3457   save_WindowPos4fMESA(x, y, z, 1.0F);
3458}
3459
3460static void save_WindowPos3iMESA(GLint x, GLint y, GLint z)
3461{
3462   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
3463}
3464
3465static void save_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
3466{
3467   save_WindowPos4fMESA(x, y, z, 1.0F);
3468}
3469
3470static void save_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
3471{
3472   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
3473}
3474
3475static void save_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
3476{
3477   save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
3478}
3479
3480static void save_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
3481{
3482   save_WindowPos4fMESA(x, y, z, w);
3483}
3484
3485static void save_WindowPos2dvMESA(const GLdouble *v)
3486{
3487   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
3488}
3489
3490static void save_WindowPos2fvMESA(const GLfloat *v)
3491{
3492   save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
3493}
3494
3495static void save_WindowPos2ivMESA(const GLint *v)
3496{
3497   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
3498}
3499
3500static void save_WindowPos2svMESA(const GLshort *v)
3501{
3502   save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
3503}
3504
3505static void save_WindowPos3dvMESA(const GLdouble *v)
3506{
3507   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
3508}
3509
3510static void save_WindowPos3fvMESA(const GLfloat *v)
3511{
3512   save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
3513}
3514
3515static void save_WindowPos3ivMESA(const GLint *v)
3516{
3517   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
3518}
3519
3520static void save_WindowPos3svMESA(const GLshort *v)
3521{
3522   save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
3523}
3524
3525static void save_WindowPos4dvMESA(const GLdouble *v)
3526{
3527   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
3528			(GLfloat) v[2], (GLfloat) v[3]);
3529}
3530
3531static void save_WindowPos4fvMESA(const GLfloat *v)
3532{
3533   save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
3534}
3535
3536static void save_WindowPos4ivMESA(const GLint *v)
3537{
3538   save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
3539			(GLfloat) v[2], (GLfloat) v[3]);
3540}
3541
3542static void save_WindowPos4svMESA(const GLshort *v)
3543{
3544   save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
3545}
3546
3547
3548
3549/* GL_ARB_multitexture */
3550static void save_ActiveTextureARB( GLenum target )
3551{
3552   GET_CURRENT_CONTEXT(ctx);
3553   Node *n;
3554   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3555   n = ALLOC_INSTRUCTION( ctx, OPCODE_ACTIVE_TEXTURE, 1 );
3556   if (n) {
3557      n[1].e = target;
3558   }
3559   if (ctx->ExecuteFlag) {
3560      (*ctx->Exec->ActiveTextureARB)( target );
3561   }
3562}
3563
3564
3565/* GL_ARB_transpose_matrix */
3566
3567static void save_LoadTransposeMatrixdARB( const GLdouble m[16] )
3568{
3569   GLfloat tm[16];
3570   _math_transposefd(tm, m);
3571   save_LoadMatrixf(tm);
3572}
3573
3574
3575static void save_LoadTransposeMatrixfARB( const GLfloat m[16] )
3576{
3577   GLfloat tm[16];
3578   _math_transposef(tm, m);
3579   save_LoadMatrixf(tm);
3580}
3581
3582
3583static void
3584save_MultTransposeMatrixdARB( const GLdouble m[16] )
3585{
3586   GLfloat tm[16];
3587   _math_transposefd(tm, m);
3588   save_MultMatrixf(tm);
3589}
3590
3591
3592static void
3593save_MultTransposeMatrixfARB( const GLfloat m[16] )
3594{
3595   GLfloat tm[16];
3596   _math_transposef(tm, m);
3597   save_MultMatrixf(tm);
3598}
3599
3600
3601static void
3602save_PixelTexGenSGIX(GLenum mode)
3603{
3604   GET_CURRENT_CONTEXT(ctx);
3605   Node *n;
3606   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3607   n = ALLOC_INSTRUCTION( ctx, OPCODE_PIXEL_TEXGEN_SGIX, 1 );
3608   if (n) {
3609      n[1].e = mode;
3610   }
3611   if (ctx->ExecuteFlag) {
3612      (*ctx->Exec->PixelTexGenSGIX)( mode );
3613   }
3614}
3615
3616
3617/* GL_ARB_texture_compression */
3618static void
3619save_CompressedTexImage1DARB(GLenum target, GLint level,
3620                             GLenum internalFormat, GLsizei width,
3621                             GLint border, GLsizei imageSize,
3622                             const GLvoid *data)
3623{
3624   GET_CURRENT_CONTEXT(ctx);
3625   if (target == GL_PROXY_TEXTURE_1D) {
3626      /* don't compile, execute immediately */
3627      (*ctx->Exec->CompressedTexImage1DARB)(target, level, internalFormat,
3628                                            width, border, imageSize, data);
3629   }
3630   else {
3631      Node *n;
3632      GLvoid *image;
3633      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3634      /* make copy of image */
3635      image = MALLOC(imageSize);
3636      if (!image) {
3637         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
3638         return;
3639      }
3640      MEMCPY(image, data, imageSize);
3641      n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_IMAGE_1D, 7 );
3642      if (n) {
3643         n[1].e = target;
3644         n[2].i = level;
3645         n[3].e = internalFormat;
3646         n[4].i = (GLint) width;
3647         n[5].i = border;
3648         n[6].i = imageSize;
3649         n[7].data = image;
3650      }
3651      else if (image) {
3652         FREE(image);
3653      }
3654      if (ctx->ExecuteFlag) {
3655         (*ctx->Exec->CompressedTexImage1DARB)(target, level, internalFormat,
3656                                               width, border, imageSize, data);
3657      }
3658   }
3659}
3660
3661
3662static void
3663save_CompressedTexImage2DARB(GLenum target, GLint level,
3664                             GLenum internalFormat, GLsizei width,
3665                             GLsizei height, GLint border, GLsizei imageSize,
3666                             const GLvoid *data)
3667{
3668   GET_CURRENT_CONTEXT(ctx);
3669   if (target == GL_PROXY_TEXTURE_2D) {
3670      /* don't compile, execute immediately */
3671      (*ctx->Exec->CompressedTexImage2DARB)(target, level, internalFormat,
3672                                       width, height, border, imageSize, data);
3673   }
3674   else {
3675      Node *n;
3676      GLvoid *image;
3677      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3678      /* make copy of image */
3679      image = MALLOC(imageSize);
3680      if (!image) {
3681         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
3682         return;
3683      }
3684      MEMCPY(image, data, imageSize);
3685      n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_IMAGE_2D, 8 );
3686      if (n) {
3687         n[1].e = target;
3688         n[2].i = level;
3689         n[3].e = internalFormat;
3690         n[4].i = (GLint) width;
3691         n[5].i = (GLint) height;
3692         n[6].i = border;
3693         n[7].i = imageSize;
3694         n[8].data = image;
3695      }
3696      else if (image) {
3697         FREE(image);
3698      }
3699      if (ctx->ExecuteFlag) {
3700         (*ctx->Exec->CompressedTexImage2DARB)(target, level, internalFormat,
3701                                      width, height, border, imageSize, data);
3702      }
3703   }
3704}
3705
3706
3707static void
3708save_CompressedTexImage3DARB(GLenum target, GLint level,
3709                             GLenum internalFormat, GLsizei width,
3710                             GLsizei height, GLsizei depth, GLint border,
3711                             GLsizei imageSize, const GLvoid *data)
3712{
3713   GET_CURRENT_CONTEXT(ctx);
3714   if (target == GL_PROXY_TEXTURE_3D) {
3715      /* don't compile, execute immediately */
3716      (*ctx->Exec->CompressedTexImage3DARB)(target, level, internalFormat,
3717                                width, height, depth, border, imageSize, data);
3718   }
3719   else {
3720      Node *n;
3721      GLvoid *image;
3722      ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3723      /* make copy of image */
3724      image = MALLOC(imageSize);
3725      if (!image) {
3726         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
3727         return;
3728      }
3729      MEMCPY(image, data, imageSize);
3730      n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_IMAGE_3D, 9 );
3731      if (n) {
3732         n[1].e = target;
3733         n[2].i = level;
3734         n[3].e = internalFormat;
3735         n[4].i = (GLint) width;
3736         n[5].i = (GLint) height;
3737         n[6].i = (GLint) depth;
3738         n[7].i = border;
3739         n[8].i = imageSize;
3740         n[9].data = image;
3741      }
3742      else if (image) {
3743         FREE(image);
3744      }
3745      if (ctx->ExecuteFlag) {
3746         (*ctx->Exec->CompressedTexImage3DARB)(target, level, internalFormat,
3747                                width, height, depth, border, imageSize, data);
3748      }
3749   }
3750}
3751
3752
3753static void
3754save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
3755                                GLsizei width, GLenum format,
3756                                GLsizei imageSize, const GLvoid *data)
3757{
3758   Node *n;
3759   GLvoid *image;
3760
3761   GET_CURRENT_CONTEXT(ctx);
3762   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3763
3764   /* make copy of image */
3765   image = MALLOC(imageSize);
3766   if (!image) {
3767      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage1DARB");
3768      return;
3769   }
3770   MEMCPY(image, data, imageSize);
3771   n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D, 7 );
3772   if (n) {
3773      n[1].e = target;
3774      n[2].i = level;
3775      n[3].i = xoffset;
3776      n[4].i = (GLint) width;
3777      n[5].e = format;
3778      n[6].i = imageSize;
3779      n[7].data = image;
3780   }
3781   else if (image) {
3782      FREE(image);
3783   }
3784   if (ctx->ExecuteFlag) {
3785      (*ctx->Exec->CompressedTexSubImage1DARB)(target, level, xoffset,
3786                                               width, format, imageSize, data);
3787   }
3788}
3789
3790
3791static void
3792save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
3793                                GLint yoffset, GLsizei width, GLsizei height,
3794                                GLenum format, GLsizei imageSize,
3795                                const GLvoid *data)
3796{
3797   Node *n;
3798   GLvoid *image;
3799
3800   GET_CURRENT_CONTEXT(ctx);
3801   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3802
3803   /* make copy of image */
3804   image = MALLOC(imageSize);
3805   if (!image) {
3806      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2DARB");
3807      return;
3808   }
3809   MEMCPY(image, data, imageSize);
3810   n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D, 9 );
3811   if (n) {
3812      n[1].e = target;
3813      n[2].i = level;
3814      n[3].i = xoffset;
3815      n[4].i = yoffset;
3816      n[5].i = (GLint) width;
3817      n[6].i = (GLint) height;
3818      n[7].e = format;
3819      n[8].i = imageSize;
3820      n[9].data = image;
3821   }
3822   else if (image) {
3823      FREE(image);
3824   }
3825   if (ctx->ExecuteFlag) {
3826      (*ctx->Exec->CompressedTexSubImage2DARB)(target, level, xoffset, yoffset,
3827                                       width, height, format, imageSize, data);
3828   }
3829}
3830
3831
3832static void
3833save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
3834                                GLint yoffset, GLint zoffset, GLsizei width,
3835                                GLsizei height, GLsizei depth, GLenum format,
3836                                GLsizei imageSize, const GLvoid *data)
3837{
3838   Node *n;
3839   GLvoid *image;
3840
3841   GET_CURRENT_CONTEXT(ctx);
3842   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3843
3844   /* make copy of image */
3845   image = MALLOC(imageSize);
3846   if (!image) {
3847      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage3DARB");
3848      return;
3849   }
3850   MEMCPY(image, data, imageSize);
3851   n = ALLOC_INSTRUCTION( ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D, 11 );
3852   if (n) {
3853      n[1].e = target;
3854      n[2].i = level;
3855      n[3].i = xoffset;
3856      n[4].i = yoffset;
3857      n[5].i = zoffset;
3858      n[6].i = (GLint) width;
3859      n[7].i = (GLint) height;
3860      n[8].i = (GLint) depth;
3861      n[9].e = format;
3862      n[10].i = imageSize;
3863      n[11].data = image;
3864   }
3865   else if (image) {
3866      FREE(image);
3867   }
3868   if (ctx->ExecuteFlag) {
3869      (*ctx->Exec->CompressedTexSubImage3DARB)(target, level, xoffset, yoffset,
3870                       zoffset, width, height, depth, format, imageSize, data);
3871   }
3872}
3873
3874
3875/* GL_ARB_multisample */
3876static void
3877save_SampleCoverageARB(GLclampf value, GLboolean invert)
3878{
3879   GET_CURRENT_CONTEXT(ctx);
3880   Node *n;
3881   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3882   n = ALLOC_INSTRUCTION( ctx, OPCODE_SAMPLE_COVERAGE, 2 );
3883   if (n) {
3884      n[1].f = value;
3885      n[2].b = invert;
3886   }
3887   if (ctx->ExecuteFlag) {
3888      (*ctx->Exec->SampleCoverageARB)( value, invert );
3889   }
3890}
3891
3892
3893/* GL_SGIS_pixel_texture */
3894
3895static void
3896save_PixelTexGenParameteriSGIS(GLenum target, GLint value)
3897{
3898   GET_CURRENT_CONTEXT(ctx);
3899   Node *n;
3900   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3901   n = ALLOC_INSTRUCTION( ctx, OPCODE_PIXEL_TEXGEN_PARAMETER_SGIS, 2 );
3902   if (n) {
3903      n[1].e = target;
3904      n[2].i = value;
3905   }
3906   if (ctx->ExecuteFlag) {
3907      (*ctx->Exec->PixelTexGenParameteriSGIS)( target, value );
3908   }
3909}
3910
3911
3912static void
3913save_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
3914{
3915   save_PixelTexGenParameteriSGIS(target, (GLint) value);
3916}
3917
3918
3919static void
3920save_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
3921{
3922   save_PixelTexGenParameteriSGIS(target, *value);
3923}
3924
3925
3926static void
3927save_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
3928{
3929   save_PixelTexGenParameteriSGIS(target, (GLint) *value);
3930}
3931
3932
3933/* KW: Compile commands
3934 *
3935 * Will appear in the list before the vertex buffer containing the
3936 * command that provoked the error.  I don't see this as a problem.
3937 */
3938void
3939_mesa_save_error( GLcontext *ctx, GLenum error, const char *s )
3940{
3941   Node *n;
3942   n = ALLOC_INSTRUCTION( ctx, OPCODE_ERROR, 2 );
3943   if (n) {
3944      n[1].e = error;
3945      n[2].data = (void *) s;
3946   }
3947   /* execute already done */
3948}
3949
3950
3951static GLboolean
3952islist(GLcontext *ctx, GLuint list)
3953{
3954   if (list > 0 && _mesa_HashLookup(ctx->Shared->DisplayList, list)) {
3955      return GL_TRUE;
3956   }
3957   else {
3958      return GL_FALSE;
3959   }
3960}
3961
3962
3963
3964/**********************************************************************/
3965/*                     Display list execution                         */
3966/**********************************************************************/
3967
3968
3969/*
3970 * Execute a display list.  Note that the ListBase offset must have already
3971 * been added before calling this function.  I.e. the list argument is
3972 * the absolute list number, not relative to ListBase.
3973 * Input:  list - display list number
3974 */
3975static void
3976execute_list( GLcontext *ctx, GLuint list )
3977{
3978   Node *n;
3979   GLboolean done;
3980
3981   if (!islist(ctx,list))
3982      return;
3983
3984   if (ctx->Driver.BeginCallList)
3985      ctx->Driver.BeginCallList( ctx, list );
3986
3987/*     fprintf(stderr, "execute list %d\n", list); */
3988/*     mesa_print_display_list( list );  */
3989
3990   ctx->CallDepth++;
3991
3992   n = (Node *) _mesa_HashLookup(ctx->Shared->DisplayList, list);
3993
3994   done = GL_FALSE;
3995   while (!done) {
3996      OpCode opcode = n[0].opcode;
3997      int i = (int)n[0].opcode - (int)OPCODE_DRV_0;
3998
3999      if (i >= 0 && i < (GLint) ctx->listext.nr_opcodes) {
4000	 ctx->listext.opcode[i].execute(ctx, &n[1]);
4001	 n += ctx->listext.opcode[i].size;
4002      }
4003      else {
4004	 switch (opcode) {
4005	 case OPCODE_ERROR:
4006	    _mesa_error( ctx, n[1].e, (const char *) n[2].data );
4007	    break;
4008         case OPCODE_ACCUM:
4009	    (*ctx->Exec->Accum)( n[1].e, n[2].f );
4010	    break;
4011         case OPCODE_ALPHA_FUNC:
4012	    (*ctx->Exec->AlphaFunc)( n[1].e, n[2].f );
4013	    break;
4014         case OPCODE_BIND_TEXTURE:
4015            (*ctx->Exec->BindTexture)( n[1].e, n[2].ui );
4016            break;
4017	 case OPCODE_BITMAP:
4018            {
4019               struct gl_pixelstore_attrib save = ctx->Unpack;
4020               ctx->Unpack = _mesa_native_packing;
4021               (*ctx->Exec->Bitmap)( (GLsizei) n[1].i, (GLsizei) n[2].i,
4022                 n[3].f, n[4].f, n[5].f, n[6].f, (const GLubyte *) n[7].data );
4023               ctx->Unpack = save;  /* restore */
4024            }
4025	    break;
4026	 case OPCODE_BLEND_COLOR:
4027	    (*ctx->Exec->BlendColor)( n[1].f, n[2].f, n[3].f, n[4].f );
4028	    break;
4029	 case OPCODE_BLEND_EQUATION:
4030	    (*ctx->Exec->BlendEquation)( n[1].e );
4031	    break;
4032	 case OPCODE_BLEND_FUNC:
4033	    (*ctx->Exec->BlendFunc)( n[1].e, n[2].e );
4034	    break;
4035	 case OPCODE_BLEND_FUNC_SEPARATE:
4036	    (*ctx->Exec->BlendFuncSeparateEXT)(n[1].e, n[2].e, n[3].e, n[4].e);
4037	    break;
4038         case OPCODE_CALL_LIST:
4039	    /* Generated by glCallList(), don't add ListBase */
4040            if (ctx->CallDepth<MAX_LIST_NESTING) {
4041               execute_list( ctx, n[1].ui );
4042            }
4043            break;
4044         case OPCODE_CALL_LIST_OFFSET:
4045	    /* Generated by glCallLists() so we must add ListBase */
4046            if (ctx->CallDepth<MAX_LIST_NESTING) {
4047               execute_list( ctx, ctx->List.ListBase + n[1].ui );
4048            }
4049            break;
4050	 case OPCODE_CLEAR:
4051	    (*ctx->Exec->Clear)( n[1].bf );
4052	    break;
4053	 case OPCODE_CLEAR_COLOR:
4054	    (*ctx->Exec->ClearColor)( n[1].f, n[2].f, n[3].f, n[4].f );
4055	    break;
4056	 case OPCODE_CLEAR_ACCUM:
4057	    (*ctx->Exec->ClearAccum)( n[1].f, n[2].f, n[3].f, n[4].f );
4058	    break;
4059	 case OPCODE_CLEAR_DEPTH:
4060	    (*ctx->Exec->ClearDepth)( (GLclampd) n[1].f );
4061	    break;
4062	 case OPCODE_CLEAR_INDEX:
4063	    (*ctx->Exec->ClearIndex)( (GLfloat) n[1].ui );
4064	    break;
4065	 case OPCODE_CLEAR_STENCIL:
4066	    (*ctx->Exec->ClearStencil)( n[1].i );
4067	    break;
4068         case OPCODE_CLIP_PLANE:
4069            {
4070               GLdouble eq[4];
4071               eq[0] = n[2].f;
4072               eq[1] = n[3].f;
4073               eq[2] = n[4].f;
4074               eq[3] = n[5].f;
4075               (*ctx->Exec->ClipPlane)( n[1].e, eq );
4076            }
4077            break;
4078	 case OPCODE_COLOR_MASK:
4079	    (*ctx->Exec->ColorMask)( n[1].b, n[2].b, n[3].b, n[4].b );
4080	    break;
4081	 case OPCODE_COLOR_MATERIAL:
4082	    (*ctx->Exec->ColorMaterial)( n[1].e, n[2].e );
4083	    break;
4084         case OPCODE_COLOR_TABLE:
4085            {
4086               struct gl_pixelstore_attrib save = ctx->Unpack;
4087               ctx->Unpack = _mesa_native_packing;
4088               (*ctx->Exec->ColorTable)( n[1].e, n[2].e, n[3].i, n[4].e,
4089                                         n[5].e, n[6].data );
4090               ctx->Unpack = save;  /* restore */
4091            }
4092            break;
4093         case OPCODE_COLOR_TABLE_PARAMETER_FV:
4094            {
4095               GLfloat params[4];
4096               params[0] = n[3].f;
4097               params[1] = n[4].f;
4098               params[2] = n[5].f;
4099               params[3] = n[6].f;
4100               (*ctx->Exec->ColorTableParameterfv)( n[1].e, n[2].e, params );
4101            }
4102            break;
4103         case OPCODE_COLOR_TABLE_PARAMETER_IV:
4104            {
4105               GLint params[4];
4106               params[0] = n[3].i;
4107               params[1] = n[4].i;
4108               params[2] = n[5].i;
4109               params[3] = n[6].i;
4110               (*ctx->Exec->ColorTableParameteriv)( n[1].e, n[2].e, params );
4111            }
4112            break;
4113         case OPCODE_COLOR_SUB_TABLE:
4114            {
4115               struct gl_pixelstore_attrib save = ctx->Unpack;
4116               ctx->Unpack = _mesa_native_packing;
4117               (*ctx->Exec->ColorSubTable)( n[1].e, n[2].i, n[3].i,
4118                                            n[4].e, n[5].e, n[6].data );
4119               ctx->Unpack = save;  /* restore */
4120            }
4121            break;
4122         case OPCODE_CONVOLUTION_FILTER_1D:
4123            {
4124               struct gl_pixelstore_attrib save = ctx->Unpack;
4125               ctx->Unpack = _mesa_native_packing;
4126               (*ctx->Exec->ConvolutionFilter1D)( n[1].e, n[2].i, n[3].i,
4127                                                  n[4].e, n[5].e, n[6].data );
4128               ctx->Unpack = save;  /* restore */
4129            }
4130            break;
4131         case OPCODE_CONVOLUTION_FILTER_2D:
4132            {
4133               struct gl_pixelstore_attrib save = ctx->Unpack;
4134               ctx->Unpack = _mesa_native_packing;
4135               (*ctx->Exec->ConvolutionFilter2D)( n[1].e, n[2].i, n[3].i,
4136                                       n[4].i, n[5].e, n[6].e, n[7].data );
4137               ctx->Unpack = save;  /* restore */
4138            }
4139            break;
4140         case OPCODE_CONVOLUTION_PARAMETER_I:
4141            (*ctx->Exec->ConvolutionParameteri)( n[1].e, n[2].e, n[3].i );
4142            break;
4143         case OPCODE_CONVOLUTION_PARAMETER_IV:
4144            {
4145               GLint params[4];
4146               params[0] = n[3].i;
4147               params[1] = n[4].i;
4148               params[2] = n[5].i;
4149               params[3] = n[6].i;
4150               (*ctx->Exec->ConvolutionParameteriv)( n[1].e, n[2].e, params );
4151            }
4152            break;
4153         case OPCODE_CONVOLUTION_PARAMETER_F:
4154            (*ctx->Exec->ConvolutionParameterf)( n[1].e, n[2].e, n[3].f );
4155            break;
4156         case OPCODE_CONVOLUTION_PARAMETER_FV:
4157            {
4158               GLfloat params[4];
4159               params[0] = n[3].f;
4160               params[1] = n[4].f;
4161               params[2] = n[5].f;
4162               params[3] = n[6].f;
4163               (*ctx->Exec->ConvolutionParameterfv)( n[1].e, n[2].e, params );
4164            }
4165            break;
4166         case OPCODE_COPY_COLOR_SUB_TABLE:
4167            (*ctx->Exec->CopyColorSubTable)( n[1].e, n[2].i,
4168                                             n[3].i, n[4].i, n[5].i );
4169            break;
4170         case OPCODE_COPY_COLOR_TABLE:
4171            (*ctx->Exec->CopyColorSubTable)( n[1].e, n[2].i,
4172                                             n[3].i, n[4].i, n[5].i );
4173            break;
4174	 case OPCODE_COPY_PIXELS:
4175	    (*ctx->Exec->CopyPixels)( n[1].i, n[2].i,
4176			   (GLsizei) n[3].i, (GLsizei) n[4].i, n[5].e );
4177	    break;
4178         case OPCODE_COPY_TEX_IMAGE1D:
4179	    (*ctx->Exec->CopyTexImage1D)( n[1].e, n[2].i, n[3].e, n[4].i,
4180                                         n[5].i, n[6].i, n[7].i );
4181            break;
4182         case OPCODE_COPY_TEX_IMAGE2D:
4183	    (*ctx->Exec->CopyTexImage2D)( n[1].e, n[2].i, n[3].e, n[4].i,
4184                                         n[5].i, n[6].i, n[7].i, n[8].i );
4185            break;
4186         case OPCODE_COPY_TEX_SUB_IMAGE1D:
4187	    (*ctx->Exec->CopyTexSubImage1D)( n[1].e, n[2].i, n[3].i,
4188                                            n[4].i, n[5].i, n[6].i );
4189            break;
4190         case OPCODE_COPY_TEX_SUB_IMAGE2D:
4191	    (*ctx->Exec->CopyTexSubImage2D)( n[1].e, n[2].i, n[3].i,
4192                                     n[4].i, n[5].i, n[6].i, n[7].i, n[8].i );
4193            break;
4194         case OPCODE_COPY_TEX_SUB_IMAGE3D:
4195            (*ctx->Exec->CopyTexSubImage3D)( n[1].e, n[2].i, n[3].i,
4196                            n[4].i, n[5].i, n[6].i, n[7].i, n[8].i , n[9].i);
4197            break;
4198	 case OPCODE_CULL_FACE:
4199	    (*ctx->Exec->CullFace)( n[1].e );
4200	    break;
4201	 case OPCODE_DEPTH_FUNC:
4202	    (*ctx->Exec->DepthFunc)( n[1].e );
4203	    break;
4204	 case OPCODE_DEPTH_MASK:
4205	    (*ctx->Exec->DepthMask)( n[1].b );
4206	    break;
4207	 case OPCODE_DEPTH_RANGE:
4208	    (*ctx->Exec->DepthRange)( (GLclampd) n[1].f, (GLclampd) n[2].f );
4209	    break;
4210	 case OPCODE_DISABLE:
4211	    (*ctx->Exec->Disable)( n[1].e );
4212	    break;
4213	 case OPCODE_DRAW_BUFFER:
4214	    (*ctx->Exec->DrawBuffer)( n[1].e );
4215	    break;
4216	 case OPCODE_DRAW_PIXELS:
4217            {
4218               struct gl_pixelstore_attrib save = ctx->Unpack;
4219               ctx->Unpack = _mesa_native_packing;
4220               (*ctx->Exec->DrawPixels)( n[1].i, n[2].i, n[3].e, n[4].e,
4221                                        n[5].data );
4222               ctx->Unpack = save;  /* restore */
4223            }
4224	    break;
4225	 case OPCODE_ENABLE:
4226	    (*ctx->Exec->Enable)( n[1].e );
4227	    break;
4228	 case OPCODE_EVALMESH1:
4229	    (*ctx->Exec->EvalMesh1)( n[1].e, n[2].i, n[3].i );
4230	    break;
4231	 case OPCODE_EVALMESH2:
4232	    (*ctx->Exec->EvalMesh2)( n[1].e, n[2].i, n[3].i, n[4].i, n[5].i );
4233	    break;
4234	 case OPCODE_FOG:
4235	    {
4236	       GLfloat p[4];
4237	       p[0] = n[2].f;
4238	       p[1] = n[3].f;
4239	       p[2] = n[4].f;
4240	       p[3] = n[5].f;
4241	       (*ctx->Exec->Fogfv)( n[1].e, p );
4242	    }
4243	    break;
4244	 case OPCODE_FRONT_FACE:
4245	    (*ctx->Exec->FrontFace)( n[1].e );
4246	    break;
4247         case OPCODE_FRUSTUM:
4248            (*ctx->Exec->Frustum)( n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f );
4249            break;
4250	 case OPCODE_HINT:
4251	    (*ctx->Exec->Hint)( n[1].e, n[2].e );
4252	    break;
4253	 case OPCODE_HISTOGRAM:
4254	    (*ctx->Exec->Histogram)( n[1].e, n[2].i, n[3].e, n[4].b );
4255	    break;
4256	 case OPCODE_INDEX_MASK:
4257	    (*ctx->Exec->IndexMask)( n[1].ui );
4258	    break;
4259	 case OPCODE_INIT_NAMES:
4260	    (*ctx->Exec->InitNames)();
4261	    break;
4262         case OPCODE_LIGHT:
4263	    {
4264	       GLfloat p[4];
4265	       p[0] = n[3].f;
4266	       p[1] = n[4].f;
4267	       p[2] = n[5].f;
4268	       p[3] = n[6].f;
4269	       (*ctx->Exec->Lightfv)( n[1].e, n[2].e, p );
4270	    }
4271	    break;
4272         case OPCODE_LIGHT_MODEL:
4273	    {
4274	       GLfloat p[4];
4275	       p[0] = n[2].f;
4276	       p[1] = n[3].f;
4277	       p[2] = n[4].f;
4278	       p[3] = n[5].f;
4279	       (*ctx->Exec->LightModelfv)( n[1].e, p );
4280	    }
4281	    break;
4282	 case OPCODE_LINE_STIPPLE:
4283	    (*ctx->Exec->LineStipple)( n[1].i, n[2].us );
4284	    break;
4285	 case OPCODE_LINE_WIDTH:
4286	    (*ctx->Exec->LineWidth)( n[1].f );
4287	    break;
4288	 case OPCODE_LIST_BASE:
4289	    (*ctx->Exec->ListBase)( n[1].ui );
4290	    break;
4291	 case OPCODE_LOAD_IDENTITY:
4292            (*ctx->Exec->LoadIdentity)();
4293            break;
4294	 case OPCODE_LOAD_MATRIX:
4295	    if (sizeof(Node)==sizeof(GLfloat)) {
4296	       (*ctx->Exec->LoadMatrixf)( &n[1].f );
4297	    }
4298	    else {
4299	       GLfloat m[16];
4300	       GLuint i;
4301	       for (i=0;i<16;i++) {
4302		  m[i] = n[1+i].f;
4303	       }
4304	       (*ctx->Exec->LoadMatrixf)( m );
4305	    }
4306	    break;
4307	 case OPCODE_LOAD_NAME:
4308	    (*ctx->Exec->LoadName)( n[1].ui );
4309	    break;
4310	 case OPCODE_LOGIC_OP:
4311	    (*ctx->Exec->LogicOp)( n[1].e );
4312	    break;
4313	 case OPCODE_MAP1:
4314            {
4315               GLenum target = n[1].e;
4316               GLint ustride = _mesa_evaluator_components(target);
4317               GLint uorder = n[5].i;
4318               GLfloat u1 = n[2].f;
4319               GLfloat u2 = n[3].f;
4320               (*ctx->Exec->Map1f)( target, u1, u2, ustride, uorder,
4321                                   (GLfloat *) n[6].data );
4322            }
4323	    break;
4324	 case OPCODE_MAP2:
4325            {
4326               GLenum target = n[1].e;
4327               GLfloat u1 = n[2].f;
4328               GLfloat u2 = n[3].f;
4329               GLfloat v1 = n[4].f;
4330               GLfloat v2 = n[5].f;
4331               GLint ustride = n[6].i;
4332               GLint vstride = n[7].i;
4333               GLint uorder = n[8].i;
4334               GLint vorder = n[9].i;
4335               (*ctx->Exec->Map2f)( target, u1, u2, ustride, uorder,
4336                                   v1, v2, vstride, vorder,
4337                                   (GLfloat *) n[10].data );
4338            }
4339	    break;
4340	 case OPCODE_MAPGRID1:
4341	    (*ctx->Exec->MapGrid1f)( n[1].i, n[2].f, n[3].f );
4342	    break;
4343	 case OPCODE_MAPGRID2:
4344	    (*ctx->Exec->MapGrid2f)( n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f);
4345	    break;
4346         case OPCODE_MATRIX_MODE:
4347            (*ctx->Exec->MatrixMode)( n[1].e );
4348            break;
4349         case OPCODE_MIN_MAX:
4350            (*ctx->Exec->Minmax)(n[1].e, n[2].e, n[3].b);
4351            break;
4352	 case OPCODE_MULT_MATRIX:
4353	    if (sizeof(Node)==sizeof(GLfloat)) {
4354	       (*ctx->Exec->MultMatrixf)( &n[1].f );
4355	    }
4356	    else {
4357	       GLfloat m[16];
4358	       GLuint i;
4359	       for (i=0;i<16;i++) {
4360		  m[i] = n[1+i].f;
4361	       }
4362	       (*ctx->Exec->MultMatrixf)( m );
4363	    }
4364	    break;
4365         case OPCODE_ORTHO:
4366            (*ctx->Exec->Ortho)( n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f );
4367            break;
4368	 case OPCODE_PASSTHROUGH:
4369	    (*ctx->Exec->PassThrough)( n[1].f );
4370	    break;
4371	 case OPCODE_PIXEL_MAP:
4372	    (*ctx->Exec->PixelMapfv)( n[1].e, n[2].i, (GLfloat *) n[3].data );
4373	    break;
4374	 case OPCODE_PIXEL_TRANSFER:
4375	    (*ctx->Exec->PixelTransferf)( n[1].e, n[2].f );
4376	    break;
4377	 case OPCODE_PIXEL_ZOOM:
4378	    (*ctx->Exec->PixelZoom)( n[1].f, n[2].f );
4379	    break;
4380	 case OPCODE_POINT_SIZE:
4381	    (*ctx->Exec->PointSize)( n[1].f );
4382	    break;
4383	 case OPCODE_POINT_PARAMETERS:
4384	    {
4385		GLfloat params[3];
4386		params[0] = n[2].f;
4387		params[1] = n[3].f;
4388		params[2] = n[4].f;
4389		(*ctx->Exec->PointParameterfvEXT)( n[1].e, params );
4390	    }
4391	    break;
4392	 case OPCODE_POLYGON_MODE:
4393	    (*ctx->Exec->PolygonMode)( n[1].e, n[2].e );
4394	    break;
4395	 case OPCODE_POLYGON_STIPPLE:
4396	    (*ctx->Exec->PolygonStipple)( (GLubyte *) n[1].data );
4397	    break;
4398	 case OPCODE_POLYGON_OFFSET:
4399	    (*ctx->Exec->PolygonOffset)( n[1].f, n[2].f );
4400	    break;
4401	 case OPCODE_POP_ATTRIB:
4402	    (*ctx->Exec->PopAttrib)();
4403	    break;
4404	 case OPCODE_POP_MATRIX:
4405	    (*ctx->Exec->PopMatrix)();
4406	    break;
4407	 case OPCODE_POP_NAME:
4408	    (*ctx->Exec->PopName)();
4409	    break;
4410	 case OPCODE_PRIORITIZE_TEXTURE:
4411            (*ctx->Exec->PrioritizeTextures)( 1, &n[1].ui, &n[2].f );
4412	    break;
4413	 case OPCODE_PUSH_ATTRIB:
4414	    (*ctx->Exec->PushAttrib)( n[1].bf );
4415	    break;
4416	 case OPCODE_PUSH_MATRIX:
4417	    (*ctx->Exec->PushMatrix)();
4418	    break;
4419	 case OPCODE_PUSH_NAME:
4420	    (*ctx->Exec->PushName)( n[1].ui );
4421	    break;
4422	 case OPCODE_RASTER_POS:
4423            (*ctx->Exec->RasterPos4f)( n[1].f, n[2].f, n[3].f, n[4].f );
4424	    break;
4425	 case OPCODE_READ_BUFFER:
4426	    (*ctx->Exec->ReadBuffer)( n[1].e );
4427	    break;
4428         case OPCODE_RESET_HISTOGRAM:
4429            (*ctx->Exec->ResetHistogram)( n[1].e );
4430            break;
4431         case OPCODE_RESET_MIN_MAX:
4432            (*ctx->Exec->ResetMinmax)( n[1].e );
4433            break;
4434         case OPCODE_ROTATE:
4435            (*ctx->Exec->Rotatef)( n[1].f, n[2].f, n[3].f, n[4].f );
4436            break;
4437         case OPCODE_SCALE:
4438            (*ctx->Exec->Scalef)( n[1].f, n[2].f, n[3].f );
4439            break;
4440	 case OPCODE_SCISSOR:
4441	    (*ctx->Exec->Scissor)( n[1].i, n[2].i, n[3].i, n[4].i );
4442	    break;
4443	 case OPCODE_SHADE_MODEL:
4444	    (*ctx->Exec->ShadeModel)( n[1].e );
4445	    break;
4446	 case OPCODE_STENCIL_FUNC:
4447	    (*ctx->Exec->StencilFunc)( n[1].e, n[2].i, n[3].ui );
4448	    break;
4449	 case OPCODE_STENCIL_MASK:
4450	    (*ctx->Exec->StencilMask)( n[1].ui );
4451	    break;
4452	 case OPCODE_STENCIL_OP:
4453	    (*ctx->Exec->StencilOp)( n[1].e, n[2].e, n[3].e );
4454	    break;
4455         case OPCODE_TEXENV:
4456            {
4457               GLfloat params[4];
4458               params[0] = n[3].f;
4459               params[1] = n[4].f;
4460               params[2] = n[5].f;
4461               params[3] = n[6].f;
4462               (*ctx->Exec->TexEnvfv)( n[1].e, n[2].e, params );
4463            }
4464            break;
4465         case OPCODE_TEXGEN:
4466            {
4467               GLfloat params[4];
4468               params[0] = n[3].f;
4469               params[1] = n[4].f;
4470               params[2] = n[5].f;
4471               params[3] = n[6].f;
4472               (*ctx->Exec->TexGenfv)( n[1].e, n[2].e, params );
4473            }
4474            break;
4475         case OPCODE_TEXPARAMETER:
4476            {
4477               GLfloat params[4];
4478               params[0] = n[3].f;
4479               params[1] = n[4].f;
4480               params[2] = n[5].f;
4481               params[3] = n[6].f;
4482               (*ctx->Exec->TexParameterfv)( n[1].e, n[2].e, params );
4483            }
4484            break;
4485	 case OPCODE_TEX_IMAGE1D:
4486            {
4487               struct gl_pixelstore_attrib save = ctx->Unpack;
4488               ctx->Unpack = _mesa_native_packing;
4489               (*ctx->Exec->TexImage1D)(
4490                                        n[1].e, /* target */
4491                                        n[2].i, /* level */
4492                                        n[3].i, /* components */
4493                                        n[4].i, /* width */
4494                                        n[5].e, /* border */
4495                                        n[6].e, /* format */
4496                                        n[7].e, /* type */
4497                                        n[8].data );
4498               ctx->Unpack = save;  /* restore */
4499            }
4500	    break;
4501	 case OPCODE_TEX_IMAGE2D:
4502            {
4503               struct gl_pixelstore_attrib save = ctx->Unpack;
4504               ctx->Unpack = _mesa_native_packing;
4505               (*ctx->Exec->TexImage2D)(
4506                                        n[1].e, /* target */
4507                                        n[2].i, /* level */
4508                                        n[3].i, /* components */
4509                                        n[4].i, /* width */
4510                                        n[5].i, /* height */
4511                                        n[6].e, /* border */
4512                                        n[7].e, /* format */
4513                                        n[8].e, /* type */
4514                                        n[9].data );
4515               ctx->Unpack = save;  /* restore */
4516            }
4517	    break;
4518         case OPCODE_TEX_IMAGE3D:
4519            {
4520               struct gl_pixelstore_attrib save = ctx->Unpack;
4521               ctx->Unpack = _mesa_native_packing;
4522               (*ctx->Exec->TexImage3D)(
4523                                        n[1].e, /* target */
4524                                        n[2].i, /* level */
4525                                        n[3].i, /* components */
4526                                        n[4].i, /* width */
4527                                        n[5].i, /* height */
4528                                        n[6].i, /* depth  */
4529                                        n[7].e, /* border */
4530                                        n[8].e, /* format */
4531                                        n[9].e, /* type */
4532                                        n[10].data );
4533               ctx->Unpack = save;  /* restore */
4534            }
4535            break;
4536         case OPCODE_TEX_SUB_IMAGE1D:
4537            {
4538               struct gl_pixelstore_attrib save = ctx->Unpack;
4539               ctx->Unpack = _mesa_native_packing;
4540               (*ctx->Exec->TexSubImage1D)( n[1].e, n[2].i, n[3].i,
4541                                           n[4].i, n[5].e,
4542                                           n[6].e, n[7].data );
4543               ctx->Unpack = save;  /* restore */
4544            }
4545            break;
4546         case OPCODE_TEX_SUB_IMAGE2D:
4547            {
4548               struct gl_pixelstore_attrib save = ctx->Unpack;
4549               ctx->Unpack = _mesa_native_packing;
4550               (*ctx->Exec->TexSubImage2D)( n[1].e, n[2].i, n[3].i,
4551                                           n[4].i, n[5].e,
4552                                           n[6].i, n[7].e, n[8].e, n[9].data );
4553               ctx->Unpack = save;  /* restore */
4554            }
4555            break;
4556         case OPCODE_TEX_SUB_IMAGE3D:
4557            {
4558               struct gl_pixelstore_attrib save = ctx->Unpack;
4559               ctx->Unpack = _mesa_native_packing;
4560               (*ctx->Exec->TexSubImage3D)( n[1].e, n[2].i, n[3].i,
4561                                           n[4].i, n[5].i, n[6].i, n[7].i,
4562                                           n[8].i, n[9].e, n[10].e,
4563                                           n[11].data );
4564               ctx->Unpack = save;  /* restore */
4565            }
4566            break;
4567         case OPCODE_TRANSLATE:
4568            (*ctx->Exec->Translatef)( n[1].f, n[2].f, n[3].f );
4569            break;
4570	 case OPCODE_VIEWPORT:
4571	    (*ctx->Exec->Viewport)(n[1].i, n[2].i,
4572                                  (GLsizei) n[3].i, (GLsizei) n[4].i);
4573	    break;
4574	 case OPCODE_WINDOW_POS:
4575            (*ctx->Exec->WindowPos4fMESA)( n[1].f, n[2].f, n[3].f, n[4].f );
4576	    break;
4577         case OPCODE_ACTIVE_TEXTURE:  /* GL_ARB_multitexture */
4578            (*ctx->Exec->ActiveTextureARB)( n[1].e );
4579            break;
4580         case OPCODE_PIXEL_TEXGEN_SGIX:  /* GL_SGIX_pixel_texture */
4581            (*ctx->Exec->PixelTexGenSGIX)( n[1].e );
4582            break;
4583         case OPCODE_PIXEL_TEXGEN_PARAMETER_SGIS:  /* GL_SGIS_pixel_texture */
4584            (*ctx->Exec->PixelTexGenParameteriSGIS)( n[1].e, n[2].i );
4585            break;
4586         case OPCODE_COMPRESSED_TEX_IMAGE_1D: /* GL_ARB_texture_compression */
4587            (*ctx->Exec->CompressedTexImage1DARB)(n[1].e, n[2].i, n[3].e,
4588                                            n[4].i, n[5].i, n[6].i, n[7].data);
4589            break;
4590         case OPCODE_COMPRESSED_TEX_IMAGE_2D: /* GL_ARB_texture_compression */
4591            (*ctx->Exec->CompressedTexImage2DARB)(n[1].e, n[2].i, n[3].e,
4592                                    n[4].i, n[5].i, n[6].i, n[7].i, n[8].data);
4593            break;
4594         case OPCODE_COMPRESSED_TEX_IMAGE_3D: /* GL_ARB_texture_compression */
4595            (*ctx->Exec->CompressedTexImage3DARB)(n[1].e, n[2].i, n[3].e,
4596                            n[4].i, n[5].i, n[6].i, n[7].i, n[8].i, n[9].data);
4597            break;
4598         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D: /* GL_ARB_texture_compress */
4599            (*ctx->Exec->CompressedTexSubImage1DARB)(n[1].e, n[2].i, n[3].i,
4600                                            n[4].i, n[5].e, n[6].i, n[7].data);
4601            break;
4602         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D: /* GL_ARB_texture_compress */
4603            (*ctx->Exec->CompressedTexSubImage2DARB)(n[1].e, n[2].i, n[3].i,
4604                            n[4].i, n[5].i, n[6].i, n[7].e, n[8].i, n[9].data);
4605            break;
4606         case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D: /* GL_ARB_texture_compress */
4607            (*ctx->Exec->CompressedTexSubImage3DARB)(n[1].e, n[2].i, n[3].i,
4608                                        n[4].i, n[5].i, n[6].i, n[7].i, n[8].i,
4609                                        n[9].e, n[10].i, n[11].data);
4610            break;
4611         case OPCODE_SAMPLE_COVERAGE: /* GL_ARB_multisample */
4612            (*ctx->Exec->SampleCoverageARB)(n[1].f, n[2].b);
4613            break;
4614	 case OPCODE_CONTINUE:
4615	    n = (Node *) n[1].next;
4616	    break;
4617	 case OPCODE_END_OF_LIST:
4618	    done = GL_TRUE;
4619	    break;
4620	 default:
4621            {
4622               char msg[1000];
4623               sprintf(msg, "Error in execute_list: opcode=%d", (int) opcode);
4624               _mesa_problem( ctx, msg );
4625            }
4626            done = GL_TRUE;
4627	 }
4628
4629	 /* increment n to point to next compiled command */
4630	 if (opcode!=OPCODE_CONTINUE) {
4631	    n += InstSize[opcode];
4632	 }
4633      }
4634   }
4635   ctx->CallDepth--;
4636
4637   if (ctx->Driver.EndCallList)
4638      ctx->Driver.EndCallList( ctx );
4639}
4640
4641
4642
4643
4644
4645/**********************************************************************/
4646/*                           GL functions                             */
4647/**********************************************************************/
4648
4649
4650
4651
4652/*
4653 * Test if a display list number is valid.
4654 */
4655GLboolean
4656_mesa_IsList( GLuint list )
4657{
4658   GET_CURRENT_CONTEXT(ctx);
4659   FLUSH_VERTICES(ctx, 0);	/* must be called before assert */
4660   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
4661   return islist(ctx, list);
4662}
4663
4664
4665/*
4666 * Delete a sequence of consecutive display lists.
4667 */
4668void
4669_mesa_DeleteLists( GLuint list, GLsizei range )
4670{
4671   GET_CURRENT_CONTEXT(ctx);
4672   GLuint i;
4673   FLUSH_VERTICES(ctx, 0);	/* must be called before assert */
4674   ASSERT_OUTSIDE_BEGIN_END(ctx);
4675
4676   if (range<0) {
4677      _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteLists" );
4678      return;
4679   }
4680   for (i=list;i<list+range;i++) {
4681      _mesa_destroy_list( ctx, i );
4682   }
4683}
4684
4685
4686
4687/*
4688 * Return a display list number, n, such that lists n through n+range-1
4689 * are free.
4690 */
4691GLuint
4692_mesa_GenLists(GLsizei range )
4693{
4694   GET_CURRENT_CONTEXT(ctx);
4695   GLuint base;
4696   FLUSH_VERTICES(ctx, 0);	/* must be called before assert */
4697   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
4698
4699   if (range<0) {
4700      _mesa_error( ctx, GL_INVALID_VALUE, "glGenLists" );
4701      return 0;
4702   }
4703   if (range==0) {
4704      return 0;
4705   }
4706
4707   /*
4708    * Make this an atomic operation
4709    */
4710   _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
4711
4712   base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
4713   if (base) {
4714      /* reserve the list IDs by with empty/dummy lists */
4715      GLint i;
4716      for (i=0; i<range; i++) {
4717         _mesa_HashInsert(ctx->Shared->DisplayList, base+i, make_empty_list());
4718      }
4719   }
4720
4721   _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
4722
4723   return base;
4724}
4725
4726
4727
4728/*
4729 * Begin a new display list.
4730 */
4731void
4732_mesa_NewList( GLuint list, GLenum mode )
4733{
4734   GET_CURRENT_CONTEXT(ctx);
4735   FLUSH_CURRENT(ctx, 0);	/* must be called before assert */
4736   ASSERT_OUTSIDE_BEGIN_END(ctx);
4737
4738   if (MESA_VERBOSE&VERBOSE_API)
4739      fprintf(stderr, "glNewList %u %s\n", list, _mesa_lookup_enum_by_nr(mode));
4740
4741   if (list==0) {
4742      _mesa_error( ctx, GL_INVALID_VALUE, "glNewList" );
4743      return;
4744   }
4745
4746   if (mode!=GL_COMPILE && mode!=GL_COMPILE_AND_EXECUTE) {
4747      _mesa_error( ctx, GL_INVALID_ENUM, "glNewList" );
4748      return;
4749   }
4750
4751   if (ctx->CurrentListPtr) {
4752      /* already compiling a display list */
4753      _mesa_error( ctx, GL_INVALID_OPERATION, "glNewList" );
4754      return;
4755   }
4756
4757   /* Allocate new display list */
4758   ctx->CurrentListNum = list;
4759   ctx->CurrentBlock = (Node *) MALLOC( sizeof(Node) * BLOCK_SIZE );
4760   ctx->CurrentListPtr = ctx->CurrentBlock;
4761   ctx->CurrentPos = 0;
4762   ctx->CompileFlag = GL_TRUE;
4763   ctx->ExecuteFlag = (mode == GL_COMPILE_AND_EXECUTE);
4764
4765   ctx->Driver.NewList( ctx, list, mode );
4766
4767   ctx->CurrentDispatch = ctx->Save;
4768   _glapi_set_dispatch( ctx->CurrentDispatch );
4769}
4770
4771
4772
4773/*
4774 * End definition of current display list.  Is the current
4775 * ASSERT_OUTSIDE_BEGIN_END strong enough to really guarentee that
4776 * we are outside begin/end calls?
4777 */
4778void
4779_mesa_EndList( void )
4780{
4781   GET_CURRENT_CONTEXT(ctx);
4782   FLUSH_CURRENT(ctx, 0);	/* must be called before assert */
4783   ASSERT_OUTSIDE_BEGIN_END(ctx);
4784   if (MESA_VERBOSE&VERBOSE_API)
4785      fprintf(stderr, "glEndList\n");
4786
4787   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx ); /* ??? */
4788
4789   /* Check that a list is under construction */
4790   if (!ctx->CurrentListPtr) {
4791      _mesa_error( ctx, GL_INVALID_OPERATION, "glEndList" );
4792      return;
4793   }
4794
4795   (void) ALLOC_INSTRUCTION( ctx, OPCODE_END_OF_LIST, 0 );
4796
4797   /* Destroy old list, if any */
4798   _mesa_destroy_list(ctx, ctx->CurrentListNum);
4799   /* Install the list */
4800   _mesa_HashInsert(ctx->Shared->DisplayList, ctx->CurrentListNum, ctx->CurrentListPtr);
4801
4802
4803   if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
4804      mesa_print_display_list(ctx->CurrentListNum);
4805
4806   ctx->CurrentListNum = 0;
4807   ctx->CurrentListPtr = NULL;
4808   ctx->ExecuteFlag = GL_TRUE;
4809   ctx->CompileFlag = GL_FALSE;
4810
4811   ctx->Driver.EndList( ctx );
4812
4813   ctx->CurrentDispatch = ctx->Exec;
4814   _glapi_set_dispatch( ctx->CurrentDispatch );
4815
4816}
4817
4818
4819
4820void
4821_mesa_CallList( GLuint list )
4822{
4823   GLboolean save_compile_flag;
4824   GET_CURRENT_CONTEXT(ctx);
4825   FLUSH_CURRENT(ctx, 0);
4826   /* VERY IMPORTANT:  Save the CompileFlag status, turn it off, */
4827   /* execute the display list, and restore the CompileFlag. */
4828
4829/*     mesa_print_display_list( list ); */
4830
4831   save_compile_flag = ctx->CompileFlag;
4832   if (save_compile_flag) {
4833      ctx->CompileFlag = GL_FALSE;
4834   }
4835
4836   execute_list( ctx, list );
4837   ctx->CompileFlag = save_compile_flag;
4838
4839   /* also restore API function pointers to point to "save" versions */
4840   if (save_compile_flag) {
4841      ctx->CurrentDispatch = ctx->Save;
4842      _glapi_set_dispatch( ctx->CurrentDispatch );
4843   }
4844}
4845
4846
4847
4848/*
4849 * Execute glCallLists:  call multiple display lists.
4850 */
4851void
4852_mesa_CallLists( GLsizei n, GLenum type, const GLvoid *lists )
4853{
4854   GET_CURRENT_CONTEXT(ctx);
4855   GLuint list;
4856   GLint i;
4857   GLboolean save_compile_flag;
4858
4859   /* Save the CompileFlag status, turn it off, execute display list,
4860    * and restore the CompileFlag.
4861    */
4862   save_compile_flag = ctx->CompileFlag;
4863   ctx->CompileFlag = GL_FALSE;
4864
4865   for (i=0;i<n;i++) {
4866      list = translate_id( i, type, lists );
4867      execute_list( ctx, ctx->List.ListBase + list );
4868   }
4869
4870   ctx->CompileFlag = save_compile_flag;
4871
4872   /* also restore API function pointers to point to "save" versions */
4873   if (save_compile_flag) {
4874      ctx->CurrentDispatch = ctx->Save;
4875      _glapi_set_dispatch( ctx->CurrentDispatch );
4876   }
4877}
4878
4879
4880
4881/*
4882 * Set the offset added to list numbers in glCallLists.
4883 */
4884void
4885_mesa_ListBase( GLuint base )
4886{
4887   GET_CURRENT_CONTEXT(ctx);
4888   FLUSH_VERTICES(ctx, 0);	/* must be called before assert */
4889   ASSERT_OUTSIDE_BEGIN_END(ctx);
4890   ctx->List.ListBase = base;
4891}
4892
4893
4894/* Can no longer assume ctx->Exec->Func is equal to _mesa_Func.
4895 */
4896static void exec_Finish( void )
4897{
4898   GET_CURRENT_CONTEXT(ctx);
4899   FLUSH_VERTICES(ctx, 0);
4900   ctx->Exec->Finish();
4901}
4902
4903static void exec_Flush( void )
4904{
4905   GET_CURRENT_CONTEXT(ctx);
4906   FLUSH_VERTICES(ctx, 0);
4907   ctx->Exec->Flush( );
4908}
4909
4910static void exec_GetBooleanv( GLenum pname, GLboolean *params )
4911{
4912   GET_CURRENT_CONTEXT(ctx);
4913   FLUSH_VERTICES(ctx, 0);
4914   ctx->Exec->GetBooleanv( pname, params );
4915}
4916
4917static void exec_GetClipPlane( GLenum plane, GLdouble *equation )
4918{
4919   GET_CURRENT_CONTEXT(ctx);
4920   FLUSH_VERTICES(ctx, 0);
4921   ctx->Exec->GetClipPlane( plane, equation );
4922}
4923
4924static void exec_GetDoublev( GLenum pname, GLdouble *params )
4925{
4926   GET_CURRENT_CONTEXT(ctx);
4927   FLUSH_VERTICES(ctx, 0);
4928   ctx->Exec->GetDoublev(  pname, params );
4929}
4930
4931static GLenum exec_GetError( void )
4932{
4933   GET_CURRENT_CONTEXT(ctx);
4934   FLUSH_VERTICES(ctx, 0);
4935   return ctx->Exec->GetError( );
4936}
4937
4938static void exec_GetFloatv( GLenum pname, GLfloat *params )
4939{
4940   GET_CURRENT_CONTEXT(ctx);
4941   FLUSH_VERTICES(ctx, 0);
4942   ctx->Exec->GetFloatv( pname, params );
4943}
4944
4945static void exec_GetIntegerv( GLenum pname, GLint *params )
4946{
4947   GET_CURRENT_CONTEXT(ctx);
4948   FLUSH_VERTICES(ctx, 0);
4949   ctx->Exec->GetIntegerv( pname, params );
4950}
4951
4952static void exec_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
4953{
4954   GET_CURRENT_CONTEXT(ctx);
4955   FLUSH_VERTICES(ctx, 0);
4956   ctx->Exec->GetLightfv( light, pname, params );
4957}
4958
4959static void exec_GetLightiv( GLenum light, GLenum pname, GLint *params )
4960{
4961   GET_CURRENT_CONTEXT(ctx);
4962   FLUSH_VERTICES(ctx, 0);
4963   ctx->Exec->GetLightiv( light, pname, params );
4964}
4965
4966static void exec_GetMapdv( GLenum target, GLenum query, GLdouble *v )
4967{
4968   GET_CURRENT_CONTEXT(ctx);
4969   FLUSH_VERTICES(ctx, 0);
4970   ctx->Exec->GetMapdv( target, query, v );
4971}
4972
4973static void exec_GetMapfv( GLenum target, GLenum query, GLfloat *v )
4974{
4975   GET_CURRENT_CONTEXT(ctx);
4976   FLUSH_VERTICES(ctx, 0);
4977   ctx->Exec->GetMapfv( target, query, v );
4978}
4979
4980static void exec_GetMapiv( GLenum target, GLenum query, GLint *v )
4981{
4982   GET_CURRENT_CONTEXT(ctx);
4983   FLUSH_VERTICES(ctx, 0);
4984   ctx->Exec->GetMapiv( target, query, v );
4985}
4986
4987static void exec_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
4988{
4989   GET_CURRENT_CONTEXT(ctx);
4990   FLUSH_VERTICES(ctx, 0);
4991   ctx->Exec->GetMaterialfv( face, pname, params );
4992}
4993
4994static void exec_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
4995{
4996   GET_CURRENT_CONTEXT(ctx);
4997   FLUSH_VERTICES(ctx, 0);
4998   ctx->Exec->GetMaterialiv( face, pname, params );
4999}
5000
5001static void exec_GetPixelMapfv( GLenum map, GLfloat *values )
5002{
5003   GET_CURRENT_CONTEXT(ctx);
5004   FLUSH_VERTICES(ctx, 0);
5005   ctx->Exec->GetPixelMapfv( map,  values );
5006}
5007
5008static void exec_GetPixelMapuiv( GLenum map, GLuint *values )
5009{
5010   GET_CURRENT_CONTEXT(ctx);
5011   FLUSH_VERTICES(ctx, 0);
5012   ctx->Exec->GetPixelMapuiv( map, values );
5013}
5014
5015static void exec_GetPixelMapusv( GLenum map, GLushort *values )
5016{
5017   GET_CURRENT_CONTEXT(ctx);
5018   FLUSH_VERTICES(ctx, 0);
5019   ctx->Exec->GetPixelMapusv( map, values );
5020}
5021
5022static void exec_GetPolygonStipple( GLubyte *dest )
5023{
5024   GET_CURRENT_CONTEXT(ctx);
5025   FLUSH_VERTICES(ctx, 0);
5026   ctx->Exec->GetPolygonStipple( dest );
5027}
5028
5029static const GLubyte *exec_GetString( GLenum name )
5030{
5031   GET_CURRENT_CONTEXT(ctx);
5032   FLUSH_VERTICES(ctx, 0);
5033   return ctx->Exec->GetString( name );
5034}
5035
5036static void exec_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
5037{
5038   GET_CURRENT_CONTEXT(ctx);
5039   FLUSH_VERTICES(ctx, 0);
5040   ctx->Exec->GetTexEnvfv( target, pname, params );
5041}
5042
5043static void exec_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
5044{
5045   GET_CURRENT_CONTEXT(ctx);
5046   FLUSH_VERTICES(ctx, 0);
5047   ctx->Exec->GetTexEnviv( target, pname, params );
5048}
5049
5050static void exec_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
5051{
5052   GET_CURRENT_CONTEXT(ctx);
5053   FLUSH_VERTICES(ctx, 0);
5054   ctx->Exec->GetTexGendv( coord, pname, params );
5055}
5056
5057static void exec_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
5058{
5059   GET_CURRENT_CONTEXT(ctx);
5060   FLUSH_VERTICES(ctx, 0);
5061   ctx->Exec->GetTexGenfv( coord, pname, params );
5062}
5063
5064static void exec_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
5065{
5066   GET_CURRENT_CONTEXT(ctx);
5067   FLUSH_VERTICES(ctx, 0);
5068   ctx->Exec->GetTexGeniv( coord, pname, params );
5069}
5070
5071static void exec_GetTexImage( GLenum target, GLint level, GLenum format,
5072                   GLenum type, GLvoid *pixels )
5073{
5074   GET_CURRENT_CONTEXT(ctx);
5075   FLUSH_VERTICES(ctx, 0);
5076   ctx->Exec->GetTexImage( target, level, format, type, pixels );
5077}
5078
5079static void exec_GetTexLevelParameterfv( GLenum target, GLint level,
5080                              GLenum pname, GLfloat *params )
5081{
5082   GET_CURRENT_CONTEXT(ctx);
5083   FLUSH_VERTICES(ctx, 0);
5084   ctx->Exec->GetTexLevelParameterfv( target, level, pname, params );
5085}
5086
5087static void exec_GetTexLevelParameteriv( GLenum target, GLint level,
5088                              GLenum pname, GLint *params )
5089{
5090   GET_CURRENT_CONTEXT(ctx);
5091   FLUSH_VERTICES(ctx, 0);
5092   ctx->Exec->GetTexLevelParameteriv( target, level, pname, params );
5093}
5094
5095static void exec_GetTexParameterfv( GLenum target, GLenum pname,
5096				    GLfloat *params )
5097{
5098   GET_CURRENT_CONTEXT(ctx);
5099   FLUSH_VERTICES(ctx, 0);
5100   ctx->Exec->GetTexParameterfv( target, pname, params );
5101}
5102
5103static void exec_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
5104{
5105   GET_CURRENT_CONTEXT(ctx);
5106   FLUSH_VERTICES(ctx, 0);
5107   ctx->Exec->GetTexParameteriv( target, pname, params );
5108}
5109
5110static GLboolean exec_IsEnabled( GLenum cap )
5111{
5112   GET_CURRENT_CONTEXT(ctx);
5113   FLUSH_VERTICES(ctx, 0);
5114   return ctx->Exec->IsEnabled( cap );
5115}
5116
5117static void exec_PixelStoref( GLenum pname, GLfloat param )
5118{
5119   GET_CURRENT_CONTEXT(ctx);
5120   FLUSH_VERTICES(ctx, 0);
5121   ctx->Exec->PixelStoref( pname, param );
5122}
5123
5124static void exec_PixelStorei( GLenum pname, GLint param )
5125{
5126   GET_CURRENT_CONTEXT(ctx);
5127   FLUSH_VERTICES(ctx, 0);
5128   ctx->Exec->PixelStorei( pname, param );
5129}
5130
5131static void exec_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
5132		  GLenum format, GLenum type, GLvoid *pixels )
5133{
5134   GET_CURRENT_CONTEXT(ctx);
5135   FLUSH_VERTICES(ctx, 0);
5136   ctx->Exec->ReadPixels( x, y, width, height, format, type, pixels );
5137}
5138
5139static GLint exec_RenderMode( GLenum mode )
5140{
5141   GET_CURRENT_CONTEXT(ctx);
5142   FLUSH_VERTICES(ctx, 0);
5143   return ctx->Exec->RenderMode( mode );
5144}
5145
5146static void exec_FeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer )
5147{
5148   GET_CURRENT_CONTEXT(ctx);
5149   FLUSH_VERTICES(ctx, 0);
5150   ctx->Exec->FeedbackBuffer( size, type, buffer );
5151}
5152
5153static void exec_SelectBuffer( GLsizei size, GLuint *buffer )
5154{
5155   GET_CURRENT_CONTEXT(ctx);
5156   FLUSH_VERTICES(ctx, 0);
5157   ctx->Exec->SelectBuffer( size, buffer );
5158}
5159
5160static GLboolean exec_AreTexturesResident(GLsizei n, const GLuint *texName,
5161					  GLboolean *residences)
5162{
5163   GET_CURRENT_CONTEXT(ctx);
5164   FLUSH_VERTICES(ctx, 0);
5165   return ctx->Exec->AreTexturesResident( n, texName, residences);
5166}
5167
5168static void exec_ColorPointer(GLint size, GLenum type, GLsizei stride,
5169			      const GLvoid *ptr)
5170{
5171   GET_CURRENT_CONTEXT(ctx);
5172   FLUSH_VERTICES(ctx, 0);
5173   ctx->Exec->ColorPointer( size, type, stride, ptr);
5174}
5175
5176static void exec_DeleteTextures( GLsizei n, const GLuint *texName)
5177{
5178   GET_CURRENT_CONTEXT(ctx);
5179   FLUSH_VERTICES(ctx, 0);
5180   ctx->Exec->DeleteTextures( n, texName);
5181}
5182
5183static void exec_DisableClientState( GLenum cap )
5184{
5185   GET_CURRENT_CONTEXT(ctx);
5186   FLUSH_VERTICES(ctx, 0);
5187   ctx->Exec->DisableClientState( cap );
5188}
5189
5190static void exec_EdgeFlagPointer(GLsizei stride, const void *vptr)
5191{
5192   GET_CURRENT_CONTEXT(ctx);
5193   FLUSH_VERTICES(ctx, 0);
5194   ctx->Exec->EdgeFlagPointer( stride, vptr);
5195}
5196
5197static void exec_EnableClientState( GLenum cap )
5198{
5199   GET_CURRENT_CONTEXT(ctx);
5200   FLUSH_VERTICES(ctx, 0);
5201   ctx->Exec->EnableClientState( cap );
5202}
5203
5204static void exec_GenTextures( GLsizei n, GLuint *texName )
5205{
5206   GET_CURRENT_CONTEXT(ctx);
5207   FLUSH_VERTICES(ctx, 0);
5208   ctx->Exec->GenTextures( n, texName );
5209}
5210
5211static void exec_GetPointerv( GLenum pname, GLvoid **params )
5212{
5213   GET_CURRENT_CONTEXT(ctx);
5214   FLUSH_VERTICES(ctx, 0);
5215   ctx->Exec->GetPointerv( pname, params );
5216}
5217
5218static void exec_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
5219{
5220   GET_CURRENT_CONTEXT(ctx);
5221   FLUSH_VERTICES(ctx, 0);
5222   ctx->Exec->IndexPointer( type, stride, ptr);
5223}
5224
5225static void exec_InterleavedArrays(GLenum format, GLsizei stride,
5226				   const GLvoid *pointer)
5227{
5228   GET_CURRENT_CONTEXT(ctx);
5229   FLUSH_VERTICES(ctx, 0);
5230   ctx->Exec->InterleavedArrays( format, stride, pointer);
5231}
5232
5233static GLboolean exec_IsTexture( GLuint texture )
5234{
5235   GET_CURRENT_CONTEXT(ctx);
5236   FLUSH_VERTICES(ctx, 0);
5237   return ctx->Exec->IsTexture( texture );
5238}
5239
5240static void exec_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
5241{
5242   GET_CURRENT_CONTEXT(ctx);
5243   FLUSH_VERTICES(ctx, 0);
5244   ctx->Exec->NormalPointer( type, stride, ptr );
5245}
5246
5247static void exec_PopClientAttrib(void)
5248{
5249   GET_CURRENT_CONTEXT(ctx);
5250   FLUSH_VERTICES(ctx, 0);
5251   ctx->Exec->PopClientAttrib();
5252}
5253
5254static void exec_PushClientAttrib(GLbitfield mask)
5255{
5256   GET_CURRENT_CONTEXT(ctx);
5257   FLUSH_VERTICES(ctx, 0);
5258   ctx->Exec->PushClientAttrib( mask);
5259}
5260
5261static void exec_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
5262				 const GLvoid *ptr)
5263{
5264   GET_CURRENT_CONTEXT(ctx);
5265   FLUSH_VERTICES(ctx, 0);
5266   ctx->Exec->TexCoordPointer( size,  type,  stride, ptr);
5267}
5268
5269static void exec_GetCompressedTexImageARB(GLenum target, GLint level,
5270					  GLvoid *img)
5271{
5272   GET_CURRENT_CONTEXT(ctx);
5273   FLUSH_VERTICES(ctx, 0);
5274   ctx->Exec->GetCompressedTexImageARB( target, level, img);
5275}
5276
5277static void exec_VertexPointer(GLint size, GLenum type, GLsizei stride,
5278			       const GLvoid *ptr)
5279{
5280   GET_CURRENT_CONTEXT(ctx);
5281   FLUSH_VERTICES(ctx, 0);
5282   ctx->Exec->VertexPointer( size, type, stride, ptr);
5283}
5284
5285static void exec_CopyConvolutionFilter1D(GLenum target, GLenum internalFormat,
5286					 GLint x, GLint y, GLsizei width)
5287{
5288   GET_CURRENT_CONTEXT(ctx);
5289   FLUSH_VERTICES(ctx, 0);
5290   ctx->Exec->CopyConvolutionFilter1D( target, internalFormat, x, y, width);
5291}
5292
5293static void exec_CopyConvolutionFilter2D(GLenum target, GLenum internalFormat,
5294					 GLint x, GLint y, GLsizei width,
5295					 GLsizei height)
5296{
5297   GET_CURRENT_CONTEXT(ctx);
5298   FLUSH_VERTICES(ctx, 0);
5299   ctx->Exec->CopyConvolutionFilter2D( target, internalFormat, x, y, width,
5300				       height);
5301}
5302
5303static void exec_GetColorTable( GLenum target, GLenum format,
5304				GLenum type, GLvoid *data )
5305{
5306   GET_CURRENT_CONTEXT(ctx);
5307   FLUSH_VERTICES(ctx, 0);
5308   ctx->Exec->GetColorTable( target, format, type, data );
5309}
5310
5311static void exec_GetColorTableParameterfv( GLenum target, GLenum pname,
5312					   GLfloat *params )
5313{
5314   GET_CURRENT_CONTEXT(ctx);
5315   FLUSH_VERTICES(ctx, 0);
5316   ctx->Exec->GetColorTableParameterfv( target, pname, params );
5317}
5318
5319static void exec_GetColorTableParameteriv( GLenum target, GLenum pname,
5320					   GLint *params )
5321{
5322   GET_CURRENT_CONTEXT(ctx);
5323   FLUSH_VERTICES(ctx, 0);
5324   ctx->Exec->GetColorTableParameteriv( target, pname, params );
5325}
5326
5327static void exec_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
5328				      GLvoid *image)
5329{
5330   GET_CURRENT_CONTEXT(ctx);
5331   FLUSH_VERTICES(ctx, 0);
5332   ctx->Exec->GetConvolutionFilter( target, format, type, image);
5333}
5334
5335static void exec_GetConvolutionParameterfv(GLenum target, GLenum pname,
5336					   GLfloat *params)
5337{
5338   GET_CURRENT_CONTEXT(ctx);
5339   FLUSH_VERTICES(ctx, 0);
5340   ctx->Exec->GetConvolutionParameterfv( target, pname, params);
5341}
5342
5343static void exec_GetConvolutionParameteriv(GLenum target, GLenum pname,
5344					   GLint *params)
5345{
5346   GET_CURRENT_CONTEXT(ctx);
5347   FLUSH_VERTICES(ctx, 0);
5348   ctx->Exec->GetConvolutionParameteriv( target, pname, params);
5349}
5350
5351static void exec_GetHistogram(GLenum target, GLboolean reset, GLenum format,
5352			      GLenum type, GLvoid *values)
5353{
5354   GET_CURRENT_CONTEXT(ctx);
5355   FLUSH_VERTICES(ctx, 0);
5356   ctx->Exec->GetHistogram( target, reset, format, type, values);
5357}
5358
5359static void exec_GetHistogramParameterfv(GLenum target, GLenum pname,
5360					 GLfloat *params)
5361{
5362   GET_CURRENT_CONTEXT(ctx);
5363   FLUSH_VERTICES(ctx, 0);
5364   ctx->Exec->GetHistogramParameterfv( target, pname, params);
5365}
5366
5367static void exec_GetHistogramParameteriv(GLenum target, GLenum pname,
5368					 GLint *params)
5369{
5370   GET_CURRENT_CONTEXT(ctx);
5371   FLUSH_VERTICES(ctx, 0);
5372   ctx->Exec->GetHistogramParameteriv( target, pname, params);
5373}
5374
5375static void exec_GetMinmax(GLenum target, GLboolean reset, GLenum format,
5376			   GLenum type, GLvoid *values)
5377{
5378   GET_CURRENT_CONTEXT(ctx);
5379   FLUSH_VERTICES(ctx, 0);
5380   ctx->Exec->GetMinmax( target, reset, format, type, values);
5381}
5382
5383static void exec_GetMinmaxParameterfv(GLenum target, GLenum pname,
5384				      GLfloat *params)
5385{
5386   GET_CURRENT_CONTEXT(ctx);
5387   FLUSH_VERTICES(ctx, 0);
5388   ctx->Exec->GetMinmaxParameterfv( target, pname, params);
5389}
5390
5391static void exec_GetMinmaxParameteriv(GLenum target, GLenum pname,
5392				      GLint *params)
5393{
5394   GET_CURRENT_CONTEXT(ctx);
5395   FLUSH_VERTICES(ctx, 0);
5396   ctx->Exec->GetMinmaxParameteriv( target, pname, params);
5397}
5398
5399static void exec_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
5400				    GLvoid *row, GLvoid *column, GLvoid *span)
5401{
5402   GET_CURRENT_CONTEXT(ctx);
5403   FLUSH_VERTICES(ctx, 0);
5404   ctx->Exec->GetSeparableFilter( target, format, type, row, column, span);
5405}
5406
5407static void exec_SeparableFilter2D(GLenum target, GLenum internalFormat,
5408				   GLsizei width, GLsizei height, GLenum format,
5409				   GLenum type, const GLvoid *row,
5410				   const GLvoid *column)
5411{
5412   GET_CURRENT_CONTEXT(ctx);
5413   FLUSH_VERTICES(ctx, 0);
5414   ctx->Exec->SeparableFilter2D( target, internalFormat, width, height, format,
5415				 type, row, column);
5416}
5417
5418static void exec_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
5419{
5420   GET_CURRENT_CONTEXT(ctx);
5421   FLUSH_VERTICES(ctx, 0);
5422   ctx->Exec->GetPixelTexGenParameterivSGIS( target, value);
5423}
5424
5425static void exec_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
5426{
5427   GET_CURRENT_CONTEXT(ctx);
5428   FLUSH_VERTICES(ctx, 0);
5429   ctx->Exec->GetPixelTexGenParameterfvSGIS( target, value);
5430}
5431
5432static void exec_ColorPointerEXT(GLint size, GLenum type, GLsizei stride,
5433				 GLsizei count, const GLvoid *ptr)
5434{
5435   GET_CURRENT_CONTEXT(ctx);
5436   FLUSH_VERTICES(ctx, 0);
5437   ctx->Exec->ColorPointerEXT( size, type, stride, count, ptr);
5438}
5439
5440static void exec_EdgeFlagPointerEXT(GLsizei stride, GLsizei count,
5441				    const GLboolean *ptr)
5442{
5443   GET_CURRENT_CONTEXT(ctx);
5444   FLUSH_VERTICES(ctx, 0);
5445   ctx->Exec->EdgeFlagPointerEXT( stride, count, ptr);
5446}
5447
5448static void exec_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
5449                      const GLvoid *ptr)
5450{
5451   GET_CURRENT_CONTEXT(ctx);
5452   FLUSH_VERTICES(ctx, 0);
5453   ctx->Exec->IndexPointerEXT( type, stride, count, ptr);
5454}
5455
5456static void exec_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
5457                       const GLvoid *ptr)
5458{
5459   GET_CURRENT_CONTEXT(ctx);
5460   FLUSH_VERTICES(ctx, 0);
5461   ctx->Exec->NormalPointerEXT( type, stride, count, ptr);
5462}
5463
5464static void exec_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
5465				    GLsizei count, const GLvoid *ptr)
5466{
5467   GET_CURRENT_CONTEXT(ctx);
5468   FLUSH_VERTICES(ctx, 0);
5469   ctx->Exec->TexCoordPointerEXT( size, type, stride, count, ptr);
5470}
5471
5472static void exec_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
5473                       GLsizei count, const GLvoid *ptr)
5474{
5475   GET_CURRENT_CONTEXT(ctx);
5476   FLUSH_VERTICES(ctx, 0);
5477   ctx->Exec->VertexPointerEXT( size, type, stride, count, ptr);
5478}
5479
5480static void exec_LockArraysEXT(GLint first, GLsizei count)
5481{
5482   GET_CURRENT_CONTEXT(ctx);
5483   FLUSH_VERTICES(ctx, 0);
5484   ctx->Exec->LockArraysEXT( first, count);
5485}
5486
5487static void exec_UnlockArraysEXT( void )
5488{
5489   GET_CURRENT_CONTEXT(ctx);
5490   FLUSH_VERTICES(ctx, 0);
5491   ctx->Exec->UnlockArraysEXT( );
5492}
5493
5494static void exec_ResizeBuffersMESA( void )
5495{
5496   GET_CURRENT_CONTEXT(ctx);
5497   FLUSH_VERTICES(ctx, 0);
5498   ctx->Exec->ResizeBuffersMESA( );
5499}
5500
5501
5502static void exec_ClientActiveTextureARB( GLenum target )
5503{
5504   GET_CURRENT_CONTEXT(ctx);
5505   FLUSH_VERTICES(ctx, 0);
5506   ctx->Exec->ClientActiveTextureARB(target);
5507}
5508
5509static void exec_SecondaryColorPointerEXT(GLint size, GLenum type,
5510			       GLsizei stride, const GLvoid *ptr)
5511{
5512   GET_CURRENT_CONTEXT(ctx);
5513   FLUSH_VERTICES(ctx, 0);
5514   ctx->Exec->SecondaryColorPointerEXT( size, type, stride, ptr);
5515}
5516
5517static void exec_FogCoordPointerEXT(GLenum type, GLsizei stride,
5518				    const GLvoid *ptr)
5519{
5520   GET_CURRENT_CONTEXT(ctx);
5521   FLUSH_VERTICES(ctx, 0);
5522   ctx->Exec->FogCoordPointerEXT( type, stride, ptr);
5523}
5524
5525
5526/*
5527 * Assign all the pointers in <table> to point to Mesa's display list
5528 * building functions.
5529 *
5530 * This does not include any of the tnl functions - they are
5531 * initialized from _mesa_init_api_defaults and from the active vtxfmt
5532 * struct.
5533 */
5534void
5535_mesa_init_dlist_table( struct _glapi_table *table, GLuint tableSize )
5536{
5537   _mesa_init_no_op_table(table, tableSize);
5538
5539   _mesa_loopback_init_api_table( table, GL_TRUE );
5540
5541   /* GL 1.0 */
5542   table->Accum = save_Accum;
5543   table->AlphaFunc = save_AlphaFunc;
5544   table->Bitmap = save_Bitmap;
5545   table->BlendFunc = save_BlendFunc;
5546   table->CallList = _mesa_save_CallList;
5547   table->CallLists = _mesa_save_CallLists;
5548   table->Clear = save_Clear;
5549   table->ClearAccum = save_ClearAccum;
5550   table->ClearColor = save_ClearColor;
5551   table->ClearDepth = save_ClearDepth;
5552   table->ClearIndex = save_ClearIndex;
5553   table->ClearStencil = save_ClearStencil;
5554   table->ClipPlane = save_ClipPlane;
5555   table->ColorMask = save_ColorMask;
5556   table->ColorMaterial = save_ColorMaterial;
5557   table->CopyPixels = save_CopyPixels;
5558   table->CullFace = save_CullFace;
5559   table->DeleteLists = _mesa_DeleteLists;
5560   table->DepthFunc = save_DepthFunc;
5561   table->DepthMask = save_DepthMask;
5562   table->DepthRange = save_DepthRange;
5563   table->Disable = save_Disable;
5564   table->DrawBuffer = save_DrawBuffer;
5565   table->DrawPixels = save_DrawPixels;
5566   table->Enable = save_Enable;
5567   table->EndList = _mesa_EndList;
5568   table->EvalMesh1 = _mesa_save_EvalMesh1;
5569   table->EvalMesh2 = _mesa_save_EvalMesh2;
5570   table->Finish = exec_Finish;
5571   table->Flush = exec_Flush;
5572   table->Fogf = save_Fogf;
5573   table->Fogfv = save_Fogfv;
5574   table->Fogi = save_Fogi;
5575   table->Fogiv = save_Fogiv;
5576   table->FrontFace = save_FrontFace;
5577   table->Frustum = save_Frustum;
5578   table->GenLists = _mesa_GenLists;
5579   table->GetBooleanv = exec_GetBooleanv;
5580   table->GetClipPlane = exec_GetClipPlane;
5581   table->GetDoublev = exec_GetDoublev;
5582   table->GetError = exec_GetError;
5583   table->GetFloatv = exec_GetFloatv;
5584   table->GetIntegerv = exec_GetIntegerv;
5585   table->GetLightfv = exec_GetLightfv;
5586   table->GetLightiv = exec_GetLightiv;
5587   table->GetMapdv = exec_GetMapdv;
5588   table->GetMapfv = exec_GetMapfv;
5589   table->GetMapiv = exec_GetMapiv;
5590   table->GetMaterialfv = exec_GetMaterialfv;
5591   table->GetMaterialiv = exec_GetMaterialiv;
5592   table->GetPixelMapfv = exec_GetPixelMapfv;
5593   table->GetPixelMapuiv = exec_GetPixelMapuiv;
5594   table->GetPixelMapusv = exec_GetPixelMapusv;
5595   table->GetPolygonStipple = exec_GetPolygonStipple;
5596   table->GetString = exec_GetString;
5597   table->GetTexEnvfv = exec_GetTexEnvfv;
5598   table->GetTexEnviv = exec_GetTexEnviv;
5599   table->GetTexGendv = exec_GetTexGendv;
5600   table->GetTexGenfv = exec_GetTexGenfv;
5601   table->GetTexGeniv = exec_GetTexGeniv;
5602   table->GetTexImage = exec_GetTexImage;
5603   table->GetTexLevelParameterfv = exec_GetTexLevelParameterfv;
5604   table->GetTexLevelParameteriv = exec_GetTexLevelParameteriv;
5605   table->GetTexParameterfv = exec_GetTexParameterfv;
5606   table->GetTexParameteriv = exec_GetTexParameteriv;
5607   table->Hint = save_Hint;
5608   table->IndexMask = save_IndexMask;
5609   table->InitNames = save_InitNames;
5610   table->IsEnabled = exec_IsEnabled;
5611   table->IsList = _mesa_IsList;
5612   table->LightModelf = save_LightModelf;
5613   table->LightModelfv = save_LightModelfv;
5614   table->LightModeli = save_LightModeli;
5615   table->LightModeliv = save_LightModeliv;
5616   table->Lightf = save_Lightf;
5617   table->Lightfv = save_Lightfv;
5618   table->Lighti = save_Lighti;
5619   table->Lightiv = save_Lightiv;
5620   table->LineStipple = save_LineStipple;
5621   table->LineWidth = save_LineWidth;
5622   table->ListBase = save_ListBase;
5623   table->LoadIdentity = save_LoadIdentity;
5624   table->LoadMatrixd = save_LoadMatrixd;
5625   table->LoadMatrixf = save_LoadMatrixf;
5626   table->LoadName = save_LoadName;
5627   table->LogicOp = save_LogicOp;
5628   table->Map1d = save_Map1d;
5629   table->Map1f = save_Map1f;
5630   table->Map2d = save_Map2d;
5631   table->Map2f = save_Map2f;
5632   table->MapGrid1d = save_MapGrid1d;
5633   table->MapGrid1f = save_MapGrid1f;
5634   table->MapGrid2d = save_MapGrid2d;
5635   table->MapGrid2f = save_MapGrid2f;
5636   table->MatrixMode = save_MatrixMode;
5637   table->MultMatrixd = save_MultMatrixd;
5638   table->MultMatrixf = save_MultMatrixf;
5639   table->NewList = save_NewList;
5640   table->Ortho = save_Ortho;
5641   table->PassThrough = save_PassThrough;
5642   table->PixelMapfv = save_PixelMapfv;
5643   table->PixelMapuiv = save_PixelMapuiv;
5644   table->PixelMapusv = save_PixelMapusv;
5645   table->PixelStoref = exec_PixelStoref;
5646   table->PixelStorei = exec_PixelStorei;
5647   table->PixelTransferf = save_PixelTransferf;
5648   table->PixelTransferi = save_PixelTransferi;
5649   table->PixelZoom = save_PixelZoom;
5650   table->PointSize = save_PointSize;
5651   table->PolygonMode = save_PolygonMode;
5652   table->PolygonOffset = save_PolygonOffset;
5653   table->PolygonStipple = save_PolygonStipple;
5654   table->PopAttrib = save_PopAttrib;
5655   table->PopMatrix = save_PopMatrix;
5656   table->PopName = save_PopName;
5657   table->PushAttrib = save_PushAttrib;
5658   table->PushMatrix = save_PushMatrix;
5659   table->PushName = save_PushName;
5660   table->RasterPos2d = save_RasterPos2d;
5661   table->RasterPos2dv = save_RasterPos2dv;
5662   table->RasterPos2f = save_RasterPos2f;
5663   table->RasterPos2fv = save_RasterPos2fv;
5664   table->RasterPos2i = save_RasterPos2i;
5665   table->RasterPos2iv = save_RasterPos2iv;
5666   table->RasterPos2s = save_RasterPos2s;
5667   table->RasterPos2sv = save_RasterPos2sv;
5668   table->RasterPos3d = save_RasterPos3d;
5669   table->RasterPos3dv = save_RasterPos3dv;
5670   table->RasterPos3f = save_RasterPos3f;
5671   table->RasterPos3fv = save_RasterPos3fv;
5672   table->RasterPos3i = save_RasterPos3i;
5673   table->RasterPos3iv = save_RasterPos3iv;
5674   table->RasterPos3s = save_RasterPos3s;
5675   table->RasterPos3sv = save_RasterPos3sv;
5676   table->RasterPos4d = save_RasterPos4d;
5677   table->RasterPos4dv = save_RasterPos4dv;
5678   table->RasterPos4f = save_RasterPos4f;
5679   table->RasterPos4fv = save_RasterPos4fv;
5680   table->RasterPos4i = save_RasterPos4i;
5681   table->RasterPos4iv = save_RasterPos4iv;
5682   table->RasterPos4s = save_RasterPos4s;
5683   table->RasterPos4sv = save_RasterPos4sv;
5684   table->ReadBuffer = save_ReadBuffer;
5685   table->ReadPixels = exec_ReadPixels;
5686   table->RenderMode = exec_RenderMode;
5687   table->Rotated = save_Rotated;
5688   table->Rotatef = save_Rotatef;
5689   table->Scaled = save_Scaled;
5690   table->Scalef = save_Scalef;
5691   table->Scissor = save_Scissor;
5692   table->FeedbackBuffer = exec_FeedbackBuffer;
5693   table->SelectBuffer = exec_SelectBuffer;
5694   table->ShadeModel = save_ShadeModel;
5695   table->StencilFunc = save_StencilFunc;
5696   table->StencilMask = save_StencilMask;
5697   table->StencilOp = save_StencilOp;
5698   table->TexEnvf = save_TexEnvf;
5699   table->TexEnvfv = save_TexEnvfv;
5700   table->TexEnvi = save_TexEnvi;
5701   table->TexEnviv = save_TexEnviv;
5702   table->TexGend = save_TexGend;
5703   table->TexGendv = save_TexGendv;
5704   table->TexGenf = save_TexGenf;
5705   table->TexGenfv = save_TexGenfv;
5706   table->TexGeni = save_TexGeni;
5707   table->TexGeniv = save_TexGeniv;
5708   table->TexImage1D = save_TexImage1D;
5709   table->TexImage2D = save_TexImage2D;
5710   table->TexParameterf = save_TexParameterf;
5711   table->TexParameterfv = save_TexParameterfv;
5712   table->TexParameteri = save_TexParameteri;
5713   table->TexParameteriv = save_TexParameteriv;
5714   table->Translated = save_Translated;
5715   table->Translatef = save_Translatef;
5716   table->Viewport = save_Viewport;
5717
5718   /* GL 1.1 */
5719   table->AreTexturesResident = exec_AreTexturesResident;
5720   table->BindTexture = save_BindTexture;
5721   table->ColorPointer = exec_ColorPointer;
5722   table->CopyTexImage1D = save_CopyTexImage1D;
5723   table->CopyTexImage2D = save_CopyTexImage2D;
5724   table->CopyTexSubImage1D = save_CopyTexSubImage1D;
5725   table->CopyTexSubImage2D = save_CopyTexSubImage2D;
5726   table->DeleteTextures = exec_DeleteTextures;
5727   table->DisableClientState = exec_DisableClientState;
5728   table->EdgeFlagPointer = exec_EdgeFlagPointer;
5729   table->EnableClientState = exec_EnableClientState;
5730   table->GenTextures = exec_GenTextures;
5731   table->GetPointerv = exec_GetPointerv;
5732   table->IndexPointer = exec_IndexPointer;
5733   table->InterleavedArrays = exec_InterleavedArrays;
5734   table->IsTexture = exec_IsTexture;
5735   table->NormalPointer = exec_NormalPointer;
5736   table->PopClientAttrib = exec_PopClientAttrib;
5737   table->PrioritizeTextures = save_PrioritizeTextures;
5738   table->PushClientAttrib = exec_PushClientAttrib;
5739   table->TexCoordPointer = exec_TexCoordPointer;
5740   table->TexSubImage1D = save_TexSubImage1D;
5741   table->TexSubImage2D = save_TexSubImage2D;
5742   table->VertexPointer = exec_VertexPointer;
5743
5744   /* GL 1.2 */
5745   table->CopyTexSubImage3D = save_CopyTexSubImage3D;
5746   table->TexImage3D = save_TexImage3D;
5747   table->TexSubImage3D = save_TexSubImage3D;
5748
5749   /* GL_ARB_imaging */
5750   /* Not all are supported */
5751   table->BlendColor = save_BlendColor;
5752   table->BlendEquation = save_BlendEquation;
5753   table->ColorSubTable = save_ColorSubTable;
5754   table->ColorTable = save_ColorTable;
5755   table->ColorTableParameterfv = save_ColorTableParameterfv;
5756   table->ColorTableParameteriv = save_ColorTableParameteriv;
5757   table->ConvolutionFilter1D = save_ConvolutionFilter1D;
5758   table->ConvolutionFilter2D = save_ConvolutionFilter2D;
5759   table->ConvolutionParameterf = save_ConvolutionParameterf;
5760   table->ConvolutionParameterfv = save_ConvolutionParameterfv;
5761   table->ConvolutionParameteri = save_ConvolutionParameteri;
5762   table->ConvolutionParameteriv = save_ConvolutionParameteriv;
5763   table->CopyColorSubTable = save_CopyColorSubTable;
5764   table->CopyColorTable = save_CopyColorTable;
5765   table->CopyConvolutionFilter1D = exec_CopyConvolutionFilter1D;
5766   table->CopyConvolutionFilter2D = exec_CopyConvolutionFilter2D;
5767   table->GetColorTable = exec_GetColorTable;
5768   table->GetColorTableParameterfv = exec_GetColorTableParameterfv;
5769   table->GetColorTableParameteriv = exec_GetColorTableParameteriv;
5770   table->GetConvolutionFilter = exec_GetConvolutionFilter;
5771   table->GetConvolutionParameterfv = exec_GetConvolutionParameterfv;
5772   table->GetConvolutionParameteriv = exec_GetConvolutionParameteriv;
5773   table->GetHistogram = exec_GetHistogram;
5774   table->GetHistogramParameterfv = exec_GetHistogramParameterfv;
5775   table->GetHistogramParameteriv = exec_GetHistogramParameteriv;
5776   table->GetMinmax = exec_GetMinmax;
5777   table->GetMinmaxParameterfv = exec_GetMinmaxParameterfv;
5778   table->GetMinmaxParameteriv = exec_GetMinmaxParameteriv;
5779   table->GetSeparableFilter = exec_GetSeparableFilter;
5780   table->Histogram = save_Histogram;
5781   table->Minmax = save_Minmax;
5782   table->ResetHistogram = save_ResetHistogram;
5783   table->ResetMinmax = save_ResetMinmax;
5784   table->SeparableFilter2D = exec_SeparableFilter2D;
5785
5786   /* 2. GL_EXT_blend_color */
5787#if 0
5788   table->BlendColorEXT = save_BlendColorEXT;
5789#endif
5790
5791   /* 3. GL_EXT_polygon_offset */
5792   table->PolygonOffsetEXT = save_PolygonOffsetEXT;
5793
5794   /* 6. GL_EXT_texture3d */
5795#if 0
5796   table->CopyTexSubImage3DEXT = save_CopyTexSubImage3D;
5797   table->TexImage3DEXT = save_TexImage3DEXT;
5798   table->TexSubImage3DEXT = save_TexSubImage3D;
5799#endif
5800
5801   /* 15. GL_SGIX_pixel_texture */
5802   table->PixelTexGenSGIX = save_PixelTexGenSGIX;
5803
5804   /* 15. GL_SGIS_pixel_texture */
5805   table->PixelTexGenParameteriSGIS = save_PixelTexGenParameteriSGIS;
5806   table->PixelTexGenParameterfSGIS = save_PixelTexGenParameterfSGIS;
5807   table->PixelTexGenParameterivSGIS = save_PixelTexGenParameterivSGIS;
5808   table->PixelTexGenParameterfvSGIS = save_PixelTexGenParameterfvSGIS;
5809   table->GetPixelTexGenParameterivSGIS = exec_GetPixelTexGenParameterivSGIS;
5810   table->GetPixelTexGenParameterfvSGIS = exec_GetPixelTexGenParameterfvSGIS;
5811
5812   /* 30. GL_EXT_vertex_array */
5813   table->ColorPointerEXT = exec_ColorPointerEXT;
5814   table->EdgeFlagPointerEXT = exec_EdgeFlagPointerEXT;
5815   table->IndexPointerEXT = exec_IndexPointerEXT;
5816   table->NormalPointerEXT = exec_NormalPointerEXT;
5817   table->TexCoordPointerEXT = exec_TexCoordPointerEXT;
5818   table->VertexPointerEXT = exec_VertexPointerEXT;
5819
5820   /* 37. GL_EXT_blend_minmax */
5821#if 0
5822   table->BlendEquationEXT = save_BlendEquationEXT;
5823#endif
5824
5825   /* 54. GL_EXT_point_parameters */
5826   table->PointParameterfEXT = save_PointParameterfEXT;
5827   table->PointParameterfvEXT = save_PointParameterfvEXT;
5828
5829   /* 78. GL_EXT_paletted_texture */
5830#if 0
5831   table->ColorTableEXT = save_ColorTable;
5832   table->ColorSubTableEXT = save_ColorSubTable;
5833#endif
5834   table->GetColorTableEXT = exec_GetColorTable;
5835   table->GetColorTableParameterfvEXT = exec_GetColorTableParameterfv;
5836   table->GetColorTableParameterivEXT = exec_GetColorTableParameteriv;
5837
5838   /* 97. GL_EXT_compiled_vertex_array */
5839   table->LockArraysEXT = exec_LockArraysEXT;
5840   table->UnlockArraysEXT = exec_UnlockArraysEXT;
5841
5842   /* GL_ARB_multitexture */
5843   table->ActiveTextureARB = save_ActiveTextureARB;
5844   table->ClientActiveTextureARB = exec_ClientActiveTextureARB;
5845
5846   /* GL_EXT_blend_func_separate */
5847   table->BlendFuncSeparateEXT = save_BlendFuncSeparateEXT;
5848
5849   /* GL_MESA_window_pos */
5850   table->WindowPos2dMESA = save_WindowPos2dMESA;
5851   table->WindowPos2dvMESA = save_WindowPos2dvMESA;
5852   table->WindowPos2fMESA = save_WindowPos2fMESA;
5853   table->WindowPos2fvMESA = save_WindowPos2fvMESA;
5854   table->WindowPos2iMESA = save_WindowPos2iMESA;
5855   table->WindowPos2ivMESA = save_WindowPos2ivMESA;
5856   table->WindowPos2sMESA = save_WindowPos2sMESA;
5857   table->WindowPos2svMESA = save_WindowPos2svMESA;
5858   table->WindowPos3dMESA = save_WindowPos3dMESA;
5859   table->WindowPos3dvMESA = save_WindowPos3dvMESA;
5860   table->WindowPos3fMESA = save_WindowPos3fMESA;
5861   table->WindowPos3fvMESA = save_WindowPos3fvMESA;
5862   table->WindowPos3iMESA = save_WindowPos3iMESA;
5863   table->WindowPos3ivMESA = save_WindowPos3ivMESA;
5864   table->WindowPos3sMESA = save_WindowPos3sMESA;
5865   table->WindowPos3svMESA = save_WindowPos3svMESA;
5866   table->WindowPos4dMESA = save_WindowPos4dMESA;
5867   table->WindowPos4dvMESA = save_WindowPos4dvMESA;
5868   table->WindowPos4fMESA = save_WindowPos4fMESA;
5869   table->WindowPos4fvMESA = save_WindowPos4fvMESA;
5870   table->WindowPos4iMESA = save_WindowPos4iMESA;
5871   table->WindowPos4ivMESA = save_WindowPos4ivMESA;
5872   table->WindowPos4sMESA = save_WindowPos4sMESA;
5873   table->WindowPos4svMESA = save_WindowPos4svMESA;
5874
5875   /* GL_MESA_resize_buffers */
5876   table->ResizeBuffersMESA = exec_ResizeBuffersMESA;
5877
5878   /* GL_ARB_transpose_matrix */
5879   table->LoadTransposeMatrixdARB = save_LoadTransposeMatrixdARB;
5880   table->LoadTransposeMatrixfARB = save_LoadTransposeMatrixfARB;
5881   table->MultTransposeMatrixdARB = save_MultTransposeMatrixdARB;
5882   table->MultTransposeMatrixfARB = save_MultTransposeMatrixfARB;
5883
5884   /* GL_ARB_multisample */
5885   table->SampleCoverageARB = save_SampleCoverageARB;
5886
5887   /* ARB 12. GL_ARB_texture_compression */
5888   table->CompressedTexImage3DARB = save_CompressedTexImage3DARB;
5889   table->CompressedTexImage2DARB = save_CompressedTexImage2DARB;
5890   table->CompressedTexImage1DARB = save_CompressedTexImage1DARB;
5891   table->CompressedTexSubImage3DARB = save_CompressedTexSubImage3DARB;
5892   table->CompressedTexSubImage2DARB = save_CompressedTexSubImage2DARB;
5893   table->CompressedTexSubImage1DARB = save_CompressedTexSubImage1DARB;
5894   table->GetCompressedTexImageARB = exec_GetCompressedTexImageARB;
5895
5896   /* GL_EXT_secondary_color */
5897   table->SecondaryColorPointerEXT = exec_SecondaryColorPointerEXT;
5898
5899   /* GL_EXT_fog_coord */
5900   table->FogCoordPointerEXT = exec_FogCoordPointerEXT;
5901}
5902
5903
5904
5905/***
5906 *** Debugging code
5907 ***/
5908static const char *enum_string( GLenum k )
5909{
5910   return _mesa_lookup_enum_by_nr( k );
5911}
5912
5913
5914/*
5915 * Print the commands in a display list.  For debugging only.
5916 * TODO: many commands aren't handled yet.
5917 */
5918static void print_list( GLcontext *ctx, FILE *f, GLuint list )
5919{
5920   Node *n;
5921   GLboolean done;
5922
5923   if (!glIsList(list)) {
5924      fprintf(f,"%u is not a display list ID\n",list);
5925      return;
5926   }
5927
5928   n = (Node *) _mesa_HashLookup(ctx->Shared->DisplayList, list);
5929
5930   fprintf( f, "START-LIST %u, address %p\n", list, (void*)n );
5931
5932   done = n ? GL_FALSE : GL_TRUE;
5933   while (!done) {
5934      OpCode opcode = n[0].opcode;
5935      GLint i = (GLint) n[0].opcode - (GLint) OPCODE_DRV_0;
5936
5937      if (i >= 0 && i < (GLint) ctx->listext.nr_opcodes) {
5938	 ctx->listext.opcode[i].print(ctx, &n[1]);
5939	 n += ctx->listext.opcode[i].size;
5940      }
5941      else {
5942	 switch (opcode) {
5943         case OPCODE_ACCUM:
5944            fprintf(f,"accum %s %g\n", enum_string(n[1].e), n[2].f );
5945	    break;
5946	 case OPCODE_BITMAP:
5947            fprintf(f,"Bitmap %d %d %g %g %g %g %p\n", n[1].i, n[2].i,
5948		       n[3].f, n[4].f, n[5].f, n[6].f, (void *) n[7].data );
5949	    break;
5950         case OPCODE_CALL_LIST:
5951            fprintf(f,"CallList %d\n", (int) n[1].ui );
5952            break;
5953         case OPCODE_CALL_LIST_OFFSET:
5954            fprintf(f,"CallList %d + offset %u = %u\n", (int) n[1].ui,
5955                    ctx->List.ListBase, ctx->List.ListBase + n[1].ui );
5956            break;
5957         case OPCODE_COLOR_TABLE_PARAMETER_FV:
5958            fprintf(f,"ColorTableParameterfv %s %s %f %f %f %f\n",
5959                    enum_string(n[1].e), enum_string(n[2].e),
5960                    n[3].f, n[4].f, n[5].f, n[6].f);
5961            break;
5962         case OPCODE_COLOR_TABLE_PARAMETER_IV:
5963            fprintf(f,"ColorTableParameteriv %s %s %d %d %d %d\n",
5964                    enum_string(n[1].e), enum_string(n[2].e),
5965                    n[3].i, n[4].i, n[5].i, n[6].i);
5966            break;
5967	 case OPCODE_DISABLE:
5968            fprintf(f,"Disable %s\n", enum_string(n[1].e));
5969	    break;
5970	 case OPCODE_ENABLE:
5971            fprintf(f,"Enable %s\n", enum_string(n[1].e));
5972	    break;
5973         case OPCODE_FRUSTUM:
5974            fprintf(f,"Frustum %g %g %g %g %g %g\n",
5975                    n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f );
5976            break;
5977	 case OPCODE_LINE_STIPPLE:
5978	    fprintf(f,"LineStipple %d %x\n", n[1].i, (int) n[2].us );
5979	    break;
5980	 case OPCODE_LOAD_IDENTITY:
5981            fprintf(f,"LoadIdentity\n");
5982	    break;
5983	 case OPCODE_LOAD_MATRIX:
5984            fprintf(f,"LoadMatrix\n");
5985            fprintf(f,"  %8f %8f %8f %8f\n", n[1].f, n[5].f,  n[9].f, n[13].f);
5986            fprintf(f,"  %8f %8f %8f %8f\n", n[2].f, n[6].f, n[10].f, n[14].f);
5987            fprintf(f,"  %8f %8f %8f %8f\n", n[3].f, n[7].f, n[11].f, n[15].f);
5988            fprintf(f,"  %8f %8f %8f %8f\n", n[4].f, n[8].f, n[12].f, n[16].f);
5989	    break;
5990	 case OPCODE_MULT_MATRIX:
5991            fprintf(f,"MultMatrix (or Rotate)\n");
5992            fprintf(f,"  %8f %8f %8f %8f\n", n[1].f, n[5].f,  n[9].f, n[13].f);
5993            fprintf(f,"  %8f %8f %8f %8f\n", n[2].f, n[6].f, n[10].f, n[14].f);
5994            fprintf(f,"  %8f %8f %8f %8f\n", n[3].f, n[7].f, n[11].f, n[15].f);
5995            fprintf(f,"  %8f %8f %8f %8f\n", n[4].f, n[8].f, n[12].f, n[16].f);
5996	    break;
5997         case OPCODE_ORTHO:
5998            fprintf(f,"Ortho %g %g %g %g %g %g\n",
5999                    n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f );
6000            break;
6001	 case OPCODE_POP_ATTRIB:
6002            fprintf(f,"PopAttrib\n");
6003	    break;
6004	 case OPCODE_POP_MATRIX:
6005            fprintf(f,"PopMatrix\n");
6006	    break;
6007	 case OPCODE_POP_NAME:
6008            fprintf(f,"PopName\n");
6009	    break;
6010	 case OPCODE_PUSH_ATTRIB:
6011            fprintf(f,"PushAttrib %x\n", n[1].bf );
6012	    break;
6013	 case OPCODE_PUSH_MATRIX:
6014            fprintf(f,"PushMatrix\n");
6015	    break;
6016	 case OPCODE_PUSH_NAME:
6017            fprintf(f,"PushName %d\n", (int) n[1].ui );
6018	    break;
6019	 case OPCODE_RASTER_POS:
6020            fprintf(f,"RasterPos %g %g %g %g\n", n[1].f, n[2].f,n[3].f,n[4].f);
6021	    break;
6022         case OPCODE_ROTATE:
6023            fprintf(f,"Rotate %g %g %g %g\n", n[1].f, n[2].f, n[3].f, n[4].f );
6024            break;
6025         case OPCODE_SCALE:
6026            fprintf(f,"Scale %g %g %g\n", n[1].f, n[2].f, n[3].f );
6027            break;
6028         case OPCODE_TRANSLATE:
6029            fprintf(f,"Translate %g %g %g\n", n[1].f, n[2].f, n[3].f );
6030            break;
6031         case OPCODE_BIND_TEXTURE:
6032	    fprintf(f,"BindTexture %s %d\n", _mesa_lookup_enum_by_nr(n[1].ui),
6033		    n[2].ui);
6034	    break;
6035         case OPCODE_SHADE_MODEL:
6036	    fprintf(f,"ShadeModel %s\n", _mesa_lookup_enum_by_nr(n[1].ui));
6037	    break;
6038	 case OPCODE_MAP1:
6039	    fprintf(f,"Map1 %s %.3f %.3f %d %d\n",
6040		    _mesa_lookup_enum_by_nr(n[1].ui),
6041		    n[2].f, n[3].f, n[4].i, n[5].i);
6042	    break;
6043	 case OPCODE_MAP2:
6044	    fprintf(f,"Map2 %s %.3f %.3f %.3f %.3f %d %d %d %d\n",
6045		    _mesa_lookup_enum_by_nr(n[1].ui),
6046		    n[2].f, n[3].f, n[4].f, n[5].f,
6047		    n[6].i, n[7].i, n[8].i, n[9].i);
6048	    break;
6049	 case OPCODE_MAPGRID1:
6050	    fprintf(f,"MapGrid1 %d %.3f %.3f\n", n[1].i, n[2].f, n[3].f);
6051	    break;
6052	 case OPCODE_MAPGRID2:
6053	    fprintf(f,"MapGrid2 %d %.3f %.3f, %d %.3f %.3f\n",
6054		    n[1].i, n[2].f, n[3].f,
6055		    n[4].i, n[5].f, n[6].f);
6056	    break;
6057	 case OPCODE_EVALMESH1:
6058	    fprintf(f,"EvalMesh1 %d %d\n", n[1].i, n[2].i);
6059	    break;
6060	 case OPCODE_EVALMESH2:
6061	    fprintf(f,"EvalMesh2 %d %d %d %d\n",
6062		    n[1].i, n[2].i, n[3].i, n[4].i);
6063	    break;
6064
6065	 /*
6066	  * meta opcodes/commands
6067	  */
6068         case OPCODE_ERROR:
6069            fprintf(f,"Error: %s %s\n", enum_string(n[1].e), (const char *)n[2].data );
6070            break;
6071	 case OPCODE_CONTINUE:
6072            fprintf(f,"DISPLAY-LIST-CONTINUE\n");
6073	    n = (Node *) n[1].next;
6074	    break;
6075	 case OPCODE_END_OF_LIST:
6076            fprintf(f,"END-LIST %u\n", list);
6077	    done = GL_TRUE;
6078	    break;
6079         default:
6080            if (opcode < 0 || opcode > OPCODE_END_OF_LIST) {
6081               fprintf(f,"ERROR IN DISPLAY LIST: opcode = %d, address = %p\n",
6082                       opcode, (void*) n);
6083               return;
6084            }
6085            else {
6086               fprintf(f,"command %d, %u operands\n",opcode,InstSize[opcode]);
6087            }
6088	 }
6089	 /* increment n to point to next compiled command */
6090	 if (opcode!=OPCODE_CONTINUE) {
6091	    n += InstSize[opcode];
6092	 }
6093      }
6094   }
6095}
6096
6097
6098
6099/*
6100 * Clients may call this function to help debug display list problems.
6101 * This function is _ONLY_FOR_DEBUGGING_PURPOSES_.  It may be removed,
6102 * changed, or break in the future without notice.
6103 */
6104void mesa_print_display_list( GLuint list )
6105{
6106   GET_CURRENT_CONTEXT(ctx);
6107   print_list( ctx, stderr, list );
6108}
6109