7ed966556e3ede3ecb6e0c4826d57f2f3f7fbbbb
[platform/upstream/mesa.git] / src / mesa / main / dlist.c
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.7
4  *
5  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26
27 /**
28  * \file dlist.c
29  * Display lists management functions.
30  */
31
32 #include "glheader.h"
33 #include "imports.h"
34 #include "api_arrayelt.h"
35 #include "api_exec.h"
36 #include "api_loopback.h"
37 #include "api_validate.h"
38 #if FEATURE_ATI_fragment_shader
39 #include "atifragshader.h"
40 #endif
41 #include "config.h"
42 #include "mfeatures.h"
43 #include "bufferobj.h"
44 #include "arrayobj.h"
45 #include "context.h"
46 #include "dlist.h"
47 #include "enums.h"
48 #include "eval.h"
49 #include "fbobject.h"
50 #include "framebuffer.h"
51 #include "glapi/glapi.h"
52 #include "glformats.h"
53 #include "hash.h"
54 #include "image.h"
55 #include "light.h"
56 #include "macros.h"
57 #include "pack.h"
58 #include "pbo.h"
59 #include "queryobj.h"
60 #include "samplerobj.h"
61 #include "shaderapi.h"
62 #include "syncobj.h"
63 #include "teximage.h"
64 #include "texstorage.h"
65 #include "mtypes.h"
66 #include "varray.h"
67 #include "arbprogram.h"
68 #include "nvprogram.h"
69 #include "transformfeedback.h"
70
71 #include "math/m_matrix.h"
72
73 #include "main/dispatch.h"
74
75
76
77 /**
78  * Other parts of Mesa (such as the VBO module) can plug into the display
79  * list system.  This structure describes new display list instructions.
80  */
81 struct gl_list_instruction
82 {
83    GLuint Size;
84    void (*Execute)( struct gl_context *ctx, void *data );
85    void (*Destroy)( struct gl_context *ctx, void *data );
86    void (*Print)( struct gl_context *ctx, void *data );
87 };
88
89
90 #define MAX_DLIST_EXT_OPCODES 16
91
92 /**
93  * Used by device drivers to hook new commands into display lists.
94  */
95 struct gl_list_extensions
96 {
97    struct gl_list_instruction Opcode[MAX_DLIST_EXT_OPCODES];
98    GLuint NumOpcodes;
99 };
100
101
102
103 /**
104  * Flush vertices.
105  *
106  * \param ctx GL context.
107  *
108  * Checks if dd_function_table::SaveNeedFlush is marked to flush
109  * stored (save) vertices, and calls
110  * dd_function_table::SaveFlushVertices if so.
111  */
112 #define SAVE_FLUSH_VERTICES(ctx)                \
113 do {                                            \
114    if (ctx->Driver.SaveNeedFlush)               \
115       ctx->Driver.SaveFlushVertices(ctx);       \
116 } while (0)
117
118
119 /**
120  * Macro to assert that the API call was made outside the
121  * glBegin()/glEnd() pair, with return value.
122  * 
123  * \param ctx GL context.
124  * \param retval value to return value in case the assertion fails.
125  */
126 #define ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval)          \
127 do {                                                                    \
128    if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON ||                \
129        ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) {  \
130       _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glBegin/End" );  \
131       return retval;                                                    \
132    }                                                                    \
133 } while (0)
134
135 /**
136  * Macro to assert that the API call was made outside the
137  * glBegin()/glEnd() pair.
138  * 
139  * \param ctx GL context.
140  */
141 #define ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx)                              \
142 do {                                                                    \
143    if (ctx->Driver.CurrentSavePrimitive <= GL_POLYGON ||                \
144        ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM) {  \
145       _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glBegin/End" );  \
146       return;                                                           \
147    }                                                                    \
148 } while (0)
149
150 /**
151  * Macro to assert that the API call was made outside the
152  * glBegin()/glEnd() pair and flush the vertices.
153  * 
154  * \param ctx GL context.
155  */
156 #define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx)                    \
157 do {                                                                    \
158    ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx);                                  \
159    SAVE_FLUSH_VERTICES(ctx);                                            \
160 } while (0)
161
162 /**
163  * Macro to assert that the API call was made outside the
164  * glBegin()/glEnd() pair and flush the vertices, with return value.
165  * 
166  * \param ctx GL context.
167  * \param retval value to return value in case the assertion fails.
168  */
169 #define ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)\
170 do {                                                                    \
171    ASSERT_OUTSIDE_SAVE_BEGIN_END_WITH_RETVAL(ctx, retval);              \
172    SAVE_FLUSH_VERTICES(ctx);                                            \
173 } while (0)
174
175
176
177 /**
178  * Display list opcodes.
179  *
180  * The fact that these identifiers are assigned consecutive
181  * integer values starting at 0 is very important, see InstSize array usage)
182  */
183 typedef enum
184 {
185    OPCODE_INVALID = -1,         /* Force signed enum */
186    OPCODE_ACCUM,
187    OPCODE_ALPHA_FUNC,
188    OPCODE_BIND_TEXTURE,
189    OPCODE_BITMAP,
190    OPCODE_BLEND_COLOR,
191    OPCODE_BLEND_EQUATION,
192    OPCODE_BLEND_EQUATION_SEPARATE,
193    OPCODE_BLEND_FUNC_SEPARATE,
194
195    OPCODE_BLEND_EQUATION_I,
196    OPCODE_BLEND_EQUATION_SEPARATE_I,
197    OPCODE_BLEND_FUNC_I,
198    OPCODE_BLEND_FUNC_SEPARATE_I,
199
200    OPCODE_CALL_LIST,
201    OPCODE_CALL_LIST_OFFSET,
202    OPCODE_CLEAR,
203    OPCODE_CLEAR_ACCUM,
204    OPCODE_CLEAR_COLOR,
205    OPCODE_CLEAR_DEPTH,
206    OPCODE_CLEAR_INDEX,
207    OPCODE_CLEAR_STENCIL,
208    OPCODE_CLEAR_BUFFER_IV,
209    OPCODE_CLEAR_BUFFER_UIV,
210    OPCODE_CLEAR_BUFFER_FV,
211    OPCODE_CLEAR_BUFFER_FI,
212    OPCODE_CLIP_PLANE,
213    OPCODE_COLOR_MASK,
214    OPCODE_COLOR_MASK_INDEXED,
215    OPCODE_COLOR_MATERIAL,
216    OPCODE_COLOR_TABLE,
217    OPCODE_COLOR_TABLE_PARAMETER_FV,
218    OPCODE_COLOR_TABLE_PARAMETER_IV,
219    OPCODE_COLOR_SUB_TABLE,
220    OPCODE_CONVOLUTION_FILTER_1D,
221    OPCODE_CONVOLUTION_FILTER_2D,
222    OPCODE_CONVOLUTION_PARAMETER_I,
223    OPCODE_CONVOLUTION_PARAMETER_IV,
224    OPCODE_CONVOLUTION_PARAMETER_F,
225    OPCODE_CONVOLUTION_PARAMETER_FV,
226    OPCODE_COPY_COLOR_SUB_TABLE,
227    OPCODE_COPY_COLOR_TABLE,
228    OPCODE_COPY_PIXELS,
229    OPCODE_COPY_TEX_IMAGE1D,
230    OPCODE_COPY_TEX_IMAGE2D,
231    OPCODE_COPY_TEX_SUB_IMAGE1D,
232    OPCODE_COPY_TEX_SUB_IMAGE2D,
233    OPCODE_COPY_TEX_SUB_IMAGE3D,
234    OPCODE_CULL_FACE,
235    OPCODE_DEPTH_FUNC,
236    OPCODE_DEPTH_MASK,
237    OPCODE_DEPTH_RANGE,
238    OPCODE_DISABLE,
239    OPCODE_DISABLE_INDEXED,
240    OPCODE_DRAW_BUFFER,
241    OPCODE_DRAW_PIXELS,
242    OPCODE_ENABLE,
243    OPCODE_ENABLE_INDEXED,
244    OPCODE_EVALMESH1,
245    OPCODE_EVALMESH2,
246    OPCODE_FOG,
247    OPCODE_FRONT_FACE,
248    OPCODE_FRUSTUM,
249    OPCODE_HINT,
250    OPCODE_HISTOGRAM,
251    OPCODE_INDEX_MASK,
252    OPCODE_INIT_NAMES,
253    OPCODE_LIGHT,
254    OPCODE_LIGHT_MODEL,
255    OPCODE_LINE_STIPPLE,
256    OPCODE_LINE_WIDTH,
257    OPCODE_LIST_BASE,
258    OPCODE_LOAD_IDENTITY,
259    OPCODE_LOAD_MATRIX,
260    OPCODE_LOAD_NAME,
261    OPCODE_LOGIC_OP,
262    OPCODE_MAP1,
263    OPCODE_MAP2,
264    OPCODE_MAPGRID1,
265    OPCODE_MAPGRID2,
266    OPCODE_MATRIX_MODE,
267    OPCODE_MIN_MAX,
268    OPCODE_MULT_MATRIX,
269    OPCODE_ORTHO,
270    OPCODE_PASSTHROUGH,
271    OPCODE_PIXEL_MAP,
272    OPCODE_PIXEL_TRANSFER,
273    OPCODE_PIXEL_ZOOM,
274    OPCODE_POINT_SIZE,
275    OPCODE_POINT_PARAMETERS,
276    OPCODE_POLYGON_MODE,
277    OPCODE_POLYGON_STIPPLE,
278    OPCODE_POLYGON_OFFSET,
279    OPCODE_POP_ATTRIB,
280    OPCODE_POP_MATRIX,
281    OPCODE_POP_NAME,
282    OPCODE_PRIORITIZE_TEXTURE,
283    OPCODE_PUSH_ATTRIB,
284    OPCODE_PUSH_MATRIX,
285    OPCODE_PUSH_NAME,
286    OPCODE_RASTER_POS,
287    OPCODE_READ_BUFFER,
288    OPCODE_RESET_HISTOGRAM,
289    OPCODE_RESET_MIN_MAX,
290    OPCODE_ROTATE,
291    OPCODE_SCALE,
292    OPCODE_SCISSOR,
293    OPCODE_SELECT_TEXTURE_SGIS,
294    OPCODE_SELECT_TEXTURE_COORD_SET,
295    OPCODE_SHADE_MODEL,
296    OPCODE_STENCIL_FUNC,
297    OPCODE_STENCIL_MASK,
298    OPCODE_STENCIL_OP,
299    OPCODE_TEXENV,
300    OPCODE_TEXGEN,
301    OPCODE_TEXPARAMETER,
302    OPCODE_TEX_IMAGE1D,
303    OPCODE_TEX_IMAGE2D,
304    OPCODE_TEX_IMAGE3D,
305    OPCODE_TEX_SUB_IMAGE1D,
306    OPCODE_TEX_SUB_IMAGE2D,
307    OPCODE_TEX_SUB_IMAGE3D,
308    OPCODE_TRANSLATE,
309    OPCODE_VIEWPORT,
310    OPCODE_WINDOW_POS,
311    /* GL_ARB_multitexture */
312    OPCODE_ACTIVE_TEXTURE,
313    /* GL_ARB_texture_compression */
314    OPCODE_COMPRESSED_TEX_IMAGE_1D,
315    OPCODE_COMPRESSED_TEX_IMAGE_2D,
316    OPCODE_COMPRESSED_TEX_IMAGE_3D,
317    OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D,
318    OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D,
319    OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D,
320    /* GL_ARB_multisample */
321    OPCODE_SAMPLE_COVERAGE,
322    /* GL_ARB_window_pos */
323    OPCODE_WINDOW_POS_ARB,
324    /* GL_NV_vertex_program */
325    OPCODE_BIND_PROGRAM_NV,
326    OPCODE_EXECUTE_PROGRAM_NV,
327    OPCODE_REQUEST_RESIDENT_PROGRAMS_NV,
328    OPCODE_LOAD_PROGRAM_NV,
329    OPCODE_TRACK_MATRIX_NV,
330    /* GL_NV_fragment_program */
331    OPCODE_PROGRAM_LOCAL_PARAMETER_ARB,
332    OPCODE_PROGRAM_NAMED_PARAMETER_NV,
333    /* GL_EXT_stencil_two_side */
334    OPCODE_ACTIVE_STENCIL_FACE_EXT,
335    /* GL_EXT_depth_bounds_test */
336    OPCODE_DEPTH_BOUNDS_EXT,
337    /* GL_ARB_vertex/fragment_program */
338    OPCODE_PROGRAM_STRING_ARB,
339    OPCODE_PROGRAM_ENV_PARAMETER_ARB,
340    /* GL_ARB_occlusion_query */
341    OPCODE_BEGIN_QUERY_ARB,
342    OPCODE_END_QUERY_ARB,
343    /* GL_ARB_draw_buffers */
344    OPCODE_DRAW_BUFFERS_ARB,
345    /* GL_ATI_fragment_shader */
346    OPCODE_TEX_BUMP_PARAMETER_ATI,
347    /* GL_ATI_fragment_shader */
348    OPCODE_BIND_FRAGMENT_SHADER_ATI,
349    OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI,
350    /* OpenGL 2.0 */
351    OPCODE_STENCIL_FUNC_SEPARATE,
352    OPCODE_STENCIL_OP_SEPARATE,
353    OPCODE_STENCIL_MASK_SEPARATE,
354
355    /* GL_ARB_shader_objects */
356    OPCODE_USE_PROGRAM,
357    OPCODE_UNIFORM_1F,
358    OPCODE_UNIFORM_2F,
359    OPCODE_UNIFORM_3F,
360    OPCODE_UNIFORM_4F,
361    OPCODE_UNIFORM_1FV,
362    OPCODE_UNIFORM_2FV,
363    OPCODE_UNIFORM_3FV,
364    OPCODE_UNIFORM_4FV,
365    OPCODE_UNIFORM_1I,
366    OPCODE_UNIFORM_2I,
367    OPCODE_UNIFORM_3I,
368    OPCODE_UNIFORM_4I,
369    OPCODE_UNIFORM_1IV,
370    OPCODE_UNIFORM_2IV,
371    OPCODE_UNIFORM_3IV,
372    OPCODE_UNIFORM_4IV,
373    OPCODE_UNIFORM_MATRIX22,
374    OPCODE_UNIFORM_MATRIX33,
375    OPCODE_UNIFORM_MATRIX44,
376    OPCODE_UNIFORM_MATRIX23,
377    OPCODE_UNIFORM_MATRIX32,
378    OPCODE_UNIFORM_MATRIX24,
379    OPCODE_UNIFORM_MATRIX42,
380    OPCODE_UNIFORM_MATRIX34,
381    OPCODE_UNIFORM_MATRIX43,
382
383    /* OpenGL 3.0 */
384    OPCODE_UNIFORM_1UI,
385    OPCODE_UNIFORM_2UI,
386    OPCODE_UNIFORM_3UI,
387    OPCODE_UNIFORM_4UI,
388    OPCODE_UNIFORM_1UIV,
389    OPCODE_UNIFORM_2UIV,
390    OPCODE_UNIFORM_3UIV,
391    OPCODE_UNIFORM_4UIV,
392
393    /* GL_ARB_color_buffer_float */
394    OPCODE_CLAMP_COLOR,
395
396    /* GL_EXT_framebuffer_blit */
397    OPCODE_BLIT_FRAMEBUFFER,
398
399    /* Vertex attributes -- fallback for when optimized display
400     * list build isn't active.
401     */
402    OPCODE_ATTR_1F_NV,
403    OPCODE_ATTR_2F_NV,
404    OPCODE_ATTR_3F_NV,
405    OPCODE_ATTR_4F_NV,
406    OPCODE_ATTR_1F_ARB,
407    OPCODE_ATTR_2F_ARB,
408    OPCODE_ATTR_3F_ARB,
409    OPCODE_ATTR_4F_ARB,
410    OPCODE_MATERIAL,
411    OPCODE_BEGIN,
412    OPCODE_END,
413    OPCODE_RECTF,
414    OPCODE_EVAL_C1,
415    OPCODE_EVAL_C2,
416    OPCODE_EVAL_P1,
417    OPCODE_EVAL_P2,
418
419    /* GL_EXT_provoking_vertex */
420    OPCODE_PROVOKING_VERTEX,
421
422    /* GL_EXT_transform_feedback */
423    OPCODE_BEGIN_TRANSFORM_FEEDBACK,
424    OPCODE_END_TRANSFORM_FEEDBACK,
425    OPCODE_BIND_TRANSFORM_FEEDBACK,
426    OPCODE_PAUSE_TRANSFORM_FEEDBACK,
427    OPCODE_RESUME_TRANSFORM_FEEDBACK,
428    OPCODE_DRAW_TRANSFORM_FEEDBACK,
429
430    /* GL_EXT_texture_integer */
431    OPCODE_CLEARCOLOR_I,
432    OPCODE_CLEARCOLOR_UI,
433    OPCODE_TEXPARAMETER_I,
434    OPCODE_TEXPARAMETER_UI,
435
436    /* GL_EXT_separate_shader_objects */
437    OPCODE_ACTIVE_PROGRAM_EXT,
438    OPCODE_USE_SHADER_PROGRAM_EXT,
439
440    /* GL_ARB_instanced_arrays */
441    OPCODE_VERTEX_ATTRIB_DIVISOR,
442
443    /* GL_NV_texture_barrier */
444    OPCODE_TEXTURE_BARRIER_NV,
445
446    /* GL_ARB_sampler_object */
447    OPCODE_BIND_SAMPLER,
448    OPCODE_SAMPLER_PARAMETERIV,
449    OPCODE_SAMPLER_PARAMETERFV,
450    OPCODE_SAMPLER_PARAMETERIIV,
451    OPCODE_SAMPLER_PARAMETERUIV,
452
453    /* GL_ARB_geometry_shader4 */
454    OPCODE_PROGRAM_PARAMETERI,
455    OPCODE_FRAMEBUFFER_TEXTURE,
456    OPCODE_FRAMEBUFFER_TEXTURE_FACE,
457
458    /* GL_ARB_sync */
459    OPCODE_WAIT_SYNC,
460
461    /* GL_NV_conditional_render */
462    OPCODE_BEGIN_CONDITIONAL_RENDER,
463    OPCODE_END_CONDITIONAL_RENDER,
464
465    /* ARB_timer_query */
466    OPCODE_QUERY_COUNTER,
467
468    /* ARB_transform_feedback3 */
469    OPCODE_BEGIN_QUERY_INDEXED,
470    OPCODE_END_QUERY_INDEXED,
471    OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM,
472
473    /* ARB_transform_feedback_instanced */
474    OPCODE_DRAW_TRANSFORM_FEEDBACK_INSTANCED,
475    OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM_INSTANCED,
476
477    /* ARB_uniform_buffer_object */
478    OPCODE_UNIFORM_BLOCK_BINDING,
479
480    /* The following three are meta instructions */
481    OPCODE_ERROR,                /* raise compiled-in error */
482    OPCODE_CONTINUE,
483    OPCODE_END_OF_LIST,
484    OPCODE_EXT_0
485 } OpCode;
486
487
488
489 /**
490  * Display list node.
491  *
492  * Display list instructions are stored as sequences of "nodes".  Nodes
493  * are allocated in blocks.  Each block has BLOCK_SIZE nodes.  Blocks
494  * are linked together with a pointer.
495  *
496  * Each instruction in the display list is stored as a sequence of
497  * contiguous nodes in memory.
498  * Each node is the union of a variety of data types.
499  */
500 union gl_dlist_node
501 {
502    OpCode opcode;
503    GLboolean b;
504    GLbitfield bf;
505    GLubyte ub;
506    GLshort s;
507    GLushort us;
508    GLint i;
509    GLuint ui;
510    GLenum e;
511    GLfloat f;
512    GLsizei si;
513    GLvoid *data;
514    void *next;                  /* If prev node's opcode==OPCODE_CONTINUE */
515 };
516
517
518 typedef union gl_dlist_node Node;
519
520
521 /**
522  * Used to store a 64-bit uint in a pair of "Nodes" for the sake of 32-bit
523  * environment.  In 64-bit env, sizeof(Node)==8 anyway.
524  */
525 union uint64_pair
526 {
527    GLuint64 uint64;
528    GLuint uint32[2];
529 };
530
531
532 /**
533  * How many nodes to allocate at a time.
534  *
535  * \note Reduced now that we hold vertices etc. elsewhere.
536  */
537 #define BLOCK_SIZE 256
538
539
540
541 /**
542  * Number of nodes of storage needed for each instruction.
543  * Sizes for dynamically allocated opcodes are stored in the context struct.
544  */
545 static GLuint InstSize[OPCODE_END_OF_LIST + 1];
546
547
548 void mesa_print_display_list(GLuint list);
549
550
551 /**********************************************************************/
552 /*****                           Private                          *****/
553 /**********************************************************************/
554
555
556 /**
557  * Make an empty display list.  This is used by glGenLists() to
558  * reserve display list IDs.
559  */
560 static struct gl_display_list *
561 make_list(GLuint name, GLuint count)
562 {
563    struct gl_display_list *dlist = CALLOC_STRUCT(gl_display_list);
564    dlist->Name = name;
565    dlist->Head = malloc(sizeof(Node) * count);
566    dlist->Head[0].opcode = OPCODE_END_OF_LIST;
567    return dlist;
568 }
569
570
571 /**
572  * Lookup function to just encapsulate casting.
573  */
574 static inline struct gl_display_list *
575 lookup_list(struct gl_context *ctx, GLuint list)
576 {
577    return (struct gl_display_list *)
578       _mesa_HashLookup(ctx->Shared->DisplayList, list);
579 }
580
581
582 /** Is the given opcode an extension code? */
583 static inline GLboolean
584 is_ext_opcode(OpCode opcode)
585 {
586    return (opcode >= OPCODE_EXT_0);
587 }
588
589
590 /** Destroy an extended opcode instruction */
591 static GLint
592 ext_opcode_destroy(struct gl_context *ctx, Node *node)
593 {
594    const GLint i = node[0].opcode - OPCODE_EXT_0;
595    GLint step;
596    ctx->ListExt->Opcode[i].Destroy(ctx, &node[1]);
597    step = ctx->ListExt->Opcode[i].Size;
598    return step;
599 }
600
601
602 /** Execute an extended opcode instruction */
603 static GLint
604 ext_opcode_execute(struct gl_context *ctx, Node *node)
605 {
606    const GLint i = node[0].opcode - OPCODE_EXT_0;
607    GLint step;
608    ctx->ListExt->Opcode[i].Execute(ctx, &node[1]);
609    step = ctx->ListExt->Opcode[i].Size;
610    return step;
611 }
612
613
614 /** Print an extended opcode instruction */
615 static GLint
616 ext_opcode_print(struct gl_context *ctx, Node *node)
617 {
618    const GLint i = node[0].opcode - OPCODE_EXT_0;
619    GLint step;
620    ctx->ListExt->Opcode[i].Print(ctx, &node[1]);
621    step = ctx->ListExt->Opcode[i].Size;
622    return step;
623 }
624
625
626 /**
627  * Delete the named display list, but don't remove from hash table.
628  * \param dlist - display list pointer
629  */
630 void
631 _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist)
632 {
633    Node *n, *block;
634    GLboolean done;
635
636    n = block = dlist->Head;
637
638    done = block ? GL_FALSE : GL_TRUE;
639    while (!done) {
640       const OpCode opcode = n[0].opcode;
641
642       /* check for extension opcodes first */
643       if (is_ext_opcode(opcode)) {
644          n += ext_opcode_destroy(ctx, n);
645       }
646       else {
647          switch (opcode) {
648             /* for some commands, we need to free malloc'd memory */
649          case OPCODE_MAP1:
650             free(n[6].data);
651             n += InstSize[n[0].opcode];
652             break;
653          case OPCODE_MAP2:
654             free(n[10].data);
655             n += InstSize[n[0].opcode];
656             break;
657          case OPCODE_DRAW_PIXELS:
658             free(n[5].data);
659             n += InstSize[n[0].opcode];
660             break;
661          case OPCODE_BITMAP:
662             free(n[7].data);
663             n += InstSize[n[0].opcode];
664             break;
665          case OPCODE_COLOR_TABLE:
666             free(n[6].data);
667             n += InstSize[n[0].opcode];
668             break;
669          case OPCODE_COLOR_SUB_TABLE:
670             free(n[6].data);
671             n += InstSize[n[0].opcode];
672             break;
673          case OPCODE_CONVOLUTION_FILTER_1D:
674             free(n[6].data);
675             n += InstSize[n[0].opcode];
676             break;
677          case OPCODE_CONVOLUTION_FILTER_2D:
678             free(n[7].data);
679             n += InstSize[n[0].opcode];
680             break;
681          case OPCODE_POLYGON_STIPPLE:
682             free(n[1].data);
683             n += InstSize[n[0].opcode];
684             break;
685          case OPCODE_TEX_IMAGE1D:
686             free(n[8].data);
687             n += InstSize[n[0].opcode];
688             break;
689          case OPCODE_TEX_IMAGE2D:
690             free(n[9].data);
691             n += InstSize[n[0].opcode];
692             break;
693          case OPCODE_TEX_IMAGE3D:
694             free(n[10].data);
695             n += InstSize[n[0].opcode];
696             break;
697          case OPCODE_TEX_SUB_IMAGE1D:
698             free(n[7].data);
699             n += InstSize[n[0].opcode];
700             break;
701          case OPCODE_TEX_SUB_IMAGE2D:
702             free(n[9].data);
703             n += InstSize[n[0].opcode];
704             break;
705          case OPCODE_TEX_SUB_IMAGE3D:
706             free(n[11].data);
707             n += InstSize[n[0].opcode];
708             break;
709          case OPCODE_COMPRESSED_TEX_IMAGE_1D:
710             free(n[7].data);
711             n += InstSize[n[0].opcode];
712             break;
713          case OPCODE_COMPRESSED_TEX_IMAGE_2D:
714             free(n[8].data);
715             n += InstSize[n[0].opcode];
716             break;
717          case OPCODE_COMPRESSED_TEX_IMAGE_3D:
718             free(n[9].data);
719             n += InstSize[n[0].opcode];
720             break;
721          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D:
722             free(n[7].data);
723             n += InstSize[n[0].opcode];
724             break;
725          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D:
726             free(n[9].data);
727             n += InstSize[n[0].opcode];
728             break;
729          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D:
730             free(n[11].data);
731             n += InstSize[n[0].opcode];
732             break;
733          case OPCODE_LOAD_PROGRAM_NV:
734             free(n[4].data);      /* program string */
735             n += InstSize[n[0].opcode];
736             break;
737          case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
738             free(n[2].data);      /* array of program ids */
739             n += InstSize[n[0].opcode];
740             break;
741          case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
742             free(n[3].data);      /* parameter name */
743             n += InstSize[n[0].opcode];
744             break;
745          case OPCODE_PROGRAM_STRING_ARB:
746             free(n[4].data);      /* program string */
747             n += InstSize[n[0].opcode];
748             break;
749          case OPCODE_UNIFORM_1FV:
750          case OPCODE_UNIFORM_2FV:
751          case OPCODE_UNIFORM_3FV:
752          case OPCODE_UNIFORM_4FV:
753          case OPCODE_UNIFORM_1IV:
754          case OPCODE_UNIFORM_2IV:
755          case OPCODE_UNIFORM_3IV:
756          case OPCODE_UNIFORM_4IV:
757          case OPCODE_UNIFORM_1UIV:
758          case OPCODE_UNIFORM_2UIV:
759          case OPCODE_UNIFORM_3UIV:
760          case OPCODE_UNIFORM_4UIV:
761             free(n[3].data);
762             n += InstSize[n[0].opcode];
763             break;
764          case OPCODE_UNIFORM_MATRIX22:
765          case OPCODE_UNIFORM_MATRIX33:
766          case OPCODE_UNIFORM_MATRIX44:
767          case OPCODE_UNIFORM_MATRIX24:
768          case OPCODE_UNIFORM_MATRIX42:
769          case OPCODE_UNIFORM_MATRIX23:
770          case OPCODE_UNIFORM_MATRIX32:
771          case OPCODE_UNIFORM_MATRIX34:
772          case OPCODE_UNIFORM_MATRIX43:
773             free(n[4].data);
774             n += InstSize[n[0].opcode];
775             break;
776
777          case OPCODE_CONTINUE:
778             n = (Node *) n[1].next;
779             free(block);
780             block = n;
781             break;
782          case OPCODE_END_OF_LIST:
783             free(block);
784             done = GL_TRUE;
785             break;
786          default:
787             /* Most frequent case */
788             n += InstSize[n[0].opcode];
789             break;
790          }
791       }
792    }
793
794    free(dlist);
795 }
796
797
798 /**
799  * Destroy a display list and remove from hash table.
800  * \param list - display list number
801  */
802 static void
803 destroy_list(struct gl_context *ctx, GLuint list)
804 {
805    struct gl_display_list *dlist;
806
807    if (list == 0)
808       return;
809
810    dlist = lookup_list(ctx, list);
811    if (!dlist)
812       return;
813
814    _mesa_delete_list(ctx, dlist);
815    _mesa_HashRemove(ctx->Shared->DisplayList, list);
816 }
817
818
819 /*
820  * Translate the nth element of list from <type> to GLint.
821  */
822 static GLint
823 translate_id(GLsizei n, GLenum type, const GLvoid * list)
824 {
825    GLbyte *bptr;
826    GLubyte *ubptr;
827    GLshort *sptr;
828    GLushort *usptr;
829    GLint *iptr;
830    GLuint *uiptr;
831    GLfloat *fptr;
832
833    switch (type) {
834    case GL_BYTE:
835       bptr = (GLbyte *) list;
836       return (GLint) bptr[n];
837    case GL_UNSIGNED_BYTE:
838       ubptr = (GLubyte *) list;
839       return (GLint) ubptr[n];
840    case GL_SHORT:
841       sptr = (GLshort *) list;
842       return (GLint) sptr[n];
843    case GL_UNSIGNED_SHORT:
844       usptr = (GLushort *) list;
845       return (GLint) usptr[n];
846    case GL_INT:
847       iptr = (GLint *) list;
848       return iptr[n];
849    case GL_UNSIGNED_INT:
850       uiptr = (GLuint *) list;
851       return (GLint) uiptr[n];
852    case GL_FLOAT:
853       fptr = (GLfloat *) list;
854       return (GLint) FLOORF(fptr[n]);
855    case GL_2_BYTES:
856       ubptr = ((GLubyte *) list) + 2 * n;
857       return (GLint) ubptr[0] * 256
858            + (GLint) ubptr[1];
859    case GL_3_BYTES:
860       ubptr = ((GLubyte *) list) + 3 * n;
861       return (GLint) ubptr[0] * 65536
862            + (GLint) ubptr[1] * 256
863            + (GLint) ubptr[2];
864    case GL_4_BYTES:
865       ubptr = ((GLubyte *) list) + 4 * n;
866       return (GLint) ubptr[0] * 16777216
867            + (GLint) ubptr[1] * 65536
868            + (GLint) ubptr[2] * 256
869            + (GLint) ubptr[3];
870    default:
871       return 0;
872    }
873 }
874
875
876
877
878 /**********************************************************************/
879 /*****                        Public                              *****/
880 /**********************************************************************/
881
882 /**
883  * Wrapper for _mesa_unpack_image/bitmap() that handles pixel buffer objects.
884  * If width < 0 or height < 0 or format or type are invalid we'll just
885  * return NULL.  We will not generate an error since OpenGL command
886  * arguments aren't error-checked until the command is actually executed
887  * (not when they're compiled).
888  * But if we run out of memory, GL_OUT_OF_MEMORY will be recorded.
889  */
890 static GLvoid *
891 unpack_image(struct gl_context *ctx, GLuint dimensions,
892              GLsizei width, GLsizei height, GLsizei depth,
893              GLenum format, GLenum type, const GLvoid * pixels,
894              const struct gl_pixelstore_attrib *unpack)
895 {
896    if (width <= 0 || height <= 0) {
897       return NULL;
898    }
899
900    if (_mesa_bytes_per_pixel(format, type) < 0) {
901       /* bad format and/or type */
902       return NULL;
903    }
904
905    if (!_mesa_is_bufferobj(unpack->BufferObj)) {
906       /* no PBO */
907       GLvoid *image;
908
909       if (type == GL_BITMAP)
910          image = _mesa_unpack_bitmap(width, height, pixels, unpack);
911       else
912          image = _mesa_unpack_image(dimensions, width, height, depth,
913                                     format, type, pixels, unpack);
914       if (pixels && !image) {
915          _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
916       }
917       return image;
918    }
919    else if (_mesa_validate_pbo_access(dimensions, unpack, width, height,
920                                       depth, format, type, INT_MAX, pixels)) {
921       const GLubyte *map, *src;
922       GLvoid *image;
923
924       map = (GLubyte *)
925          ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size,
926                                     GL_MAP_READ_BIT, unpack->BufferObj);
927       if (!map) {
928          /* unable to map src buffer! */
929          _mesa_error(ctx, GL_INVALID_OPERATION, "unable to map PBO");
930          return NULL;
931       }
932
933       src = ADD_POINTERS(map, pixels);
934       if (type == GL_BITMAP)
935          image = _mesa_unpack_bitmap(width, height, src, unpack);
936       else
937          image = _mesa_unpack_image(dimensions, width, height, depth,
938                                     format, type, src, unpack);
939
940       ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj);
941
942       if (!image) {
943          _mesa_error(ctx, GL_OUT_OF_MEMORY, "display list construction");
944       }
945       return image;
946    }
947
948    /* bad access! */
949    _mesa_error(ctx, GL_INVALID_OPERATION, "invalid PBO access");
950    return NULL;
951 }
952
953 /**
954  * Allocate space for a display list instruction (opcode + payload space).
955  * \param opcode  the instruction opcode (OPCODE_* value)
956  * \param bytes   instruction payload size (not counting opcode)
957  * \return pointer to allocated memory (the opcode space)
958  */
959 static Node *
960 dlist_alloc(struct gl_context *ctx, OpCode opcode, GLuint bytes)
961 {
962    const GLuint numNodes = 1 + (bytes + sizeof(Node) - 1) / sizeof(Node);
963    Node *n;
964
965    if (opcode < (GLuint) OPCODE_EXT_0) {
966       if (InstSize[opcode] == 0) {
967          /* save instruction size now */
968          InstSize[opcode] = numNodes;
969       }
970       else {
971          /* make sure instruction size agrees */
972          ASSERT(numNodes == InstSize[opcode]);
973       }
974    }
975
976    if (ctx->ListState.CurrentPos + numNodes + 2 > BLOCK_SIZE) {
977       /* This block is full.  Allocate a new block and chain to it */
978       Node *newblock;
979       n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
980       n[0].opcode = OPCODE_CONTINUE;
981       newblock = malloc(sizeof(Node) * BLOCK_SIZE);
982       if (!newblock) {
983          _mesa_error(ctx, GL_OUT_OF_MEMORY, "Building display list");
984          return NULL;
985       }
986       n[1].next = (Node *) newblock;
987       ctx->ListState.CurrentBlock = newblock;
988       ctx->ListState.CurrentPos = 0;
989    }
990
991    n = ctx->ListState.CurrentBlock + ctx->ListState.CurrentPos;
992    ctx->ListState.CurrentPos += numNodes;
993
994    n[0].opcode = opcode;
995
996    return n;
997 }
998
999
1000
1001 /**
1002  * Allocate space for a display list instruction.  Used by callers outside
1003  * this file for things like VBO vertex data.
1004  *
1005  * \param opcode  the instruction opcode (OPCODE_* value)
1006  * \param bytes   instruction size in bytes, not counting opcode.
1007  * \return pointer to the usable data area (not including the internal
1008  *         opcode).
1009  */
1010 void *
1011 _mesa_dlist_alloc(struct gl_context *ctx, GLuint opcode, GLuint bytes)
1012 {
1013    Node *n = dlist_alloc(ctx, (OpCode) opcode, bytes);
1014    if (n)
1015       return n + 1;  /* return pointer to payload area, after opcode */
1016    else
1017       return NULL;
1018 }
1019
1020
1021 /**
1022  * This function allows modules and drivers to get their own opcodes
1023  * for extending display list functionality.
1024  * \param ctx  the rendering context
1025  * \param size  number of bytes for storing the new display list command
1026  * \param execute  function to execute the new display list command
1027  * \param destroy  function to destroy the new display list command
1028  * \param print  function to print the new display list command
1029  * \return  the new opcode number or -1 if error
1030  */
1031 GLint
1032 _mesa_dlist_alloc_opcode(struct gl_context *ctx,
1033                          GLuint size,
1034                          void (*execute) (struct gl_context *, void *),
1035                          void (*destroy) (struct gl_context *, void *),
1036                          void (*print) (struct gl_context *, void *))
1037 {
1038    if (ctx->ListExt->NumOpcodes < MAX_DLIST_EXT_OPCODES) {
1039       const GLuint i = ctx->ListExt->NumOpcodes++;
1040       ctx->ListExt->Opcode[i].Size =
1041          1 + (size + sizeof(Node) - 1) / sizeof(Node);
1042       ctx->ListExt->Opcode[i].Execute = execute;
1043       ctx->ListExt->Opcode[i].Destroy = destroy;
1044       ctx->ListExt->Opcode[i].Print = print;
1045       return i + OPCODE_EXT_0;
1046    }
1047    return -1;
1048 }
1049
1050
1051 /**
1052  * Allocate space for a display list instruction.  The space is basically
1053  * an array of Nodes where node[0] holds the opcode, node[1] is the first
1054  * function parameter, node[2] is the second parameter, etc.
1055  *
1056  * \param opcode  one of OPCODE_x
1057  * \param nparams  number of function parameters
1058  * \return  pointer to start of instruction space
1059  */
1060 static inline Node *
1061 alloc_instruction(struct gl_context *ctx, OpCode opcode, GLuint nparams)
1062 {
1063    return dlist_alloc(ctx, opcode, nparams * sizeof(Node));
1064 }
1065
1066
1067
1068 /*
1069  * Display List compilation functions
1070  */
1071 static void GLAPIENTRY
1072 save_Accum(GLenum op, GLfloat value)
1073 {
1074    GET_CURRENT_CONTEXT(ctx);
1075    Node *n;
1076    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1077    n = alloc_instruction(ctx, OPCODE_ACCUM, 2);
1078    if (n) {
1079       n[1].e = op;
1080       n[2].f = value;
1081    }
1082    if (ctx->ExecuteFlag) {
1083       CALL_Accum(ctx->Exec, (op, value));
1084    }
1085 }
1086
1087
1088 static void GLAPIENTRY
1089 save_AlphaFunc(GLenum func, GLclampf ref)
1090 {
1091    GET_CURRENT_CONTEXT(ctx);
1092    Node *n;
1093    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1094    n = alloc_instruction(ctx, OPCODE_ALPHA_FUNC, 2);
1095    if (n) {
1096       n[1].e = func;
1097       n[2].f = (GLfloat) ref;
1098    }
1099    if (ctx->ExecuteFlag) {
1100       CALL_AlphaFunc(ctx->Exec, (func, ref));
1101    }
1102 }
1103
1104
1105 static void GLAPIENTRY
1106 save_BindTexture(GLenum target, GLuint texture)
1107 {
1108    GET_CURRENT_CONTEXT(ctx);
1109    Node *n;
1110    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1111    n = alloc_instruction(ctx, OPCODE_BIND_TEXTURE, 2);
1112    if (n) {
1113       n[1].e = target;
1114       n[2].ui = texture;
1115    }
1116    if (ctx->ExecuteFlag) {
1117       CALL_BindTexture(ctx->Exec, (target, texture));
1118    }
1119 }
1120
1121
1122 static void GLAPIENTRY
1123 save_Bitmap(GLsizei width, GLsizei height,
1124             GLfloat xorig, GLfloat yorig,
1125             GLfloat xmove, GLfloat ymove, const GLubyte * pixels)
1126 {
1127    GET_CURRENT_CONTEXT(ctx);
1128    Node *n;
1129    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1130    n = alloc_instruction(ctx, OPCODE_BITMAP, 7);
1131    if (n) {
1132       n[1].i = (GLint) width;
1133       n[2].i = (GLint) height;
1134       n[3].f = xorig;
1135       n[4].f = yorig;
1136       n[5].f = xmove;
1137       n[6].f = ymove;
1138       n[7].data = unpack_image(ctx, 2, width, height, 1, GL_COLOR_INDEX,
1139                                GL_BITMAP, pixels, &ctx->Unpack);
1140    }
1141    if (ctx->ExecuteFlag) {
1142       CALL_Bitmap(ctx->Exec, (width, height,
1143                               xorig, yorig, xmove, ymove, pixels));
1144    }
1145 }
1146
1147
1148 static void GLAPIENTRY
1149 save_BlendEquation(GLenum mode)
1150 {
1151    GET_CURRENT_CONTEXT(ctx);
1152    Node *n;
1153    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1154    n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION, 1);
1155    if (n) {
1156       n[1].e = mode;
1157    }
1158    if (ctx->ExecuteFlag) {
1159       CALL_BlendEquation(ctx->Exec, (mode));
1160    }
1161 }
1162
1163
1164 static void GLAPIENTRY
1165 save_BlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA)
1166 {
1167    GET_CURRENT_CONTEXT(ctx);
1168    Node *n;
1169    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1170    n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE, 2);
1171    if (n) {
1172       n[1].e = modeRGB;
1173       n[2].e = modeA;
1174    }
1175    if (ctx->ExecuteFlag) {
1176       CALL_BlendEquationSeparateEXT(ctx->Exec, (modeRGB, modeA));
1177    }
1178 }
1179
1180
1181 static void GLAPIENTRY
1182 save_BlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB,
1183                           GLenum sfactorA, GLenum dfactorA)
1184 {
1185    GET_CURRENT_CONTEXT(ctx);
1186    Node *n;
1187    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1188    n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE, 4);
1189    if (n) {
1190       n[1].e = sfactorRGB;
1191       n[2].e = dfactorRGB;
1192       n[3].e = sfactorA;
1193       n[4].e = dfactorA;
1194    }
1195    if (ctx->ExecuteFlag) {
1196       CALL_BlendFuncSeparateEXT(ctx->Exec,
1197                                 (sfactorRGB, dfactorRGB, sfactorA, dfactorA));
1198    }
1199 }
1200
1201
1202 static void GLAPIENTRY
1203 save_BlendFunc(GLenum srcfactor, GLenum dstfactor)
1204 {
1205    save_BlendFuncSeparateEXT(srcfactor, dstfactor, srcfactor, dstfactor);
1206 }
1207
1208
1209 static void GLAPIENTRY
1210 save_BlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
1211 {
1212    GET_CURRENT_CONTEXT(ctx);
1213    Node *n;
1214    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1215    n = alloc_instruction(ctx, OPCODE_BLEND_COLOR, 4);
1216    if (n) {
1217       n[1].f = red;
1218       n[2].f = green;
1219       n[3].f = blue;
1220       n[4].f = alpha;
1221    }
1222    if (ctx->ExecuteFlag) {
1223       CALL_BlendColor(ctx->Exec, (red, green, blue, alpha));
1224    }
1225 }
1226
1227 /* GL_ARB_draw_buffers_blend */
1228 static void GLAPIENTRY
1229 save_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
1230                         GLenum sfactorA, GLenum dfactorA)
1231 {
1232    GET_CURRENT_CONTEXT(ctx);
1233    Node *n;
1234    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1235    n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 5);
1236    if (n) {
1237       n[1].ui = buf;
1238       n[2].e = sfactorRGB;
1239       n[3].e = dfactorRGB;
1240       n[4].e = sfactorA;
1241       n[5].e = dfactorA;
1242    }
1243    if (ctx->ExecuteFlag) {
1244       CALL_BlendFuncSeparateiARB(ctx->Exec, (buf, sfactorRGB, dfactorRGB,
1245                                              sfactorA, dfactorA));
1246    }
1247 }
1248
1249 /* GL_ARB_draw_buffers_blend */
1250 static void GLAPIENTRY
1251 save_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
1252 {
1253    GET_CURRENT_CONTEXT(ctx);
1254    Node *n;
1255    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1256    n = alloc_instruction(ctx, OPCODE_BLEND_FUNC_SEPARATE_I, 3);
1257    if (n) {
1258       n[1].ui = buf;
1259       n[2].e = sfactor;
1260       n[3].e = dfactor;
1261    }
1262    if (ctx->ExecuteFlag) {
1263       CALL_BlendFunciARB(ctx->Exec, (buf, sfactor, dfactor));
1264    }
1265 }
1266
1267 /* GL_ARB_draw_buffers_blend */
1268 static void GLAPIENTRY
1269 save_BlendEquationi(GLuint buf, GLenum mode)
1270 {
1271    GET_CURRENT_CONTEXT(ctx);
1272    Node *n;
1273    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1274    n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_I, 2);
1275    if (n) {
1276       n[1].ui = buf;
1277       n[2].e = mode;
1278    }
1279    if (ctx->ExecuteFlag) {
1280       CALL_BlendEquationiARB(ctx->Exec, (buf, mode));
1281    }
1282 }
1283
1284 /* GL_ARB_draw_buffers_blend */
1285 static void GLAPIENTRY
1286 save_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
1287 {
1288    GET_CURRENT_CONTEXT(ctx);
1289    Node *n;
1290    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1291    n = alloc_instruction(ctx, OPCODE_BLEND_EQUATION_SEPARATE_I, 3);
1292    if (n) {
1293       n[1].ui = buf;
1294       n[2].e = modeRGB;
1295       n[3].e = modeA;
1296    }
1297    if (ctx->ExecuteFlag) {
1298       CALL_BlendEquationSeparateiARB(ctx->Exec, (buf, modeRGB, modeA));
1299    }
1300 }
1301
1302
1303 /* GL_ARB_draw_instanced. */
1304 static void GLAPIENTRY
1305 save_DrawArraysInstancedARB(GLenum mode,
1306                             GLint first,
1307                             GLsizei count,
1308                             GLsizei primcount)
1309 {
1310    GET_CURRENT_CONTEXT(ctx);
1311    _mesa_error(ctx, GL_INVALID_OPERATION,
1312                "glDrawArraysInstanced() during display list compile");
1313 }
1314
1315 static void GLAPIENTRY
1316 save_DrawElementsInstancedARB(GLenum mode,
1317                               GLsizei count,
1318                               GLenum type,
1319                               const GLvoid *indices,
1320                               GLsizei primcount)
1321 {
1322    GET_CURRENT_CONTEXT(ctx);
1323    _mesa_error(ctx, GL_INVALID_OPERATION,
1324                "glDrawElementsInstanced() during display list compile");
1325 }
1326
1327 static void GLAPIENTRY
1328 save_DrawElementsInstancedBaseVertexARB(GLenum mode,
1329                                         GLsizei count,
1330                                         GLenum type,
1331                                         const GLvoid *indices,
1332                                         GLsizei primcount,
1333                                         GLint basevertex)
1334 {
1335    GET_CURRENT_CONTEXT(ctx);
1336    _mesa_error(ctx, GL_INVALID_OPERATION,
1337                "glDrawElementsInstancedBaseVertex() during display list compile");
1338 }
1339
1340 /* GL_ARB_base_instance. */
1341 static void GLAPIENTRY
1342 save_DrawArraysInstancedBaseInstance(GLenum mode,
1343                                      GLint first,
1344                                      GLsizei count,
1345                                      GLsizei primcount,
1346                                      GLuint baseinstance)
1347 {
1348    GET_CURRENT_CONTEXT(ctx);
1349    _mesa_error(ctx, GL_INVALID_OPERATION,
1350                "glDrawArraysInstancedBaseInstance() during display list compile");
1351 }
1352
1353 static void APIENTRY
1354 save_DrawElementsInstancedBaseInstance(GLenum mode,
1355                                        GLsizei count,
1356                                        GLenum type,
1357                                        const void *indices,
1358                                        GLsizei primcount,
1359                                        GLuint baseinstance)
1360 {
1361    GET_CURRENT_CONTEXT(ctx);
1362    _mesa_error(ctx, GL_INVALID_OPERATION,
1363                "glDrawElementsInstancedBaseInstance() during display list compile");
1364 }
1365
1366 static void APIENTRY
1367 save_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode,
1368                                                  GLsizei count,
1369                                                  GLenum type,
1370                                                  const void *indices,
1371                                                  GLsizei primcount,
1372                                                  GLint basevertex,
1373                                                  GLuint baseinstance)
1374 {
1375    GET_CURRENT_CONTEXT(ctx);
1376    _mesa_error(ctx, GL_INVALID_OPERATION,
1377                "glDrawElementsInstancedBaseVertexBaseInstance() during display list compile");
1378 }
1379
1380 static void invalidate_saved_current_state( struct gl_context *ctx )
1381 {
1382    GLint i;
1383
1384    for (i = 0; i < VERT_ATTRIB_MAX; i++)
1385       ctx->ListState.ActiveAttribSize[i] = 0;
1386
1387    for (i = 0; i < MAT_ATTRIB_MAX; i++)
1388       ctx->ListState.ActiveMaterialSize[i] = 0;
1389
1390    memset(&ctx->ListState.Current, 0, sizeof ctx->ListState.Current);
1391
1392    ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
1393 }
1394
1395 static void GLAPIENTRY
1396 save_CallList(GLuint list)
1397 {
1398    GET_CURRENT_CONTEXT(ctx);
1399    Node *n;
1400    SAVE_FLUSH_VERTICES(ctx);
1401
1402    n = alloc_instruction(ctx, OPCODE_CALL_LIST, 1);
1403    if (n) {
1404       n[1].ui = list;
1405    }
1406
1407    /* After this, we don't know what state we're in.  Invalidate all
1408     * cached information previously gathered:
1409     */
1410    invalidate_saved_current_state( ctx );
1411
1412    if (ctx->ExecuteFlag) {
1413       _mesa_CallList(list);
1414    }
1415 }
1416
1417
1418 static void GLAPIENTRY
1419 save_CallLists(GLsizei num, GLenum type, const GLvoid * lists)
1420 {
1421    GET_CURRENT_CONTEXT(ctx);
1422    GLint i;
1423    GLboolean typeErrorFlag;
1424
1425    SAVE_FLUSH_VERTICES(ctx);
1426
1427    switch (type) {
1428    case GL_BYTE:
1429    case GL_UNSIGNED_BYTE:
1430    case GL_SHORT:
1431    case GL_UNSIGNED_SHORT:
1432    case GL_INT:
1433    case GL_UNSIGNED_INT:
1434    case GL_FLOAT:
1435    case GL_2_BYTES:
1436    case GL_3_BYTES:
1437    case GL_4_BYTES:
1438       typeErrorFlag = GL_FALSE;
1439       break;
1440    default:
1441       typeErrorFlag = GL_TRUE;
1442    }
1443
1444    for (i = 0; i < num; i++) {
1445       GLint list = translate_id(i, type, lists);
1446       Node *n = alloc_instruction(ctx, OPCODE_CALL_LIST_OFFSET, 2);
1447       if (n) {
1448          n[1].i = list;
1449          n[2].b = typeErrorFlag;
1450       }
1451    }
1452
1453    /* After this, we don't know what state we're in.  Invalidate all
1454     * cached information previously gathered:
1455     */
1456    invalidate_saved_current_state( ctx );
1457
1458    if (ctx->ExecuteFlag) {
1459       CALL_CallLists(ctx->Exec, (num, type, lists));
1460    }
1461 }
1462
1463
1464 static void GLAPIENTRY
1465 save_Clear(GLbitfield mask)
1466 {
1467    GET_CURRENT_CONTEXT(ctx);
1468    Node *n;
1469    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1470    n = alloc_instruction(ctx, OPCODE_CLEAR, 1);
1471    if (n) {
1472       n[1].bf = mask;
1473    }
1474    if (ctx->ExecuteFlag) {
1475       CALL_Clear(ctx->Exec, (mask));
1476    }
1477 }
1478
1479
1480 static void GLAPIENTRY
1481 save_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
1482 {
1483    GET_CURRENT_CONTEXT(ctx);
1484    Node *n;
1485    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1486    n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_IV, 6);
1487    if (n) {
1488       n[1].e = buffer;
1489       n[2].i = drawbuffer;
1490       n[3].i = value[0];
1491       if (buffer == GL_COLOR) {
1492          n[4].i = value[1];
1493          n[5].i = value[2];
1494          n[6].i = value[3];
1495       }
1496       else {
1497          n[4].i = 0;
1498          n[5].i = 0;
1499          n[6].i = 0;
1500       }
1501    }
1502    if (ctx->ExecuteFlag) {
1503       CALL_ClearBufferiv(ctx->Exec, (buffer, drawbuffer, value));
1504    }
1505 }
1506
1507
1508 static void GLAPIENTRY
1509 save_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
1510 {
1511    GET_CURRENT_CONTEXT(ctx);
1512    Node *n;
1513    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1514    n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_UIV, 6);
1515    if (n) {
1516       n[1].e = buffer;
1517       n[2].i = drawbuffer;
1518       n[3].ui = value[0];
1519       if (buffer == GL_COLOR) {
1520          n[4].ui = value[1];
1521          n[5].ui = value[2];
1522          n[6].ui = value[3];
1523       }
1524       else {
1525          n[4].ui = 0;
1526          n[5].ui = 0;
1527          n[6].ui = 0;
1528       }
1529    }
1530    if (ctx->ExecuteFlag) {
1531       CALL_ClearBufferuiv(ctx->Exec, (buffer, drawbuffer, value));
1532    }
1533 }
1534
1535
1536 static void GLAPIENTRY
1537 save_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
1538 {
1539    GET_CURRENT_CONTEXT(ctx);
1540    Node *n;
1541    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1542    n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FV, 6);
1543    if (n) {
1544       n[1].e = buffer;
1545       n[2].i = drawbuffer;
1546       n[3].f = value[0];
1547       if (buffer == GL_COLOR) {
1548          n[4].f = value[1];
1549          n[5].f = value[2];
1550          n[6].f = value[3];
1551       }
1552       else {
1553          n[4].f = 0.0F;
1554          n[5].f = 0.0F;
1555          n[6].f = 0.0F;
1556       }
1557    }
1558    if (ctx->ExecuteFlag) {
1559       CALL_ClearBufferfv(ctx->Exec, (buffer, drawbuffer, value));
1560    }
1561 }
1562
1563
1564 static void GLAPIENTRY
1565 save_ClearBufferfi(GLenum buffer, GLint drawbuffer,
1566                    GLfloat depth, GLint stencil)
1567 {
1568    GET_CURRENT_CONTEXT(ctx);
1569    Node *n;
1570    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1571    n = alloc_instruction(ctx, OPCODE_CLEAR_BUFFER_FI, 4);
1572    if (n) {
1573       n[1].e = buffer;
1574       n[2].i = drawbuffer;
1575       n[3].f = depth;
1576       n[4].i = stencil;
1577    }
1578    if (ctx->ExecuteFlag) {
1579       CALL_ClearBufferfi(ctx->Exec, (buffer, drawbuffer, depth, stencil));
1580    }
1581 }
1582
1583
1584 static void GLAPIENTRY
1585 save_ClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
1586 {
1587    GET_CURRENT_CONTEXT(ctx);
1588    Node *n;
1589    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1590    n = alloc_instruction(ctx, OPCODE_CLEAR_ACCUM, 4);
1591    if (n) {
1592       n[1].f = red;
1593       n[2].f = green;
1594       n[3].f = blue;
1595       n[4].f = alpha;
1596    }
1597    if (ctx->ExecuteFlag) {
1598       CALL_ClearAccum(ctx->Exec, (red, green, blue, alpha));
1599    }
1600 }
1601
1602
1603 static void GLAPIENTRY
1604 save_ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1605 {
1606    GET_CURRENT_CONTEXT(ctx);
1607    Node *n;
1608    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1609    n = alloc_instruction(ctx, OPCODE_CLEAR_COLOR, 4);
1610    if (n) {
1611       n[1].f = red;
1612       n[2].f = green;
1613       n[3].f = blue;
1614       n[4].f = alpha;
1615    }
1616    if (ctx->ExecuteFlag) {
1617       CALL_ClearColor(ctx->Exec, (red, green, blue, alpha));
1618    }
1619 }
1620
1621
1622 static void GLAPIENTRY
1623 save_ClearDepth(GLclampd depth)
1624 {
1625    GET_CURRENT_CONTEXT(ctx);
1626    Node *n;
1627    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1628    n = alloc_instruction(ctx, OPCODE_CLEAR_DEPTH, 1);
1629    if (n) {
1630       n[1].f = (GLfloat) depth;
1631    }
1632    if (ctx->ExecuteFlag) {
1633       CALL_ClearDepth(ctx->Exec, (depth));
1634    }
1635 }
1636
1637
1638 static void GLAPIENTRY
1639 save_ClearIndex(GLfloat c)
1640 {
1641    GET_CURRENT_CONTEXT(ctx);
1642    Node *n;
1643    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1644    n = alloc_instruction(ctx, OPCODE_CLEAR_INDEX, 1);
1645    if (n) {
1646       n[1].f = c;
1647    }
1648    if (ctx->ExecuteFlag) {
1649       CALL_ClearIndex(ctx->Exec, (c));
1650    }
1651 }
1652
1653
1654 static void GLAPIENTRY
1655 save_ClearStencil(GLint s)
1656 {
1657    GET_CURRENT_CONTEXT(ctx);
1658    Node *n;
1659    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1660    n = alloc_instruction(ctx, OPCODE_CLEAR_STENCIL, 1);
1661    if (n) {
1662       n[1].i = s;
1663    }
1664    if (ctx->ExecuteFlag) {
1665       CALL_ClearStencil(ctx->Exec, (s));
1666    }
1667 }
1668
1669
1670 static void GLAPIENTRY
1671 save_ClipPlane(GLenum plane, const GLdouble * equ)
1672 {
1673    GET_CURRENT_CONTEXT(ctx);
1674    Node *n;
1675    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1676    n = alloc_instruction(ctx, OPCODE_CLIP_PLANE, 5);
1677    if (n) {
1678       n[1].e = plane;
1679       n[2].f = (GLfloat) equ[0];
1680       n[3].f = (GLfloat) equ[1];
1681       n[4].f = (GLfloat) equ[2];
1682       n[5].f = (GLfloat) equ[3];
1683    }
1684    if (ctx->ExecuteFlag) {
1685       CALL_ClipPlane(ctx->Exec, (plane, equ));
1686    }
1687 }
1688
1689
1690
1691 static void GLAPIENTRY
1692 save_ColorMask(GLboolean red, GLboolean green,
1693                GLboolean blue, GLboolean alpha)
1694 {
1695    GET_CURRENT_CONTEXT(ctx);
1696    Node *n;
1697    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1698    n = alloc_instruction(ctx, OPCODE_COLOR_MASK, 4);
1699    if (n) {
1700       n[1].b = red;
1701       n[2].b = green;
1702       n[3].b = blue;
1703       n[4].b = alpha;
1704    }
1705    if (ctx->ExecuteFlag) {
1706       CALL_ColorMask(ctx->Exec, (red, green, blue, alpha));
1707    }
1708 }
1709
1710
1711 static void GLAPIENTRY
1712 save_ColorMaskIndexed(GLuint buf, GLboolean red, GLboolean green,
1713                       GLboolean blue, GLboolean alpha)
1714 {
1715    GET_CURRENT_CONTEXT(ctx);
1716    Node *n;
1717    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1718    n = alloc_instruction(ctx, OPCODE_COLOR_MASK_INDEXED, 5);
1719    if (n) {
1720       n[1].ui = buf;
1721       n[2].b = red;
1722       n[3].b = green;
1723       n[4].b = blue;
1724       n[5].b = alpha;
1725    }
1726    if (ctx->ExecuteFlag) {
1727       /*CALL_ColorMaskIndexedEXT(ctx->Exec, (buf, red, green, blue, alpha));*/
1728    }
1729 }
1730
1731
1732 static void GLAPIENTRY
1733 save_ColorMaterial(GLenum face, GLenum mode)
1734 {
1735    GET_CURRENT_CONTEXT(ctx);
1736    Node *n;
1737    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1738
1739    n = alloc_instruction(ctx, OPCODE_COLOR_MATERIAL, 2);
1740    if (n) {
1741       n[1].e = face;
1742       n[2].e = mode;
1743    }
1744    if (ctx->ExecuteFlag) {
1745       CALL_ColorMaterial(ctx->Exec, (face, mode));
1746    }
1747 }
1748
1749
1750 static void GLAPIENTRY
1751 save_ColorTable(GLenum target, GLenum internalFormat,
1752                 GLsizei width, GLenum format, GLenum type,
1753                 const GLvoid * table)
1754 {
1755    GET_CURRENT_CONTEXT(ctx);
1756    if (_mesa_is_proxy_texture(target)) {
1757       /* execute immediately */
1758       CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
1759                                   format, type, table));
1760    }
1761    else {
1762       Node *n;
1763       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1764       n = alloc_instruction(ctx, OPCODE_COLOR_TABLE, 6);
1765       if (n) {
1766          n[1].e = target;
1767          n[2].e = internalFormat;
1768          n[3].i = width;
1769          n[4].e = format;
1770          n[5].e = type;
1771          n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, table,
1772                                   &ctx->Unpack);
1773       }
1774       if (ctx->ExecuteFlag) {
1775          CALL_ColorTable(ctx->Exec, (target, internalFormat, width,
1776                                      format, type, table));
1777       }
1778    }
1779 }
1780
1781
1782
1783 static void GLAPIENTRY
1784 save_ColorTableParameterfv(GLenum target, GLenum pname,
1785                            const GLfloat *params)
1786 {
1787    GET_CURRENT_CONTEXT(ctx);
1788    Node *n;
1789
1790    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1791
1792    n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_FV, 6);
1793    if (n) {
1794       n[1].e = target;
1795       n[2].e = pname;
1796       n[3].f = params[0];
1797       if (pname == GL_COLOR_TABLE_SGI ||
1798           pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1799           pname == GL_TEXTURE_COLOR_TABLE_SGI) {
1800          n[4].f = params[1];
1801          n[5].f = params[2];
1802          n[6].f = params[3];
1803       }
1804    }
1805
1806    if (ctx->ExecuteFlag) {
1807       CALL_ColorTableParameterfv(ctx->Exec, (target, pname, params));
1808    }
1809 }
1810
1811
1812 static void GLAPIENTRY
1813 save_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
1814 {
1815    GET_CURRENT_CONTEXT(ctx);
1816    Node *n;
1817
1818    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1819
1820    n = alloc_instruction(ctx, OPCODE_COLOR_TABLE_PARAMETER_IV, 6);
1821    if (n) {
1822       n[1].e = target;
1823       n[2].e = pname;
1824       n[3].i = params[0];
1825       if (pname == GL_COLOR_TABLE_SGI ||
1826           pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1827           pname == GL_TEXTURE_COLOR_TABLE_SGI) {
1828          n[4].i = params[1];
1829          n[5].i = params[2];
1830          n[6].i = params[3];
1831       }
1832    }
1833
1834    if (ctx->ExecuteFlag) {
1835       CALL_ColorTableParameteriv(ctx->Exec, (target, pname, params));
1836    }
1837 }
1838
1839
1840
1841 static void GLAPIENTRY
1842 save_ColorSubTable(GLenum target, GLsizei start, GLsizei count,
1843                    GLenum format, GLenum type, const GLvoid * table)
1844 {
1845    GET_CURRENT_CONTEXT(ctx);
1846    Node *n;
1847    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1848    n = alloc_instruction(ctx, OPCODE_COLOR_SUB_TABLE, 6);
1849    if (n) {
1850       n[1].e = target;
1851       n[2].i = start;
1852       n[3].i = count;
1853       n[4].e = format;
1854       n[5].e = type;
1855       n[6].data = unpack_image(ctx, 1, count, 1, 1, format, type, table,
1856                                &ctx->Unpack);
1857    }
1858    if (ctx->ExecuteFlag) {
1859       CALL_ColorSubTable(ctx->Exec,
1860                          (target, start, count, format, type, table));
1861    }
1862 }
1863
1864
1865 static void GLAPIENTRY
1866 save_CopyColorSubTable(GLenum target, GLsizei start,
1867                        GLint x, GLint y, GLsizei width)
1868 {
1869    GET_CURRENT_CONTEXT(ctx);
1870    Node *n;
1871
1872    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1873    n = alloc_instruction(ctx, OPCODE_COPY_COLOR_SUB_TABLE, 5);
1874    if (n) {
1875       n[1].e = target;
1876       n[2].i = start;
1877       n[3].i = x;
1878       n[4].i = y;
1879       n[5].i = width;
1880    }
1881    if (ctx->ExecuteFlag) {
1882       CALL_CopyColorSubTable(ctx->Exec, (target, start, x, y, width));
1883    }
1884 }
1885
1886
1887 static void GLAPIENTRY
1888 save_CopyColorTable(GLenum target, GLenum internalformat,
1889                     GLint x, GLint y, GLsizei width)
1890 {
1891    GET_CURRENT_CONTEXT(ctx);
1892    Node *n;
1893
1894    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1895    n = alloc_instruction(ctx, OPCODE_COPY_COLOR_TABLE, 5);
1896    if (n) {
1897       n[1].e = target;
1898       n[2].e = internalformat;
1899       n[3].i = x;
1900       n[4].i = y;
1901       n[5].i = width;
1902    }
1903    if (ctx->ExecuteFlag) {
1904       CALL_CopyColorTable(ctx->Exec, (target, internalformat, x, y, width));
1905    }
1906 }
1907
1908
1909 static void GLAPIENTRY
1910 save_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width,
1911                          GLenum format, GLenum type, const GLvoid * filter)
1912 {
1913    GET_CURRENT_CONTEXT(ctx);
1914    Node *n;
1915
1916    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1917
1918    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_1D, 6);
1919    if (n) {
1920       n[1].e = target;
1921       n[2].e = internalFormat;
1922       n[3].i = width;
1923       n[4].e = format;
1924       n[5].e = type;
1925       n[6].data = unpack_image(ctx, 1, width, 1, 1, format, type, filter,
1926                                &ctx->Unpack);
1927    }
1928    if (ctx->ExecuteFlag) {
1929       CALL_ConvolutionFilter1D(ctx->Exec, (target, internalFormat, width,
1930                                            format, type, filter));
1931    }
1932 }
1933
1934
1935 static void GLAPIENTRY
1936 save_ConvolutionFilter2D(GLenum target, GLenum internalFormat,
1937                          GLsizei width, GLsizei height, GLenum format,
1938                          GLenum type, const GLvoid * filter)
1939 {
1940    GET_CURRENT_CONTEXT(ctx);
1941    Node *n;
1942
1943    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1944
1945    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_FILTER_2D, 7);
1946    if (n) {
1947       n[1].e = target;
1948       n[2].e = internalFormat;
1949       n[3].i = width;
1950       n[4].i = height;
1951       n[5].e = format;
1952       n[6].e = type;
1953       n[7].data = unpack_image(ctx, 2, width, height, 1, format, type, filter,
1954                                &ctx->Unpack);
1955    }
1956    if (ctx->ExecuteFlag) {
1957       CALL_ConvolutionFilter2D(ctx->Exec,
1958                                (target, internalFormat, width, height, format,
1959                                 type, filter));
1960    }
1961 }
1962
1963
1964 static void GLAPIENTRY
1965 save_ConvolutionParameteri(GLenum target, GLenum pname, GLint param)
1966 {
1967    GET_CURRENT_CONTEXT(ctx);
1968    Node *n;
1969    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1970    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_I, 3);
1971    if (n) {
1972       n[1].e = target;
1973       n[2].e = pname;
1974       n[3].i = param;
1975    }
1976    if (ctx->ExecuteFlag) {
1977       CALL_ConvolutionParameteri(ctx->Exec, (target, pname, param));
1978    }
1979 }
1980
1981
1982 static void GLAPIENTRY
1983 save_ConvolutionParameteriv(GLenum target, GLenum pname, const GLint *params)
1984 {
1985    GET_CURRENT_CONTEXT(ctx);
1986    Node *n;
1987    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
1988    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_IV, 6);
1989    if (n) {
1990       n[1].e = target;
1991       n[2].e = pname;
1992       n[3].i = params[0];
1993       if (pname == GL_CONVOLUTION_BORDER_COLOR ||
1994           pname == GL_CONVOLUTION_FILTER_SCALE ||
1995           pname == GL_CONVOLUTION_FILTER_BIAS) {
1996          n[4].i = params[1];
1997          n[5].i = params[2];
1998          n[6].i = params[3];
1999       }
2000       else {
2001          n[4].i = n[5].i = n[6].i = 0;
2002       }
2003    }
2004    if (ctx->ExecuteFlag) {
2005       CALL_ConvolutionParameteriv(ctx->Exec, (target, pname, params));
2006    }
2007 }
2008
2009
2010 static void GLAPIENTRY
2011 save_ConvolutionParameterf(GLenum target, GLenum pname, GLfloat param)
2012 {
2013    GET_CURRENT_CONTEXT(ctx);
2014    Node *n;
2015    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2016    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_F, 3);
2017    if (n) {
2018       n[1].e = target;
2019       n[2].e = pname;
2020       n[3].f = param;
2021    }
2022    if (ctx->ExecuteFlag) {
2023       CALL_ConvolutionParameterf(ctx->Exec, (target, pname, param));
2024    }
2025 }
2026
2027
2028 static void GLAPIENTRY
2029 save_ConvolutionParameterfv(GLenum target, GLenum pname,
2030                             const GLfloat *params)
2031 {
2032    GET_CURRENT_CONTEXT(ctx);
2033    Node *n;
2034    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2035    n = alloc_instruction(ctx, OPCODE_CONVOLUTION_PARAMETER_FV, 6);
2036    if (n) {
2037       n[1].e = target;
2038       n[2].e = pname;
2039       n[3].f = params[0];
2040       if (pname == GL_CONVOLUTION_BORDER_COLOR ||
2041           pname == GL_CONVOLUTION_FILTER_SCALE ||
2042           pname == GL_CONVOLUTION_FILTER_BIAS) {
2043          n[4].f = params[1];
2044          n[5].f = params[2];
2045          n[6].f = params[3];
2046       }
2047       else {
2048          n[4].f = n[5].f = n[6].f = 0.0F;
2049       }
2050    }
2051    if (ctx->ExecuteFlag) {
2052       CALL_ConvolutionParameterfv(ctx->Exec, (target, pname, params));
2053    }
2054 }
2055
2056
2057 static void GLAPIENTRY
2058 save_CopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)
2059 {
2060    GET_CURRENT_CONTEXT(ctx);
2061    Node *n;
2062    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2063    n = alloc_instruction(ctx, OPCODE_COPY_PIXELS, 5);
2064    if (n) {
2065       n[1].i = x;
2066       n[2].i = y;
2067       n[3].i = (GLint) width;
2068       n[4].i = (GLint) height;
2069       n[5].e = type;
2070    }
2071    if (ctx->ExecuteFlag) {
2072       CALL_CopyPixels(ctx->Exec, (x, y, width, height, type));
2073    }
2074 }
2075
2076
2077
2078 static void GLAPIENTRY
2079 save_CopyTexImage1D(GLenum target, GLint level, GLenum internalformat,
2080                     GLint x, GLint y, GLsizei width, GLint border)
2081 {
2082    GET_CURRENT_CONTEXT(ctx);
2083    Node *n;
2084    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2085    n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE1D, 7);
2086    if (n) {
2087       n[1].e = target;
2088       n[2].i = level;
2089       n[3].e = internalformat;
2090       n[4].i = x;
2091       n[5].i = y;
2092       n[6].i = width;
2093       n[7].i = border;
2094    }
2095    if (ctx->ExecuteFlag) {
2096       CALL_CopyTexImage1D(ctx->Exec, (target, level, internalformat,
2097                                       x, y, width, border));
2098    }
2099 }
2100
2101
2102 static void GLAPIENTRY
2103 save_CopyTexImage2D(GLenum target, GLint level,
2104                     GLenum internalformat,
2105                     GLint x, GLint y, GLsizei width,
2106                     GLsizei height, GLint border)
2107 {
2108    GET_CURRENT_CONTEXT(ctx);
2109    Node *n;
2110    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2111    n = alloc_instruction(ctx, OPCODE_COPY_TEX_IMAGE2D, 8);
2112    if (n) {
2113       n[1].e = target;
2114       n[2].i = level;
2115       n[3].e = internalformat;
2116       n[4].i = x;
2117       n[5].i = y;
2118       n[6].i = width;
2119       n[7].i = height;
2120       n[8].i = border;
2121    }
2122    if (ctx->ExecuteFlag) {
2123       CALL_CopyTexImage2D(ctx->Exec, (target, level, internalformat,
2124                                       x, y, width, height, border));
2125    }
2126 }
2127
2128
2129
2130 static void GLAPIENTRY
2131 save_CopyTexSubImage1D(GLenum target, GLint level,
2132                        GLint xoffset, GLint x, GLint y, GLsizei width)
2133 {
2134    GET_CURRENT_CONTEXT(ctx);
2135    Node *n;
2136    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2137    n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE1D, 6);
2138    if (n) {
2139       n[1].e = target;
2140       n[2].i = level;
2141       n[3].i = xoffset;
2142       n[4].i = x;
2143       n[5].i = y;
2144       n[6].i = width;
2145    }
2146    if (ctx->ExecuteFlag) {
2147       CALL_CopyTexSubImage1D(ctx->Exec,
2148                              (target, level, xoffset, x, y, width));
2149    }
2150 }
2151
2152
2153 static void GLAPIENTRY
2154 save_CopyTexSubImage2D(GLenum target, GLint level,
2155                        GLint xoffset, GLint yoffset,
2156                        GLint x, GLint y, GLsizei width, GLint height)
2157 {
2158    GET_CURRENT_CONTEXT(ctx);
2159    Node *n;
2160    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2161    n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE2D, 8);
2162    if (n) {
2163       n[1].e = target;
2164       n[2].i = level;
2165       n[3].i = xoffset;
2166       n[4].i = yoffset;
2167       n[5].i = x;
2168       n[6].i = y;
2169       n[7].i = width;
2170       n[8].i = height;
2171    }
2172    if (ctx->ExecuteFlag) {
2173       CALL_CopyTexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
2174                                          x, y, width, height));
2175    }
2176 }
2177
2178
2179 static void GLAPIENTRY
2180 save_CopyTexSubImage3D(GLenum target, GLint level,
2181                        GLint xoffset, GLint yoffset, GLint zoffset,
2182                        GLint x, GLint y, GLsizei width, GLint height)
2183 {
2184    GET_CURRENT_CONTEXT(ctx);
2185    Node *n;
2186    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2187    n = alloc_instruction(ctx, OPCODE_COPY_TEX_SUB_IMAGE3D, 9);
2188    if (n) {
2189       n[1].e = target;
2190       n[2].i = level;
2191       n[3].i = xoffset;
2192       n[4].i = yoffset;
2193       n[5].i = zoffset;
2194       n[6].i = x;
2195       n[7].i = y;
2196       n[8].i = width;
2197       n[9].i = height;
2198    }
2199    if (ctx->ExecuteFlag) {
2200       CALL_CopyTexSubImage3D(ctx->Exec, (target, level,
2201                                          xoffset, yoffset, zoffset,
2202                                          x, y, width, height));
2203    }
2204 }
2205
2206
2207 static void GLAPIENTRY
2208 save_CullFace(GLenum mode)
2209 {
2210    GET_CURRENT_CONTEXT(ctx);
2211    Node *n;
2212    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2213    n = alloc_instruction(ctx, OPCODE_CULL_FACE, 1);
2214    if (n) {
2215       n[1].e = mode;
2216    }
2217    if (ctx->ExecuteFlag) {
2218       CALL_CullFace(ctx->Exec, (mode));
2219    }
2220 }
2221
2222
2223 static void GLAPIENTRY
2224 save_DepthFunc(GLenum func)
2225 {
2226    GET_CURRENT_CONTEXT(ctx);
2227    Node *n;
2228    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2229    n = alloc_instruction(ctx, OPCODE_DEPTH_FUNC, 1);
2230    if (n) {
2231       n[1].e = func;
2232    }
2233    if (ctx->ExecuteFlag) {
2234       CALL_DepthFunc(ctx->Exec, (func));
2235    }
2236 }
2237
2238
2239 static void GLAPIENTRY
2240 save_DepthMask(GLboolean mask)
2241 {
2242    GET_CURRENT_CONTEXT(ctx);
2243    Node *n;
2244    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2245    n = alloc_instruction(ctx, OPCODE_DEPTH_MASK, 1);
2246    if (n) {
2247       n[1].b = mask;
2248    }
2249    if (ctx->ExecuteFlag) {
2250       CALL_DepthMask(ctx->Exec, (mask));
2251    }
2252 }
2253
2254
2255 static void GLAPIENTRY
2256 save_DepthRange(GLclampd nearval, GLclampd farval)
2257 {
2258    GET_CURRENT_CONTEXT(ctx);
2259    Node *n;
2260    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2261    n = alloc_instruction(ctx, OPCODE_DEPTH_RANGE, 2);
2262    if (n) {
2263       n[1].f = (GLfloat) nearval;
2264       n[2].f = (GLfloat) farval;
2265    }
2266    if (ctx->ExecuteFlag) {
2267       CALL_DepthRange(ctx->Exec, (nearval, farval));
2268    }
2269 }
2270
2271
2272 static void GLAPIENTRY
2273 save_Disable(GLenum cap)
2274 {
2275    GET_CURRENT_CONTEXT(ctx);
2276    Node *n;
2277    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2278    n = alloc_instruction(ctx, OPCODE_DISABLE, 1);
2279    if (n) {
2280       n[1].e = cap;
2281    }
2282    if (ctx->ExecuteFlag) {
2283       CALL_Disable(ctx->Exec, (cap));
2284    }
2285 }
2286
2287
2288 static void GLAPIENTRY
2289 save_DisableIndexed(GLuint index, GLenum cap)
2290 {
2291    GET_CURRENT_CONTEXT(ctx);
2292    Node *n;
2293    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2294    n = alloc_instruction(ctx, OPCODE_DISABLE_INDEXED, 2);
2295    if (n) {
2296       n[1].ui = index;
2297       n[2].e = cap;
2298    }
2299    if (ctx->ExecuteFlag) {
2300       CALL_DisableIndexedEXT(ctx->Exec, (index, cap));
2301    }
2302 }
2303
2304
2305 static void GLAPIENTRY
2306 save_DrawBuffer(GLenum mode)
2307 {
2308    GET_CURRENT_CONTEXT(ctx);
2309    Node *n;
2310    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2311    n = alloc_instruction(ctx, OPCODE_DRAW_BUFFER, 1);
2312    if (n) {
2313       n[1].e = mode;
2314    }
2315    if (ctx->ExecuteFlag) {
2316       CALL_DrawBuffer(ctx->Exec, (mode));
2317    }
2318 }
2319
2320
2321 static void GLAPIENTRY
2322 save_DrawPixels(GLsizei width, GLsizei height,
2323                 GLenum format, GLenum type, const GLvoid * pixels)
2324 {
2325    GET_CURRENT_CONTEXT(ctx);
2326    Node *n;
2327
2328    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2329
2330    n = alloc_instruction(ctx, OPCODE_DRAW_PIXELS, 5);
2331    if (n) {
2332       n[1].i = width;
2333       n[2].i = height;
2334       n[3].e = format;
2335       n[4].e = type;
2336       n[5].data = unpack_image(ctx, 2, width, height, 1, format, type,
2337                                pixels, &ctx->Unpack);
2338    }
2339    if (ctx->ExecuteFlag) {
2340       CALL_DrawPixels(ctx->Exec, (width, height, format, type, pixels));
2341    }
2342 }
2343
2344
2345
2346 static void GLAPIENTRY
2347 save_Enable(GLenum cap)
2348 {
2349    GET_CURRENT_CONTEXT(ctx);
2350    Node *n;
2351    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2352    n = alloc_instruction(ctx, OPCODE_ENABLE, 1);
2353    if (n) {
2354       n[1].e = cap;
2355    }
2356    if (ctx->ExecuteFlag) {
2357       CALL_Enable(ctx->Exec, (cap));
2358    }
2359 }
2360
2361
2362
2363 static void GLAPIENTRY
2364 save_EnableIndexed(GLuint index, GLenum cap)
2365 {
2366    GET_CURRENT_CONTEXT(ctx);
2367    Node *n;
2368    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2369    n = alloc_instruction(ctx, OPCODE_ENABLE_INDEXED, 2);
2370    if (n) {
2371       n[1].ui = index;
2372       n[2].e = cap;
2373    }
2374    if (ctx->ExecuteFlag) {
2375       CALL_EnableIndexedEXT(ctx->Exec, (index, cap));
2376    }
2377 }
2378
2379
2380
2381 static void GLAPIENTRY
2382 save_EvalMesh1(GLenum mode, GLint i1, GLint i2)
2383 {
2384    GET_CURRENT_CONTEXT(ctx);
2385    Node *n;
2386    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2387    n = alloc_instruction(ctx, OPCODE_EVALMESH1, 3);
2388    if (n) {
2389       n[1].e = mode;
2390       n[2].i = i1;
2391       n[3].i = i2;
2392    }
2393    if (ctx->ExecuteFlag) {
2394       CALL_EvalMesh1(ctx->Exec, (mode, i1, i2));
2395    }
2396 }
2397
2398
2399 static void GLAPIENTRY
2400 save_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
2401 {
2402    GET_CURRENT_CONTEXT(ctx);
2403    Node *n;
2404    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2405    n = alloc_instruction(ctx, OPCODE_EVALMESH2, 5);
2406    if (n) {
2407       n[1].e = mode;
2408       n[2].i = i1;
2409       n[3].i = i2;
2410       n[4].i = j1;
2411       n[5].i = j2;
2412    }
2413    if (ctx->ExecuteFlag) {
2414       CALL_EvalMesh2(ctx->Exec, (mode, i1, i2, j1, j2));
2415    }
2416 }
2417
2418
2419
2420
2421 static void GLAPIENTRY
2422 save_Fogfv(GLenum pname, const GLfloat *params)
2423 {
2424    GET_CURRENT_CONTEXT(ctx);
2425    Node *n;
2426    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2427    n = alloc_instruction(ctx, OPCODE_FOG, 5);
2428    if (n) {
2429       n[1].e = pname;
2430       n[2].f = params[0];
2431       n[3].f = params[1];
2432       n[4].f = params[2];
2433       n[5].f = params[3];
2434    }
2435    if (ctx->ExecuteFlag) {
2436       CALL_Fogfv(ctx->Exec, (pname, params));
2437    }
2438 }
2439
2440
2441 static void GLAPIENTRY
2442 save_Fogf(GLenum pname, GLfloat param)
2443 {
2444    GLfloat parray[4];
2445    parray[0] = param;
2446    parray[1] = parray[2] = parray[3] = 0.0F;
2447    save_Fogfv(pname, parray);
2448 }
2449
2450
2451 static void GLAPIENTRY
2452 save_Fogiv(GLenum pname, const GLint *params)
2453 {
2454    GLfloat p[4];
2455    switch (pname) {
2456    case GL_FOG_MODE:
2457    case GL_FOG_DENSITY:
2458    case GL_FOG_START:
2459    case GL_FOG_END:
2460    case GL_FOG_INDEX:
2461       p[0] = (GLfloat) *params;
2462       p[1] = 0.0f;
2463       p[2] = 0.0f;
2464       p[3] = 0.0f;
2465       break;
2466    case GL_FOG_COLOR:
2467       p[0] = INT_TO_FLOAT(params[0]);
2468       p[1] = INT_TO_FLOAT(params[1]);
2469       p[2] = INT_TO_FLOAT(params[2]);
2470       p[3] = INT_TO_FLOAT(params[3]);
2471       break;
2472    default:
2473       /* Error will be caught later in gl_Fogfv */
2474       ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F);
2475    }
2476    save_Fogfv(pname, p);
2477 }
2478
2479
2480 static void GLAPIENTRY
2481 save_Fogi(GLenum pname, GLint param)
2482 {
2483    GLint parray[4];
2484    parray[0] = param;
2485    parray[1] = parray[2] = parray[3] = 0;
2486    save_Fogiv(pname, parray);
2487 }
2488
2489
2490 static void GLAPIENTRY
2491 save_FrontFace(GLenum mode)
2492 {
2493    GET_CURRENT_CONTEXT(ctx);
2494    Node *n;
2495    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2496    n = alloc_instruction(ctx, OPCODE_FRONT_FACE, 1);
2497    if (n) {
2498       n[1].e = mode;
2499    }
2500    if (ctx->ExecuteFlag) {
2501       CALL_FrontFace(ctx->Exec, (mode));
2502    }
2503 }
2504
2505
2506 static void GLAPIENTRY
2507 save_Frustum(GLdouble left, GLdouble right,
2508              GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
2509 {
2510    GET_CURRENT_CONTEXT(ctx);
2511    Node *n;
2512    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2513    n = alloc_instruction(ctx, OPCODE_FRUSTUM, 6);
2514    if (n) {
2515       n[1].f = (GLfloat) left;
2516       n[2].f = (GLfloat) right;
2517       n[3].f = (GLfloat) bottom;
2518       n[4].f = (GLfloat) top;
2519       n[5].f = (GLfloat) nearval;
2520       n[6].f = (GLfloat) farval;
2521    }
2522    if (ctx->ExecuteFlag) {
2523       CALL_Frustum(ctx->Exec, (left, right, bottom, top, nearval, farval));
2524    }
2525 }
2526
2527
2528 static void GLAPIENTRY
2529 save_Hint(GLenum target, GLenum mode)
2530 {
2531    GET_CURRENT_CONTEXT(ctx);
2532    Node *n;
2533    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2534    n = alloc_instruction(ctx, OPCODE_HINT, 2);
2535    if (n) {
2536       n[1].e = target;
2537       n[2].e = mode;
2538    }
2539    if (ctx->ExecuteFlag) {
2540       CALL_Hint(ctx->Exec, (target, mode));
2541    }
2542 }
2543
2544
2545 static void GLAPIENTRY
2546 save_Histogram(GLenum target, GLsizei width, GLenum internalFormat,
2547                GLboolean sink)
2548 {
2549    GET_CURRENT_CONTEXT(ctx);
2550    Node *n;
2551
2552    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2553    n = alloc_instruction(ctx, OPCODE_HISTOGRAM, 4);
2554    if (n) {
2555       n[1].e = target;
2556       n[2].i = width;
2557       n[3].e = internalFormat;
2558       n[4].b = sink;
2559    }
2560    if (ctx->ExecuteFlag) {
2561       CALL_Histogram(ctx->Exec, (target, width, internalFormat, sink));
2562    }
2563 }
2564
2565
2566 static void GLAPIENTRY
2567 save_IndexMask(GLuint mask)
2568 {
2569    GET_CURRENT_CONTEXT(ctx);
2570    Node *n;
2571    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2572    n = alloc_instruction(ctx, OPCODE_INDEX_MASK, 1);
2573    if (n) {
2574       n[1].ui = mask;
2575    }
2576    if (ctx->ExecuteFlag) {
2577       CALL_IndexMask(ctx->Exec, (mask));
2578    }
2579 }
2580
2581
2582 static void GLAPIENTRY
2583 save_InitNames(void)
2584 {
2585    GET_CURRENT_CONTEXT(ctx);
2586    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2587    (void) alloc_instruction(ctx, OPCODE_INIT_NAMES, 0);
2588    if (ctx->ExecuteFlag) {
2589       CALL_InitNames(ctx->Exec, ());
2590    }
2591 }
2592
2593
2594 static void GLAPIENTRY
2595 save_Lightfv(GLenum light, GLenum pname, const GLfloat *params)
2596 {
2597    GET_CURRENT_CONTEXT(ctx);
2598    Node *n;
2599    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2600    n = alloc_instruction(ctx, OPCODE_LIGHT, 6);
2601    if (n) {
2602       GLint i, nParams;
2603       n[1].e = light;
2604       n[2].e = pname;
2605       switch (pname) {
2606       case GL_AMBIENT:
2607          nParams = 4;
2608          break;
2609       case GL_DIFFUSE:
2610          nParams = 4;
2611          break;
2612       case GL_SPECULAR:
2613          nParams = 4;
2614          break;
2615       case GL_POSITION:
2616          nParams = 4;
2617          break;
2618       case GL_SPOT_DIRECTION:
2619          nParams = 3;
2620          break;
2621       case GL_SPOT_EXPONENT:
2622          nParams = 1;
2623          break;
2624       case GL_SPOT_CUTOFF:
2625          nParams = 1;
2626          break;
2627       case GL_CONSTANT_ATTENUATION:
2628          nParams = 1;
2629          break;
2630       case GL_LINEAR_ATTENUATION:
2631          nParams = 1;
2632          break;
2633       case GL_QUADRATIC_ATTENUATION:
2634          nParams = 1;
2635          break;
2636       default:
2637          nParams = 0;
2638       }
2639       for (i = 0; i < nParams; i++) {
2640          n[3 + i].f = params[i];
2641       }
2642    }
2643    if (ctx->ExecuteFlag) {
2644       CALL_Lightfv(ctx->Exec, (light, pname, params));
2645    }
2646 }
2647
2648
2649 static void GLAPIENTRY
2650 save_Lightf(GLenum light, GLenum pname, GLfloat param)
2651 {
2652    GLfloat parray[4];
2653    parray[0] = param;
2654    parray[1] = parray[2] = parray[3] = 0.0F;
2655    save_Lightfv(light, pname, parray);
2656 }
2657
2658
2659 static void GLAPIENTRY
2660 save_Lightiv(GLenum light, GLenum pname, const GLint *params)
2661 {
2662    GLfloat fparam[4];
2663    switch (pname) {
2664    case GL_AMBIENT:
2665    case GL_DIFFUSE:
2666    case GL_SPECULAR:
2667       fparam[0] = INT_TO_FLOAT(params[0]);
2668       fparam[1] = INT_TO_FLOAT(params[1]);
2669       fparam[2] = INT_TO_FLOAT(params[2]);
2670       fparam[3] = INT_TO_FLOAT(params[3]);
2671       break;
2672    case GL_POSITION:
2673       fparam[0] = (GLfloat) params[0];
2674       fparam[1] = (GLfloat) params[1];
2675       fparam[2] = (GLfloat) params[2];
2676       fparam[3] = (GLfloat) params[3];
2677       break;
2678    case GL_SPOT_DIRECTION:
2679       fparam[0] = (GLfloat) params[0];
2680       fparam[1] = (GLfloat) params[1];
2681       fparam[2] = (GLfloat) params[2];
2682       break;
2683    case GL_SPOT_EXPONENT:
2684    case GL_SPOT_CUTOFF:
2685    case GL_CONSTANT_ATTENUATION:
2686    case GL_LINEAR_ATTENUATION:
2687    case GL_QUADRATIC_ATTENUATION:
2688       fparam[0] = (GLfloat) params[0];
2689       break;
2690    default:
2691       /* error will be caught later in gl_Lightfv */
2692       ;
2693    }
2694    save_Lightfv(light, pname, fparam);
2695 }
2696
2697
2698 static void GLAPIENTRY
2699 save_Lighti(GLenum light, GLenum pname, GLint param)
2700 {
2701    GLint parray[4];
2702    parray[0] = param;
2703    parray[1] = parray[2] = parray[3] = 0;
2704    save_Lightiv(light, pname, parray);
2705 }
2706
2707
2708 static void GLAPIENTRY
2709 save_LightModelfv(GLenum pname, const GLfloat *params)
2710 {
2711    GET_CURRENT_CONTEXT(ctx);
2712    Node *n;
2713    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2714    n = alloc_instruction(ctx, OPCODE_LIGHT_MODEL, 5);
2715    if (n) {
2716       n[1].e = pname;
2717       n[2].f = params[0];
2718       n[3].f = params[1];
2719       n[4].f = params[2];
2720       n[5].f = params[3];
2721    }
2722    if (ctx->ExecuteFlag) {
2723       CALL_LightModelfv(ctx->Exec, (pname, params));
2724    }
2725 }
2726
2727
2728 static void GLAPIENTRY
2729 save_LightModelf(GLenum pname, GLfloat param)
2730 {
2731    GLfloat parray[4];
2732    parray[0] = param;
2733    parray[1] = parray[2] = parray[3] = 0.0F;
2734    save_LightModelfv(pname, parray);
2735 }
2736
2737
2738 static void GLAPIENTRY
2739 save_LightModeliv(GLenum pname, const GLint *params)
2740 {
2741    GLfloat fparam[4];
2742    switch (pname) {
2743    case GL_LIGHT_MODEL_AMBIENT:
2744       fparam[0] = INT_TO_FLOAT(params[0]);
2745       fparam[1] = INT_TO_FLOAT(params[1]);
2746       fparam[2] = INT_TO_FLOAT(params[2]);
2747       fparam[3] = INT_TO_FLOAT(params[3]);
2748       break;
2749    case GL_LIGHT_MODEL_LOCAL_VIEWER:
2750    case GL_LIGHT_MODEL_TWO_SIDE:
2751    case GL_LIGHT_MODEL_COLOR_CONTROL:
2752       fparam[0] = (GLfloat) params[0];
2753       fparam[1] = 0.0F;
2754       fparam[2] = 0.0F;
2755       fparam[3] = 0.0F;
2756       break;
2757    default:
2758       /* Error will be caught later in gl_LightModelfv */
2759       ASSIGN_4V(fparam, 0.0F, 0.0F, 0.0F, 0.0F);
2760    }
2761    save_LightModelfv(pname, fparam);
2762 }
2763
2764
2765 static void GLAPIENTRY
2766 save_LightModeli(GLenum pname, GLint param)
2767 {
2768    GLint parray[4];
2769    parray[0] = param;
2770    parray[1] = parray[2] = parray[3] = 0;
2771    save_LightModeliv(pname, parray);
2772 }
2773
2774
2775 static void GLAPIENTRY
2776 save_LineStipple(GLint factor, GLushort pattern)
2777 {
2778    GET_CURRENT_CONTEXT(ctx);
2779    Node *n;
2780    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2781    n = alloc_instruction(ctx, OPCODE_LINE_STIPPLE, 2);
2782    if (n) {
2783       n[1].i = factor;
2784       n[2].us = pattern;
2785    }
2786    if (ctx->ExecuteFlag) {
2787       CALL_LineStipple(ctx->Exec, (factor, pattern));
2788    }
2789 }
2790
2791
2792 static void GLAPIENTRY
2793 save_LineWidth(GLfloat width)
2794 {
2795    GET_CURRENT_CONTEXT(ctx);
2796    Node *n;
2797    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2798    n = alloc_instruction(ctx, OPCODE_LINE_WIDTH, 1);
2799    if (n) {
2800       n[1].f = width;
2801    }
2802    if (ctx->ExecuteFlag) {
2803       CALL_LineWidth(ctx->Exec, (width));
2804    }
2805 }
2806
2807
2808 static void GLAPIENTRY
2809 save_ListBase(GLuint base)
2810 {
2811    GET_CURRENT_CONTEXT(ctx);
2812    Node *n;
2813    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2814    n = alloc_instruction(ctx, OPCODE_LIST_BASE, 1);
2815    if (n) {
2816       n[1].ui = base;
2817    }
2818    if (ctx->ExecuteFlag) {
2819       CALL_ListBase(ctx->Exec, (base));
2820    }
2821 }
2822
2823
2824 static void GLAPIENTRY
2825 save_LoadIdentity(void)
2826 {
2827    GET_CURRENT_CONTEXT(ctx);
2828    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2829    (void) alloc_instruction(ctx, OPCODE_LOAD_IDENTITY, 0);
2830    if (ctx->ExecuteFlag) {
2831       CALL_LoadIdentity(ctx->Exec, ());
2832    }
2833 }
2834
2835
2836 static void GLAPIENTRY
2837 save_LoadMatrixf(const GLfloat * m)
2838 {
2839    GET_CURRENT_CONTEXT(ctx);
2840    Node *n;
2841    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2842    n = alloc_instruction(ctx, OPCODE_LOAD_MATRIX, 16);
2843    if (n) {
2844       GLuint i;
2845       for (i = 0; i < 16; i++) {
2846          n[1 + i].f = m[i];
2847       }
2848    }
2849    if (ctx->ExecuteFlag) {
2850       CALL_LoadMatrixf(ctx->Exec, (m));
2851    }
2852 }
2853
2854
2855 static void GLAPIENTRY
2856 save_LoadMatrixd(const GLdouble * m)
2857 {
2858    GLfloat f[16];
2859    GLint i;
2860    for (i = 0; i < 16; i++) {
2861       f[i] = (GLfloat) m[i];
2862    }
2863    save_LoadMatrixf(f);
2864 }
2865
2866
2867 static void GLAPIENTRY
2868 save_LoadName(GLuint name)
2869 {
2870    GET_CURRENT_CONTEXT(ctx);
2871    Node *n;
2872    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2873    n = alloc_instruction(ctx, OPCODE_LOAD_NAME, 1);
2874    if (n) {
2875       n[1].ui = name;
2876    }
2877    if (ctx->ExecuteFlag) {
2878       CALL_LoadName(ctx->Exec, (name));
2879    }
2880 }
2881
2882
2883 static void GLAPIENTRY
2884 save_LogicOp(GLenum opcode)
2885 {
2886    GET_CURRENT_CONTEXT(ctx);
2887    Node *n;
2888    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2889    n = alloc_instruction(ctx, OPCODE_LOGIC_OP, 1);
2890    if (n) {
2891       n[1].e = opcode;
2892    }
2893    if (ctx->ExecuteFlag) {
2894       CALL_LogicOp(ctx->Exec, (opcode));
2895    }
2896 }
2897
2898
2899 static void GLAPIENTRY
2900 save_Map1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
2901            GLint order, const GLdouble * points)
2902 {
2903    GET_CURRENT_CONTEXT(ctx);
2904    Node *n;
2905    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2906    n = alloc_instruction(ctx, OPCODE_MAP1, 6);
2907    if (n) {
2908       GLfloat *pnts = _mesa_copy_map_points1d(target, stride, order, points);
2909       n[1].e = target;
2910       n[2].f = (GLfloat) u1;
2911       n[3].f = (GLfloat) u2;
2912       n[4].i = _mesa_evaluator_components(target);      /* stride */
2913       n[5].i = order;
2914       n[6].data = (void *) pnts;
2915    }
2916    if (ctx->ExecuteFlag) {
2917       CALL_Map1d(ctx->Exec, (target, u1, u2, stride, order, points));
2918    }
2919 }
2920
2921 static void GLAPIENTRY
2922 save_Map1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
2923            GLint order, const GLfloat * points)
2924 {
2925    GET_CURRENT_CONTEXT(ctx);
2926    Node *n;
2927    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2928    n = alloc_instruction(ctx, OPCODE_MAP1, 6);
2929    if (n) {
2930       GLfloat *pnts = _mesa_copy_map_points1f(target, stride, order, points);
2931       n[1].e = target;
2932       n[2].f = u1;
2933       n[3].f = u2;
2934       n[4].i = _mesa_evaluator_components(target);      /* stride */
2935       n[5].i = order;
2936       n[6].data = (void *) pnts;
2937    }
2938    if (ctx->ExecuteFlag) {
2939       CALL_Map1f(ctx->Exec, (target, u1, u2, stride, order, points));
2940    }
2941 }
2942
2943
2944 static void GLAPIENTRY
2945 save_Map2d(GLenum target,
2946            GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
2947            GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
2948            const GLdouble * points)
2949 {
2950    GET_CURRENT_CONTEXT(ctx);
2951    Node *n;
2952    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2953    n = alloc_instruction(ctx, OPCODE_MAP2, 10);
2954    if (n) {
2955       GLfloat *pnts = _mesa_copy_map_points2d(target, ustride, uorder,
2956                                               vstride, vorder, points);
2957       n[1].e = target;
2958       n[2].f = (GLfloat) u1;
2959       n[3].f = (GLfloat) u2;
2960       n[4].f = (GLfloat) v1;
2961       n[5].f = (GLfloat) v2;
2962       /* XXX verify these strides are correct */
2963       n[6].i = _mesa_evaluator_components(target) * vorder;     /*ustride */
2964       n[7].i = _mesa_evaluator_components(target);      /*vstride */
2965       n[8].i = uorder;
2966       n[9].i = vorder;
2967       n[10].data = (void *) pnts;
2968    }
2969    if (ctx->ExecuteFlag) {
2970       CALL_Map2d(ctx->Exec, (target,
2971                              u1, u2, ustride, uorder,
2972                              v1, v2, vstride, vorder, points));
2973    }
2974 }
2975
2976
2977 static void GLAPIENTRY
2978 save_Map2f(GLenum target,
2979            GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
2980            GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
2981            const GLfloat * points)
2982 {
2983    GET_CURRENT_CONTEXT(ctx);
2984    Node *n;
2985    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
2986    n = alloc_instruction(ctx, OPCODE_MAP2, 10);
2987    if (n) {
2988       GLfloat *pnts = _mesa_copy_map_points2f(target, ustride, uorder,
2989                                               vstride, vorder, points);
2990       n[1].e = target;
2991       n[2].f = u1;
2992       n[3].f = u2;
2993       n[4].f = v1;
2994       n[5].f = v2;
2995       /* XXX verify these strides are correct */
2996       n[6].i = _mesa_evaluator_components(target) * vorder;     /*ustride */
2997       n[7].i = _mesa_evaluator_components(target);      /*vstride */
2998       n[8].i = uorder;
2999       n[9].i = vorder;
3000       n[10].data = (void *) pnts;
3001    }
3002    if (ctx->ExecuteFlag) {
3003       CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
3004                              v1, v2, vstride, vorder, points));
3005    }
3006 }
3007
3008
3009 static void GLAPIENTRY
3010 save_MapGrid1f(GLint un, GLfloat u1, GLfloat u2)
3011 {
3012    GET_CURRENT_CONTEXT(ctx);
3013    Node *n;
3014    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3015    n = alloc_instruction(ctx, OPCODE_MAPGRID1, 3);
3016    if (n) {
3017       n[1].i = un;
3018       n[2].f = u1;
3019       n[3].f = u2;
3020    }
3021    if (ctx->ExecuteFlag) {
3022       CALL_MapGrid1f(ctx->Exec, (un, u1, u2));
3023    }
3024 }
3025
3026
3027 static void GLAPIENTRY
3028 save_MapGrid1d(GLint un, GLdouble u1, GLdouble u2)
3029 {
3030    save_MapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
3031 }
3032
3033
3034 static void GLAPIENTRY
3035 save_MapGrid2f(GLint un, GLfloat u1, GLfloat u2,
3036                GLint vn, GLfloat v1, GLfloat v2)
3037 {
3038    GET_CURRENT_CONTEXT(ctx);
3039    Node *n;
3040    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3041    n = alloc_instruction(ctx, OPCODE_MAPGRID2, 6);
3042    if (n) {
3043       n[1].i = un;
3044       n[2].f = u1;
3045       n[3].f = u2;
3046       n[4].i = vn;
3047       n[5].f = v1;
3048       n[6].f = v2;
3049    }
3050    if (ctx->ExecuteFlag) {
3051       CALL_MapGrid2f(ctx->Exec, (un, u1, u2, vn, v1, v2));
3052    }
3053 }
3054
3055
3056
3057 static void GLAPIENTRY
3058 save_MapGrid2d(GLint un, GLdouble u1, GLdouble u2,
3059                GLint vn, GLdouble v1, GLdouble v2)
3060 {
3061    save_MapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
3062                   vn, (GLfloat) v1, (GLfloat) v2);
3063 }
3064
3065
3066 static void GLAPIENTRY
3067 save_MatrixMode(GLenum mode)
3068 {
3069    GET_CURRENT_CONTEXT(ctx);
3070    Node *n;
3071    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3072    n = alloc_instruction(ctx, OPCODE_MATRIX_MODE, 1);
3073    if (n) {
3074       n[1].e = mode;
3075    }
3076    if (ctx->ExecuteFlag) {
3077       CALL_MatrixMode(ctx->Exec, (mode));
3078    }
3079 }
3080
3081
3082 static void GLAPIENTRY
3083 save_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
3084 {
3085    GET_CURRENT_CONTEXT(ctx);
3086    Node *n;
3087
3088    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3089    n = alloc_instruction(ctx, OPCODE_MIN_MAX, 3);
3090    if (n) {
3091       n[1].e = target;
3092       n[2].e = internalFormat;
3093       n[3].b = sink;
3094    }
3095    if (ctx->ExecuteFlag) {
3096       CALL_Minmax(ctx->Exec, (target, internalFormat, sink));
3097    }
3098 }
3099
3100
3101 static void GLAPIENTRY
3102 save_MultMatrixf(const GLfloat * m)
3103 {
3104    GET_CURRENT_CONTEXT(ctx);
3105    Node *n;
3106    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3107    n = alloc_instruction(ctx, OPCODE_MULT_MATRIX, 16);
3108    if (n) {
3109       GLuint i;
3110       for (i = 0; i < 16; i++) {
3111          n[1 + i].f = m[i];
3112       }
3113    }
3114    if (ctx->ExecuteFlag) {
3115       CALL_MultMatrixf(ctx->Exec, (m));
3116    }
3117 }
3118
3119
3120 static void GLAPIENTRY
3121 save_MultMatrixd(const GLdouble * m)
3122 {
3123    GLfloat f[16];
3124    GLint i;
3125    for (i = 0; i < 16; i++) {
3126       f[i] = (GLfloat) m[i];
3127    }
3128    save_MultMatrixf(f);
3129 }
3130
3131
3132 static void GLAPIENTRY
3133 save_NewList(GLuint name, GLenum mode)
3134 {
3135    GET_CURRENT_CONTEXT(ctx);
3136    /* It's an error to call this function while building a display list */
3137    _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
3138    (void) name;
3139    (void) mode;
3140 }
3141
3142
3143
3144 static void GLAPIENTRY
3145 save_Ortho(GLdouble left, GLdouble right,
3146            GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
3147 {
3148    GET_CURRENT_CONTEXT(ctx);
3149    Node *n;
3150    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3151    n = alloc_instruction(ctx, OPCODE_ORTHO, 6);
3152    if (n) {
3153       n[1].f = (GLfloat) left;
3154       n[2].f = (GLfloat) right;
3155       n[3].f = (GLfloat) bottom;
3156       n[4].f = (GLfloat) top;
3157       n[5].f = (GLfloat) nearval;
3158       n[6].f = (GLfloat) farval;
3159    }
3160    if (ctx->ExecuteFlag) {
3161       CALL_Ortho(ctx->Exec, (left, right, bottom, top, nearval, farval));
3162    }
3163 }
3164
3165
3166 static void GLAPIENTRY
3167 save_PixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
3168 {
3169    GET_CURRENT_CONTEXT(ctx);
3170    Node *n;
3171    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3172    n = alloc_instruction(ctx, OPCODE_PIXEL_MAP, 3);
3173    if (n) {
3174       n[1].e = map;
3175       n[2].i = mapsize;
3176       n[3].data = malloc(mapsize * sizeof(GLfloat));
3177       memcpy(n[3].data, (void *) values, mapsize * sizeof(GLfloat));
3178    }
3179    if (ctx->ExecuteFlag) {
3180       CALL_PixelMapfv(ctx->Exec, (map, mapsize, values));
3181    }
3182 }
3183
3184
3185 static void GLAPIENTRY
3186 save_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values)
3187 {
3188    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
3189    GLint i;
3190    if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
3191       for (i = 0; i < mapsize; i++) {
3192          fvalues[i] = (GLfloat) values[i];
3193       }
3194    }
3195    else {
3196       for (i = 0; i < mapsize; i++) {
3197          fvalues[i] = UINT_TO_FLOAT(values[i]);
3198       }
3199    }
3200    save_PixelMapfv(map, mapsize, fvalues);
3201 }
3202
3203
3204 static void GLAPIENTRY
3205 save_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
3206 {
3207    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
3208    GLint i;
3209    if (map == GL_PIXEL_MAP_I_TO_I || map == GL_PIXEL_MAP_S_TO_S) {
3210       for (i = 0; i < mapsize; i++) {
3211          fvalues[i] = (GLfloat) values[i];
3212       }
3213    }
3214    else {
3215       for (i = 0; i < mapsize; i++) {
3216          fvalues[i] = USHORT_TO_FLOAT(values[i]);
3217       }
3218    }
3219    save_PixelMapfv(map, mapsize, fvalues);
3220 }
3221
3222
3223 static void GLAPIENTRY
3224 save_PixelTransferf(GLenum pname, GLfloat param)
3225 {
3226    GET_CURRENT_CONTEXT(ctx);
3227    Node *n;
3228    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3229    n = alloc_instruction(ctx, OPCODE_PIXEL_TRANSFER, 2);
3230    if (n) {
3231       n[1].e = pname;
3232       n[2].f = param;
3233    }
3234    if (ctx->ExecuteFlag) {
3235       CALL_PixelTransferf(ctx->Exec, (pname, param));
3236    }
3237 }
3238
3239
3240 static void GLAPIENTRY
3241 save_PixelTransferi(GLenum pname, GLint param)
3242 {
3243    save_PixelTransferf(pname, (GLfloat) param);
3244 }
3245
3246
3247 static void GLAPIENTRY
3248 save_PixelZoom(GLfloat xfactor, GLfloat yfactor)
3249 {
3250    GET_CURRENT_CONTEXT(ctx);
3251    Node *n;
3252    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3253    n = alloc_instruction(ctx, OPCODE_PIXEL_ZOOM, 2);
3254    if (n) {
3255       n[1].f = xfactor;
3256       n[2].f = yfactor;
3257    }
3258    if (ctx->ExecuteFlag) {
3259       CALL_PixelZoom(ctx->Exec, (xfactor, yfactor));
3260    }
3261 }
3262
3263
3264 static void GLAPIENTRY
3265 save_PointParameterfvEXT(GLenum pname, const GLfloat *params)
3266 {
3267    GET_CURRENT_CONTEXT(ctx);
3268    Node *n;
3269    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3270    n = alloc_instruction(ctx, OPCODE_POINT_PARAMETERS, 4);
3271    if (n) {
3272       n[1].e = pname;
3273       n[2].f = params[0];
3274       n[3].f = params[1];
3275       n[4].f = params[2];
3276    }
3277    if (ctx->ExecuteFlag) {
3278       CALL_PointParameterfvEXT(ctx->Exec, (pname, params));
3279    }
3280 }
3281
3282
3283 static void GLAPIENTRY
3284 save_PointParameterfEXT(GLenum pname, GLfloat param)
3285 {
3286    GLfloat parray[3];
3287    parray[0] = param;
3288    parray[1] = parray[2] = 0.0F;
3289    save_PointParameterfvEXT(pname, parray);
3290 }
3291
3292 static void GLAPIENTRY
3293 save_PointParameteriNV(GLenum pname, GLint param)
3294 {
3295    GLfloat parray[3];
3296    parray[0] = (GLfloat) param;
3297    parray[1] = parray[2] = 0.0F;
3298    save_PointParameterfvEXT(pname, parray);
3299 }
3300
3301 static void GLAPIENTRY
3302 save_PointParameterivNV(GLenum pname, const GLint * param)
3303 {
3304    GLfloat parray[3];
3305    parray[0] = (GLfloat) param[0];
3306    parray[1] = parray[2] = 0.0F;
3307    save_PointParameterfvEXT(pname, parray);
3308 }
3309
3310
3311 static void GLAPIENTRY
3312 save_PointSize(GLfloat size)
3313 {
3314    GET_CURRENT_CONTEXT(ctx);
3315    Node *n;
3316    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3317    n = alloc_instruction(ctx, OPCODE_POINT_SIZE, 1);
3318    if (n) {
3319       n[1].f = size;
3320    }
3321    if (ctx->ExecuteFlag) {
3322       CALL_PointSize(ctx->Exec, (size));
3323    }
3324 }
3325
3326
3327 static void GLAPIENTRY
3328 save_PolygonMode(GLenum face, GLenum mode)
3329 {
3330    GET_CURRENT_CONTEXT(ctx);
3331    Node *n;
3332    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3333    n = alloc_instruction(ctx, OPCODE_POLYGON_MODE, 2);
3334    if (n) {
3335       n[1].e = face;
3336       n[2].e = mode;
3337    }
3338    if (ctx->ExecuteFlag) {
3339       CALL_PolygonMode(ctx->Exec, (face, mode));
3340    }
3341 }
3342
3343
3344 static void GLAPIENTRY
3345 save_PolygonStipple(const GLubyte * pattern)
3346 {
3347    GET_CURRENT_CONTEXT(ctx);
3348    Node *n;
3349
3350    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3351
3352    n = alloc_instruction(ctx, OPCODE_POLYGON_STIPPLE, 1);
3353    if (n) {
3354       n[1].data = unpack_image(ctx, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP,
3355                                pattern, &ctx->Unpack);
3356    }
3357    if (ctx->ExecuteFlag) {
3358       CALL_PolygonStipple(ctx->Exec, ((GLubyte *) pattern));
3359    }
3360 }
3361
3362
3363 static void GLAPIENTRY
3364 save_PolygonOffset(GLfloat factor, GLfloat units)
3365 {
3366    GET_CURRENT_CONTEXT(ctx);
3367    Node *n;
3368    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3369    n = alloc_instruction(ctx, OPCODE_POLYGON_OFFSET, 2);
3370    if (n) {
3371       n[1].f = factor;
3372       n[2].f = units;
3373    }
3374    if (ctx->ExecuteFlag) {
3375       CALL_PolygonOffset(ctx->Exec, (factor, units));
3376    }
3377 }
3378
3379
3380 static void GLAPIENTRY
3381 save_PolygonOffsetEXT(GLfloat factor, GLfloat bias)
3382 {
3383    GET_CURRENT_CONTEXT(ctx);
3384    /* XXX mult by DepthMaxF here??? */
3385    save_PolygonOffset(factor, ctx->DrawBuffer->_DepthMaxF * bias);
3386 }
3387
3388
3389 static void GLAPIENTRY
3390 save_PopAttrib(void)
3391 {
3392    GET_CURRENT_CONTEXT(ctx);
3393    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3394    (void) alloc_instruction(ctx, OPCODE_POP_ATTRIB, 0);
3395    if (ctx->ExecuteFlag) {
3396       CALL_PopAttrib(ctx->Exec, ());
3397    }
3398 }
3399
3400
3401 static void GLAPIENTRY
3402 save_PopMatrix(void)
3403 {
3404    GET_CURRENT_CONTEXT(ctx);
3405    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3406    (void) alloc_instruction(ctx, OPCODE_POP_MATRIX, 0);
3407    if (ctx->ExecuteFlag) {
3408       CALL_PopMatrix(ctx->Exec, ());
3409    }
3410 }
3411
3412
3413 static void GLAPIENTRY
3414 save_PopName(void)
3415 {
3416    GET_CURRENT_CONTEXT(ctx);
3417    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3418    (void) alloc_instruction(ctx, OPCODE_POP_NAME, 0);
3419    if (ctx->ExecuteFlag) {
3420       CALL_PopName(ctx->Exec, ());
3421    }
3422 }
3423
3424
3425 static void GLAPIENTRY
3426 save_PrioritizeTextures(GLsizei num, const GLuint * textures,
3427                         const GLclampf * priorities)
3428 {
3429    GET_CURRENT_CONTEXT(ctx);
3430    GLint i;
3431    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3432
3433    for (i = 0; i < num; i++) {
3434       Node *n;
3435       n = alloc_instruction(ctx, OPCODE_PRIORITIZE_TEXTURE, 2);
3436       if (n) {
3437          n[1].ui = textures[i];
3438          n[2].f = priorities[i];
3439       }
3440    }
3441    if (ctx->ExecuteFlag) {
3442       CALL_PrioritizeTextures(ctx->Exec, (num, textures, priorities));
3443    }
3444 }
3445
3446
3447 static void GLAPIENTRY
3448 save_PushAttrib(GLbitfield mask)
3449 {
3450    GET_CURRENT_CONTEXT(ctx);
3451    Node *n;
3452    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3453    n = alloc_instruction(ctx, OPCODE_PUSH_ATTRIB, 1);
3454    if (n) {
3455       n[1].bf = mask;
3456    }
3457    if (ctx->ExecuteFlag) {
3458       CALL_PushAttrib(ctx->Exec, (mask));
3459    }
3460 }
3461
3462
3463 static void GLAPIENTRY
3464 save_PushMatrix(void)
3465 {
3466    GET_CURRENT_CONTEXT(ctx);
3467    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3468    (void) alloc_instruction(ctx, OPCODE_PUSH_MATRIX, 0);
3469    if (ctx->ExecuteFlag) {
3470       CALL_PushMatrix(ctx->Exec, ());
3471    }
3472 }
3473
3474
3475 static void GLAPIENTRY
3476 save_PushName(GLuint name)
3477 {
3478    GET_CURRENT_CONTEXT(ctx);
3479    Node *n;
3480    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3481    n = alloc_instruction(ctx, OPCODE_PUSH_NAME, 1);
3482    if (n) {
3483       n[1].ui = name;
3484    }
3485    if (ctx->ExecuteFlag) {
3486       CALL_PushName(ctx->Exec, (name));
3487    }
3488 }
3489
3490
3491 static void GLAPIENTRY
3492 save_RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3493 {
3494    GET_CURRENT_CONTEXT(ctx);
3495    Node *n;
3496    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3497    n = alloc_instruction(ctx, OPCODE_RASTER_POS, 4);
3498    if (n) {
3499       n[1].f = x;
3500       n[2].f = y;
3501       n[3].f = z;
3502       n[4].f = w;
3503    }
3504    if (ctx->ExecuteFlag) {
3505       CALL_RasterPos4f(ctx->Exec, (x, y, z, w));
3506    }
3507 }
3508
3509 static void GLAPIENTRY
3510 save_RasterPos2d(GLdouble x, GLdouble y)
3511 {
3512    save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
3513 }
3514
3515 static void GLAPIENTRY
3516 save_RasterPos2f(GLfloat x, GLfloat y)
3517 {
3518    save_RasterPos4f(x, y, 0.0F, 1.0F);
3519 }
3520
3521 static void GLAPIENTRY
3522 save_RasterPos2i(GLint x, GLint y)
3523 {
3524    save_RasterPos4f((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
3525 }
3526
3527 static void GLAPIENTRY
3528 save_RasterPos2s(GLshort x, GLshort y)
3529 {
3530    save_RasterPos4f(x, y, 0.0F, 1.0F);
3531 }
3532
3533 static void GLAPIENTRY
3534 save_RasterPos3d(GLdouble x, GLdouble y, GLdouble z)
3535 {
3536    save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
3537 }
3538
3539 static void GLAPIENTRY
3540 save_RasterPos3f(GLfloat x, GLfloat y, GLfloat z)
3541 {
3542    save_RasterPos4f(x, y, z, 1.0F);
3543 }
3544
3545 static void GLAPIENTRY
3546 save_RasterPos3i(GLint x, GLint y, GLint z)
3547 {
3548    save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
3549 }
3550
3551 static void GLAPIENTRY
3552 save_RasterPos3s(GLshort x, GLshort y, GLshort z)
3553 {
3554    save_RasterPos4f(x, y, z, 1.0F);
3555 }
3556
3557 static void GLAPIENTRY
3558 save_RasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
3559 {
3560    save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
3561 }
3562
3563 static void GLAPIENTRY
3564 save_RasterPos4i(GLint x, GLint y, GLint z, GLint w)
3565 {
3566    save_RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
3567 }
3568
3569 static void GLAPIENTRY
3570 save_RasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
3571 {
3572    save_RasterPos4f(x, y, z, w);
3573 }
3574
3575 static void GLAPIENTRY
3576 save_RasterPos2dv(const GLdouble * v)
3577 {
3578    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
3579 }
3580
3581 static void GLAPIENTRY
3582 save_RasterPos2fv(const GLfloat * v)
3583 {
3584    save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
3585 }
3586
3587 static void GLAPIENTRY
3588 save_RasterPos2iv(const GLint * v)
3589 {
3590    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
3591 }
3592
3593 static void GLAPIENTRY
3594 save_RasterPos2sv(const GLshort * v)
3595 {
3596    save_RasterPos4f(v[0], v[1], 0.0F, 1.0F);
3597 }
3598
3599 static void GLAPIENTRY
3600 save_RasterPos3dv(const GLdouble * v)
3601 {
3602    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
3603 }
3604
3605 static void GLAPIENTRY
3606 save_RasterPos3fv(const GLfloat * v)
3607 {
3608    save_RasterPos4f(v[0], v[1], v[2], 1.0F);
3609 }
3610
3611 static void GLAPIENTRY
3612 save_RasterPos3iv(const GLint * v)
3613 {
3614    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
3615 }
3616
3617 static void GLAPIENTRY
3618 save_RasterPos3sv(const GLshort * v)
3619 {
3620    save_RasterPos4f(v[0], v[1], v[2], 1.0F);
3621 }
3622
3623 static void GLAPIENTRY
3624 save_RasterPos4dv(const GLdouble * v)
3625 {
3626    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
3627                     (GLfloat) v[2], (GLfloat) v[3]);
3628 }
3629
3630 static void GLAPIENTRY
3631 save_RasterPos4fv(const GLfloat * v)
3632 {
3633    save_RasterPos4f(v[0], v[1], v[2], v[3]);
3634 }
3635
3636 static void GLAPIENTRY
3637 save_RasterPos4iv(const GLint * v)
3638 {
3639    save_RasterPos4f((GLfloat) v[0], (GLfloat) v[1],
3640                     (GLfloat) v[2], (GLfloat) v[3]);
3641 }
3642
3643 static void GLAPIENTRY
3644 save_RasterPos4sv(const GLshort * v)
3645 {
3646    save_RasterPos4f(v[0], v[1], v[2], v[3]);
3647 }
3648
3649
3650 static void GLAPIENTRY
3651 save_PassThrough(GLfloat token)
3652 {
3653    GET_CURRENT_CONTEXT(ctx);
3654    Node *n;
3655    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3656    n = alloc_instruction(ctx, OPCODE_PASSTHROUGH, 1);
3657    if (n) {
3658       n[1].f = token;
3659    }
3660    if (ctx->ExecuteFlag) {
3661       CALL_PassThrough(ctx->Exec, (token));
3662    }
3663 }
3664
3665
3666 static void GLAPIENTRY
3667 save_ReadBuffer(GLenum mode)
3668 {
3669    GET_CURRENT_CONTEXT(ctx);
3670    Node *n;
3671    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3672    n = alloc_instruction(ctx, OPCODE_READ_BUFFER, 1);
3673    if (n) {
3674       n[1].e = mode;
3675    }
3676    if (ctx->ExecuteFlag) {
3677       CALL_ReadBuffer(ctx->Exec, (mode));
3678    }
3679 }
3680
3681
3682 static void GLAPIENTRY
3683 save_ResetHistogram(GLenum target)
3684 {
3685    GET_CURRENT_CONTEXT(ctx);
3686    Node *n;
3687    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3688    n = alloc_instruction(ctx, OPCODE_RESET_HISTOGRAM, 1);
3689    if (n) {
3690       n[1].e = target;
3691    }
3692    if (ctx->ExecuteFlag) {
3693       CALL_ResetHistogram(ctx->Exec, (target));
3694    }
3695 }
3696
3697
3698 static void GLAPIENTRY
3699 save_ResetMinmax(GLenum target)
3700 {
3701    GET_CURRENT_CONTEXT(ctx);
3702    Node *n;
3703    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3704    n = alloc_instruction(ctx, OPCODE_RESET_MIN_MAX, 1);
3705    if (n) {
3706       n[1].e = target;
3707    }
3708    if (ctx->ExecuteFlag) {
3709       CALL_ResetMinmax(ctx->Exec, (target));
3710    }
3711 }
3712
3713
3714 static void GLAPIENTRY
3715 save_Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
3716 {
3717    GET_CURRENT_CONTEXT(ctx);
3718    Node *n;
3719    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3720    n = alloc_instruction(ctx, OPCODE_ROTATE, 4);
3721    if (n) {
3722       n[1].f = angle;
3723       n[2].f = x;
3724       n[3].f = y;
3725       n[4].f = z;
3726    }
3727    if (ctx->ExecuteFlag) {
3728       CALL_Rotatef(ctx->Exec, (angle, x, y, z));
3729    }
3730 }
3731
3732
3733 static void GLAPIENTRY
3734 save_Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
3735 {
3736    save_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
3737 }
3738
3739
3740 static void GLAPIENTRY
3741 save_Scalef(GLfloat x, GLfloat y, GLfloat z)
3742 {
3743    GET_CURRENT_CONTEXT(ctx);
3744    Node *n;
3745    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3746    n = alloc_instruction(ctx, OPCODE_SCALE, 3);
3747    if (n) {
3748       n[1].f = x;
3749       n[2].f = y;
3750       n[3].f = z;
3751    }
3752    if (ctx->ExecuteFlag) {
3753       CALL_Scalef(ctx->Exec, (x, y, z));
3754    }
3755 }
3756
3757
3758 static void GLAPIENTRY
3759 save_Scaled(GLdouble x, GLdouble y, GLdouble z)
3760 {
3761    save_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
3762 }
3763
3764
3765 static void GLAPIENTRY
3766 save_Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3767 {
3768    GET_CURRENT_CONTEXT(ctx);
3769    Node *n;
3770    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3771    n = alloc_instruction(ctx, OPCODE_SCISSOR, 4);
3772    if (n) {
3773       n[1].i = x;
3774       n[2].i = y;
3775       n[3].i = width;
3776       n[4].i = height;
3777    }
3778    if (ctx->ExecuteFlag) {
3779       CALL_Scissor(ctx->Exec, (x, y, width, height));
3780    }
3781 }
3782
3783
3784 static void GLAPIENTRY
3785 save_ShadeModel(GLenum mode)
3786 {
3787    GET_CURRENT_CONTEXT(ctx);
3788    Node *n;
3789    ASSERT_OUTSIDE_SAVE_BEGIN_END(ctx);
3790
3791    if (ctx->ExecuteFlag) {
3792       CALL_ShadeModel(ctx->Exec, (mode));
3793    }
3794
3795    if (ctx->ListState.Current.ShadeModel == mode)
3796       return;
3797
3798    SAVE_FLUSH_VERTICES(ctx);
3799
3800    /* Only save the value if we know the statechange will take effect:
3801     */
3802    if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END)
3803       ctx->ListState.Current.ShadeModel = mode;
3804
3805    n = alloc_instruction(ctx, OPCODE_SHADE_MODEL, 1);
3806    if (n) {
3807       n[1].e = mode;
3808    }
3809 }
3810
3811
3812 static void GLAPIENTRY
3813 save_StencilFunc(GLenum func, GLint ref, GLuint mask)
3814 {
3815    GET_CURRENT_CONTEXT(ctx);
3816    Node *n;
3817    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3818    n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC, 3);
3819    if (n) {
3820       n[1].e = func;
3821       n[2].i = ref;
3822       n[3].ui = mask;
3823    }
3824    if (ctx->ExecuteFlag) {
3825       CALL_StencilFunc(ctx->Exec, (func, ref, mask));
3826    }
3827 }
3828
3829
3830 static void GLAPIENTRY
3831 save_StencilMask(GLuint mask)
3832 {
3833    GET_CURRENT_CONTEXT(ctx);
3834    Node *n;
3835    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3836    n = alloc_instruction(ctx, OPCODE_STENCIL_MASK, 1);
3837    if (n) {
3838       n[1].ui = mask;
3839    }
3840    if (ctx->ExecuteFlag) {
3841       CALL_StencilMask(ctx->Exec, (mask));
3842    }
3843 }
3844
3845
3846 static void GLAPIENTRY
3847 save_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
3848 {
3849    GET_CURRENT_CONTEXT(ctx);
3850    Node *n;
3851    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3852    n = alloc_instruction(ctx, OPCODE_STENCIL_OP, 3);
3853    if (n) {
3854       n[1].e = fail;
3855       n[2].e = zfail;
3856       n[3].e = zpass;
3857    }
3858    if (ctx->ExecuteFlag) {
3859       CALL_StencilOp(ctx->Exec, (fail, zfail, zpass));
3860    }
3861 }
3862
3863
3864 static void GLAPIENTRY
3865 save_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3866 {
3867    GET_CURRENT_CONTEXT(ctx);
3868    Node *n;
3869    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3870    n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
3871    if (n) {
3872       n[1].e = face;
3873       n[2].e = func;
3874       n[3].i = ref;
3875       n[4].ui = mask;
3876    }
3877    if (ctx->ExecuteFlag) {
3878       CALL_StencilFuncSeparate(ctx->Exec, (face, func, ref, mask));
3879    }
3880 }
3881
3882
3883 static void GLAPIENTRY
3884 save_StencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref,
3885                             GLuint mask)
3886 {
3887    GET_CURRENT_CONTEXT(ctx);
3888    Node *n;
3889    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3890    /* GL_FRONT */
3891    n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
3892    if (n) {
3893       n[1].e = GL_FRONT;
3894       n[2].e = frontfunc;
3895       n[3].i = ref;
3896       n[4].ui = mask;
3897    }
3898    /* GL_BACK */
3899    n = alloc_instruction(ctx, OPCODE_STENCIL_FUNC_SEPARATE, 4);
3900    if (n) {
3901       n[1].e = GL_BACK;
3902       n[2].e = backfunc;
3903       n[3].i = ref;
3904       n[4].ui = mask;
3905    }
3906    if (ctx->ExecuteFlag) {
3907       CALL_StencilFuncSeparate(ctx->Exec, (GL_FRONT, frontfunc, ref, mask));
3908       CALL_StencilFuncSeparate(ctx->Exec, (GL_BACK, backfunc, ref, mask));
3909    }
3910 }
3911
3912
3913 static void GLAPIENTRY
3914 save_StencilMaskSeparate(GLenum face, GLuint mask)
3915 {
3916    GET_CURRENT_CONTEXT(ctx);
3917    Node *n;
3918    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3919    n = alloc_instruction(ctx, OPCODE_STENCIL_MASK_SEPARATE, 2);
3920    if (n) {
3921       n[1].e = face;
3922       n[2].ui = mask;
3923    }
3924    if (ctx->ExecuteFlag) {
3925       CALL_StencilMaskSeparate(ctx->Exec, (face, mask));
3926    }
3927 }
3928
3929
3930 static void GLAPIENTRY
3931 save_StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3932 {
3933    GET_CURRENT_CONTEXT(ctx);
3934    Node *n;
3935    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3936    n = alloc_instruction(ctx, OPCODE_STENCIL_OP_SEPARATE, 4);
3937    if (n) {
3938       n[1].e = face;
3939       n[2].e = fail;
3940       n[3].e = zfail;
3941       n[4].e = zpass;
3942    }
3943    if (ctx->ExecuteFlag) {
3944       CALL_StencilOpSeparate(ctx->Exec, (face, fail, zfail, zpass));
3945    }
3946 }
3947
3948
3949 static void GLAPIENTRY
3950 save_TexEnvfv(GLenum target, GLenum pname, const GLfloat *params)
3951 {
3952    GET_CURRENT_CONTEXT(ctx);
3953    Node *n;
3954    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
3955    n = alloc_instruction(ctx, OPCODE_TEXENV, 6);
3956    if (n) {
3957       n[1].e = target;
3958       n[2].e = pname;
3959       if (pname == GL_TEXTURE_ENV_COLOR) {
3960          n[3].f = params[0];
3961          n[4].f = params[1];
3962          n[5].f = params[2];
3963          n[6].f = params[3];
3964       }
3965       else {
3966          n[3].f = params[0];
3967          n[4].f = n[5].f = n[6].f = 0.0F;
3968       }
3969    }
3970    if (ctx->ExecuteFlag) {
3971       CALL_TexEnvfv(ctx->Exec, (target, pname, params));
3972    }
3973 }
3974
3975
3976 static void GLAPIENTRY
3977 save_TexEnvf(GLenum target, GLenum pname, GLfloat param)
3978 {
3979    GLfloat parray[4];
3980    parray[0] = (GLfloat) param;
3981    parray[1] = parray[2] = parray[3] = 0.0F;
3982    save_TexEnvfv(target, pname, parray);
3983 }
3984
3985
3986 static void GLAPIENTRY
3987 save_TexEnvi(GLenum target, GLenum pname, GLint param)
3988 {
3989    GLfloat p[4];
3990    p[0] = (GLfloat) param;
3991    p[1] = p[2] = p[3] = 0.0F;
3992    save_TexEnvfv(target, pname, p);
3993 }
3994
3995
3996 static void GLAPIENTRY
3997 save_TexEnviv(GLenum target, GLenum pname, const GLint * param)
3998 {
3999    GLfloat p[4];
4000    if (pname == GL_TEXTURE_ENV_COLOR) {
4001       p[0] = INT_TO_FLOAT(param[0]);
4002       p[1] = INT_TO_FLOAT(param[1]);
4003       p[2] = INT_TO_FLOAT(param[2]);
4004       p[3] = INT_TO_FLOAT(param[3]);
4005    }
4006    else {
4007       p[0] = (GLfloat) param[0];
4008       p[1] = p[2] = p[3] = 0.0F;
4009    }
4010    save_TexEnvfv(target, pname, p);
4011 }
4012
4013
4014 static void GLAPIENTRY
4015 save_TexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
4016 {
4017    GET_CURRENT_CONTEXT(ctx);
4018    Node *n;
4019    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4020    n = alloc_instruction(ctx, OPCODE_TEXGEN, 6);
4021    if (n) {
4022       n[1].e = coord;
4023       n[2].e = pname;
4024       n[3].f = params[0];
4025       n[4].f = params[1];
4026       n[5].f = params[2];
4027       n[6].f = params[3];
4028    }
4029    if (ctx->ExecuteFlag) {
4030       CALL_TexGenfv(ctx->Exec, (coord, pname, params));
4031    }
4032 }
4033
4034
4035 static void GLAPIENTRY
4036 save_TexGeniv(GLenum coord, GLenum pname, const GLint *params)
4037 {
4038    GLfloat p[4];
4039    p[0] = (GLfloat) params[0];
4040    p[1] = (GLfloat) params[1];
4041    p[2] = (GLfloat) params[2];
4042    p[3] = (GLfloat) params[3];
4043    save_TexGenfv(coord, pname, p);
4044 }
4045
4046
4047 static void GLAPIENTRY
4048 save_TexGend(GLenum coord, GLenum pname, GLdouble param)
4049 {
4050    GLfloat parray[4];
4051    parray[0] = (GLfloat) param;
4052    parray[1] = parray[2] = parray[3] = 0.0F;
4053    save_TexGenfv(coord, pname, parray);
4054 }
4055
4056
4057 static void GLAPIENTRY
4058 save_TexGendv(GLenum coord, GLenum pname, const GLdouble *params)
4059 {
4060    GLfloat p[4];
4061    p[0] = (GLfloat) params[0];
4062    p[1] = (GLfloat) params[1];
4063    p[2] = (GLfloat) params[2];
4064    p[3] = (GLfloat) params[3];
4065    save_TexGenfv(coord, pname, p);
4066 }
4067
4068
4069 static void GLAPIENTRY
4070 save_TexGenf(GLenum coord, GLenum pname, GLfloat param)
4071 {
4072    GLfloat parray[4];
4073    parray[0] = param;
4074    parray[1] = parray[2] = parray[3] = 0.0F;
4075    save_TexGenfv(coord, pname, parray);
4076 }
4077
4078
4079 static void GLAPIENTRY
4080 save_TexGeni(GLenum coord, GLenum pname, GLint param)
4081 {
4082    GLint parray[4];
4083    parray[0] = param;
4084    parray[1] = parray[2] = parray[3] = 0;
4085    save_TexGeniv(coord, pname, parray);
4086 }
4087
4088
4089 static void GLAPIENTRY
4090 save_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
4091 {
4092    GET_CURRENT_CONTEXT(ctx);
4093    Node *n;
4094    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4095    n = alloc_instruction(ctx, OPCODE_TEXPARAMETER, 6);
4096    if (n) {
4097       n[1].e = target;
4098       n[2].e = pname;
4099       n[3].f = params[0];
4100       n[4].f = params[1];
4101       n[5].f = params[2];
4102       n[6].f = params[3];
4103    }
4104    if (ctx->ExecuteFlag) {
4105       CALL_TexParameterfv(ctx->Exec, (target, pname, params));
4106    }
4107 }
4108
4109
4110 static void GLAPIENTRY
4111 save_TexParameterf(GLenum target, GLenum pname, GLfloat param)
4112 {
4113    GLfloat parray[4];
4114    parray[0] = param;
4115    parray[1] = parray[2] = parray[3] = 0.0F;
4116    save_TexParameterfv(target, pname, parray);
4117 }
4118
4119
4120 static void GLAPIENTRY
4121 save_TexParameteri(GLenum target, GLenum pname, GLint param)
4122 {
4123    GLfloat fparam[4];
4124    fparam[0] = (GLfloat) param;
4125    fparam[1] = fparam[2] = fparam[3] = 0.0F;
4126    save_TexParameterfv(target, pname, fparam);
4127 }
4128
4129
4130 static void GLAPIENTRY
4131 save_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
4132 {
4133    GLfloat fparam[4];
4134    fparam[0] = (GLfloat) params[0];
4135    fparam[1] = fparam[2] = fparam[3] = 0.0F;
4136    save_TexParameterfv(target, pname, fparam);
4137 }
4138
4139
4140 static void GLAPIENTRY
4141 save_TexImage1D(GLenum target,
4142                 GLint level, GLint components,
4143                 GLsizei width, GLint border,
4144                 GLenum format, GLenum type, const GLvoid * pixels)
4145 {
4146    GET_CURRENT_CONTEXT(ctx);
4147    if (target == GL_PROXY_TEXTURE_1D) {
4148       /* don't compile, execute immediately */
4149       CALL_TexImage1D(ctx->Exec, (target, level, components, width,
4150                                   border, format, type, pixels));
4151    }
4152    else {
4153       Node *n;
4154       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4155       n = alloc_instruction(ctx, OPCODE_TEX_IMAGE1D, 8);
4156       if (n) {
4157          n[1].e = target;
4158          n[2].i = level;
4159          n[3].i = components;
4160          n[4].i = (GLint) width;
4161          n[5].i = border;
4162          n[6].e = format;
4163          n[7].e = type;
4164          n[8].data = unpack_image(ctx, 1, width, 1, 1, format, type,
4165                                   pixels, &ctx->Unpack);
4166       }
4167       if (ctx->ExecuteFlag) {
4168          CALL_TexImage1D(ctx->Exec, (target, level, components, width,
4169                                      border, format, type, pixels));
4170       }
4171    }
4172 }
4173
4174
4175 static void GLAPIENTRY
4176 save_TexImage2D(GLenum target,
4177                 GLint level, GLint components,
4178                 GLsizei width, GLsizei height, GLint border,
4179                 GLenum format, GLenum type, const GLvoid * pixels)
4180 {
4181    GET_CURRENT_CONTEXT(ctx);
4182    if (target == GL_PROXY_TEXTURE_2D) {
4183       /* don't compile, execute immediately */
4184       CALL_TexImage2D(ctx->Exec, (target, level, components, width,
4185                                   height, border, format, type, pixels));
4186    }
4187    else {
4188       Node *n;
4189       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4190       n = alloc_instruction(ctx, OPCODE_TEX_IMAGE2D, 9);
4191       if (n) {
4192          n[1].e = target;
4193          n[2].i = level;
4194          n[3].i = components;
4195          n[4].i = (GLint) width;
4196          n[5].i = (GLint) height;
4197          n[6].i = border;
4198          n[7].e = format;
4199          n[8].e = type;
4200          n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
4201                                   pixels, &ctx->Unpack);
4202       }
4203       if (ctx->ExecuteFlag) {
4204          CALL_TexImage2D(ctx->Exec, (target, level, components, width,
4205                                      height, border, format, type, pixels));
4206       }
4207    }
4208 }
4209
4210
4211 static void GLAPIENTRY
4212 save_TexImage3D(GLenum target,
4213                 GLint level, GLint internalFormat,
4214                 GLsizei width, GLsizei height, GLsizei depth,
4215                 GLint border,
4216                 GLenum format, GLenum type, const GLvoid * pixels)
4217 {
4218    GET_CURRENT_CONTEXT(ctx);
4219    if (target == GL_PROXY_TEXTURE_3D) {
4220       /* don't compile, execute immediately */
4221       CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
4222                                   height, depth, border, format, type,
4223                                   pixels));
4224    }
4225    else {
4226       Node *n;
4227       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4228       n = alloc_instruction(ctx, OPCODE_TEX_IMAGE3D, 10);
4229       if (n) {
4230          n[1].e = target;
4231          n[2].i = level;
4232          n[3].i = (GLint) internalFormat;
4233          n[4].i = (GLint) width;
4234          n[5].i = (GLint) height;
4235          n[6].i = (GLint) depth;
4236          n[7].i = border;
4237          n[8].e = format;
4238          n[9].e = type;
4239          n[10].data = unpack_image(ctx, 3, width, height, depth, format, type,
4240                                    pixels, &ctx->Unpack);
4241       }
4242       if (ctx->ExecuteFlag) {
4243          CALL_TexImage3D(ctx->Exec, (target, level, internalFormat, width,
4244                                      height, depth, border, format, type,
4245                                      pixels));
4246       }
4247    }
4248 }
4249
4250
4251 static void GLAPIENTRY
4252 save_TexSubImage1D(GLenum target, GLint level, GLint xoffset,
4253                    GLsizei width, GLenum format, GLenum type,
4254                    const GLvoid * pixels)
4255 {
4256    GET_CURRENT_CONTEXT(ctx);
4257    Node *n;
4258
4259    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4260
4261    n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE1D, 7);
4262    if (n) {
4263       n[1].e = target;
4264       n[2].i = level;
4265       n[3].i = xoffset;
4266       n[4].i = (GLint) width;
4267       n[5].e = format;
4268       n[6].e = type;
4269       n[7].data = unpack_image(ctx, 1, width, 1, 1, format, type,
4270                                pixels, &ctx->Unpack);
4271    }
4272    if (ctx->ExecuteFlag) {
4273       CALL_TexSubImage1D(ctx->Exec, (target, level, xoffset, width,
4274                                      format, type, pixels));
4275    }
4276 }
4277
4278
4279 static void GLAPIENTRY
4280 save_TexSubImage2D(GLenum target, GLint level,
4281                    GLint xoffset, GLint yoffset,
4282                    GLsizei width, GLsizei height,
4283                    GLenum format, GLenum type, const GLvoid * pixels)
4284 {
4285    GET_CURRENT_CONTEXT(ctx);
4286    Node *n;
4287
4288    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4289
4290    n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE2D, 9);
4291    if (n) {
4292       n[1].e = target;
4293       n[2].i = level;
4294       n[3].i = xoffset;
4295       n[4].i = yoffset;
4296       n[5].i = (GLint) width;
4297       n[6].i = (GLint) height;
4298       n[7].e = format;
4299       n[8].e = type;
4300       n[9].data = unpack_image(ctx, 2, width, height, 1, format, type,
4301                                pixels, &ctx->Unpack);
4302    }
4303    if (ctx->ExecuteFlag) {
4304       CALL_TexSubImage2D(ctx->Exec, (target, level, xoffset, yoffset,
4305                                      width, height, format, type, pixels));
4306    }
4307 }
4308
4309
4310 static void GLAPIENTRY
4311 save_TexSubImage3D(GLenum target, GLint level,
4312                    GLint xoffset, GLint yoffset, GLint zoffset,
4313                    GLsizei width, GLsizei height, GLsizei depth,
4314                    GLenum format, GLenum type, const GLvoid * pixels)
4315 {
4316    GET_CURRENT_CONTEXT(ctx);
4317    Node *n;
4318
4319    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4320
4321    n = alloc_instruction(ctx, OPCODE_TEX_SUB_IMAGE3D, 11);
4322    if (n) {
4323       n[1].e = target;
4324       n[2].i = level;
4325       n[3].i = xoffset;
4326       n[4].i = yoffset;
4327       n[5].i = zoffset;
4328       n[6].i = (GLint) width;
4329       n[7].i = (GLint) height;
4330       n[8].i = (GLint) depth;
4331       n[9].e = format;
4332       n[10].e = type;
4333       n[11].data = unpack_image(ctx, 3, width, height, depth, format, type,
4334                                 pixels, &ctx->Unpack);
4335    }
4336    if (ctx->ExecuteFlag) {
4337       CALL_TexSubImage3D(ctx->Exec, (target, level,
4338                                      xoffset, yoffset, zoffset,
4339                                      width, height, depth, format, type,
4340                                      pixels));
4341    }
4342 }
4343
4344
4345 static void GLAPIENTRY
4346 save_Translatef(GLfloat x, GLfloat y, GLfloat z)
4347 {
4348    GET_CURRENT_CONTEXT(ctx);
4349    Node *n;
4350    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4351    n = alloc_instruction(ctx, OPCODE_TRANSLATE, 3);
4352    if (n) {
4353       n[1].f = x;
4354       n[2].f = y;
4355       n[3].f = z;
4356    }
4357    if (ctx->ExecuteFlag) {
4358       CALL_Translatef(ctx->Exec, (x, y, z));
4359    }
4360 }
4361
4362
4363 static void GLAPIENTRY
4364 save_Translated(GLdouble x, GLdouble y, GLdouble z)
4365 {
4366    save_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
4367 }
4368
4369
4370
4371 static void GLAPIENTRY
4372 save_Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4373 {
4374    GET_CURRENT_CONTEXT(ctx);
4375    Node *n;
4376    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4377    n = alloc_instruction(ctx, OPCODE_VIEWPORT, 4);
4378    if (n) {
4379       n[1].i = x;
4380       n[2].i = y;
4381       n[3].i = (GLint) width;
4382       n[4].i = (GLint) height;
4383    }
4384    if (ctx->ExecuteFlag) {
4385       CALL_Viewport(ctx->Exec, (x, y, width, height));
4386    }
4387 }
4388
4389
4390 static void GLAPIENTRY
4391 save_WindowPos4fMESA(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4392 {
4393    GET_CURRENT_CONTEXT(ctx);
4394    Node *n;
4395    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4396    n = alloc_instruction(ctx, OPCODE_WINDOW_POS, 4);
4397    if (n) {
4398       n[1].f = x;
4399       n[2].f = y;
4400       n[3].f = z;
4401       n[4].f = w;
4402    }
4403    if (ctx->ExecuteFlag) {
4404       CALL_WindowPos4fMESA(ctx->Exec, (x, y, z, w));
4405    }
4406 }
4407
4408 static void GLAPIENTRY
4409 save_WindowPos2dMESA(GLdouble x, GLdouble y)
4410 {
4411    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
4412 }
4413
4414 static void GLAPIENTRY
4415 save_WindowPos2fMESA(GLfloat x, GLfloat y)
4416 {
4417    save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
4418 }
4419
4420 static void GLAPIENTRY
4421 save_WindowPos2iMESA(GLint x, GLint y)
4422 {
4423    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, 0.0F, 1.0F);
4424 }
4425
4426 static void GLAPIENTRY
4427 save_WindowPos2sMESA(GLshort x, GLshort y)
4428 {
4429    save_WindowPos4fMESA(x, y, 0.0F, 1.0F);
4430 }
4431
4432 static void GLAPIENTRY
4433 save_WindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z)
4434 {
4435    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
4436 }
4437
4438 static void GLAPIENTRY
4439 save_WindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z)
4440 {
4441    save_WindowPos4fMESA(x, y, z, 1.0F);
4442 }
4443
4444 static void GLAPIENTRY
4445 save_WindowPos3iMESA(GLint x, GLint y, GLint z)
4446 {
4447    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F);
4448 }
4449
4450 static void GLAPIENTRY
4451 save_WindowPos3sMESA(GLshort x, GLshort y, GLshort z)
4452 {
4453    save_WindowPos4fMESA(x, y, z, 1.0F);
4454 }
4455
4456 static void GLAPIENTRY
4457 save_WindowPos4dMESA(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
4458 {
4459    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
4460 }
4461
4462 static void GLAPIENTRY
4463 save_WindowPos4iMESA(GLint x, GLint y, GLint z, GLint w)
4464 {
4465    save_WindowPos4fMESA((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
4466 }
4467
4468 static void GLAPIENTRY
4469 save_WindowPos4sMESA(GLshort x, GLshort y, GLshort z, GLshort w)
4470 {
4471    save_WindowPos4fMESA(x, y, z, w);
4472 }
4473
4474 static void GLAPIENTRY
4475 save_WindowPos2dvMESA(const GLdouble * v)
4476 {
4477    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
4478 }
4479
4480 static void GLAPIENTRY
4481 save_WindowPos2fvMESA(const GLfloat * v)
4482 {
4483    save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
4484 }
4485
4486 static void GLAPIENTRY
4487 save_WindowPos2ivMESA(const GLint * v)
4488 {
4489    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], 0.0F, 1.0F);
4490 }
4491
4492 static void GLAPIENTRY
4493 save_WindowPos2svMESA(const GLshort * v)
4494 {
4495    save_WindowPos4fMESA(v[0], v[1], 0.0F, 1.0F);
4496 }
4497
4498 static void GLAPIENTRY
4499 save_WindowPos3dvMESA(const GLdouble * v)
4500 {
4501    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
4502 }
4503
4504 static void GLAPIENTRY
4505 save_WindowPos3fvMESA(const GLfloat * v)
4506 {
4507    save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
4508 }
4509
4510 static void GLAPIENTRY
4511 save_WindowPos3ivMESA(const GLint * v)
4512 {
4513    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0F);
4514 }
4515
4516 static void GLAPIENTRY
4517 save_WindowPos3svMESA(const GLshort * v)
4518 {
4519    save_WindowPos4fMESA(v[0], v[1], v[2], 1.0F);
4520 }
4521
4522 static void GLAPIENTRY
4523 save_WindowPos4dvMESA(const GLdouble * v)
4524 {
4525    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
4526                         (GLfloat) v[2], (GLfloat) v[3]);
4527 }
4528
4529 static void GLAPIENTRY
4530 save_WindowPos4fvMESA(const GLfloat * v)
4531 {
4532    save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
4533 }
4534
4535 static void GLAPIENTRY
4536 save_WindowPos4ivMESA(const GLint * v)
4537 {
4538    save_WindowPos4fMESA((GLfloat) v[0], (GLfloat) v[1],
4539                         (GLfloat) v[2], (GLfloat) v[3]);
4540 }
4541
4542 static void GLAPIENTRY
4543 save_WindowPos4svMESA(const GLshort * v)
4544 {
4545    save_WindowPos4fMESA(v[0], v[1], v[2], v[3]);
4546 }
4547
4548
4549
4550 /* GL_ARB_multitexture */
4551 static void GLAPIENTRY
4552 save_ActiveTextureARB(GLenum target)
4553 {
4554    GET_CURRENT_CONTEXT(ctx);
4555    Node *n;
4556    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4557    n = alloc_instruction(ctx, OPCODE_ACTIVE_TEXTURE, 1);
4558    if (n) {
4559       n[1].e = target;
4560    }
4561    if (ctx->ExecuteFlag) {
4562       CALL_ActiveTextureARB(ctx->Exec, (target));
4563    }
4564 }
4565
4566
4567 /* GL_ARB_transpose_matrix */
4568
4569 static void GLAPIENTRY
4570 save_LoadTransposeMatrixdARB(const GLdouble m[16])
4571 {
4572    GLfloat tm[16];
4573    _math_transposefd(tm, m);
4574    save_LoadMatrixf(tm);
4575 }
4576
4577
4578 static void GLAPIENTRY
4579 save_LoadTransposeMatrixfARB(const GLfloat m[16])
4580 {
4581    GLfloat tm[16];
4582    _math_transposef(tm, m);
4583    save_LoadMatrixf(tm);
4584 }
4585
4586
4587 static void GLAPIENTRY
4588 save_MultTransposeMatrixdARB(const GLdouble m[16])
4589 {
4590    GLfloat tm[16];
4591    _math_transposefd(tm, m);
4592    save_MultMatrixf(tm);
4593 }
4594
4595
4596 static void GLAPIENTRY
4597 save_MultTransposeMatrixfARB(const GLfloat m[16])
4598 {
4599    GLfloat tm[16];
4600    _math_transposef(tm, m);
4601    save_MultMatrixf(tm);
4602 }
4603
4604 static GLvoid *copy_data(const GLvoid *data, GLsizei size, const char *func)
4605 {
4606    GET_CURRENT_CONTEXT(ctx);
4607    GLvoid *image;
4608
4609    if (!data)
4610       return NULL;
4611
4612    image = malloc(size);
4613    if (!image) {
4614       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
4615       return NULL;
4616    }
4617    memcpy(image, data, size);
4618
4619    return image;
4620 }
4621
4622
4623 /* GL_ARB_texture_compression */
4624 static void GLAPIENTRY
4625 save_CompressedTexImage1DARB(GLenum target, GLint level,
4626                              GLenum internalFormat, GLsizei width,
4627                              GLint border, GLsizei imageSize,
4628                              const GLvoid * data)
4629 {
4630    GET_CURRENT_CONTEXT(ctx);
4631    if (target == GL_PROXY_TEXTURE_1D) {
4632       /* don't compile, execute immediately */
4633       CALL_CompressedTexImage1DARB(ctx->Exec, (target, level, internalFormat,
4634                                                width, border, imageSize,
4635                                                data));
4636    }
4637    else {
4638       Node *n;
4639       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4640
4641       n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_1D, 7);
4642       if (n) {
4643          n[1].e = target;
4644          n[2].i = level;
4645          n[3].e = internalFormat;
4646          n[4].i = (GLint) width;
4647          n[5].i = border;
4648          n[6].i = imageSize;
4649          n[7].data = copy_data(data, imageSize, "glCompressedTexImage1DARB");
4650       }
4651       if (ctx->ExecuteFlag) {
4652          CALL_CompressedTexImage1DARB(ctx->Exec,
4653                                       (target, level, internalFormat, width,
4654                                        border, imageSize, data));
4655       }
4656    }
4657 }
4658
4659
4660 static void GLAPIENTRY
4661 save_CompressedTexImage2DARB(GLenum target, GLint level,
4662                              GLenum internalFormat, GLsizei width,
4663                              GLsizei height, GLint border, GLsizei imageSize,
4664                              const GLvoid * data)
4665 {
4666    GET_CURRENT_CONTEXT(ctx);
4667    if (target == GL_PROXY_TEXTURE_2D) {
4668       /* don't compile, execute immediately */
4669       CALL_CompressedTexImage2DARB(ctx->Exec, (target, level, internalFormat,
4670                                                width, height, border,
4671                                                imageSize, data));
4672    }
4673    else {
4674       Node *n;
4675       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4676
4677       n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_2D, 8);
4678       if (n) {
4679          n[1].e = target;
4680          n[2].i = level;
4681          n[3].e = internalFormat;
4682          n[4].i = (GLint) width;
4683          n[5].i = (GLint) height;
4684          n[6].i = border;
4685          n[7].i = imageSize;
4686          n[8].data = copy_data(data, imageSize, "glCompressedTexImage2DARB");
4687       }
4688       if (ctx->ExecuteFlag) {
4689          CALL_CompressedTexImage2DARB(ctx->Exec,
4690                                       (target, level, internalFormat, width,
4691                                        height, border, imageSize, data));
4692       }
4693    }
4694 }
4695
4696
4697 static void GLAPIENTRY
4698 save_CompressedTexImage3DARB(GLenum target, GLint level,
4699                              GLenum internalFormat, GLsizei width,
4700                              GLsizei height, GLsizei depth, GLint border,
4701                              GLsizei imageSize, const GLvoid * data)
4702 {
4703    GET_CURRENT_CONTEXT(ctx);
4704    if (target == GL_PROXY_TEXTURE_3D) {
4705       /* don't compile, execute immediately */
4706       CALL_CompressedTexImage3DARB(ctx->Exec, (target, level, internalFormat,
4707                                                width, height, depth, border,
4708                                                imageSize, data));
4709    }
4710    else {
4711       Node *n;
4712       ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4713
4714       n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_3D, 9);
4715       if (n) {
4716          n[1].e = target;
4717          n[2].i = level;
4718          n[3].e = internalFormat;
4719          n[4].i = (GLint) width;
4720          n[5].i = (GLint) height;
4721          n[6].i = (GLint) depth;
4722          n[7].i = border;
4723          n[8].i = imageSize;
4724          n[9].data = copy_data(data, imageSize, "glCompressedTexImage3DARB");
4725       }
4726       if (ctx->ExecuteFlag) {
4727          CALL_CompressedTexImage3DARB(ctx->Exec,
4728                                       (target, level, internalFormat, width,
4729                                        height, depth, border, imageSize,
4730                                        data));
4731       }
4732    }
4733 }
4734
4735
4736 static void GLAPIENTRY
4737 save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
4738                                 GLsizei width, GLenum format,
4739                                 GLsizei imageSize, const GLvoid * data)
4740 {
4741    Node *n;
4742    GET_CURRENT_CONTEXT(ctx);
4743    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4744
4745    n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D, 7);
4746    if (n) {
4747       n[1].e = target;
4748       n[2].i = level;
4749       n[3].i = xoffset;
4750       n[4].i = (GLint) width;
4751       n[5].e = format;
4752       n[6].i = imageSize;
4753       n[7].data = copy_data(data, imageSize, "glCompressedTexSubImage1DARB");
4754    }
4755    if (ctx->ExecuteFlag) {
4756       CALL_CompressedTexSubImage1DARB(ctx->Exec, (target, level, xoffset,
4757                                                   width, format, imageSize,
4758                                                   data));
4759    }
4760 }
4761
4762
4763 static void GLAPIENTRY
4764 save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
4765                                 GLint yoffset, GLsizei width, GLsizei height,
4766                                 GLenum format, GLsizei imageSize,
4767                                 const GLvoid * data)
4768 {
4769    Node *n;
4770    GET_CURRENT_CONTEXT(ctx);
4771    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4772
4773    n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D, 9);
4774    if (n) {
4775       n[1].e = target;
4776       n[2].i = level;
4777       n[3].i = xoffset;
4778       n[4].i = yoffset;
4779       n[5].i = (GLint) width;
4780       n[6].i = (GLint) height;
4781       n[7].e = format;
4782       n[8].i = imageSize;
4783       n[9].data = copy_data(data, imageSize, "glCompressedTexSubImage2DARB");
4784    }
4785    if (ctx->ExecuteFlag) {
4786       CALL_CompressedTexSubImage2DARB(ctx->Exec,
4787                                       (target, level, xoffset, yoffset, width,
4788                                        height, format, imageSize, data));
4789    }
4790 }
4791
4792
4793 static void GLAPIENTRY
4794 save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
4795                                 GLint yoffset, GLint zoffset, GLsizei width,
4796                                 GLsizei height, GLsizei depth, GLenum format,
4797                                 GLsizei imageSize, const GLvoid * data)
4798 {
4799    Node *n;
4800    GET_CURRENT_CONTEXT(ctx);
4801    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4802
4803    n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D, 11);
4804    if (n) {
4805       n[1].e = target;
4806       n[2].i = level;
4807       n[3].i = xoffset;
4808       n[4].i = yoffset;
4809       n[5].i = zoffset;
4810       n[6].i = (GLint) width;
4811       n[7].i = (GLint) height;
4812       n[8].i = (GLint) depth;
4813       n[9].e = format;
4814       n[10].i = imageSize;
4815       n[11].data = copy_data(data, imageSize, "glCompressedTexSubImage3DARB");
4816    }
4817    if (ctx->ExecuteFlag) {
4818       CALL_CompressedTexSubImage3DARB(ctx->Exec,
4819                                       (target, level, xoffset, yoffset,
4820                                        zoffset, width, height, depth, format,
4821                                        imageSize, data));
4822    }
4823 }
4824
4825
4826 /* GL_ARB_multisample */
4827 static void GLAPIENTRY
4828 save_SampleCoverageARB(GLclampf value, GLboolean invert)
4829 {
4830    GET_CURRENT_CONTEXT(ctx);
4831    Node *n;
4832    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4833    n = alloc_instruction(ctx, OPCODE_SAMPLE_COVERAGE, 2);
4834    if (n) {
4835       n[1].f = value;
4836       n[2].b = invert;
4837    }
4838    if (ctx->ExecuteFlag) {
4839       CALL_SampleCoverageARB(ctx->Exec, (value, invert));
4840    }
4841 }
4842
4843
4844 /*
4845  * GL_NV_vertex_program
4846  */
4847 static void GLAPIENTRY
4848 save_BindProgramNV(GLenum target, GLuint id)
4849 {
4850    GET_CURRENT_CONTEXT(ctx);
4851    Node *n;
4852    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4853    n = alloc_instruction(ctx, OPCODE_BIND_PROGRAM_NV, 2);
4854    if (n) {
4855       n[1].e = target;
4856       n[2].ui = id;
4857    }
4858    if (ctx->ExecuteFlag) {
4859       CALL_BindProgramNV(ctx->Exec, (target, id));
4860    }
4861 }
4862
4863 static void GLAPIENTRY
4864 save_ProgramEnvParameter4fARB(GLenum target, GLuint index,
4865                               GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4866 {
4867    GET_CURRENT_CONTEXT(ctx);
4868    Node *n;
4869    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4870    n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
4871    if (n) {
4872       n[1].e = target;
4873       n[2].ui = index;
4874       n[3].f = x;
4875       n[4].f = y;
4876       n[5].f = z;
4877       n[6].f = w;
4878    }
4879    if (ctx->ExecuteFlag) {
4880       CALL_ProgramEnvParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
4881    }
4882 }
4883
4884
4885 static void GLAPIENTRY
4886 save_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
4887                                const GLfloat *params)
4888 {
4889    save_ProgramEnvParameter4fARB(target, index, params[0], params[1],
4890                                  params[2], params[3]);
4891 }
4892
4893
4894 static void GLAPIENTRY
4895 save_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
4896                                 const GLfloat * params)
4897 {
4898    GET_CURRENT_CONTEXT(ctx);
4899    Node *n;
4900    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4901
4902    if (count > 0) {
4903       GLint i;
4904       const GLfloat * p = params;
4905
4906       for (i = 0 ; i < count ; i++) {
4907          n = alloc_instruction(ctx, OPCODE_PROGRAM_ENV_PARAMETER_ARB, 6);
4908          if (n) {
4909             n[1].e = target;
4910             n[2].ui = index;
4911             n[3].f = p[0];
4912             n[4].f = p[1];
4913             n[5].f = p[2];
4914             n[6].f = p[3];
4915             p += 4;
4916          }
4917       }
4918    }
4919
4920    if (ctx->ExecuteFlag) {
4921       CALL_ProgramEnvParameters4fvEXT(ctx->Exec, (target, index, count, params));
4922    }
4923 }
4924
4925
4926 static void GLAPIENTRY
4927 save_ProgramEnvParameter4dARB(GLenum target, GLuint index,
4928                               GLdouble x, GLdouble y, GLdouble z, GLdouble w)
4929 {
4930    save_ProgramEnvParameter4fARB(target, index,
4931                                  (GLfloat) x,
4932                                  (GLfloat) y, (GLfloat) z, (GLfloat) w);
4933 }
4934
4935
4936 static void GLAPIENTRY
4937 save_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
4938                                const GLdouble *params)
4939 {
4940    save_ProgramEnvParameter4fARB(target, index,
4941                                  (GLfloat) params[0],
4942                                  (GLfloat) params[1],
4943                                  (GLfloat) params[2], (GLfloat) params[3]);
4944 }
4945
4946
4947 static void GLAPIENTRY
4948 save_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
4949 {
4950    GET_CURRENT_CONTEXT(ctx);
4951    Node *n;
4952    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4953    n = alloc_instruction(ctx, OPCODE_EXECUTE_PROGRAM_NV, 6);
4954    if (n) {
4955       n[1].e = target;
4956       n[2].ui = id;
4957       n[3].f = params[0];
4958       n[4].f = params[1];
4959       n[5].f = params[2];
4960       n[6].f = params[3];
4961    }
4962    if (ctx->ExecuteFlag) {
4963       CALL_ExecuteProgramNV(ctx->Exec, (target, id, params));
4964    }
4965 }
4966
4967
4968 static void GLAPIENTRY
4969 save_ProgramParameters4dvNV(GLenum target, GLuint index,
4970                             GLsizei num, const GLdouble *params)
4971 {
4972    GLint i;
4973    for (i = 0; i < num; i++) {
4974       save_ProgramEnvParameter4dvARB(target, index + i, params + 4 * i);
4975    }
4976 }
4977
4978
4979 static void GLAPIENTRY
4980 save_ProgramParameters4fvNV(GLenum target, GLuint index,
4981                             GLsizei num, const GLfloat *params)
4982 {
4983    GLint i;
4984    for (i = 0; i < num; i++) {
4985       save_ProgramEnvParameter4fvARB(target, index + i, params + 4 * i);
4986    }
4987 }
4988
4989
4990 static void GLAPIENTRY
4991 save_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
4992                    const GLubyte * program)
4993 {
4994    GET_CURRENT_CONTEXT(ctx);
4995    Node *n;
4996
4997    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
4998
4999    n = alloc_instruction(ctx, OPCODE_LOAD_PROGRAM_NV, 4);
5000    if (n) {
5001       GLubyte *programCopy = malloc(len);
5002       if (!programCopy) {
5003          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
5004          return;
5005       }
5006       memcpy(programCopy, program, len);
5007       n[1].e = target;
5008       n[2].ui = id;
5009       n[3].i = len;
5010       n[4].data = programCopy;
5011    }
5012    if (ctx->ExecuteFlag) {
5013       CALL_LoadProgramNV(ctx->Exec, (target, id, len, program));
5014    }
5015 }
5016
5017
5018 static void GLAPIENTRY
5019 save_RequestResidentProgramsNV(GLsizei num, const GLuint * ids)
5020 {
5021    GET_CURRENT_CONTEXT(ctx);
5022    Node *n;
5023
5024    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5025
5026    n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 2);
5027    if (n) {
5028       GLuint *idCopy = malloc(num * sizeof(GLuint));
5029       if (!idCopy) {
5030          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glRequestResidentProgramsNV");
5031          return;
5032       }
5033       memcpy(idCopy, ids, num * sizeof(GLuint));
5034       n[1].i = num;
5035       n[2].data = idCopy;
5036    }
5037    if (ctx->ExecuteFlag) {
5038       CALL_RequestResidentProgramsNV(ctx->Exec, (num, ids));
5039    }
5040 }
5041
5042
5043 static void GLAPIENTRY
5044 save_TrackMatrixNV(GLenum target, GLuint address,
5045                    GLenum matrix, GLenum transform)
5046 {
5047    GET_CURRENT_CONTEXT(ctx);
5048    Node *n;
5049    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5050    n = alloc_instruction(ctx, OPCODE_TRACK_MATRIX_NV, 4);
5051    if (n) {
5052       n[1].e = target;
5053       n[2].ui = address;
5054       n[3].e = matrix;
5055       n[4].e = transform;
5056    }
5057    if (ctx->ExecuteFlag) {
5058       CALL_TrackMatrixNV(ctx->Exec, (target, address, matrix, transform));
5059    }
5060 }
5061
5062
5063 /*
5064  * GL_NV_fragment_program
5065  */
5066 static void GLAPIENTRY
5067 save_ProgramLocalParameter4fARB(GLenum target, GLuint index,
5068                                 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5069 {
5070    GET_CURRENT_CONTEXT(ctx);
5071    Node *n;
5072    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5073    n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
5074    if (n) {
5075       n[1].e = target;
5076       n[2].ui = index;
5077       n[3].f = x;
5078       n[4].f = y;
5079       n[5].f = z;
5080       n[6].f = w;
5081    }
5082    if (ctx->ExecuteFlag) {
5083       CALL_ProgramLocalParameter4fARB(ctx->Exec, (target, index, x, y, z, w));
5084    }
5085 }
5086
5087
5088 static void GLAPIENTRY
5089 save_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
5090                                  const GLfloat *params)
5091 {
5092    GET_CURRENT_CONTEXT(ctx);
5093    Node *n;
5094    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5095    n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
5096    if (n) {
5097       n[1].e = target;
5098       n[2].ui = index;
5099       n[3].f = params[0];
5100       n[4].f = params[1];
5101       n[5].f = params[2];
5102       n[6].f = params[3];
5103    }
5104    if (ctx->ExecuteFlag) {
5105       CALL_ProgramLocalParameter4fvARB(ctx->Exec, (target, index, params));
5106    }
5107 }
5108
5109
5110 static void GLAPIENTRY
5111 save_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
5112                                   const GLfloat *params)
5113 {
5114    GET_CURRENT_CONTEXT(ctx);
5115    Node *n;
5116    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5117
5118    if (count > 0) {
5119       GLint i;
5120       const GLfloat * p = params;
5121
5122       for (i = 0 ; i < count ; i++) {
5123          n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
5124          if (n) {
5125             n[1].e = target;
5126             n[2].ui = index;
5127             n[3].f = p[0];
5128             n[4].f = p[1];
5129             n[5].f = p[2];
5130             n[6].f = p[3];
5131             p += 4;
5132          }
5133       }
5134    }
5135
5136    if (ctx->ExecuteFlag) {
5137       CALL_ProgramLocalParameters4fvEXT(ctx->Exec, (target, index, count, params));
5138    }
5139 }
5140
5141
5142 static void GLAPIENTRY
5143 save_ProgramLocalParameter4dARB(GLenum target, GLuint index,
5144                                 GLdouble x, GLdouble y,
5145                                 GLdouble z, GLdouble w)
5146 {
5147    GET_CURRENT_CONTEXT(ctx);
5148    Node *n;
5149    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5150    n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
5151    if (n) {
5152       n[1].e = target;
5153       n[2].ui = index;
5154       n[3].f = (GLfloat) x;
5155       n[4].f = (GLfloat) y;
5156       n[5].f = (GLfloat) z;
5157       n[6].f = (GLfloat) w;
5158    }
5159    if (ctx->ExecuteFlag) {
5160       CALL_ProgramLocalParameter4dARB(ctx->Exec, (target, index, x, y, z, w));
5161    }
5162 }
5163
5164
5165 static void GLAPIENTRY
5166 save_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
5167                                  const GLdouble *params)
5168 {
5169    GET_CURRENT_CONTEXT(ctx);
5170    Node *n;
5171    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5172    n = alloc_instruction(ctx, OPCODE_PROGRAM_LOCAL_PARAMETER_ARB, 6);
5173    if (n) {
5174       n[1].e = target;
5175       n[2].ui = index;
5176       n[3].f = (GLfloat) params[0];
5177       n[4].f = (GLfloat) params[1];
5178       n[5].f = (GLfloat) params[2];
5179       n[6].f = (GLfloat) params[3];
5180    }
5181    if (ctx->ExecuteFlag) {
5182       CALL_ProgramLocalParameter4dvARB(ctx->Exec, (target, index, params));
5183    }
5184 }
5185
5186 static void GLAPIENTRY
5187 save_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte * name,
5188                                GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5189 {
5190    GET_CURRENT_CONTEXT(ctx);
5191    Node *n;
5192
5193    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5194
5195    n = alloc_instruction(ctx, OPCODE_PROGRAM_NAMED_PARAMETER_NV, 6);
5196    if (n) {
5197       GLubyte *nameCopy = malloc(len);
5198       if (!nameCopy) {
5199          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramNamedParameter4fNV");
5200          return;
5201       }
5202       memcpy(nameCopy, name, len);
5203       n[1].ui = id;
5204       n[2].i = len;
5205       n[3].data = nameCopy;
5206       n[4].f = x;
5207       n[5].f = y;
5208       n[6].f = z;
5209       n[7].f = w;
5210    }
5211    if (ctx->ExecuteFlag) {
5212       CALL_ProgramNamedParameter4fNV(ctx->Exec, (id, len, name, x, y, z, w));
5213    }
5214 }
5215
5216
5217 static void GLAPIENTRY
5218 save_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte * name,
5219                                 const float v[])
5220 {
5221    save_ProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
5222 }
5223
5224
5225 static void GLAPIENTRY
5226 save_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte * name,
5227                                GLdouble x, GLdouble y, GLdouble z, GLdouble w)
5228 {
5229    save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) x, (GLfloat) y,
5230                                   (GLfloat) z, (GLfloat) w);
5231 }
5232
5233
5234 static void GLAPIENTRY
5235 save_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte * name,
5236                                 const double v[])
5237 {
5238    save_ProgramNamedParameter4fNV(id, len, name, (GLfloat) v[0],
5239                                   (GLfloat) v[1], (GLfloat) v[2],
5240                                   (GLfloat) v[3]);
5241 }
5242
5243
5244 /* GL_EXT_stencil_two_side */
5245 static void GLAPIENTRY
5246 save_ActiveStencilFaceEXT(GLenum face)
5247 {
5248    GET_CURRENT_CONTEXT(ctx);
5249    Node *n;
5250    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5251    n = alloc_instruction(ctx, OPCODE_ACTIVE_STENCIL_FACE_EXT, 1);
5252    if (n) {
5253       n[1].e = face;
5254    }
5255    if (ctx->ExecuteFlag) {
5256       CALL_ActiveStencilFaceEXT(ctx->Exec, (face));
5257    }
5258 }
5259
5260
5261 /* GL_EXT_depth_bounds_test */
5262 static void GLAPIENTRY
5263 save_DepthBoundsEXT(GLclampd zmin, GLclampd zmax)
5264 {
5265    GET_CURRENT_CONTEXT(ctx);
5266    Node *n;
5267    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5268    n = alloc_instruction(ctx, OPCODE_DEPTH_BOUNDS_EXT, 2);
5269    if (n) {
5270       n[1].f = (GLfloat) zmin;
5271       n[2].f = (GLfloat) zmax;
5272    }
5273    if (ctx->ExecuteFlag) {
5274       CALL_DepthBoundsEXT(ctx->Exec, (zmin, zmax));
5275    }
5276 }
5277
5278
5279
5280 static void GLAPIENTRY
5281 save_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
5282                       const GLvoid * string)
5283 {
5284    GET_CURRENT_CONTEXT(ctx);
5285    Node *n;
5286
5287    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5288
5289    n = alloc_instruction(ctx, OPCODE_PROGRAM_STRING_ARB, 4);
5290    if (n) {
5291       GLubyte *programCopy = malloc(len);
5292       if (!programCopy) {
5293          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
5294          return;
5295       }
5296       memcpy(programCopy, string, len);
5297       n[1].e = target;
5298       n[2].e = format;
5299       n[3].i = len;
5300       n[4].data = programCopy;
5301    }
5302    if (ctx->ExecuteFlag) {
5303       CALL_ProgramStringARB(ctx->Exec, (target, format, len, string));
5304    }
5305 }
5306
5307
5308 static void GLAPIENTRY
5309 save_BeginQueryARB(GLenum target, GLuint id)
5310 {
5311    GET_CURRENT_CONTEXT(ctx);
5312    Node *n;
5313    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5314    n = alloc_instruction(ctx, OPCODE_BEGIN_QUERY_ARB, 2);
5315    if (n) {
5316       n[1].e = target;
5317       n[2].ui = id;
5318    }
5319    if (ctx->ExecuteFlag) {
5320       CALL_BeginQueryARB(ctx->Exec, (target, id));
5321    }
5322 }
5323
5324 static void GLAPIENTRY
5325 save_EndQueryARB(GLenum target)
5326 {
5327    GET_CURRENT_CONTEXT(ctx);
5328    Node *n;
5329    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5330    n = alloc_instruction(ctx, OPCODE_END_QUERY_ARB, 1);
5331    if (n) {
5332       n[1].e = target;
5333    }
5334    if (ctx->ExecuteFlag) {
5335       CALL_EndQueryARB(ctx->Exec, (target));
5336    }
5337 }
5338
5339 static void GLAPIENTRY
5340 save_QueryCounter(GLuint id, GLenum target)
5341 {
5342    GET_CURRENT_CONTEXT(ctx);
5343    Node *n;
5344    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5345    n = alloc_instruction(ctx, OPCODE_QUERY_COUNTER, 2);
5346    if (n) {
5347       n[1].ui = id;
5348       n[2].e = target;
5349    }
5350    if (ctx->ExecuteFlag) {
5351       CALL_QueryCounter(ctx->Exec, (id, target));
5352    }
5353 }
5354
5355 static void GLAPIENTRY
5356 save_BeginQueryIndexed(GLenum target, GLuint index, GLuint id)
5357 {
5358    GET_CURRENT_CONTEXT(ctx);
5359    Node *n;
5360    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5361    n = alloc_instruction(ctx, OPCODE_BEGIN_QUERY_INDEXED, 3);
5362    if (n) {
5363       n[1].e = target;
5364       n[2].ui = index;
5365       n[3].ui = id;
5366    }
5367    if (ctx->ExecuteFlag) {
5368       CALL_BeginQueryIndexed(ctx->Exec, (target, index, id));
5369    }
5370 }
5371
5372 static void GLAPIENTRY
5373 save_EndQueryIndexed(GLenum target, GLuint index)
5374 {
5375    GET_CURRENT_CONTEXT(ctx);
5376    Node *n;
5377    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5378    n = alloc_instruction(ctx, OPCODE_END_QUERY_INDEXED, 2);
5379    if (n) {
5380       n[1].e = target;
5381       n[2].ui = index;
5382    }
5383    if (ctx->ExecuteFlag) {
5384       CALL_EndQueryIndexed(ctx->Exec, (target, index));
5385    }
5386 }
5387
5388
5389 static void GLAPIENTRY
5390 save_DrawBuffersARB(GLsizei count, const GLenum * buffers)
5391 {
5392    GET_CURRENT_CONTEXT(ctx);
5393    Node *n;
5394    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
5395    n = alloc_instruction(ctx, OPCODE_DRAW_BUFFERS_ARB, 1 + MAX_DRAW_BUFFERS);
5396    if (n) {
5397       GLint i;
5398       n[1].i = count;
5399       if (count > MAX_DRAW_BUFFERS)
5400          count = MAX_DRAW_BUFFERS;
5401       for (i = 0; i < count; i++) {
5402          n[2 + i].e = buffers[i];
5403       }
5404    }
5405    if (ctx->ExecuteFlag) {
5406       CALL_DrawBuffersARB(ctx->Exec, (count, buffers));
5407    }
5408 }
5409
5410 static void GLAPIENTRY
5411 save_TexBumpParameterfvATI(GLenum pname, const GLfloat *param)
5412 {
5413    GET_CURRENT_CONTEXT(ctx);
5414    Node *n;
5415
5416    n = alloc_instruction(ctx, OPCODE_TEX_BUMP_PARAMETER_ATI, 5);
5417    if (n) {
5418       n[1].ui = pname;
5419       n[2].f = param[0];
5420       n[3].f = param[1];
5421       n[4].f = param[2];
5422       n[5].f = param[3];
5423    }
5424    if (ctx->ExecuteFlag) {
5425       CALL_TexBumpParameterfvATI(ctx->Exec, (pname, param));
5426    }
5427 }
5428
5429 static void GLAPIENTRY
5430 save_TexBumpParameterivATI(GLenum pname, const GLint *param)
5431 {
5432    GLfloat p[4];
5433    p[0] = INT_TO_FLOAT(param[0]);
5434    p[1] = INT_TO_FLOAT(param[1]);
5435    p[2] = INT_TO_FLOAT(param[2]);
5436    p[3] = INT_TO_FLOAT(param[3]);
5437    save_TexBumpParameterfvATI(pname, p);
5438 }
5439
5440 #if FEATURE_ATI_fragment_shader
5441 static void GLAPIENTRY
5442 save_BindFragmentShaderATI(GLuint id)
5443 {
5444    GET_CURRENT_CONTEXT(ctx);
5445    Node *n;
5446
5447    n = alloc_instruction(ctx, OPCODE_BIND_FRAGMENT_SHADER_ATI, 1);
5448    if (n) {
5449       n[1].ui = id;
5450    }
5451    if (ctx->ExecuteFlag) {
5452       CALL_BindFragmentShaderATI(ctx->Exec, (id));
5453    }
5454 }
5455
5456 static void GLAPIENTRY
5457 save_SetFragmentShaderConstantATI(GLuint dst, const GLfloat *value)
5458 {
5459    GET_CURRENT_CONTEXT(ctx);
5460    Node *n;
5461
5462    n = alloc_instruction(ctx, OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI, 5);
5463    if (n) {
5464       n[1].ui = dst;
5465       n[2].f = value[0];
5466       n[3].f = value[1];
5467       n[4].f = value[2];
5468       n[5].f = value[3];
5469    }
5470    if (ctx->ExecuteFlag) {
5471       CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, value));
5472    }
5473 }
5474 #endif
5475
5476 static void GLAPIENTRY
5477 save_Attr1fNV(GLenum attr, GLfloat x)
5478 {
5479    GET_CURRENT_CONTEXT(ctx);
5480    Node *n;
5481    SAVE_FLUSH_VERTICES(ctx);
5482    n = alloc_instruction(ctx, OPCODE_ATTR_1F_NV, 2);
5483    if (n) {
5484       n[1].e = attr;
5485       n[2].f = x;
5486    }
5487
5488    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5489    ctx->ListState.ActiveAttribSize[attr] = 1;
5490    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
5491
5492    if (ctx->ExecuteFlag) {
5493       CALL_VertexAttrib1fNV(ctx->Exec, (attr, x));
5494    }
5495 }
5496
5497 static void GLAPIENTRY
5498 save_Attr2fNV(GLenum attr, GLfloat x, GLfloat y)
5499 {
5500    GET_CURRENT_CONTEXT(ctx);
5501    Node *n;
5502    SAVE_FLUSH_VERTICES(ctx);
5503    n = alloc_instruction(ctx, OPCODE_ATTR_2F_NV, 3);
5504    if (n) {
5505       n[1].e = attr;
5506       n[2].f = x;
5507       n[3].f = y;
5508    }
5509
5510    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5511    ctx->ListState.ActiveAttribSize[attr] = 2;
5512    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
5513
5514    if (ctx->ExecuteFlag) {
5515       CALL_VertexAttrib2fNV(ctx->Exec, (attr, x, y));
5516    }
5517 }
5518
5519 static void GLAPIENTRY
5520 save_Attr3fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
5521 {
5522    GET_CURRENT_CONTEXT(ctx);
5523    Node *n;
5524    SAVE_FLUSH_VERTICES(ctx);
5525    n = alloc_instruction(ctx, OPCODE_ATTR_3F_NV, 4);
5526    if (n) {
5527       n[1].e = attr;
5528       n[2].f = x;
5529       n[3].f = y;
5530       n[4].f = z;
5531    }
5532
5533    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5534    ctx->ListState.ActiveAttribSize[attr] = 3;
5535    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
5536
5537    if (ctx->ExecuteFlag) {
5538       CALL_VertexAttrib3fNV(ctx->Exec, (attr, x, y, z));
5539    }
5540 }
5541
5542 static void GLAPIENTRY
5543 save_Attr4fNV(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5544 {
5545    GET_CURRENT_CONTEXT(ctx);
5546    Node *n;
5547    SAVE_FLUSH_VERTICES(ctx);
5548    n = alloc_instruction(ctx, OPCODE_ATTR_4F_NV, 5);
5549    if (n) {
5550       n[1].e = attr;
5551       n[2].f = x;
5552       n[3].f = y;
5553       n[4].f = z;
5554       n[5].f = w;
5555    }
5556
5557    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5558    ctx->ListState.ActiveAttribSize[attr] = 4;
5559    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
5560
5561    if (ctx->ExecuteFlag) {
5562       CALL_VertexAttrib4fNV(ctx->Exec, (attr, x, y, z, w));
5563    }
5564 }
5565
5566
5567 static void GLAPIENTRY
5568 save_Attr1fARB(GLenum attr, GLfloat x)
5569 {
5570    GET_CURRENT_CONTEXT(ctx);
5571    Node *n;
5572    SAVE_FLUSH_VERTICES(ctx);
5573    n = alloc_instruction(ctx, OPCODE_ATTR_1F_ARB, 2);
5574    if (n) {
5575       n[1].e = attr;
5576       n[2].f = x;
5577    }
5578
5579    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5580    ctx->ListState.ActiveAttribSize[attr] = 1;
5581    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, 0, 0, 1);
5582
5583    if (ctx->ExecuteFlag) {
5584       CALL_VertexAttrib1fARB(ctx->Exec, (attr, x));
5585    }
5586 }
5587
5588 static void GLAPIENTRY
5589 save_Attr2fARB(GLenum attr, GLfloat x, GLfloat y)
5590 {
5591    GET_CURRENT_CONTEXT(ctx);
5592    Node *n;
5593    SAVE_FLUSH_VERTICES(ctx);
5594    n = alloc_instruction(ctx, OPCODE_ATTR_2F_ARB, 3);
5595    if (n) {
5596       n[1].e = attr;
5597       n[2].f = x;
5598       n[3].f = y;
5599    }
5600
5601    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5602    ctx->ListState.ActiveAttribSize[attr] = 2;
5603    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, 0, 1);
5604
5605    if (ctx->ExecuteFlag) {
5606       CALL_VertexAttrib2fARB(ctx->Exec, (attr, x, y));
5607    }
5608 }
5609
5610 static void GLAPIENTRY
5611 save_Attr3fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z)
5612 {
5613    GET_CURRENT_CONTEXT(ctx);
5614    Node *n;
5615    SAVE_FLUSH_VERTICES(ctx);
5616    n = alloc_instruction(ctx, OPCODE_ATTR_3F_ARB, 4);
5617    if (n) {
5618       n[1].e = attr;
5619       n[2].f = x;
5620       n[3].f = y;
5621       n[4].f = z;
5622    }
5623
5624    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5625    ctx->ListState.ActiveAttribSize[attr] = 3;
5626    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, 1);
5627
5628    if (ctx->ExecuteFlag) {
5629       CALL_VertexAttrib3fARB(ctx->Exec, (attr, x, y, z));
5630    }
5631 }
5632
5633 static void GLAPIENTRY
5634 save_Attr4fARB(GLenum attr, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5635 {
5636    GET_CURRENT_CONTEXT(ctx);
5637    Node *n;
5638    SAVE_FLUSH_VERTICES(ctx);
5639    n = alloc_instruction(ctx, OPCODE_ATTR_4F_ARB, 5);
5640    if (n) {
5641       n[1].e = attr;
5642       n[2].f = x;
5643       n[3].f = y;
5644       n[4].f = z;
5645       n[5].f = w;
5646    }
5647
5648    ASSERT(attr < MAX_VERTEX_GENERIC_ATTRIBS);
5649    ctx->ListState.ActiveAttribSize[attr] = 4;
5650    ASSIGN_4V(ctx->ListState.CurrentAttrib[attr], x, y, z, w);
5651
5652    if (ctx->ExecuteFlag) {
5653       CALL_VertexAttrib4fARB(ctx->Exec, (attr, x, y, z, w));
5654    }
5655 }
5656
5657
5658 static void GLAPIENTRY
5659 save_EvalCoord1f(GLfloat x)
5660 {
5661    GET_CURRENT_CONTEXT(ctx);
5662    Node *n;
5663    SAVE_FLUSH_VERTICES(ctx);
5664    n = alloc_instruction(ctx, OPCODE_EVAL_C1, 1);
5665    if (n) {
5666       n[1].f = x;
5667    }
5668    if (ctx->ExecuteFlag) {
5669       CALL_EvalCoord1f(ctx->Exec, (x));
5670    }
5671 }
5672
5673 static void GLAPIENTRY
5674 save_EvalCoord1fv(const GLfloat * v)
5675 {
5676    save_EvalCoord1f(v[0]);
5677 }
5678
5679 static void GLAPIENTRY
5680 save_EvalCoord2f(GLfloat x, GLfloat y)
5681 {
5682    GET_CURRENT_CONTEXT(ctx);
5683    Node *n;
5684    SAVE_FLUSH_VERTICES(ctx);
5685    n = alloc_instruction(ctx, OPCODE_EVAL_C2, 2);
5686    if (n) {
5687       n[1].f = x;
5688       n[2].f = y;
5689    }
5690    if (ctx->ExecuteFlag) {
5691       CALL_EvalCoord2f(ctx->Exec, (x, y));
5692    }
5693 }
5694
5695 static void GLAPIENTRY
5696 save_EvalCoord2fv(const GLfloat * v)
5697 {
5698    save_EvalCoord2f(v[0], v[1]);
5699 }
5700
5701
5702 static void GLAPIENTRY
5703 save_EvalPoint1(GLint x)
5704 {
5705    GET_CURRENT_CONTEXT(ctx);
5706    Node *n;
5707    SAVE_FLUSH_VERTICES(ctx);
5708    n = alloc_instruction(ctx, OPCODE_EVAL_P1, 1);
5709    if (n) {
5710       n[1].i = x;
5711    }
5712    if (ctx->ExecuteFlag) {
5713       CALL_EvalPoint1(ctx->Exec, (x));
5714    }
5715 }
5716
5717 static void GLAPIENTRY
5718 save_EvalPoint2(GLint x, GLint y)
5719 {
5720    GET_CURRENT_CONTEXT(ctx);
5721    Node *n;
5722    SAVE_FLUSH_VERTICES(ctx);
5723    n = alloc_instruction(ctx, OPCODE_EVAL_P2, 2);
5724    if (n) {
5725       n[1].i = x;
5726       n[2].i = y;
5727    }
5728    if (ctx->ExecuteFlag) {
5729       CALL_EvalPoint2(ctx->Exec, (x, y));
5730    }
5731 }
5732
5733 static void GLAPIENTRY
5734 save_Indexf(GLfloat x)
5735 {
5736    save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, x);
5737 }
5738
5739 static void GLAPIENTRY
5740 save_Indexfv(const GLfloat * v)
5741 {
5742    save_Attr1fNV(VERT_ATTRIB_COLOR_INDEX, v[0]);
5743 }
5744
5745 static void GLAPIENTRY
5746 save_EdgeFlag(GLboolean x)
5747 {
5748    save_Attr1fNV(VERT_ATTRIB_EDGEFLAG, x ? 1.0f : 0.0f);
5749 }
5750
5751
5752 /**
5753  * Compare 'count' elements of vectors 'a' and 'b'.
5754  * \return GL_TRUE if equal, GL_FALSE if different.
5755  */
5756 static inline GLboolean
5757 compare_vec(const GLfloat *a, const GLfloat *b, GLuint count)
5758 {
5759    return memcmp( a, b, count * sizeof(GLfloat) ) == 0;
5760 }
5761
5762
5763 /**
5764  * This glMaterial function is used for glMaterial calls that are outside
5765  * a glBegin/End pair.  For glMaterial inside glBegin/End, see the VBO code.
5766  */
5767 static void GLAPIENTRY
5768 save_Materialfv(GLenum face, GLenum pname, const GLfloat * param)
5769 {
5770    GET_CURRENT_CONTEXT(ctx);
5771    Node *n;
5772    int args, i;
5773    GLuint bitmask;
5774
5775    switch (face) {
5776    case GL_BACK:
5777    case GL_FRONT:
5778    case GL_FRONT_AND_BACK:
5779       break;
5780    default:
5781       _mesa_compile_error(ctx, GL_INVALID_ENUM, "glMaterial(face)");
5782       return;
5783    }
5784
5785    switch (pname) {
5786    case GL_EMISSION:
5787    case GL_AMBIENT:
5788    case GL_DIFFUSE:
5789    case GL_SPECULAR:
5790    case GL_AMBIENT_AND_DIFFUSE:
5791       args = 4;
5792       break;
5793    case GL_SHININESS:
5794       args = 1;
5795       break;
5796    case GL_COLOR_INDEXES:
5797       args = 3;
5798       break;
5799    default:
5800       _mesa_compile_error(ctx, GL_INVALID_ENUM, "glMaterial(pname)");
5801       return;
5802    }
5803    
5804    if (ctx->ExecuteFlag) {
5805       CALL_Materialfv(ctx->Exec, (face, pname, param));
5806    }
5807
5808    bitmask = _mesa_material_bitmask(ctx, face, pname, ~0, NULL);
5809
5810    /* Try to eliminate redundant statechanges.  Because it is legal to
5811     * call glMaterial even inside begin/end calls, don't need to worry
5812     * about ctx->Driver.CurrentSavePrimitive here.
5813     */
5814    for (i = 0; i < MAT_ATTRIB_MAX; i++) {
5815       if (bitmask & (1 << i)) {
5816          if (ctx->ListState.ActiveMaterialSize[i] == args &&
5817              compare_vec(ctx->ListState.CurrentMaterial[i], param, args)) {
5818             /* no change in material value */
5819             bitmask &= ~(1 << i);
5820          }
5821          else {
5822             ctx->ListState.ActiveMaterialSize[i] = args;
5823             COPY_SZ_4V(ctx->ListState.CurrentMaterial[i], args, param);
5824          }
5825       }
5826    }
5827
5828    /* If this call has no effect, return early */
5829    if (bitmask == 0)
5830       return;
5831
5832    SAVE_FLUSH_VERTICES(ctx);
5833
5834    n = alloc_instruction(ctx, OPCODE_MATERIAL, 6);
5835    if (n) {
5836       n[1].e = face;
5837       n[2].e = pname;
5838       for (i = 0; i < args; i++)
5839          n[3 + i].f = param[i];
5840    }
5841 }
5842
5843 static void GLAPIENTRY
5844 save_Begin(GLenum mode)
5845 {
5846    GET_CURRENT_CONTEXT(ctx);
5847    Node *n;
5848    GLboolean error = GL_FALSE;
5849
5850    if (mode > GL_POLYGON) {
5851       _mesa_error(ctx, GL_INVALID_ENUM, "glBegin(mode=%x)", mode);
5852       error = GL_TRUE;
5853    }
5854    if (ctx->ExecuteFlag) {
5855       if (!_mesa_valid_prim_mode(ctx, mode, "glBegin")) {
5856          error = GL_TRUE;
5857       }
5858    }
5859
5860    else if (ctx->Driver.CurrentSavePrimitive == PRIM_UNKNOWN) {
5861       /* Typically the first begin.  This may raise an error on
5862        * playback, depending on whether CallList is issued from inside
5863        * a begin/end or not.
5864        */
5865       ctx->Driver.CurrentSavePrimitive = PRIM_INSIDE_UNKNOWN_PRIM;
5866    }
5867    else if (ctx->Driver.CurrentSavePrimitive == PRIM_OUTSIDE_BEGIN_END) {
5868       ctx->Driver.CurrentSavePrimitive = mode;
5869    }
5870    else {
5871       _mesa_compile_error(ctx, GL_INVALID_OPERATION, "recursive begin");
5872       error = GL_TRUE;
5873    }
5874
5875    if (!error) {
5876       /* Give the driver an opportunity to hook in an optimized
5877        * display list compiler.
5878        */
5879       if (ctx->Driver.NotifySaveBegin(ctx, mode))
5880          return;
5881
5882       SAVE_FLUSH_VERTICES(ctx);
5883       n = alloc_instruction(ctx, OPCODE_BEGIN, 1);
5884       if (n) {
5885          n[1].e = mode;
5886       }
5887    }
5888
5889    if (ctx->ExecuteFlag) {
5890       CALL_Begin(ctx->Exec, (mode));
5891    }
5892 }
5893
5894 static void GLAPIENTRY
5895 save_End(void)
5896 {
5897    GET_CURRENT_CONTEXT(ctx);
5898    SAVE_FLUSH_VERTICES(ctx);
5899    (void) alloc_instruction(ctx, OPCODE_END, 0);
5900    ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
5901    if (ctx->ExecuteFlag) {
5902       CALL_End(ctx->Exec, ());
5903    }
5904 }
5905
5906 static void GLAPIENTRY
5907 save_Rectf(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
5908 {
5909    GET_CURRENT_CONTEXT(ctx);
5910    Node *n;
5911    SAVE_FLUSH_VERTICES(ctx);
5912    n = alloc_instruction(ctx, OPCODE_RECTF, 4);
5913    if (n) {
5914       n[1].f = a;
5915       n[2].f = b;
5916       n[3].f = c;
5917       n[4].f = d;
5918    }
5919    if (ctx->ExecuteFlag) {
5920       CALL_Rectf(ctx->Exec, (a, b, c, d));
5921    }
5922 }
5923
5924
5925 static void GLAPIENTRY
5926 save_Vertex2f(GLfloat x, GLfloat y)
5927 {
5928    save_Attr2fNV(VERT_ATTRIB_POS, x, y);
5929 }
5930
5931 static void GLAPIENTRY
5932 save_Vertex2fv(const GLfloat * v)
5933 {
5934    save_Attr2fNV(VERT_ATTRIB_POS, v[0], v[1]);
5935 }
5936
5937 static void GLAPIENTRY
5938 save_Vertex3f(GLfloat x, GLfloat y, GLfloat z)
5939 {
5940    save_Attr3fNV(VERT_ATTRIB_POS, x, y, z);
5941 }
5942
5943 static void GLAPIENTRY
5944 save_Vertex3fv(const GLfloat * v)
5945 {
5946    save_Attr3fNV(VERT_ATTRIB_POS, v[0], v[1], v[2]);
5947 }
5948
5949 static void GLAPIENTRY
5950 save_Vertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5951 {
5952    save_Attr4fNV(VERT_ATTRIB_POS, x, y, z, w);
5953 }
5954
5955 static void GLAPIENTRY
5956 save_Vertex4fv(const GLfloat * v)
5957 {
5958    save_Attr4fNV(VERT_ATTRIB_POS, v[0], v[1], v[2], v[3]);
5959 }
5960
5961 static void GLAPIENTRY
5962 save_TexCoord1f(GLfloat x)
5963 {
5964    save_Attr1fNV(VERT_ATTRIB_TEX0, x);
5965 }
5966
5967 static void GLAPIENTRY
5968 save_TexCoord1fv(const GLfloat * v)
5969 {
5970    save_Attr1fNV(VERT_ATTRIB_TEX0, v[0]);
5971 }
5972
5973 static void GLAPIENTRY
5974 save_TexCoord2f(GLfloat x, GLfloat y)
5975 {
5976    save_Attr2fNV(VERT_ATTRIB_TEX0, x, y);
5977 }
5978
5979 static void GLAPIENTRY
5980 save_TexCoord2fv(const GLfloat * v)
5981 {
5982    save_Attr2fNV(VERT_ATTRIB_TEX0, v[0], v[1]);
5983 }
5984
5985 static void GLAPIENTRY
5986 save_TexCoord3f(GLfloat x, GLfloat y, GLfloat z)
5987 {
5988    save_Attr3fNV(VERT_ATTRIB_TEX0, x, y, z);
5989 }
5990
5991 static void GLAPIENTRY
5992 save_TexCoord3fv(const GLfloat * v)
5993 {
5994    save_Attr3fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2]);
5995 }
5996
5997 static void GLAPIENTRY
5998 save_TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5999 {
6000    save_Attr4fNV(VERT_ATTRIB_TEX0, x, y, z, w);
6001 }
6002
6003 static void GLAPIENTRY
6004 save_TexCoord4fv(const GLfloat * v)
6005 {
6006    save_Attr4fNV(VERT_ATTRIB_TEX0, v[0], v[1], v[2], v[3]);
6007 }
6008
6009 static void GLAPIENTRY
6010 save_Normal3f(GLfloat x, GLfloat y, GLfloat z)
6011 {
6012    save_Attr3fNV(VERT_ATTRIB_NORMAL, x, y, z);
6013 }
6014
6015 static void GLAPIENTRY
6016 save_Normal3fv(const GLfloat * v)
6017 {
6018    save_Attr3fNV(VERT_ATTRIB_NORMAL, v[0], v[1], v[2]);
6019 }
6020
6021 static void GLAPIENTRY
6022 save_FogCoordfEXT(GLfloat x)
6023 {
6024    save_Attr1fNV(VERT_ATTRIB_FOG, x);
6025 }
6026
6027 static void GLAPIENTRY
6028 save_FogCoordfvEXT(const GLfloat * v)
6029 {
6030    save_Attr1fNV(VERT_ATTRIB_FOG, v[0]);
6031 }
6032
6033 static void GLAPIENTRY
6034 save_Color3f(GLfloat x, GLfloat y, GLfloat z)
6035 {
6036    save_Attr3fNV(VERT_ATTRIB_COLOR0, x, y, z);
6037 }
6038
6039 static void GLAPIENTRY
6040 save_Color3fv(const GLfloat * v)
6041 {
6042    save_Attr3fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2]);
6043 }
6044
6045 static void GLAPIENTRY
6046 save_Color4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6047 {
6048    save_Attr4fNV(VERT_ATTRIB_COLOR0, x, y, z, w);
6049 }
6050
6051 static void GLAPIENTRY
6052 save_Color4fv(const GLfloat * v)
6053 {
6054    save_Attr4fNV(VERT_ATTRIB_COLOR0, v[0], v[1], v[2], v[3]);
6055 }
6056
6057 static void GLAPIENTRY
6058 save_SecondaryColor3fEXT(GLfloat x, GLfloat y, GLfloat z)
6059 {
6060    save_Attr3fNV(VERT_ATTRIB_COLOR1, x, y, z);
6061 }
6062
6063 static void GLAPIENTRY
6064 save_SecondaryColor3fvEXT(const GLfloat * v)
6065 {
6066    save_Attr3fNV(VERT_ATTRIB_COLOR1, v[0], v[1], v[2]);
6067 }
6068
6069
6070 /* Just call the respective ATTR for texcoord
6071  */
6072 static void GLAPIENTRY
6073 save_MultiTexCoord1f(GLenum target, GLfloat x)
6074 {
6075    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6076    save_Attr1fNV(attr, x);
6077 }
6078
6079 static void GLAPIENTRY
6080 save_MultiTexCoord1fv(GLenum target, const GLfloat * v)
6081 {
6082    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6083    save_Attr1fNV(attr, v[0]);
6084 }
6085
6086 static void GLAPIENTRY
6087 save_MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y)
6088 {
6089    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6090    save_Attr2fNV(attr, x, y);
6091 }
6092
6093 static void GLAPIENTRY
6094 save_MultiTexCoord2fv(GLenum target, const GLfloat * v)
6095 {
6096    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6097    save_Attr2fNV(attr, v[0], v[1]);
6098 }
6099
6100 static void GLAPIENTRY
6101 save_MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z)
6102 {
6103    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6104    save_Attr3fNV(attr, x, y, z);
6105 }
6106
6107 static void GLAPIENTRY
6108 save_MultiTexCoord3fv(GLenum target, const GLfloat * v)
6109 {
6110    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6111    save_Attr3fNV(attr, v[0], v[1], v[2]);
6112 }
6113
6114 static void GLAPIENTRY
6115 save_MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y,
6116                      GLfloat z, GLfloat w)
6117 {
6118    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6119    save_Attr4fNV(attr, x, y, z, w);
6120 }
6121
6122 static void GLAPIENTRY
6123 save_MultiTexCoord4fv(GLenum target, const GLfloat * v)
6124 {
6125    GLuint attr = (target & 0x7) + VERT_ATTRIB_TEX0;
6126    save_Attr4fNV(attr, v[0], v[1], v[2], v[3]);
6127 }
6128
6129
6130 /**
6131  * Record a GL_INVALID_VALUE error when a invalid vertex attribute
6132  * index is found.
6133  */
6134 static void
6135 index_error(void)
6136 {
6137    GET_CURRENT_CONTEXT(ctx);
6138    _mesa_error(ctx, GL_INVALID_VALUE, "VertexAttribf(index)");
6139 }
6140
6141
6142 /* First level for NV_vertex_program:
6143  *
6144  * Check for errors at compile time?.
6145  */
6146 static void GLAPIENTRY
6147 save_VertexAttrib1fNV(GLuint index, GLfloat x)
6148 {
6149    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6150       save_Attr1fNV(index, x);
6151    else
6152       index_error();
6153 }
6154
6155 static void GLAPIENTRY
6156 save_VertexAttrib1fvNV(GLuint index, const GLfloat * v)
6157 {
6158    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6159       save_Attr1fNV(index, v[0]);
6160    else
6161       index_error();
6162 }
6163
6164 static void GLAPIENTRY
6165 save_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y)
6166 {
6167    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6168       save_Attr2fNV(index, x, y);
6169    else
6170       index_error();
6171 }
6172
6173 static void GLAPIENTRY
6174 save_VertexAttrib2fvNV(GLuint index, const GLfloat * v)
6175 {
6176    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6177       save_Attr2fNV(index, v[0], v[1]);
6178    else
6179       index_error();
6180 }
6181
6182 static void GLAPIENTRY
6183 save_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z)
6184 {
6185    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6186       save_Attr3fNV(index, x, y, z);
6187    else
6188       index_error();
6189 }
6190
6191 static void GLAPIENTRY
6192 save_VertexAttrib3fvNV(GLuint index, const GLfloat * v)
6193 {
6194    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6195       save_Attr3fNV(index, v[0], v[1], v[2]);
6196    else
6197       index_error();
6198 }
6199
6200 static void GLAPIENTRY
6201 save_VertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y,
6202                       GLfloat z, GLfloat w)
6203 {
6204    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6205       save_Attr4fNV(index, x, y, z, w);
6206    else
6207       index_error();
6208 }
6209
6210 static void GLAPIENTRY
6211 save_VertexAttrib4fvNV(GLuint index, const GLfloat * v)
6212 {
6213    if (index < MAX_NV_VERTEX_PROGRAM_INPUTS)
6214       save_Attr4fNV(index, v[0], v[1], v[2], v[3]);
6215    else
6216       index_error();
6217 }
6218
6219
6220
6221
6222 static void GLAPIENTRY
6223 save_VertexAttrib1fARB(GLuint index, GLfloat x)
6224 {
6225    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6226       save_Attr1fARB(index, x);
6227    else
6228       index_error();
6229 }
6230
6231 static void GLAPIENTRY
6232 save_VertexAttrib1fvARB(GLuint index, const GLfloat * v)
6233 {
6234    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6235       save_Attr1fARB(index, v[0]);
6236    else
6237       index_error();
6238 }
6239
6240 static void GLAPIENTRY
6241 save_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y)
6242 {
6243    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6244       save_Attr2fARB(index, x, y);
6245    else
6246       index_error();
6247 }
6248
6249 static void GLAPIENTRY
6250 save_VertexAttrib2fvARB(GLuint index, const GLfloat * v)
6251 {
6252    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6253       save_Attr2fARB(index, v[0], v[1]);
6254    else
6255       index_error();
6256 }
6257
6258 static void GLAPIENTRY
6259 save_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
6260 {
6261    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6262       save_Attr3fARB(index, x, y, z);
6263    else
6264       index_error();
6265 }
6266
6267 static void GLAPIENTRY
6268 save_VertexAttrib3fvARB(GLuint index, const GLfloat * v)
6269 {
6270    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6271       save_Attr3fARB(index, v[0], v[1], v[2]);
6272    else
6273       index_error();
6274 }
6275
6276 static void GLAPIENTRY
6277 save_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z,
6278                        GLfloat w)
6279 {
6280    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6281       save_Attr4fARB(index, x, y, z, w);
6282    else
6283       index_error();
6284 }
6285
6286 static void GLAPIENTRY
6287 save_VertexAttrib4fvARB(GLuint index, const GLfloat * v)
6288 {
6289    if (index < MAX_VERTEX_GENERIC_ATTRIBS)
6290       save_Attr4fARB(index, v[0], v[1], v[2], v[3]);
6291    else
6292       index_error();
6293 }
6294
6295
6296 /* GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
6297
6298 static void GLAPIENTRY
6299 exec_BindAttribLocationARB(GLuint program, GLuint index, const GLchar *name)
6300 {
6301    GET_CURRENT_CONTEXT(ctx);
6302    FLUSH_VERTICES(ctx, 0);
6303    CALL_BindAttribLocationARB(ctx->Exec, (program, index, name));
6304 }
6305
6306 static GLint GLAPIENTRY
6307 exec_GetAttribLocationARB(GLuint program, const GLchar *name)
6308 {
6309    GET_CURRENT_CONTEXT(ctx);
6310    FLUSH_VERTICES(ctx, 0);
6311    return CALL_GetAttribLocationARB(ctx->Exec, (program, name));
6312 }
6313
6314 static GLint GLAPIENTRY
6315 exec_GetUniformLocationARB(GLuint program, const GLchar *name)
6316 {
6317    GET_CURRENT_CONTEXT(ctx);
6318    FLUSH_VERTICES(ctx, 0);
6319    return CALL_GetUniformLocationARB(ctx->Exec, (program, name));
6320 }
6321 /* XXX more shader functions needed here */
6322
6323
6324 static void GLAPIENTRY
6325 save_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
6326                         GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
6327                         GLbitfield mask, GLenum filter)
6328 {
6329    GET_CURRENT_CONTEXT(ctx);
6330    Node *n;
6331    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6332    n = alloc_instruction(ctx, OPCODE_BLIT_FRAMEBUFFER, 10);
6333    if (n) {
6334       n[1].i = srcX0;
6335       n[2].i = srcY0;
6336       n[3].i = srcX1;
6337       n[4].i = srcY1;
6338       n[5].i = dstX0;
6339       n[6].i = dstY0;
6340       n[7].i = dstX1;
6341       n[8].i = dstY1;
6342       n[9].i = mask;
6343       n[10].e = filter;
6344    }
6345    if (ctx->ExecuteFlag) {
6346       CALL_BlitFramebufferEXT(ctx->Exec, (srcX0, srcY0, srcX1, srcY1,
6347                                           dstX0, dstY0, dstX1, dstY1,
6348                                           mask, filter));
6349    }
6350 }
6351
6352
6353 /** GL_EXT_provoking_vertex */
6354 static void GLAPIENTRY
6355 save_ProvokingVertexEXT(GLenum mode)
6356 {
6357    GET_CURRENT_CONTEXT(ctx);
6358    Node *n;
6359    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6360    n = alloc_instruction(ctx, OPCODE_PROVOKING_VERTEX, 1);
6361    if (n) {
6362       n[1].e = mode;
6363    }
6364    if (ctx->ExecuteFlag) {
6365       /*CALL_ProvokingVertexEXT(ctx->Exec, (mode));*/
6366       _mesa_ProvokingVertexEXT(mode);
6367    }
6368 }
6369
6370
6371 /** GL_EXT_transform_feedback */
6372 static void GLAPIENTRY
6373 save_BeginTransformFeedback(GLenum mode)
6374 {
6375    GET_CURRENT_CONTEXT(ctx);
6376    Node *n;
6377    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6378    n = alloc_instruction(ctx, OPCODE_BEGIN_TRANSFORM_FEEDBACK, 1);
6379    if (n) {
6380       n[1].e = mode;
6381    }
6382    if (ctx->ExecuteFlag) {
6383       CALL_BeginTransformFeedbackEXT(ctx->Exec, (mode));
6384    }
6385 }
6386
6387
6388 /** GL_EXT_transform_feedback */
6389 static void GLAPIENTRY
6390 save_EndTransformFeedback(void)
6391 {
6392    GET_CURRENT_CONTEXT(ctx);
6393    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6394    (void) alloc_instruction(ctx, OPCODE_END_TRANSFORM_FEEDBACK, 0);
6395    if (ctx->ExecuteFlag) {
6396       CALL_EndTransformFeedbackEXT(ctx->Exec, ());
6397    }
6398 }
6399
6400 static void GLAPIENTRY
6401 save_BindTransformFeedback(GLenum target, GLuint name)
6402 {
6403    GET_CURRENT_CONTEXT(ctx);
6404    Node *n;
6405    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6406    n = alloc_instruction(ctx, OPCODE_BIND_TRANSFORM_FEEDBACK, 2);
6407    if (n) {
6408       n[1].e = target;
6409       n[2].ui = name;
6410    }
6411    if (ctx->ExecuteFlag) {
6412       CALL_BindTransformFeedback(ctx->Exec, (target, name));
6413    }
6414 }
6415
6416 static void GLAPIENTRY
6417 save_PauseTransformFeedback(void)
6418 {
6419    GET_CURRENT_CONTEXT(ctx);
6420    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6421    (void) alloc_instruction(ctx, OPCODE_PAUSE_TRANSFORM_FEEDBACK, 0);
6422    if (ctx->ExecuteFlag) {
6423       CALL_PauseTransformFeedback(ctx->Exec, ());
6424    }
6425 }
6426
6427 static void GLAPIENTRY
6428 save_ResumeTransformFeedback(void)
6429 {
6430    GET_CURRENT_CONTEXT(ctx);
6431    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6432    (void) alloc_instruction(ctx, OPCODE_RESUME_TRANSFORM_FEEDBACK, 0);
6433    if (ctx->ExecuteFlag) {
6434       CALL_ResumeTransformFeedback(ctx->Exec, ());
6435    }
6436 }
6437
6438 static void GLAPIENTRY
6439 save_DrawTransformFeedback(GLenum mode, GLuint name)
6440 {
6441    GET_CURRENT_CONTEXT(ctx);
6442    Node *n;
6443    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6444    n = alloc_instruction(ctx, OPCODE_DRAW_TRANSFORM_FEEDBACK, 2);
6445    if (n) {
6446       n[1].e = mode;
6447       n[2].ui = name;
6448    }
6449    if (ctx->ExecuteFlag) {
6450       CALL_DrawTransformFeedback(ctx->Exec, (mode, name));
6451    }
6452 }
6453
6454 static void GLAPIENTRY
6455 save_DrawTransformFeedbackStream(GLenum mode, GLuint name, GLuint stream)
6456 {
6457    GET_CURRENT_CONTEXT(ctx);
6458    Node *n;
6459    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6460    n = alloc_instruction(ctx, OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM, 3);
6461    if (n) {
6462       n[1].e = mode;
6463       n[2].ui = name;
6464       n[3].ui = stream;
6465    }
6466    if (ctx->ExecuteFlag) {
6467       CALL_DrawTransformFeedbackStream(ctx->Exec, (mode, name, stream));
6468    }
6469 }
6470
6471 static void GLAPIENTRY
6472 save_DrawTransformFeedbackInstanced(GLenum mode, GLuint name,
6473                                     GLsizei primcount)
6474 {
6475    GET_CURRENT_CONTEXT(ctx);
6476    Node *n;
6477    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6478    n = alloc_instruction(ctx, OPCODE_DRAW_TRANSFORM_FEEDBACK_INSTANCED, 3);
6479    if (n) {
6480       n[1].e = mode;
6481       n[2].ui = name;
6482       n[3].si = primcount;
6483    }
6484    if (ctx->ExecuteFlag) {
6485       CALL_DrawTransformFeedbackInstanced(ctx->Exec, (mode, name, primcount));
6486    }
6487 }
6488
6489 static void GLAPIENTRY
6490 save_DrawTransformFeedbackStreamInstanced(GLenum mode, GLuint name,
6491                                           GLuint stream, GLsizei primcount)
6492 {
6493    GET_CURRENT_CONTEXT(ctx);
6494    Node *n;
6495    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6496    n = alloc_instruction(ctx, OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM_INSTANCED, 4);
6497    if (n) {
6498       n[1].e = mode;
6499       n[2].ui = name;
6500       n[3].ui = stream;
6501       n[4].si = primcount;
6502    }
6503    if (ctx->ExecuteFlag) {
6504       CALL_DrawTransformFeedbackStreamInstanced(ctx->Exec, (mode, name, stream,
6505                                                             primcount));
6506    }
6507 }
6508
6509 /* aka UseProgram() */
6510 static void GLAPIENTRY
6511 save_UseProgramObjectARB(GLhandleARB program)
6512 {
6513    GET_CURRENT_CONTEXT(ctx);
6514    Node *n;
6515    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6516    n = alloc_instruction(ctx, OPCODE_USE_PROGRAM, 1);
6517    if (n) {
6518       n[1].ui = program;
6519    }
6520    if (ctx->ExecuteFlag) {
6521       CALL_UseProgramObjectARB(ctx->Exec, (program));
6522    }
6523 }
6524
6525
6526 static void GLAPIENTRY
6527 save_Uniform1fARB(GLint location, GLfloat x)
6528 {
6529    GET_CURRENT_CONTEXT(ctx);
6530    Node *n;
6531    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6532    n = alloc_instruction(ctx, OPCODE_UNIFORM_1F, 2);
6533    if (n) {
6534       n[1].i = location;
6535       n[2].f = x;
6536    }
6537    if (ctx->ExecuteFlag) {
6538       CALL_Uniform1fARB(ctx->Exec, (location, x));
6539    }
6540 }
6541
6542
6543 static void GLAPIENTRY
6544 save_Uniform2fARB(GLint location, GLfloat x, GLfloat y)
6545 {
6546    GET_CURRENT_CONTEXT(ctx);
6547    Node *n;
6548    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6549    n = alloc_instruction(ctx, OPCODE_UNIFORM_2F, 3);
6550    if (n) {
6551       n[1].i = location;
6552       n[2].f = x;
6553       n[3].f = y;
6554    }
6555    if (ctx->ExecuteFlag) {
6556       CALL_Uniform2fARB(ctx->Exec, (location, x, y));
6557    }
6558 }
6559
6560
6561 static void GLAPIENTRY
6562 save_Uniform3fARB(GLint location, GLfloat x, GLfloat y, GLfloat z)
6563 {
6564    GET_CURRENT_CONTEXT(ctx);
6565    Node *n;
6566    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6567    n = alloc_instruction(ctx, OPCODE_UNIFORM_3F, 4);
6568    if (n) {
6569       n[1].i = location;
6570       n[2].f = x;
6571       n[3].f = y;
6572       n[4].f = z;
6573    }
6574    if (ctx->ExecuteFlag) {
6575       CALL_Uniform3fARB(ctx->Exec, (location, x, y, z));
6576    }
6577 }
6578
6579
6580 static void GLAPIENTRY
6581 save_Uniform4fARB(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6582 {
6583    GET_CURRENT_CONTEXT(ctx);
6584    Node *n;
6585    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6586    n = alloc_instruction(ctx, OPCODE_UNIFORM_4F, 5);
6587    if (n) {
6588       n[1].i = location;
6589       n[2].f = x;
6590       n[3].f = y;
6591       n[4].f = z;
6592       n[5].f = w;
6593    }
6594    if (ctx->ExecuteFlag) {
6595       CALL_Uniform4fARB(ctx->Exec, (location, x, y, z, w));
6596    }
6597 }
6598
6599
6600 /** Return copy of memory */
6601 static void *
6602 memdup(const void *src, GLsizei bytes)
6603 {
6604    void *b = bytes >= 0 ? malloc(bytes) : NULL;
6605    if (b)
6606       memcpy(b, src, bytes);
6607    return b;
6608 }
6609
6610
6611 static void GLAPIENTRY
6612 save_Uniform1fvARB(GLint location, GLsizei count, const GLfloat *v)
6613 {
6614    GET_CURRENT_CONTEXT(ctx);
6615    Node *n;
6616    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6617    n = alloc_instruction(ctx, OPCODE_UNIFORM_1FV, 3);
6618    if (n) {
6619       n[1].i = location;
6620       n[2].i = count;
6621       n[3].data = memdup(v, count * 1 * sizeof(GLfloat));
6622    }
6623    if (ctx->ExecuteFlag) {
6624       CALL_Uniform1fvARB(ctx->Exec, (location, count, v));
6625    }
6626 }
6627
6628 static void GLAPIENTRY
6629 save_Uniform2fvARB(GLint location, GLsizei count, const GLfloat *v)
6630 {
6631    GET_CURRENT_CONTEXT(ctx);
6632    Node *n;
6633    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6634    n = alloc_instruction(ctx, OPCODE_UNIFORM_2FV, 3);
6635    if (n) {
6636       n[1].i = location;
6637       n[2].i = count;
6638       n[3].data = memdup(v, count * 2 * sizeof(GLfloat));
6639    }
6640    if (ctx->ExecuteFlag) {
6641       CALL_Uniform2fvARB(ctx->Exec, (location, count, v));
6642    }
6643 }
6644
6645 static void GLAPIENTRY
6646 save_Uniform3fvARB(GLint location, GLsizei count, const GLfloat *v)
6647 {
6648    GET_CURRENT_CONTEXT(ctx);
6649    Node *n;
6650    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6651    n = alloc_instruction(ctx, OPCODE_UNIFORM_3FV, 3);
6652    if (n) {
6653       n[1].i = location;
6654       n[2].i = count;
6655       n[3].data = memdup(v, count * 3 * sizeof(GLfloat));
6656    }
6657    if (ctx->ExecuteFlag) {
6658       CALL_Uniform3fvARB(ctx->Exec, (location, count, v));
6659    }
6660 }
6661
6662 static void GLAPIENTRY
6663 save_Uniform4fvARB(GLint location, GLsizei count, const GLfloat *v)
6664 {
6665    GET_CURRENT_CONTEXT(ctx);
6666    Node *n;
6667    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6668    n = alloc_instruction(ctx, OPCODE_UNIFORM_4FV, 3);
6669    if (n) {
6670       n[1].i = location;
6671       n[2].i = count;
6672       n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
6673    }
6674    if (ctx->ExecuteFlag) {
6675       CALL_Uniform4fvARB(ctx->Exec, (location, count, v));
6676    }
6677 }
6678
6679
6680 static void GLAPIENTRY
6681 save_Uniform1iARB(GLint location, GLint x)
6682 {
6683    GET_CURRENT_CONTEXT(ctx);
6684    Node *n;
6685    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6686    n = alloc_instruction(ctx, OPCODE_UNIFORM_1I, 2);
6687    if (n) {
6688       n[1].i = location;
6689       n[2].i = x;
6690    }
6691    if (ctx->ExecuteFlag) {
6692       CALL_Uniform1iARB(ctx->Exec, (location, x));
6693    }
6694 }
6695
6696 static void GLAPIENTRY
6697 save_Uniform2iARB(GLint location, GLint x, GLint y)
6698 {
6699    GET_CURRENT_CONTEXT(ctx);
6700    Node *n;
6701    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6702    n = alloc_instruction(ctx, OPCODE_UNIFORM_2I, 3);
6703    if (n) {
6704       n[1].i = location;
6705       n[2].i = x;
6706       n[3].i = y;
6707    }
6708    if (ctx->ExecuteFlag) {
6709       CALL_Uniform2iARB(ctx->Exec, (location, x, y));
6710    }
6711 }
6712
6713 static void GLAPIENTRY
6714 save_Uniform3iARB(GLint location, GLint x, GLint y, GLint z)
6715 {
6716    GET_CURRENT_CONTEXT(ctx);
6717    Node *n;
6718    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6719    n = alloc_instruction(ctx, OPCODE_UNIFORM_3I, 4);
6720    if (n) {
6721       n[1].i = location;
6722       n[2].i = x;
6723       n[3].i = y;
6724       n[4].i = z;
6725    }
6726    if (ctx->ExecuteFlag) {
6727       CALL_Uniform3iARB(ctx->Exec, (location, x, y, z));
6728    }
6729 }
6730
6731 static void GLAPIENTRY
6732 save_Uniform4iARB(GLint location, GLint x, GLint y, GLint z, GLint w)
6733 {
6734    GET_CURRENT_CONTEXT(ctx);
6735    Node *n;
6736    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6737    n = alloc_instruction(ctx, OPCODE_UNIFORM_4I, 5);
6738    if (n) {
6739       n[1].i = location;
6740       n[2].i = x;
6741       n[3].i = y;
6742       n[4].i = z;
6743       n[5].i = w;
6744    }
6745    if (ctx->ExecuteFlag) {
6746       CALL_Uniform4iARB(ctx->Exec, (location, x, y, z, w));
6747    }
6748 }
6749
6750
6751
6752 static void GLAPIENTRY
6753 save_Uniform1ivARB(GLint location, GLsizei count, const GLint *v)
6754 {
6755    GET_CURRENT_CONTEXT(ctx);
6756    Node *n;
6757    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6758    n = alloc_instruction(ctx, OPCODE_UNIFORM_1IV, 3);
6759    if (n) {
6760       n[1].i = location;
6761       n[2].i = count;
6762       n[3].data = memdup(v, count * 1 * sizeof(GLint));
6763    }
6764    if (ctx->ExecuteFlag) {
6765       CALL_Uniform1ivARB(ctx->Exec, (location, count, v));
6766    }
6767 }
6768
6769 static void GLAPIENTRY
6770 save_Uniform2ivARB(GLint location, GLsizei count, const GLint *v)
6771 {
6772    GET_CURRENT_CONTEXT(ctx);
6773    Node *n;
6774    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6775    n = alloc_instruction(ctx, OPCODE_UNIFORM_2IV, 3);
6776    if (n) {
6777       n[1].i = location;
6778       n[2].i = count;
6779       n[3].data = memdup(v, count * 2 * sizeof(GLint));
6780    }
6781    if (ctx->ExecuteFlag) {
6782       CALL_Uniform2ivARB(ctx->Exec, (location, count, v));
6783    }
6784 }
6785
6786 static void GLAPIENTRY
6787 save_Uniform3ivARB(GLint location, GLsizei count, const GLint *v)
6788 {
6789    GET_CURRENT_CONTEXT(ctx);
6790    Node *n;
6791    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6792    n = alloc_instruction(ctx, OPCODE_UNIFORM_3IV, 3);
6793    if (n) {
6794       n[1].i = location;
6795       n[2].i = count;
6796       n[3].data = memdup(v, count * 3 * sizeof(GLint));
6797    }
6798    if (ctx->ExecuteFlag) {
6799       CALL_Uniform3ivARB(ctx->Exec, (location, count, v));
6800    }
6801 }
6802
6803 static void GLAPIENTRY
6804 save_Uniform4ivARB(GLint location, GLsizei count, const GLint *v)
6805 {
6806    GET_CURRENT_CONTEXT(ctx);
6807    Node *n;
6808    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6809    n = alloc_instruction(ctx, OPCODE_UNIFORM_4IV, 3);
6810    if (n) {
6811       n[1].i = location;
6812       n[2].i = count;
6813       n[3].data = memdup(v, count * 4 * sizeof(GLfloat));
6814    }
6815    if (ctx->ExecuteFlag) {
6816       CALL_Uniform4ivARB(ctx->Exec, (location, count, v));
6817    }
6818 }
6819
6820
6821
6822 static void GLAPIENTRY
6823 save_Uniform1ui(GLint location, GLuint x)
6824 {
6825    GET_CURRENT_CONTEXT(ctx);
6826    Node *n;
6827    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6828    n = alloc_instruction(ctx, OPCODE_UNIFORM_1UI, 2);
6829    if (n) {
6830       n[1].i = location;
6831       n[2].i = x;
6832    }
6833    if (ctx->ExecuteFlag) {
6834       /*CALL_Uniform1ui(ctx->Exec, (location, x));*/
6835    }
6836 }
6837
6838 static void GLAPIENTRY
6839 save_Uniform2ui(GLint location, GLuint x, GLuint y)
6840 {
6841    GET_CURRENT_CONTEXT(ctx);
6842    Node *n;
6843    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6844    n = alloc_instruction(ctx, OPCODE_UNIFORM_2UI, 3);
6845    if (n) {
6846       n[1].i = location;
6847       n[2].i = x;
6848       n[3].i = y;
6849    }
6850    if (ctx->ExecuteFlag) {
6851       /*CALL_Uniform2ui(ctx->Exec, (location, x, y));*/
6852    }
6853 }
6854
6855 static void GLAPIENTRY
6856 save_Uniform3ui(GLint location, GLuint x, GLuint y, GLuint z)
6857 {
6858    GET_CURRENT_CONTEXT(ctx);
6859    Node *n;
6860    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6861    n = alloc_instruction(ctx, OPCODE_UNIFORM_3UI, 4);
6862    if (n) {
6863       n[1].i = location;
6864       n[2].i = x;
6865       n[3].i = y;
6866       n[4].i = z;
6867    }
6868    if (ctx->ExecuteFlag) {
6869       /*CALL_Uniform3ui(ctx->Exec, (location, x, y, z));*/
6870    }
6871 }
6872
6873 static void GLAPIENTRY
6874 save_Uniform4ui(GLint location, GLuint x, GLuint y, GLuint z, GLuint w)
6875 {
6876    GET_CURRENT_CONTEXT(ctx);
6877    Node *n;
6878    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6879    n = alloc_instruction(ctx, OPCODE_UNIFORM_4UI, 5);
6880    if (n) {
6881       n[1].i = location;
6882       n[2].i = x;
6883       n[3].i = y;
6884       n[4].i = z;
6885       n[5].i = w;
6886    }
6887    if (ctx->ExecuteFlag) {
6888       /*CALL_Uniform4ui(ctx->Exec, (location, x, y, z, w));*/
6889    }
6890 }
6891
6892
6893
6894 static void GLAPIENTRY
6895 save_Uniform1uiv(GLint location, GLsizei count, const GLuint *v)
6896 {
6897    GET_CURRENT_CONTEXT(ctx);
6898    Node *n;
6899    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6900    n = alloc_instruction(ctx, OPCODE_UNIFORM_1UIV, 3);
6901    if (n) {
6902       n[1].i = location;
6903       n[2].i = count;
6904       n[3].data = memdup(v, count * 1 * sizeof(*v));
6905    }
6906    if (ctx->ExecuteFlag) {
6907       /*CALL_Uniform1uiv(ctx->Exec, (location, count, v));*/
6908    }
6909 }
6910
6911 static void GLAPIENTRY
6912 save_Uniform2uiv(GLint location, GLsizei count, const GLuint *v)
6913 {
6914    GET_CURRENT_CONTEXT(ctx);
6915    Node *n;
6916    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6917    n = alloc_instruction(ctx, OPCODE_UNIFORM_2UIV, 3);
6918    if (n) {
6919       n[1].i = location;
6920       n[2].i = count;
6921       n[3].data = memdup(v, count * 2 * sizeof(*v));
6922    }
6923    if (ctx->ExecuteFlag) {
6924       /*CALL_Uniform2uiv(ctx->Exec, (location, count, v));*/
6925    }
6926 }
6927
6928 static void GLAPIENTRY
6929 save_Uniform3uiv(GLint location, GLsizei count, const GLuint *v)
6930 {
6931    GET_CURRENT_CONTEXT(ctx);
6932    Node *n;
6933    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6934    n = alloc_instruction(ctx, OPCODE_UNIFORM_3UIV, 3);
6935    if (n) {
6936       n[1].i = location;
6937       n[2].i = count;
6938       n[3].data = memdup(v, count * 3 * sizeof(*v));
6939    }
6940    if (ctx->ExecuteFlag) {
6941       /*CALL_Uniform3uiv(ctx->Exec, (location, count, v));*/
6942    }
6943 }
6944
6945 static void GLAPIENTRY
6946 save_Uniform4uiv(GLint location, GLsizei count, const GLuint *v)
6947 {
6948    GET_CURRENT_CONTEXT(ctx);
6949    Node *n;
6950    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6951    n = alloc_instruction(ctx, OPCODE_UNIFORM_4UIV, 3);
6952    if (n) {
6953       n[1].i = location;
6954       n[2].i = count;
6955       n[3].data = memdup(v, count * 4 * sizeof(*v));
6956    }
6957    if (ctx->ExecuteFlag) {
6958       /*CALL_Uniform4uiv(ctx->Exec, (location, count, v));*/
6959    }
6960 }
6961
6962
6963
6964 static void GLAPIENTRY
6965 save_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
6966                          const GLfloat *m)
6967 {
6968    GET_CURRENT_CONTEXT(ctx);
6969    Node *n;
6970    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6971    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX22, 4);
6972    if (n) {
6973       n[1].i = location;
6974       n[2].i = count;
6975       n[3].b = transpose;
6976       n[4].data = memdup(m, count * 2 * 2 * sizeof(GLfloat));
6977    }
6978    if (ctx->ExecuteFlag) {
6979       CALL_UniformMatrix2fvARB(ctx->Exec, (location, count, transpose, m));
6980    }
6981 }
6982
6983 static void GLAPIENTRY
6984 save_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
6985                          const GLfloat *m)
6986 {
6987    GET_CURRENT_CONTEXT(ctx);
6988    Node *n;
6989    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
6990    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX33, 4);
6991    if (n) {
6992       n[1].i = location;
6993       n[2].i = count;
6994       n[3].b = transpose;
6995       n[4].data = memdup(m, count * 3 * 3 * sizeof(GLfloat));
6996    }
6997    if (ctx->ExecuteFlag) {
6998       CALL_UniformMatrix3fvARB(ctx->Exec, (location, count, transpose, m));
6999    }
7000 }
7001
7002 static void GLAPIENTRY
7003 save_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
7004                          const GLfloat *m)
7005 {
7006    GET_CURRENT_CONTEXT(ctx);
7007    Node *n;
7008    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7009    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX44, 4);
7010    if (n) {
7011       n[1].i = location;
7012       n[2].i = count;
7013       n[3].b = transpose;
7014       n[4].data = memdup(m, count * 4 * 4 * sizeof(GLfloat));
7015    }
7016    if (ctx->ExecuteFlag) {
7017       CALL_UniformMatrix4fvARB(ctx->Exec, (location, count, transpose, m));
7018    }
7019 }
7020
7021
7022 static void GLAPIENTRY
7023 save_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
7024                         const GLfloat *m)
7025 {
7026    GET_CURRENT_CONTEXT(ctx);
7027    Node *n;
7028    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7029    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX23, 4);
7030    if (n) {
7031       n[1].i = location;
7032       n[2].i = count;
7033       n[3].b = transpose;
7034       n[4].data = memdup(m, count * 2 * 3 * sizeof(GLfloat));
7035    }
7036    if (ctx->ExecuteFlag) {
7037       CALL_UniformMatrix2x3fv(ctx->Exec, (location, count, transpose, m));
7038    }
7039 }
7040
7041 static void GLAPIENTRY
7042 save_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
7043                         const GLfloat *m)
7044 {
7045    GET_CURRENT_CONTEXT(ctx);
7046    Node *n;
7047    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7048    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX32, 4);
7049    if (n) {
7050       n[1].i = location;
7051       n[2].i = count;
7052       n[3].b = transpose;
7053       n[4].data = memdup(m, count * 3 * 2 * sizeof(GLfloat));
7054    }
7055    if (ctx->ExecuteFlag) {
7056       CALL_UniformMatrix3x2fv(ctx->Exec, (location, count, transpose, m));
7057    }
7058 }
7059
7060
7061 static void GLAPIENTRY
7062 save_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
7063                         const GLfloat *m)
7064 {
7065    GET_CURRENT_CONTEXT(ctx);
7066    Node *n;
7067    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7068    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX24, 4);
7069    if (n) {
7070       n[1].i = location;
7071       n[2].i = count;
7072       n[3].b = transpose;
7073       n[4].data = memdup(m, count * 2 * 4 * sizeof(GLfloat));
7074    }
7075    if (ctx->ExecuteFlag) {
7076       CALL_UniformMatrix2x4fv(ctx->Exec, (location, count, transpose, m));
7077    }
7078 }
7079
7080 static void GLAPIENTRY
7081 save_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
7082                         const GLfloat *m)
7083 {
7084    GET_CURRENT_CONTEXT(ctx);
7085    Node *n;
7086    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7087    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX42, 4);
7088    if (n) {
7089       n[1].i = location;
7090       n[2].i = count;
7091       n[3].b = transpose;
7092       n[4].data = memdup(m, count * 4 * 2 * sizeof(GLfloat));
7093    }
7094    if (ctx->ExecuteFlag) {
7095       CALL_UniformMatrix4x2fv(ctx->Exec, (location, count, transpose, m));
7096    }
7097 }
7098
7099
7100 static void GLAPIENTRY
7101 save_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
7102                         const GLfloat *m)
7103 {
7104    GET_CURRENT_CONTEXT(ctx);
7105    Node *n;
7106    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7107    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX34, 4);
7108    if (n) {
7109       n[1].i = location;
7110       n[2].i = count;
7111       n[3].b = transpose;
7112       n[4].data = memdup(m, count * 3 * 4 * sizeof(GLfloat));
7113    }
7114    if (ctx->ExecuteFlag) {
7115       CALL_UniformMatrix3x4fv(ctx->Exec, (location, count, transpose, m));
7116    }
7117 }
7118
7119 static void GLAPIENTRY
7120 save_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
7121                         const GLfloat *m)
7122 {
7123    GET_CURRENT_CONTEXT(ctx);
7124    Node *n;
7125    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7126    n = alloc_instruction(ctx, OPCODE_UNIFORM_MATRIX43, 4);
7127    if (n) {
7128       n[1].i = location;
7129       n[2].i = count;
7130       n[3].b = transpose;
7131       n[4].data = memdup(m, count * 4 * 3 * sizeof(GLfloat));
7132    }
7133    if (ctx->ExecuteFlag) {
7134       CALL_UniformMatrix4x3fv(ctx->Exec, (location, count, transpose, m));
7135    }
7136 }
7137
7138 static void GLAPIENTRY
7139 save_ClampColorARB(GLenum target, GLenum clamp)
7140 {
7141    GET_CURRENT_CONTEXT(ctx);
7142    Node *n;
7143    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7144    n = alloc_instruction(ctx, OPCODE_CLAMP_COLOR, 2);
7145    if (n) {
7146       n[1].e = target;
7147       n[2].e = clamp;
7148    }
7149    if (ctx->ExecuteFlag) {
7150       CALL_ClampColorARB(ctx->Exec, (target, clamp));
7151    }
7152 }
7153
7154 static void GLAPIENTRY
7155 save_UseShaderProgramEXT(GLenum type, GLuint program)
7156 {
7157    GET_CURRENT_CONTEXT(ctx);
7158    Node *n;
7159    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7160    n = alloc_instruction(ctx, OPCODE_USE_SHADER_PROGRAM_EXT, 2);
7161    if (n) {
7162       n[1].ui = type;
7163       n[2].ui = program;
7164    }
7165    if (ctx->ExecuteFlag) {
7166       CALL_UseShaderProgramEXT(ctx->Exec, (type, program));
7167    }
7168 }
7169
7170 static void GLAPIENTRY
7171 save_ActiveProgramEXT(GLuint program)
7172 {
7173    GET_CURRENT_CONTEXT(ctx);
7174    Node *n;
7175    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7176    n = alloc_instruction(ctx, OPCODE_ACTIVE_PROGRAM_EXT, 1);
7177    if (n) {
7178       n[1].ui = program;
7179    }
7180    if (ctx->ExecuteFlag) {
7181       CALL_ActiveProgramEXT(ctx->Exec, (program));
7182    }
7183 }
7184
7185 /** GL_EXT_texture_integer */
7186 static void GLAPIENTRY
7187 save_ClearColorIi(GLint red, GLint green, GLint blue, GLint alpha)
7188 {
7189    GET_CURRENT_CONTEXT(ctx);
7190    Node *n;
7191    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7192    n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_I, 4);
7193    if (n) {
7194       n[1].i = red;
7195       n[2].i = green;
7196       n[3].i = blue;
7197       n[4].i = alpha;
7198    }
7199    if (ctx->ExecuteFlag) {
7200       CALL_ClearColorIiEXT(ctx->Exec, (red, green, blue, alpha));
7201    }
7202 }
7203
7204 /** GL_EXT_texture_integer */
7205 static void GLAPIENTRY
7206 save_ClearColorIui(GLuint red, GLuint green, GLuint blue, GLuint alpha)
7207 {
7208    GET_CURRENT_CONTEXT(ctx);
7209    Node *n;
7210    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7211    n = alloc_instruction(ctx, OPCODE_CLEARCOLOR_UI, 4);
7212    if (n) {
7213       n[1].ui = red;
7214       n[2].ui = green;
7215       n[3].ui = blue;
7216       n[4].ui = alpha;
7217    }
7218    if (ctx->ExecuteFlag) {
7219       CALL_ClearColorIuiEXT(ctx->Exec, (red, green, blue, alpha));
7220    }
7221 }
7222
7223 /** GL_EXT_texture_integer */
7224 static void GLAPIENTRY
7225 save_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
7226 {
7227    GET_CURRENT_CONTEXT(ctx);
7228    Node *n;
7229    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7230    n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_I, 6);
7231    if (n) {
7232       n[1].e = target;
7233       n[2].e = pname;
7234       n[3].i = params[0];
7235       n[4].i = params[1];
7236       n[5].i = params[2];
7237       n[6].i = params[3];
7238    }
7239    if (ctx->ExecuteFlag) {
7240       CALL_TexParameterIivEXT(ctx->Exec, (target, pname, params));
7241    }
7242 }
7243
7244 /** GL_EXT_texture_integer */
7245 static void GLAPIENTRY
7246 save_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
7247 {
7248    GET_CURRENT_CONTEXT(ctx);
7249    Node *n;
7250    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7251    n = alloc_instruction(ctx, OPCODE_TEXPARAMETER_UI, 6);
7252    if (n) {
7253       n[1].e = target;
7254       n[2].e = pname;
7255       n[3].ui = params[0];
7256       n[4].ui = params[1];
7257       n[5].ui = params[2];
7258       n[6].ui = params[3];
7259    }
7260    if (ctx->ExecuteFlag) {
7261       CALL_TexParameterIuivEXT(ctx->Exec, (target, pname, params));
7262    }
7263 }
7264
7265 /** GL_EXT_texture_integer */
7266 static void GLAPIENTRY
7267 exec_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
7268 {
7269    GET_CURRENT_CONTEXT(ctx);
7270    FLUSH_VERTICES(ctx, 0);
7271    CALL_GetTexParameterIivEXT(ctx->Exec, (target, pname, params));
7272 }
7273
7274 /** GL_EXT_texture_integer */
7275 static void GLAPIENTRY
7276 exec_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
7277 {
7278    GET_CURRENT_CONTEXT(ctx);
7279    FLUSH_VERTICES(ctx, 0);
7280    CALL_GetTexParameterIuivEXT(ctx->Exec, (target, pname, params));
7281 }
7282
7283
7284 /* GL_ARB_instanced_arrays */
7285 static void GLAPIENTRY
7286 save_VertexAttribDivisor(GLuint index, GLuint divisor)
7287 {
7288    GET_CURRENT_CONTEXT(ctx);
7289    Node *n;
7290    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7291    n = alloc_instruction(ctx, OPCODE_VERTEX_ATTRIB_DIVISOR, 2);
7292    if (n) {
7293       n[1].ui = index;
7294       n[2].ui = divisor;
7295    }
7296    if (ctx->ExecuteFlag) {
7297       CALL_VertexAttribDivisorARB(ctx->Exec, (index, divisor));
7298    }
7299 }
7300
7301
7302 /* GL_NV_texture_barrier */
7303 static void GLAPIENTRY
7304 save_TextureBarrierNV(void)
7305 {
7306    GET_CURRENT_CONTEXT(ctx);
7307    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7308    alloc_instruction(ctx, OPCODE_TEXTURE_BARRIER_NV, 0);
7309    if (ctx->ExecuteFlag) {
7310       CALL_TextureBarrierNV(ctx->Exec, ());
7311    }
7312 }
7313
7314
7315 /* GL_ARB_sampler_objects */
7316 static void GLAPIENTRY
7317 save_BindSampler(GLuint unit, GLuint sampler)
7318 {
7319    Node *n;
7320    GET_CURRENT_CONTEXT(ctx);
7321    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7322    n = alloc_instruction(ctx, OPCODE_BIND_SAMPLER, 2);
7323    if (n) {
7324       n[1].ui = unit;
7325       n[2].ui = sampler;
7326    }
7327    if (ctx->ExecuteFlag) {
7328       CALL_BindSampler(ctx->Exec, (unit, sampler));
7329    }
7330 }
7331
7332 static void GLAPIENTRY
7333 save_SamplerParameteriv(GLuint sampler, GLenum pname, const GLint *params)
7334 {
7335    Node *n;
7336    GET_CURRENT_CONTEXT(ctx);
7337    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7338    n = alloc_instruction(ctx, OPCODE_SAMPLER_PARAMETERIV, 6);
7339    if (n) {
7340       n[1].ui = sampler;
7341       n[2].e = pname;
7342       n[3].i = params[0];
7343       if (pname == GL_TEXTURE_BORDER_COLOR) {
7344          n[4].i = params[1];
7345          n[5].i = params[2];
7346          n[6].i = params[3];
7347       }
7348       else {
7349          n[4].i = n[5].i = n[6].i = 0;
7350       }
7351    }
7352    if (ctx->ExecuteFlag) {
7353       CALL_SamplerParameteriv(ctx->Exec, (sampler, pname, params));
7354    }
7355 }
7356
7357 static void GLAPIENTRY
7358 save_SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
7359 {
7360    save_SamplerParameteriv(sampler, pname, &param);
7361 }
7362
7363 static void GLAPIENTRY
7364 save_SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *params)
7365 {
7366    Node *n;
7367    GET_CURRENT_CONTEXT(ctx);
7368    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7369    n = alloc_instruction(ctx, OPCODE_SAMPLER_PARAMETERFV, 6);
7370    if (n) {
7371       n[1].ui = sampler;
7372       n[2].e = pname;
7373       n[3].f = params[0];
7374       if (pname == GL_TEXTURE_BORDER_COLOR) {
7375          n[4].f = params[1];
7376          n[5].f = params[2];
7377          n[6].f = params[3];
7378       }
7379       else {
7380          n[4].f = n[5].f = n[6].f = 0.0F;
7381       }
7382    }
7383    if (ctx->ExecuteFlag) {
7384       CALL_SamplerParameterfv(ctx->Exec, (sampler, pname, params));
7385    }
7386 }
7387
7388 static void GLAPIENTRY
7389 save_SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
7390 {
7391    save_SamplerParameterfv(sampler, pname, &param);
7392 }
7393
7394 static void GLAPIENTRY
7395 save_SamplerParameterIiv(GLuint sampler, GLenum pname, const GLint *params)
7396 {
7397    Node *n;
7398    GET_CURRENT_CONTEXT(ctx);
7399    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7400    n = alloc_instruction(ctx, OPCODE_SAMPLER_PARAMETERIIV, 6);
7401    if (n) {
7402       n[1].ui = sampler;
7403       n[2].e = pname;
7404       n[3].i = params[0];
7405       if (pname == GL_TEXTURE_BORDER_COLOR) {
7406          n[4].i = params[1];
7407          n[5].i = params[2];
7408          n[6].i = params[3];
7409       }
7410       else {
7411          n[4].i = n[5].i = n[6].i = 0;
7412       }
7413    }
7414    if (ctx->ExecuteFlag) {
7415       CALL_SamplerParameterIiv(ctx->Exec, (sampler, pname, params));
7416    }
7417 }
7418
7419 static void GLAPIENTRY
7420 save_SamplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *params)
7421 {
7422    Node *n;
7423    GET_CURRENT_CONTEXT(ctx);
7424    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7425    n = alloc_instruction(ctx, OPCODE_SAMPLER_PARAMETERUIV, 6);
7426    if (n) {
7427       n[1].ui = sampler;
7428       n[2].e = pname;
7429       n[3].ui = params[0];
7430       if (pname == GL_TEXTURE_BORDER_COLOR) {
7431          n[4].ui = params[1];
7432          n[5].ui = params[2];
7433          n[6].ui = params[3];
7434       }
7435       else {
7436          n[4].ui = n[5].ui = n[6].ui = 0;
7437       }
7438    }
7439    if (ctx->ExecuteFlag) {
7440       CALL_SamplerParameterIuiv(ctx->Exec, (sampler, pname, params));
7441    }
7442 }
7443
7444 /* GL_ARB_geometry_shader4 */
7445 static void GLAPIENTRY
7446 save_ProgramParameteri(GLuint program, GLenum pname, GLint value)
7447 {
7448    Node *n;
7449    GET_CURRENT_CONTEXT(ctx);
7450    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7451    n = alloc_instruction(ctx, OPCODE_PROGRAM_PARAMETERI, 3);
7452    if (n) {
7453       n[1].ui = program;
7454       n[2].e = pname;
7455       n[3].i = value;
7456    }
7457    if (ctx->ExecuteFlag) {
7458       CALL_ProgramParameteriARB(ctx->Exec, (program, pname, value));
7459    }
7460 }
7461
7462 static void GLAPIENTRY
7463 save_FramebufferTexture(GLenum target, GLenum attachment,
7464                         GLuint texture, GLint level)
7465 {
7466    Node *n;
7467    GET_CURRENT_CONTEXT(ctx);
7468    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7469    n = alloc_instruction(ctx, OPCODE_FRAMEBUFFER_TEXTURE, 4);
7470    if (n) {
7471       n[1].e = target;
7472       n[2].e = attachment;
7473       n[3].ui = texture;
7474       n[4].i = level;
7475    }
7476    if (ctx->ExecuteFlag) {
7477       CALL_FramebufferTextureARB(ctx->Exec, (target, attachment, texture, level));
7478    }
7479 }
7480
7481 static void GLAPIENTRY
7482 save_FramebufferTextureFace(GLenum target, GLenum attachment,
7483                             GLuint texture, GLint level, GLenum face)
7484 {
7485    Node *n;
7486    GET_CURRENT_CONTEXT(ctx);
7487    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7488    n = alloc_instruction(ctx, OPCODE_FRAMEBUFFER_TEXTURE_FACE, 5);
7489    if (n) {
7490       n[1].e = target;
7491       n[2].e = attachment;
7492       n[3].ui = texture;
7493       n[4].i = level;
7494       n[5].e = face;
7495    }
7496    if (ctx->ExecuteFlag) {
7497       CALL_FramebufferTextureFaceARB(ctx->Exec, (target, attachment, texture,
7498                                                  level, face));
7499    }
7500 }
7501
7502
7503
7504 static void GLAPIENTRY
7505 save_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
7506 {
7507    Node *n;
7508    GET_CURRENT_CONTEXT(ctx);
7509    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7510    n = alloc_instruction(ctx, OPCODE_WAIT_SYNC, 4);
7511    if (n) {
7512       union uint64_pair p;
7513       p.uint64 = timeout;
7514       n[1].data = sync;
7515       n[2].e = flags;
7516       n[3].ui = p.uint32[0];
7517       n[4].ui = p.uint32[1];
7518    }
7519    if (ctx->ExecuteFlag) {
7520       CALL_WaitSync(ctx->Exec, (sync, flags, timeout));
7521    }
7522 }
7523
7524
7525 /** GL_NV_conditional_render */
7526 static void GLAPIENTRY
7527 save_BeginConditionalRender(GLuint queryId, GLenum mode)
7528 {
7529    GET_CURRENT_CONTEXT(ctx);
7530    Node *n;
7531    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7532    n = alloc_instruction(ctx, OPCODE_BEGIN_CONDITIONAL_RENDER, 2);
7533    if (n) {
7534       n[1].i = queryId;
7535       n[2].e = mode;
7536    }
7537    if (ctx->ExecuteFlag) {
7538       CALL_BeginConditionalRenderNV(ctx->Exec, (queryId, mode));
7539    }
7540 }
7541
7542 static void GLAPIENTRY
7543 save_EndConditionalRender(void)
7544 {
7545    GET_CURRENT_CONTEXT(ctx);
7546    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7547    alloc_instruction(ctx, OPCODE_END_CONDITIONAL_RENDER, 0);
7548    if (ctx->ExecuteFlag) {
7549       CALL_EndConditionalRenderNV(ctx->Exec, ());
7550    }
7551 }
7552
7553 static void GLAPIENTRY
7554 save_UniformBlockBinding(GLuint prog, GLuint index, GLuint binding)
7555 {
7556    GET_CURRENT_CONTEXT(ctx);
7557    Node *n;
7558    ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
7559    n = alloc_instruction(ctx, OPCODE_UNIFORM_BLOCK_BINDING, 3);
7560    if (n) {
7561       n[1].ui = prog;
7562       n[2].ui = index;
7563       n[3].ui = binding;
7564    }
7565    if (ctx->ExecuteFlag) {
7566       CALL_UniformBlockBinding(ctx->Exec, (prog, index, binding));
7567    }
7568 }
7569
7570
7571 /**
7572  * Save an error-generating command into display list.
7573  *
7574  * KW: Will appear in the list before the vertex buffer containing the
7575  * command that provoked the error.  I don't see this as a problem.
7576  */
7577 static void
7578 save_error(struct gl_context *ctx, GLenum error, const char *s)
7579 {
7580    Node *n;
7581    n = alloc_instruction(ctx, OPCODE_ERROR, 2);
7582    if (n) {
7583       n[1].e = error;
7584       n[2].data = (void *) s;
7585    }
7586 }
7587
7588
7589 /**
7590  * Compile an error into current display list.
7591  */
7592 void
7593 _mesa_compile_error(struct gl_context *ctx, GLenum error, const char *s)
7594 {
7595    if (ctx->CompileFlag)
7596       save_error(ctx, error, s);
7597    if (ctx->ExecuteFlag)
7598       _mesa_error(ctx, error, "%s", s);
7599 }
7600
7601
7602 /**
7603  * Test if ID names a display list.
7604  */
7605 static GLboolean
7606 islist(struct gl_context *ctx, GLuint list)
7607 {
7608    if (list > 0 && lookup_list(ctx, list)) {
7609       return GL_TRUE;
7610    }
7611    else {
7612       return GL_FALSE;
7613    }
7614 }
7615
7616
7617
7618 /**********************************************************************/
7619 /*                     Display list execution                         */
7620 /**********************************************************************/
7621
7622
7623 /*
7624  * Execute a display list.  Note that the ListBase offset must have already
7625  * been added before calling this function.  I.e. the list argument is
7626  * the absolute list number, not relative to ListBase.
7627  * \param list - display list number
7628  */
7629 static void
7630 execute_list(struct gl_context *ctx, GLuint list)
7631 {
7632    struct gl_display_list *dlist;
7633    Node *n;
7634    GLboolean done;
7635
7636    if (list == 0 || !islist(ctx, list))
7637       return;
7638
7639    if (ctx->ListState.CallDepth == MAX_LIST_NESTING) {
7640       /* raise an error? */
7641       return;
7642    }
7643
7644    dlist = lookup_list(ctx, list);
7645    if (!dlist)
7646       return;
7647
7648    ctx->ListState.CallDepth++;
7649
7650    if (ctx->Driver.BeginCallList)
7651       ctx->Driver.BeginCallList(ctx, dlist);
7652
7653    n = dlist->Head;
7654
7655    done = GL_FALSE;
7656    while (!done) {
7657       const OpCode opcode = n[0].opcode;
7658
7659       if (is_ext_opcode(opcode)) {
7660          n += ext_opcode_execute(ctx, n);
7661       }
7662       else {
7663          switch (opcode) {
7664          case OPCODE_ERROR:
7665             _mesa_error(ctx, n[1].e, "%s", (const char *) n[2].data);
7666             break;
7667          case OPCODE_ACCUM:
7668             CALL_Accum(ctx->Exec, (n[1].e, n[2].f));
7669             break;
7670          case OPCODE_ALPHA_FUNC:
7671             CALL_AlphaFunc(ctx->Exec, (n[1].e, n[2].f));
7672             break;
7673          case OPCODE_BIND_TEXTURE:
7674             CALL_BindTexture(ctx->Exec, (n[1].e, n[2].ui));
7675             break;
7676          case OPCODE_BITMAP:
7677             {
7678                const struct gl_pixelstore_attrib save = ctx->Unpack;
7679                ctx->Unpack = ctx->DefaultPacking;
7680                CALL_Bitmap(ctx->Exec, ((GLsizei) n[1].i, (GLsizei) n[2].i,
7681                                        n[3].f, n[4].f, n[5].f, n[6].f,
7682                                        (const GLubyte *) n[7].data));
7683                ctx->Unpack = save;      /* restore */
7684             }
7685             break;
7686          case OPCODE_BLEND_COLOR:
7687             CALL_BlendColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
7688             break;
7689          case OPCODE_BLEND_EQUATION:
7690             CALL_BlendEquation(ctx->Exec, (n[1].e));
7691             break;
7692          case OPCODE_BLEND_EQUATION_SEPARATE:
7693             CALL_BlendEquationSeparateEXT(ctx->Exec, (n[1].e, n[2].e));
7694             break;
7695          case OPCODE_BLEND_FUNC_SEPARATE:
7696             CALL_BlendFuncSeparateEXT(ctx->Exec,
7697                                       (n[1].e, n[2].e, n[3].e, n[4].e));
7698             break;
7699
7700          case OPCODE_BLEND_FUNC_I:
7701             /* GL_ARB_draw_buffers_blend */
7702             CALL_BlendFunciARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e));
7703             break;
7704          case OPCODE_BLEND_FUNC_SEPARATE_I:
7705             /* GL_ARB_draw_buffers_blend */
7706             CALL_BlendFuncSeparateiARB(ctx->Exec, (n[1].ui, n[2].e, n[3].e,
7707                                                    n[4].e, n[5].e));
7708             break;
7709          case OPCODE_BLEND_EQUATION_I:
7710             /* GL_ARB_draw_buffers_blend */
7711             CALL_BlendEquationiARB(ctx->Exec, (n[1].ui, n[2].e));
7712             break;
7713          case OPCODE_BLEND_EQUATION_SEPARATE_I:
7714             /* GL_ARB_draw_buffers_blend */
7715             CALL_BlendEquationSeparateiARB(ctx->Exec,
7716                                            (n[1].ui, n[2].e, n[3].e));
7717             break;
7718
7719          case OPCODE_CALL_LIST:
7720             /* Generated by glCallList(), don't add ListBase */
7721             if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
7722                execute_list(ctx, n[1].ui);
7723             }
7724             break;
7725          case OPCODE_CALL_LIST_OFFSET:
7726             /* Generated by glCallLists() so we must add ListBase */
7727             if (n[2].b) {
7728                /* user specified a bad data type at compile time */
7729                _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
7730             }
7731             else if (ctx->ListState.CallDepth < MAX_LIST_NESTING) {
7732                GLuint list = (GLuint) (ctx->List.ListBase + n[1].i);
7733                execute_list(ctx, list);
7734             }
7735             break;
7736          case OPCODE_CLEAR:
7737             CALL_Clear(ctx->Exec, (n[1].bf));
7738             break;
7739          case OPCODE_CLEAR_BUFFER_IV:
7740             {
7741                GLint value[4];
7742                value[0] = n[3].i;
7743                value[1] = n[4].i;
7744                value[2] = n[5].i;
7745                value[3] = n[6].i;
7746                CALL_ClearBufferiv(ctx->Exec, (n[1].e, n[2].i, value));
7747             }
7748             break;
7749          case OPCODE_CLEAR_BUFFER_UIV:
7750             {
7751                GLuint value[4];
7752                value[0] = n[3].ui;
7753                value[1] = n[4].ui;
7754                value[2] = n[5].ui;
7755                value[3] = n[6].ui;
7756                CALL_ClearBufferuiv(ctx->Exec, (n[1].e, n[2].i, value));
7757             }
7758             break;
7759          case OPCODE_CLEAR_BUFFER_FV:
7760             {
7761                GLfloat value[4];
7762                value[0] = n[3].f;
7763                value[1] = n[4].f;
7764                value[2] = n[5].f;
7765                value[3] = n[6].f;
7766                CALL_ClearBufferfv(ctx->Exec, (n[1].e, n[2].i, value));
7767             }
7768             break;
7769          case OPCODE_CLEAR_BUFFER_FI:
7770             CALL_ClearBufferfi(ctx->Exec, (n[1].e, n[2].i, n[3].f, n[4].i));
7771             break;
7772          case OPCODE_CLEAR_COLOR:
7773             CALL_ClearColor(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
7774             break;
7775          case OPCODE_CLEAR_ACCUM:
7776             CALL_ClearAccum(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
7777             break;
7778          case OPCODE_CLEAR_DEPTH:
7779             CALL_ClearDepth(ctx->Exec, ((GLclampd) n[1].f));
7780             break;
7781          case OPCODE_CLEAR_INDEX:
7782             CALL_ClearIndex(ctx->Exec, ((GLfloat) n[1].ui));
7783             break;
7784          case OPCODE_CLEAR_STENCIL:
7785             CALL_ClearStencil(ctx->Exec, (n[1].i));
7786             break;
7787          case OPCODE_CLIP_PLANE:
7788             {
7789                GLdouble eq[4];
7790                eq[0] = n[2].f;
7791                eq[1] = n[3].f;
7792                eq[2] = n[4].f;
7793                eq[3] = n[5].f;
7794                CALL_ClipPlane(ctx->Exec, (n[1].e, eq));
7795             }
7796             break;
7797          case OPCODE_COLOR_MASK:
7798             CALL_ColorMask(ctx->Exec, (n[1].b, n[2].b, n[3].b, n[4].b));
7799             break;
7800          case OPCODE_COLOR_MASK_INDEXED:
7801             CALL_ColorMaskIndexedEXT(ctx->Exec, (n[1].ui, n[2].b, n[3].b,
7802                                                  n[4].b, n[5].b));
7803             break;
7804          case OPCODE_COLOR_MATERIAL:
7805             CALL_ColorMaterial(ctx->Exec, (n[1].e, n[2].e));
7806             break;
7807          case OPCODE_COLOR_TABLE:
7808             {
7809                const struct gl_pixelstore_attrib save = ctx->Unpack;
7810                ctx->Unpack = ctx->DefaultPacking;
7811                CALL_ColorTable(ctx->Exec, (n[1].e, n[2].e, n[3].i, n[4].e,
7812                                            n[5].e, n[6].data));
7813                ctx->Unpack = save;      /* restore */
7814             }
7815             break;
7816          case OPCODE_COLOR_TABLE_PARAMETER_FV:
7817             {
7818                GLfloat params[4];
7819                params[0] = n[3].f;
7820                params[1] = n[4].f;
7821                params[2] = n[5].f;
7822                params[3] = n[6].f;
7823                CALL_ColorTableParameterfv(ctx->Exec,
7824                                           (n[1].e, n[2].e, params));
7825             }
7826             break;
7827          case OPCODE_COLOR_TABLE_PARAMETER_IV:
7828             {
7829                GLint params[4];
7830                params[0] = n[3].i;
7831                params[1] = n[4].i;
7832                params[2] = n[5].i;
7833                params[3] = n[6].i;
7834                CALL_ColorTableParameteriv(ctx->Exec,
7835                                           (n[1].e, n[2].e, params));
7836             }
7837             break;
7838          case OPCODE_COLOR_SUB_TABLE:
7839             {
7840                const struct gl_pixelstore_attrib save = ctx->Unpack;
7841                ctx->Unpack = ctx->DefaultPacking;
7842                CALL_ColorSubTable(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7843                                               n[4].e, n[5].e, n[6].data));
7844                ctx->Unpack = save;      /* restore */
7845             }
7846             break;
7847          case OPCODE_CONVOLUTION_FILTER_1D:
7848             {
7849                const struct gl_pixelstore_attrib save = ctx->Unpack;
7850                ctx->Unpack = ctx->DefaultPacking;
7851                CALL_ConvolutionFilter1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7852                                                     n[4].e, n[5].e,
7853                                                     n[6].data));
7854                ctx->Unpack = save;      /* restore */
7855             }
7856             break;
7857          case OPCODE_CONVOLUTION_FILTER_2D:
7858             {
7859                const struct gl_pixelstore_attrib save = ctx->Unpack;
7860                ctx->Unpack = ctx->DefaultPacking;
7861                CALL_ConvolutionFilter2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7862                                                     n[4].i, n[5].e, n[6].e,
7863                                                     n[7].data));
7864                ctx->Unpack = save;      /* restore */
7865             }
7866             break;
7867          case OPCODE_CONVOLUTION_PARAMETER_I:
7868             CALL_ConvolutionParameteri(ctx->Exec, (n[1].e, n[2].e, n[3].i));
7869             break;
7870          case OPCODE_CONVOLUTION_PARAMETER_IV:
7871             {
7872                GLint params[4];
7873                params[0] = n[3].i;
7874                params[1] = n[4].i;
7875                params[2] = n[5].i;
7876                params[3] = n[6].i;
7877                CALL_ConvolutionParameteriv(ctx->Exec,
7878                                            (n[1].e, n[2].e, params));
7879             }
7880             break;
7881          case OPCODE_CONVOLUTION_PARAMETER_F:
7882             CALL_ConvolutionParameterf(ctx->Exec, (n[1].e, n[2].e, n[3].f));
7883             break;
7884          case OPCODE_CONVOLUTION_PARAMETER_FV:
7885             {
7886                GLfloat params[4];
7887                params[0] = n[3].f;
7888                params[1] = n[4].f;
7889                params[2] = n[5].f;
7890                params[3] = n[6].f;
7891                CALL_ConvolutionParameterfv(ctx->Exec,
7892                                            (n[1].e, n[2].e, params));
7893             }
7894             break;
7895          case OPCODE_COPY_COLOR_SUB_TABLE:
7896             CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
7897                                                n[3].i, n[4].i, n[5].i));
7898             break;
7899          case OPCODE_COPY_COLOR_TABLE:
7900             CALL_CopyColorSubTable(ctx->Exec, (n[1].e, n[2].i,
7901                                                n[3].i, n[4].i, n[5].i));
7902             break;
7903          case OPCODE_COPY_PIXELS:
7904             CALL_CopyPixels(ctx->Exec, (n[1].i, n[2].i,
7905                                         (GLsizei) n[3].i, (GLsizei) n[4].i,
7906                                         n[5].e));
7907             break;
7908          case OPCODE_COPY_TEX_IMAGE1D:
7909             CALL_CopyTexImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
7910                                             n[5].i, n[6].i, n[7].i));
7911             break;
7912          case OPCODE_COPY_TEX_IMAGE2D:
7913             CALL_CopyTexImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].i,
7914                                             n[5].i, n[6].i, n[7].i, n[8].i));
7915             break;
7916          case OPCODE_COPY_TEX_SUB_IMAGE1D:
7917             CALL_CopyTexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7918                                                n[4].i, n[5].i, n[6].i));
7919             break;
7920          case OPCODE_COPY_TEX_SUB_IMAGE2D:
7921             CALL_CopyTexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7922                                                n[4].i, n[5].i, n[6].i, n[7].i,
7923                                                n[8].i));
7924             break;
7925          case OPCODE_COPY_TEX_SUB_IMAGE3D:
7926             CALL_CopyTexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
7927                                                n[4].i, n[5].i, n[6].i, n[7].i,
7928                                                n[8].i, n[9].i));
7929             break;
7930          case OPCODE_CULL_FACE:
7931             CALL_CullFace(ctx->Exec, (n[1].e));
7932             break;
7933          case OPCODE_DEPTH_FUNC:
7934             CALL_DepthFunc(ctx->Exec, (n[1].e));
7935             break;
7936          case OPCODE_DEPTH_MASK:
7937             CALL_DepthMask(ctx->Exec, (n[1].b));
7938             break;
7939          case OPCODE_DEPTH_RANGE:
7940             CALL_DepthRange(ctx->Exec,
7941                             ((GLclampd) n[1].f, (GLclampd) n[2].f));
7942             break;
7943          case OPCODE_DISABLE:
7944             CALL_Disable(ctx->Exec, (n[1].e));
7945             break;
7946          case OPCODE_DISABLE_INDEXED:
7947             CALL_DisableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
7948             break;
7949          case OPCODE_DRAW_BUFFER:
7950             CALL_DrawBuffer(ctx->Exec, (n[1].e));
7951             break;
7952          case OPCODE_DRAW_PIXELS:
7953             {
7954                const struct gl_pixelstore_attrib save = ctx->Unpack;
7955                ctx->Unpack = ctx->DefaultPacking;
7956                CALL_DrawPixels(ctx->Exec, (n[1].i, n[2].i, n[3].e, n[4].e,
7957                                            n[5].data));
7958                ctx->Unpack = save;      /* restore */
7959             }
7960             break;
7961          case OPCODE_ENABLE:
7962             CALL_Enable(ctx->Exec, (n[1].e));
7963             break;
7964          case OPCODE_ENABLE_INDEXED:
7965             CALL_EnableIndexedEXT(ctx->Exec, (n[1].ui, n[2].e));
7966             break;
7967          case OPCODE_EVALMESH1:
7968             CALL_EvalMesh1(ctx->Exec, (n[1].e, n[2].i, n[3].i));
7969             break;
7970          case OPCODE_EVALMESH2:
7971             CALL_EvalMesh2(ctx->Exec,
7972                            (n[1].e, n[2].i, n[3].i, n[4].i, n[5].i));
7973             break;
7974          case OPCODE_FOG:
7975             {
7976                GLfloat p[4];
7977                p[0] = n[2].f;
7978                p[1] = n[3].f;
7979                p[2] = n[4].f;
7980                p[3] = n[5].f;
7981                CALL_Fogfv(ctx->Exec, (n[1].e, p));
7982             }
7983             break;
7984          case OPCODE_FRONT_FACE:
7985             CALL_FrontFace(ctx->Exec, (n[1].e));
7986             break;
7987          case OPCODE_FRUSTUM:
7988             CALL_Frustum(ctx->Exec,
7989                          (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
7990             break;
7991          case OPCODE_HINT:
7992             CALL_Hint(ctx->Exec, (n[1].e, n[2].e));
7993             break;
7994          case OPCODE_HISTOGRAM:
7995             CALL_Histogram(ctx->Exec, (n[1].e, n[2].i, n[3].e, n[4].b));
7996             break;
7997          case OPCODE_INDEX_MASK:
7998             CALL_IndexMask(ctx->Exec, (n[1].ui));
7999             break;
8000          case OPCODE_INIT_NAMES:
8001             CALL_InitNames(ctx->Exec, ());
8002             break;
8003          case OPCODE_LIGHT:
8004             {
8005                GLfloat p[4];
8006                p[0] = n[3].f;
8007                p[1] = n[4].f;
8008                p[2] = n[5].f;
8009                p[3] = n[6].f;
8010                CALL_Lightfv(ctx->Exec, (n[1].e, n[2].e, p));
8011             }
8012             break;
8013          case OPCODE_LIGHT_MODEL:
8014             {
8015                GLfloat p[4];
8016                p[0] = n[2].f;
8017                p[1] = n[3].f;
8018                p[2] = n[4].f;
8019                p[3] = n[5].f;
8020                CALL_LightModelfv(ctx->Exec, (n[1].e, p));
8021             }
8022             break;
8023          case OPCODE_LINE_STIPPLE:
8024             CALL_LineStipple(ctx->Exec, (n[1].i, n[2].us));
8025             break;
8026          case OPCODE_LINE_WIDTH:
8027             CALL_LineWidth(ctx->Exec, (n[1].f));
8028             break;
8029          case OPCODE_LIST_BASE:
8030             CALL_ListBase(ctx->Exec, (n[1].ui));
8031             break;
8032          case OPCODE_LOAD_IDENTITY:
8033             CALL_LoadIdentity(ctx->Exec, ());
8034             break;
8035          case OPCODE_LOAD_MATRIX:
8036             if (sizeof(Node) == sizeof(GLfloat)) {
8037                CALL_LoadMatrixf(ctx->Exec, (&n[1].f));
8038             }
8039             else {
8040                GLfloat m[16];
8041                GLuint i;
8042                for (i = 0; i < 16; i++) {
8043                   m[i] = n[1 + i].f;
8044                }
8045                CALL_LoadMatrixf(ctx->Exec, (m));
8046             }
8047             break;
8048          case OPCODE_LOAD_NAME:
8049             CALL_LoadName(ctx->Exec, (n[1].ui));
8050             break;
8051          case OPCODE_LOGIC_OP:
8052             CALL_LogicOp(ctx->Exec, (n[1].e));
8053             break;
8054          case OPCODE_MAP1:
8055             {
8056                GLenum target = n[1].e;
8057                GLint ustride = _mesa_evaluator_components(target);
8058                GLint uorder = n[5].i;
8059                GLfloat u1 = n[2].f;
8060                GLfloat u2 = n[3].f;
8061                CALL_Map1f(ctx->Exec, (target, u1, u2, ustride, uorder,
8062                                       (GLfloat *) n[6].data));
8063             }
8064             break;
8065          case OPCODE_MAP2:
8066             {
8067                GLenum target = n[1].e;
8068                GLfloat u1 = n[2].f;
8069                GLfloat u2 = n[3].f;
8070                GLfloat v1 = n[4].f;
8071                GLfloat v2 = n[5].f;
8072                GLint ustride = n[6].i;
8073                GLint vstride = n[7].i;
8074                GLint uorder = n[8].i;
8075                GLint vorder = n[9].i;
8076                CALL_Map2f(ctx->Exec, (target, u1, u2, ustride, uorder,
8077                                       v1, v2, vstride, vorder,
8078                                       (GLfloat *) n[10].data));
8079             }
8080             break;
8081          case OPCODE_MAPGRID1:
8082             CALL_MapGrid1f(ctx->Exec, (n[1].i, n[2].f, n[3].f));
8083             break;
8084          case OPCODE_MAPGRID2:
8085             CALL_MapGrid2f(ctx->Exec,
8086                            (n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f));
8087             break;
8088          case OPCODE_MATRIX_MODE:
8089             CALL_MatrixMode(ctx->Exec, (n[1].e));
8090             break;
8091          case OPCODE_MIN_MAX:
8092             CALL_Minmax(ctx->Exec, (n[1].e, n[2].e, n[3].b));
8093             break;
8094          case OPCODE_MULT_MATRIX:
8095             if (sizeof(Node) == sizeof(GLfloat)) {
8096                CALL_MultMatrixf(ctx->Exec, (&n[1].f));
8097             }
8098             else {
8099                GLfloat m[16];
8100                GLuint i;
8101                for (i = 0; i < 16; i++) {
8102                   m[i] = n[1 + i].f;
8103                }
8104                CALL_MultMatrixf(ctx->Exec, (m));
8105             }
8106             break;
8107          case OPCODE_ORTHO:
8108             CALL_Ortho(ctx->Exec,
8109                        (n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f));
8110             break;
8111          case OPCODE_PASSTHROUGH:
8112             CALL_PassThrough(ctx->Exec, (n[1].f));
8113             break;
8114          case OPCODE_PIXEL_MAP:
8115             CALL_PixelMapfv(ctx->Exec,
8116                             (n[1].e, n[2].i, (GLfloat *) n[3].data));
8117             break;
8118          case OPCODE_PIXEL_TRANSFER:
8119             CALL_PixelTransferf(ctx->Exec, (n[1].e, n[2].f));
8120             break;
8121          case OPCODE_PIXEL_ZOOM:
8122             CALL_PixelZoom(ctx->Exec, (n[1].f, n[2].f));
8123             break;
8124          case OPCODE_POINT_SIZE:
8125             CALL_PointSize(ctx->Exec, (n[1].f));
8126             break;
8127          case OPCODE_POINT_PARAMETERS:
8128             {
8129                GLfloat params[3];
8130                params[0] = n[2].f;
8131                params[1] = n[3].f;
8132                params[2] = n[4].f;
8133                CALL_PointParameterfvEXT(ctx->Exec, (n[1].e, params));
8134             }
8135             break;
8136          case OPCODE_POLYGON_MODE:
8137             CALL_PolygonMode(ctx->Exec, (n[1].e, n[2].e));
8138             break;
8139          case OPCODE_POLYGON_STIPPLE:
8140             {
8141                const struct gl_pixelstore_attrib save = ctx->Unpack;
8142                ctx->Unpack = ctx->DefaultPacking;
8143                CALL_PolygonStipple(ctx->Exec, ((GLubyte *) n[1].data));
8144                ctx->Unpack = save;      /* restore */
8145             }
8146             break;
8147          case OPCODE_POLYGON_OFFSET:
8148             CALL_PolygonOffset(ctx->Exec, (n[1].f, n[2].f));
8149             break;
8150          case OPCODE_POP_ATTRIB:
8151             CALL_PopAttrib(ctx->Exec, ());
8152             break;
8153          case OPCODE_POP_MATRIX:
8154             CALL_PopMatrix(ctx->Exec, ());
8155             break;
8156          case OPCODE_POP_NAME:
8157             CALL_PopName(ctx->Exec, ());
8158             break;
8159          case OPCODE_PRIORITIZE_TEXTURE:
8160             CALL_PrioritizeTextures(ctx->Exec, (1, &n[1].ui, &n[2].f));
8161             break;
8162          case OPCODE_PUSH_ATTRIB:
8163             CALL_PushAttrib(ctx->Exec, (n[1].bf));
8164             break;
8165          case OPCODE_PUSH_MATRIX:
8166             CALL_PushMatrix(ctx->Exec, ());
8167             break;
8168          case OPCODE_PUSH_NAME:
8169             CALL_PushName(ctx->Exec, (n[1].ui));
8170             break;
8171          case OPCODE_RASTER_POS:
8172             CALL_RasterPos4f(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
8173             break;
8174          case OPCODE_READ_BUFFER:
8175             CALL_ReadBuffer(ctx->Exec, (n[1].e));
8176             break;
8177          case OPCODE_RESET_HISTOGRAM:
8178             CALL_ResetHistogram(ctx->Exec, (n[1].e));
8179             break;
8180          case OPCODE_RESET_MIN_MAX:
8181             CALL_ResetMinmax(ctx->Exec, (n[1].e));
8182             break;
8183          case OPCODE_ROTATE:
8184             CALL_Rotatef(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
8185             break;
8186          case OPCODE_SCALE:
8187             CALL_Scalef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
8188             break;
8189          case OPCODE_SCISSOR:
8190             CALL_Scissor(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
8191             break;
8192          case OPCODE_SHADE_MODEL:
8193             CALL_ShadeModel(ctx->Exec, (n[1].e));
8194             break;
8195          case OPCODE_PROVOKING_VERTEX:
8196             CALL_ProvokingVertexEXT(ctx->Exec, (n[1].e));
8197             break;
8198          case OPCODE_STENCIL_FUNC:
8199             CALL_StencilFunc(ctx->Exec, (n[1].e, n[2].i, n[3].ui));
8200             break;
8201          case OPCODE_STENCIL_MASK:
8202             CALL_StencilMask(ctx->Exec, (n[1].ui));
8203             break;
8204          case OPCODE_STENCIL_OP:
8205             CALL_StencilOp(ctx->Exec, (n[1].e, n[2].e, n[3].e));
8206             break;
8207          case OPCODE_STENCIL_FUNC_SEPARATE:
8208             CALL_StencilFuncSeparate(ctx->Exec,
8209                                      (n[1].e, n[2].e, n[3].i, n[4].ui));
8210             break;
8211          case OPCODE_STENCIL_MASK_SEPARATE:
8212             CALL_StencilMaskSeparate(ctx->Exec, (n[1].e, n[2].ui));
8213             break;
8214          case OPCODE_STENCIL_OP_SEPARATE:
8215             CALL_StencilOpSeparate(ctx->Exec,
8216                                    (n[1].e, n[2].e, n[3].e, n[4].e));
8217             break;
8218          case OPCODE_TEXENV:
8219             {
8220                GLfloat params[4];
8221                params[0] = n[3].f;
8222                params[1] = n[4].f;
8223                params[2] = n[5].f;
8224                params[3] = n[6].f;
8225                CALL_TexEnvfv(ctx->Exec, (n[1].e, n[2].e, params));
8226             }
8227             break;
8228          case OPCODE_TEXGEN:
8229             {
8230                GLfloat params[4];
8231                params[0] = n[3].f;
8232                params[1] = n[4].f;
8233                params[2] = n[5].f;
8234                params[3] = n[6].f;
8235                CALL_TexGenfv(ctx->Exec, (n[1].e, n[2].e, params));
8236             }
8237             break;
8238          case OPCODE_TEXPARAMETER:
8239             {
8240                GLfloat params[4];
8241                params[0] = n[3].f;
8242                params[1] = n[4].f;
8243                params[2] = n[5].f;
8244                params[3] = n[6].f;
8245                CALL_TexParameterfv(ctx->Exec, (n[1].e, n[2].e, params));
8246             }
8247             break;
8248          case OPCODE_TEX_IMAGE1D:
8249             {
8250                const struct gl_pixelstore_attrib save = ctx->Unpack;
8251                ctx->Unpack = ctx->DefaultPacking;
8252                CALL_TexImage1D(ctx->Exec, (n[1].e,      /* target */
8253                                            n[2].i,      /* level */
8254                                            n[3].i,      /* components */
8255                                            n[4].i,      /* width */
8256                                            n[5].e,      /* border */
8257                                            n[6].e,      /* format */
8258                                            n[7].e,      /* type */
8259                                            n[8].data));
8260                ctx->Unpack = save;      /* restore */
8261             }
8262             break;
8263          case OPCODE_TEX_IMAGE2D:
8264             {
8265                const struct gl_pixelstore_attrib save = ctx->Unpack;
8266                ctx->Unpack = ctx->DefaultPacking;
8267                CALL_TexImage2D(ctx->Exec, (n[1].e,      /* target */
8268                                            n[2].i,      /* level */
8269                                            n[3].i,      /* components */
8270                                            n[4].i,      /* width */
8271                                            n[5].i,      /* height */
8272                                            n[6].e,      /* border */
8273                                            n[7].e,      /* format */
8274                                            n[8].e,      /* type */
8275                                            n[9].data));
8276                ctx->Unpack = save;      /* restore */
8277             }
8278             break;
8279          case OPCODE_TEX_IMAGE3D:
8280             {
8281                const struct gl_pixelstore_attrib save = ctx->Unpack;
8282                ctx->Unpack = ctx->DefaultPacking;
8283                CALL_TexImage3D(ctx->Exec, (n[1].e,      /* target */
8284                                            n[2].i,      /* level */
8285                                            n[3].i,      /* components */
8286                                            n[4].i,      /* width */
8287                                            n[5].i,      /* height */
8288                                            n[6].i,      /* depth  */
8289                                            n[7].e,      /* border */
8290                                            n[8].e,      /* format */
8291                                            n[9].e,      /* type */
8292                                            n[10].data));
8293                ctx->Unpack = save;      /* restore */
8294             }
8295             break;
8296          case OPCODE_TEX_SUB_IMAGE1D:
8297             {
8298                const struct gl_pixelstore_attrib save = ctx->Unpack;
8299                ctx->Unpack = ctx->DefaultPacking;
8300                CALL_TexSubImage1D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
8301                                               n[4].i, n[5].e,
8302                                               n[6].e, n[7].data));
8303                ctx->Unpack = save;      /* restore */
8304             }
8305             break;
8306          case OPCODE_TEX_SUB_IMAGE2D:
8307             {
8308                const struct gl_pixelstore_attrib save = ctx->Unpack;
8309                ctx->Unpack = ctx->DefaultPacking;
8310                CALL_TexSubImage2D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
8311                                               n[4].i, n[5].e,
8312                                               n[6].i, n[7].e, n[8].e,
8313                                               n[9].data));
8314                ctx->Unpack = save;      /* restore */
8315             }
8316             break;
8317          case OPCODE_TEX_SUB_IMAGE3D:
8318             {
8319                const struct gl_pixelstore_attrib save = ctx->Unpack;
8320                ctx->Unpack = ctx->DefaultPacking;
8321                CALL_TexSubImage3D(ctx->Exec, (n[1].e, n[2].i, n[3].i,
8322                                               n[4].i, n[5].i, n[6].i, n[7].i,
8323                                               n[8].i, n[9].e, n[10].e,
8324                                               n[11].data));
8325                ctx->Unpack = save;      /* restore */
8326             }
8327             break;
8328          case OPCODE_TRANSLATE:
8329             CALL_Translatef(ctx->Exec, (n[1].f, n[2].f, n[3].f));
8330             break;
8331          case OPCODE_VIEWPORT:
8332             CALL_Viewport(ctx->Exec, (n[1].i, n[2].i,
8333                                       (GLsizei) n[3].i, (GLsizei) n[4].i));
8334             break;
8335          case OPCODE_WINDOW_POS:
8336             CALL_WindowPos4fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
8337             break;
8338          case OPCODE_ACTIVE_TEXTURE:   /* GL_ARB_multitexture */
8339             CALL_ActiveTextureARB(ctx->Exec, (n[1].e));
8340             break;
8341          case OPCODE_COMPRESSED_TEX_IMAGE_1D:  /* GL_ARB_texture_compression */
8342             CALL_CompressedTexImage1DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
8343                                                      n[4].i, n[5].i, n[6].i,
8344                                                      n[7].data));
8345             break;
8346          case OPCODE_COMPRESSED_TEX_IMAGE_2D:  /* GL_ARB_texture_compression */
8347             CALL_CompressedTexImage2DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
8348                                                      n[4].i, n[5].i, n[6].i,
8349                                                      n[7].i, n[8].data));
8350             break;
8351          case OPCODE_COMPRESSED_TEX_IMAGE_3D:  /* GL_ARB_texture_compression */
8352             CALL_CompressedTexImage3DARB(ctx->Exec, (n[1].e, n[2].i, n[3].e,
8353                                                      n[4].i, n[5].i, n[6].i,
8354                                                      n[7].i, n[8].i,
8355                                                      n[9].data));
8356             break;
8357          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D:      /* GL_ARB_texture_compress */
8358             CALL_CompressedTexSubImage1DARB(ctx->Exec,
8359                                             (n[1].e, n[2].i, n[3].i, n[4].i,
8360                                              n[5].e, n[6].i, n[7].data));
8361             break;
8362          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D:      /* GL_ARB_texture_compress */
8363             CALL_CompressedTexSubImage2DARB(ctx->Exec,
8364                                             (n[1].e, n[2].i, n[3].i, n[4].i,
8365                                              n[5].i, n[6].i, n[7].e, n[8].i,
8366                                              n[9].data));
8367             break;
8368          case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D:      /* GL_ARB_texture_compress */
8369             CALL_CompressedTexSubImage3DARB(ctx->Exec,
8370                                             (n[1].e, n[2].i, n[3].i, n[4].i,
8371                                              n[5].i, n[6].i, n[7].i, n[8].i,
8372                                              n[9].e, n[10].i, n[11].data));
8373             break;
8374          case OPCODE_SAMPLE_COVERAGE:  /* GL_ARB_multisample */
8375             CALL_SampleCoverageARB(ctx->Exec, (n[1].f, n[2].b));
8376             break;
8377          case OPCODE_WINDOW_POS_ARB:   /* GL_ARB_window_pos */
8378             CALL_WindowPos3fMESA(ctx->Exec, (n[1].f, n[2].f, n[3].f));
8379             break;
8380          case OPCODE_BIND_PROGRAM_NV:  /* GL_NV_vertex_program */
8381             CALL_BindProgramNV(ctx->Exec, (n[1].e, n[2].ui));
8382             break;
8383          case OPCODE_EXECUTE_PROGRAM_NV:
8384             {
8385                GLfloat v[4];
8386                v[0] = n[3].f;
8387                v[1] = n[4].f;
8388                v[2] = n[5].f;
8389                v[3] = n[6].f;
8390                CALL_ExecuteProgramNV(ctx->Exec, (n[1].e, n[2].ui, v));
8391             }
8392             break;
8393          case OPCODE_REQUEST_RESIDENT_PROGRAMS_NV:
8394             CALL_RequestResidentProgramsNV(ctx->Exec, (n[1].ui,
8395                                                        (GLuint *) n[2].data));
8396             break;
8397          case OPCODE_LOAD_PROGRAM_NV:
8398             CALL_LoadProgramNV(ctx->Exec, (n[1].e, n[2].ui, n[3].i,
8399                                            (const GLubyte *) n[4].data));
8400             break;
8401          case OPCODE_TRACK_MATRIX_NV:
8402             CALL_TrackMatrixNV(ctx->Exec, (n[1].e, n[2].ui, n[3].e, n[4].e));
8403             break;
8404          case OPCODE_PROGRAM_LOCAL_PARAMETER_ARB:
8405             CALL_ProgramLocalParameter4fARB(ctx->Exec,
8406                                             (n[1].e, n[2].ui, n[3].f, n[4].f,
8407                                              n[5].f, n[6].f));
8408             break;
8409          case OPCODE_PROGRAM_NAMED_PARAMETER_NV:
8410             CALL_ProgramNamedParameter4fNV(ctx->Exec, (n[1].ui, n[2].i,
8411                                                        (const GLubyte *) n[3].
8412                                                        data, n[4].f, n[5].f,
8413                                                        n[6].f, n[7].f));
8414             break;
8415          case OPCODE_ACTIVE_STENCIL_FACE_EXT:
8416             CALL_ActiveStencilFaceEXT(ctx->Exec, (n[1].e));
8417             break;
8418          case OPCODE_DEPTH_BOUNDS_EXT:
8419             CALL_DepthBoundsEXT(ctx->Exec, (n[1].f, n[2].f));
8420             break;
8421          case OPCODE_PROGRAM_STRING_ARB:
8422             CALL_ProgramStringARB(ctx->Exec,
8423                                   (n[1].e, n[2].e, n[3].i, n[4].data));
8424             break;
8425          case OPCODE_PROGRAM_ENV_PARAMETER_ARB:
8426             CALL_ProgramEnvParameter4fARB(ctx->Exec, (n[1].e, n[2].ui, n[3].f,
8427                                                       n[4].f, n[5].f,
8428                                                       n[6].f));
8429             break;
8430          case OPCODE_BEGIN_QUERY_ARB:
8431             CALL_BeginQueryARB(ctx->Exec, (n[1].e, n[2].ui));
8432             break;
8433          case OPCODE_END_QUERY_ARB:
8434             CALL_EndQueryARB(ctx->Exec, (n[1].e));
8435             break;
8436          case OPCODE_QUERY_COUNTER:
8437             CALL_QueryCounter(ctx->Exec, (n[1].ui, n[2].e));
8438             break;
8439          case OPCODE_BEGIN_QUERY_INDEXED:
8440             CALL_BeginQueryIndexed(ctx->Exec, (n[1].e, n[2].ui, n[3].ui));
8441             break;
8442          case OPCODE_END_QUERY_INDEXED:
8443             CALL_EndQueryIndexed(ctx->Exec, (n[1].e, n[2].ui));
8444             break;
8445          case OPCODE_DRAW_BUFFERS_ARB:
8446             {
8447                GLenum buffers[MAX_DRAW_BUFFERS];
8448                GLint i, count = MIN2(n[1].i, MAX_DRAW_BUFFERS);
8449                for (i = 0; i < count; i++)
8450                   buffers[i] = n[2 + i].e;
8451                CALL_DrawBuffersARB(ctx->Exec, (n[1].i, buffers));
8452             }
8453             break;
8454          case OPCODE_BLIT_FRAMEBUFFER:
8455             CALL_BlitFramebufferEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i,
8456                                                 n[5].i, n[6].i, n[7].i, n[8].i,
8457                                                 n[9].i, n[10].e));
8458             break;
8459          case OPCODE_USE_PROGRAM:
8460             CALL_UseProgramObjectARB(ctx->Exec, (n[1].ui));
8461             break;
8462          case OPCODE_USE_SHADER_PROGRAM_EXT:
8463             CALL_UseShaderProgramEXT(ctx->Exec, (n[1].ui, n[2].ui));
8464             break;
8465          case OPCODE_ACTIVE_PROGRAM_EXT:
8466             CALL_ActiveProgramEXT(ctx->Exec, (n[1].ui));
8467             break;
8468          case OPCODE_UNIFORM_1F:
8469             CALL_Uniform1fARB(ctx->Exec, (n[1].i, n[2].f));
8470             break;
8471          case OPCODE_UNIFORM_2F:
8472             CALL_Uniform2fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f));
8473             break;
8474          case OPCODE_UNIFORM_3F:
8475             CALL_Uniform3fARB(ctx->Exec, (n[1].i, n[2].f, n[3].f, n[4].f));
8476             break;
8477          case OPCODE_UNIFORM_4F:
8478             CALL_Uniform4fARB(ctx->Exec,
8479                               (n[1].i, n[2].f, n[3].f, n[4].f, n[5].f));
8480             break;
8481          case OPCODE_UNIFORM_1FV:
8482             CALL_Uniform1fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8483             break;
8484          case OPCODE_UNIFORM_2FV:
8485             CALL_Uniform2fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8486             break;
8487          case OPCODE_UNIFORM_3FV:
8488             CALL_Uniform3fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8489             break;
8490          case OPCODE_UNIFORM_4FV:
8491             CALL_Uniform4fvARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8492             break;
8493          case OPCODE_UNIFORM_1I:
8494             CALL_Uniform1iARB(ctx->Exec, (n[1].i, n[2].i));
8495             break;
8496          case OPCODE_UNIFORM_2I:
8497             CALL_Uniform2iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));
8498             break;
8499          case OPCODE_UNIFORM_3I:
8500             CALL_Uniform3iARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
8501             break;
8502          case OPCODE_UNIFORM_4I:
8503             CALL_Uniform4iARB(ctx->Exec,
8504                               (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
8505             break;
8506          case OPCODE_UNIFORM_1IV:
8507             CALL_Uniform1ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8508             break;
8509          case OPCODE_UNIFORM_2IV:
8510             CALL_Uniform2ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8511             break;
8512          case OPCODE_UNIFORM_3IV:
8513             CALL_Uniform3ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8514             break;
8515          case OPCODE_UNIFORM_4IV:
8516             CALL_Uniform4ivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));
8517             break;
8518          case OPCODE_UNIFORM_1UI:
8519             /*CALL_Uniform1uiARB(ctx->Exec, (n[1].i, n[2].i));*/
8520             break;
8521          case OPCODE_UNIFORM_2UI:
8522             /*CALL_Uniform2uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i));*/
8523             break;
8524          case OPCODE_UNIFORM_3UI:
8525             /*CALL_Uniform3uiARB(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));*/
8526             break;
8527          case OPCODE_UNIFORM_4UI:
8528             /*CALL_Uniform4uiARB(ctx->Exec,
8529                               (n[1].i, n[2].i, n[3].i, n[4].i, n[5].i));
8530             */
8531             break;
8532          case OPCODE_UNIFORM_1UIV:
8533             /*CALL_Uniform1uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
8534             break;
8535          case OPCODE_UNIFORM_2UIV:
8536             /*CALL_Uniform2uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
8537             break;
8538          case OPCODE_UNIFORM_3UIV:
8539             /*CALL_Uniform3uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
8540             break;
8541          case OPCODE_UNIFORM_4UIV:
8542             /*CALL_Uniform4uivARB(ctx->Exec, (n[1].i, n[2].i, n[3].data));*/
8543             break;
8544          case OPCODE_UNIFORM_MATRIX22:
8545             CALL_UniformMatrix2fvARB(ctx->Exec,
8546                                      (n[1].i, n[2].i, n[3].b, n[4].data));
8547             break;
8548          case OPCODE_UNIFORM_MATRIX33:
8549             CALL_UniformMatrix3fvARB(ctx->Exec,
8550                                      (n[1].i, n[2].i, n[3].b, n[4].data));
8551             break;
8552          case OPCODE_UNIFORM_MATRIX44:
8553             CALL_UniformMatrix4fvARB(ctx->Exec,
8554                                      (n[1].i, n[2].i, n[3].b, n[4].data));
8555             break;
8556          case OPCODE_UNIFORM_MATRIX23:
8557             CALL_UniformMatrix2x3fv(ctx->Exec,
8558                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8559             break;
8560          case OPCODE_UNIFORM_MATRIX32:
8561             CALL_UniformMatrix3x2fv(ctx->Exec,
8562                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8563             break;
8564          case OPCODE_UNIFORM_MATRIX24:
8565             CALL_UniformMatrix2x4fv(ctx->Exec,
8566                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8567             break;
8568          case OPCODE_UNIFORM_MATRIX42:
8569             CALL_UniformMatrix4x2fv(ctx->Exec,
8570                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8571             break;
8572          case OPCODE_UNIFORM_MATRIX34:
8573             CALL_UniformMatrix3x4fv(ctx->Exec,
8574                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8575             break;
8576          case OPCODE_UNIFORM_MATRIX43:
8577             CALL_UniformMatrix4x3fv(ctx->Exec,
8578                                     (n[1].i, n[2].i, n[3].b, n[4].data));
8579             break;
8580
8581          case OPCODE_CLAMP_COLOR:
8582             CALL_ClampColorARB(ctx->Exec, (n[1].e, n[2].e));
8583             break;
8584
8585          case OPCODE_TEX_BUMP_PARAMETER_ATI:
8586             {
8587                GLfloat values[4];
8588                GLuint i, pname = n[1].ui;
8589
8590                for (i = 0; i < 4; i++)
8591                   values[i] = n[1 + i].f;
8592                CALL_TexBumpParameterfvATI(ctx->Exec, (pname, values));
8593             }
8594             break;
8595 #if FEATURE_ATI_fragment_shader
8596          case OPCODE_BIND_FRAGMENT_SHADER_ATI:
8597             CALL_BindFragmentShaderATI(ctx->Exec, (n[1].i));
8598             break;
8599          case OPCODE_SET_FRAGMENT_SHADER_CONSTANTS_ATI:
8600             {
8601                GLfloat values[4];
8602                GLuint i, dst = n[1].ui;
8603
8604                for (i = 0; i < 4; i++)
8605                   values[i] = n[1 + i].f;
8606                CALL_SetFragmentShaderConstantATI(ctx->Exec, (dst, values));
8607             }
8608             break;
8609 #endif
8610          case OPCODE_ATTR_1F_NV:
8611             CALL_VertexAttrib1fNV(ctx->Exec, (n[1].e, n[2].f));
8612             break;
8613          case OPCODE_ATTR_2F_NV:
8614             /* Really shouldn't have to do this - the Node structure
8615              * is convenient, but it would be better to store the data
8616              * packed appropriately so that it can be sent directly
8617              * on.  With x86_64 becoming common, this will start to
8618              * matter more.
8619              */
8620             if (sizeof(Node) == sizeof(GLfloat))
8621                CALL_VertexAttrib2fvNV(ctx->Exec, (n[1].e, &n[2].f));
8622             else
8623                CALL_VertexAttrib2fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f));
8624             break;
8625          case OPCODE_ATTR_3F_NV:
8626             if (sizeof(Node) == sizeof(GLfloat))
8627                CALL_VertexAttrib3fvNV(ctx->Exec, (n[1].e, &n[2].f));
8628             else
8629                CALL_VertexAttrib3fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
8630                                                  n[4].f));
8631             break;
8632          case OPCODE_ATTR_4F_NV:
8633             if (sizeof(Node) == sizeof(GLfloat))
8634                CALL_VertexAttrib4fvNV(ctx->Exec, (n[1].e, &n[2].f));
8635             else
8636                CALL_VertexAttrib4fNV(ctx->Exec, (n[1].e, n[2].f, n[3].f,
8637                                                  n[4].f, n[5].f));
8638             break;
8639          case OPCODE_ATTR_1F_ARB:
8640             CALL_VertexAttrib1fARB(ctx->Exec, (n[1].e, n[2].f));
8641             break;
8642          case OPCODE_ATTR_2F_ARB:
8643             /* Really shouldn't have to do this - the Node structure
8644              * is convenient, but it would be better to store the data
8645              * packed appropriately so that it can be sent directly
8646              * on.  With x86_64 becoming common, this will start to
8647              * matter more.
8648              */
8649             if (sizeof(Node) == sizeof(GLfloat))
8650                CALL_VertexAttrib2fvARB(ctx->Exec, (n[1].e, &n[2].f));
8651             else
8652                CALL_VertexAttrib2fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f));
8653             break;
8654          case OPCODE_ATTR_3F_ARB:
8655             if (sizeof(Node) == sizeof(GLfloat))
8656                CALL_VertexAttrib3fvARB(ctx->Exec, (n[1].e, &n[2].f));
8657             else
8658                CALL_VertexAttrib3fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
8659                                                   n[4].f));
8660             break;
8661          case OPCODE_ATTR_4F_ARB:
8662             if (sizeof(Node) == sizeof(GLfloat))
8663                CALL_VertexAttrib4fvARB(ctx->Exec, (n[1].e, &n[2].f));
8664             else
8665                CALL_VertexAttrib4fARB(ctx->Exec, (n[1].e, n[2].f, n[3].f,
8666                                                   n[4].f, n[5].f));
8667             break;
8668          case OPCODE_MATERIAL:
8669             if (sizeof(Node) == sizeof(GLfloat))
8670                CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, &n[3].f));
8671             else {
8672                GLfloat f[4];
8673                f[0] = n[3].f;
8674                f[1] = n[4].f;
8675                f[2] = n[5].f;
8676                f[3] = n[6].f;
8677                CALL_Materialfv(ctx->Exec, (n[1].e, n[2].e, f));
8678             }
8679             break;
8680          case OPCODE_BEGIN:
8681             CALL_Begin(ctx->Exec, (n[1].e));
8682             break;
8683          case OPCODE_END:
8684             CALL_End(ctx->Exec, ());
8685             break;
8686          case OPCODE_RECTF:
8687             CALL_Rectf(ctx->Exec, (n[1].f, n[2].f, n[3].f, n[4].f));
8688             break;
8689          case OPCODE_EVAL_C1:
8690             CALL_EvalCoord1f(ctx->Exec, (n[1].f));
8691             break;
8692          case OPCODE_EVAL_C2:
8693             CALL_EvalCoord2f(ctx->Exec, (n[1].f, n[2].f));
8694             break;
8695          case OPCODE_EVAL_P1:
8696             CALL_EvalPoint1(ctx->Exec, (n[1].i));
8697             break;
8698          case OPCODE_EVAL_P2:
8699             CALL_EvalPoint2(ctx->Exec, (n[1].i, n[2].i));
8700             break;
8701
8702          /* GL_EXT_texture_integer */
8703          case OPCODE_CLEARCOLOR_I:
8704             CALL_ClearColorIiEXT(ctx->Exec, (n[1].i, n[2].i, n[3].i, n[4].i));
8705             break;
8706          case OPCODE_CLEARCOLOR_UI:
8707             CALL_ClearColorIuiEXT(ctx->Exec,
8708                                   (n[1].ui, n[2].ui, n[3].ui, n[4].ui));
8709             break;
8710          case OPCODE_TEXPARAMETER_I:
8711             {
8712                GLint params[4];
8713                params[0] = n[3].i;
8714                params[1] = n[4].i;
8715                params[2] = n[5].i;
8716                params[3] = n[6].i;
8717                CALL_TexParameterIivEXT(ctx->Exec, (n[1].e, n[2].e, params));
8718             }
8719             break;
8720          case OPCODE_TEXPARAMETER_UI:
8721             {
8722                GLuint params[4];
8723                params[0] = n[3].ui;
8724                params[1] = n[4].ui;
8725                params[2] = n[5].ui;
8726                params[3] = n[6].ui;
8727                CALL_TexParameterIuivEXT(ctx->Exec, (n[1].e, n[2].e, params));
8728             }
8729             break;
8730
8731          case OPCODE_VERTEX_ATTRIB_DIVISOR:
8732             /* GL_ARB_instanced_arrays */
8733             CALL_VertexAttribDivisorARB(ctx->Exec, (n[1].ui, n[2].ui));
8734             break;
8735
8736          case OPCODE_TEXTURE_BARRIER_NV:
8737             CALL_TextureBarrierNV(ctx->Exec, ());
8738             break;
8739
8740          /* GL_EXT/ARB_transform_feedback */
8741          case OPCODE_BEGIN_TRANSFORM_FEEDBACK:
8742             CALL_BeginTransformFeedbackEXT(ctx->Exec, (n[1].e));
8743             break;
8744          case OPCODE_END_TRANSFORM_FEEDBACK:
8745             CALL_EndTransformFeedbackEXT(ctx->Exec, ());
8746             break;
8747          case OPCODE_BIND_TRANSFORM_FEEDBACK:
8748             CALL_BindTransformFeedback(ctx->Exec, (n[1].e, n[2].ui));
8749             break;
8750          case OPCODE_PAUSE_TRANSFORM_FEEDBACK:
8751             CALL_PauseTransformFeedback(ctx->Exec, ());
8752             break;
8753          case OPCODE_RESUME_TRANSFORM_FEEDBACK:
8754             CALL_ResumeTransformFeedback(ctx->Exec, ());
8755             break;
8756          case OPCODE_DRAW_TRANSFORM_FEEDBACK:
8757             CALL_DrawTransformFeedback(ctx->Exec, (n[1].e, n[2].ui));
8758             break;
8759          case OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM:
8760             CALL_DrawTransformFeedbackStream(ctx->Exec,
8761                                              (n[1].e, n[2].ui, n[3].ui));
8762             break;
8763          case OPCODE_DRAW_TRANSFORM_FEEDBACK_INSTANCED:
8764             CALL_DrawTransformFeedbackInstanced(ctx->Exec,
8765                                                 (n[1].e, n[2].ui, n[3].si));
8766             break;
8767          case OPCODE_DRAW_TRANSFORM_FEEDBACK_STREAM_INSTANCED:
8768             CALL_DrawTransformFeedbackStreamInstanced(ctx->Exec,
8769                                        (n[1].e, n[2].ui, n[3].ui, n[4].si));
8770             break;
8771
8772
8773          case OPCODE_BIND_SAMPLER:
8774             CALL_BindSampler(ctx->Exec, (n[1].ui, n[2].ui));
8775             break;
8776          case OPCODE_SAMPLER_PARAMETERIV:
8777             {
8778                GLint params[4];
8779                params[0] = n[3].i;
8780                params[1] = n[4].i;
8781                params[2] = n[5].i;
8782                params[3] = n[6].i;
8783                CALL_SamplerParameteriv(ctx->Exec, (n[1].ui, n[2].e, params));
8784             }
8785             break;
8786          case OPCODE_SAMPLER_PARAMETERFV:
8787             {
8788                GLfloat params[4];
8789                params[0] = n[3].f;
8790                params[1] = n[4].f;
8791                params[2] = n[5].f;
8792                params[3] = n[6].f;
8793                CALL_SamplerParameterfv(ctx->Exec, (n[1].ui, n[2].e, params));
8794             }
8795             break;
8796          case OPCODE_SAMPLER_PARAMETERIIV:
8797             {
8798                GLint params[4];
8799                params[0] = n[3].i;
8800                params[1] = n[4].i;
8801                params[2] = n[5].i;
8802                params[3] = n[6].i;
8803                CALL_SamplerParameterIiv(ctx->Exec, (n[1].ui, n[2].e, params));
8804             }
8805             break;
8806          case OPCODE_SAMPLER_PARAMETERUIV:
8807             {
8808                GLuint params[4];
8809                params[0] = n[3].ui;
8810                params[1] = n[4].ui;
8811                params[2] = n[5].ui;
8812                params[3] = n[6].ui;
8813                CALL_SamplerParameterIuiv(ctx->Exec, (n[1].ui, n[2].e, params));
8814             }
8815             break;
8816
8817          /* GL_ARB_geometry_shader4 */
8818          case OPCODE_PROGRAM_PARAMETERI:
8819             CALL_ProgramParameteriARB(ctx->Exec, (n[1].ui, n[2].e, n[3].i));
8820             break;
8821          case OPCODE_FRAMEBUFFER_TEXTURE:
8822             CALL_FramebufferTextureARB(ctx->Exec, (n[1].e, n[2].e,
8823                                                    n[3].ui, n[4].i));
8824             break;
8825          case OPCODE_FRAMEBUFFER_TEXTURE_FACE:
8826             CALL_FramebufferTextureFaceARB(ctx->Exec, (n[1].e, n[2].e,
8827                                                        n[3].ui, n[4].i, n[5].e));
8828             break;
8829
8830          /* GL_ARB_sync */
8831          case OPCODE_WAIT_SYNC:
8832             {
8833                union uint64_pair p;
8834                p.uint32[0] = n[3].ui;
8835                p.uint32[1] = n[4].ui;
8836                CALL_WaitSync(ctx->Exec, (n[1].data, n[2].bf, p.uint64));
8837             }
8838             break;
8839
8840          /* GL_NV_conditional_render */
8841          case OPCODE_BEGIN_CONDITIONAL_RENDER:
8842             CALL_BeginConditionalRenderNV(ctx->Exec, (n[1].i, n[2].e));
8843             break;
8844          case OPCODE_END_CONDITIONAL_RENDER:
8845             CALL_EndConditionalRenderNV(ctx->Exec, ());
8846             break;
8847
8848          case OPCODE_UNIFORM_BLOCK_BINDING:
8849             CALL_UniformBlockBinding(ctx->Exec, (n[1].ui, n[2].ui, n[3].ui));
8850             break;
8851
8852          case OPCODE_CONTINUE:
8853             n = (Node *) n[1].next;
8854             break;
8855          case OPCODE_END_OF_LIST:
8856             done = GL_TRUE;
8857             break;
8858          default:
8859             {
8860                char msg[1000];
8861                _mesa_snprintf(msg, sizeof(msg), "Error in execute_list: opcode=%d",
8862                              (int) opcode);
8863                _mesa_problem(ctx, "%s", msg);
8864             }
8865             done = GL_TRUE;
8866          }
8867
8868          /* increment n to point to next compiled command */
8869          if (opcode != OPCODE_CONTINUE) {
8870             n += InstSize[opcode];
8871          }
8872       }
8873    }
8874
8875    if (ctx->Driver.EndCallList)
8876       ctx->Driver.EndCallList(ctx);
8877
8878    ctx->ListState.CallDepth--;
8879 }
8880
8881
8882
8883 /**********************************************************************/
8884 /*                           GL functions                             */
8885 /**********************************************************************/
8886
8887 /**
8888  * Test if a display list number is valid.
8889  */
8890 static GLboolean GLAPIENTRY
8891 _mesa_IsList(GLuint list)
8892 {
8893    GET_CURRENT_CONTEXT(ctx);
8894    FLUSH_VERTICES(ctx, 0);      /* must be called before assert */
8895    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
8896    return islist(ctx, list);
8897 }
8898
8899
8900 /**
8901  * Delete a sequence of consecutive display lists.
8902  */
8903 static void GLAPIENTRY
8904 _mesa_DeleteLists(GLuint list, GLsizei range)
8905 {
8906    GET_CURRENT_CONTEXT(ctx);
8907    GLuint i;
8908    FLUSH_VERTICES(ctx, 0);      /* must be called before assert */
8909    ASSERT_OUTSIDE_BEGIN_END(ctx);
8910
8911    if (range < 0) {
8912       _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteLists");
8913       return;
8914    }
8915    for (i = list; i < list + range; i++) {
8916       destroy_list(ctx, i);
8917    }
8918 }
8919
8920
8921 /**
8922  * Return a display list number, n, such that lists n through n+range-1
8923  * are free.
8924  */
8925 static GLuint GLAPIENTRY
8926 _mesa_GenLists(GLsizei range)
8927 {
8928    GET_CURRENT_CONTEXT(ctx);
8929    GLuint base;
8930    FLUSH_VERTICES(ctx, 0);      /* must be called before assert */
8931    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
8932
8933    if (range < 0) {
8934       _mesa_error(ctx, GL_INVALID_VALUE, "glGenLists");
8935       return 0;
8936    }
8937    if (range == 0) {
8938       return 0;
8939    }
8940
8941    /*
8942     * Make this an atomic operation
8943     */
8944    _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
8945
8946    base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
8947    if (base) {
8948       /* reserve the list IDs by with empty/dummy lists */
8949       GLint i;
8950       for (i = 0; i < range; i++) {
8951          _mesa_HashInsert(ctx->Shared->DisplayList, base + i,
8952                           make_list(base + i, 1));
8953       }
8954    }
8955
8956    _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
8957
8958    return base;
8959 }
8960
8961
8962 /**
8963  * Begin a new display list.
8964  */
8965 static void GLAPIENTRY
8966 _mesa_NewList(GLuint name, GLenum mode)
8967 {
8968    GET_CURRENT_CONTEXT(ctx);
8969
8970    FLUSH_CURRENT(ctx, 0);       /* must be called before assert */
8971    ASSERT_OUTSIDE_BEGIN_END(ctx);
8972
8973    if (MESA_VERBOSE & VERBOSE_API)
8974       _mesa_debug(ctx, "glNewList %u %s\n", name,
8975                   _mesa_lookup_enum_by_nr(mode));
8976
8977    if (name == 0) {
8978       _mesa_error(ctx, GL_INVALID_VALUE, "glNewList");
8979       return;
8980    }
8981
8982    if (mode != GL_COMPILE && mode != GL_COMPILE_AND_EXECUTE) {
8983       _mesa_error(ctx, GL_INVALID_ENUM, "glNewList");
8984       return;
8985    }
8986
8987    if (ctx->ListState.CurrentList) {
8988       /* already compiling a display list */
8989       _mesa_error(ctx, GL_INVALID_OPERATION, "glNewList");
8990       return;
8991    }
8992
8993    ctx->CompileFlag = GL_TRUE;
8994    ctx->ExecuteFlag = (mode == GL_COMPILE_AND_EXECUTE);
8995
8996    /* Reset acumulated list state:
8997     */
8998    invalidate_saved_current_state( ctx );
8999
9000    /* Allocate new display list */
9001    ctx->ListState.CurrentList = make_list(name, BLOCK_SIZE);
9002    ctx->ListState.CurrentBlock = ctx->ListState.CurrentList->Head;
9003    ctx->ListState.CurrentPos = 0;
9004
9005    ctx->Driver.NewList(ctx, name, mode);
9006
9007    ctx->CurrentDispatch = ctx->Save;
9008    _glapi_set_dispatch(ctx->CurrentDispatch);
9009 }
9010
9011
9012 /**
9013  * End definition of current display list. 
9014  */
9015 static void GLAPIENTRY
9016 _mesa_EndList(void)
9017 {
9018    GET_CURRENT_CONTEXT(ctx);
9019    SAVE_FLUSH_VERTICES(ctx);
9020    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
9021
9022    if (MESA_VERBOSE & VERBOSE_API)
9023       _mesa_debug(ctx, "glEndList\n");
9024
9025    /* Check that a list is under construction */
9026    if (!ctx->ListState.CurrentList) {
9027       _mesa_error(ctx, GL_INVALID_OPERATION, "glEndList");
9028       return;
9029    }
9030    
9031    /* Call before emitting END_OF_LIST, in case the driver wants to
9032     * emit opcodes itself.
9033     */
9034    ctx->Driver.EndList(ctx);
9035
9036    (void) alloc_instruction(ctx, OPCODE_END_OF_LIST, 0);
9037
9038    /* Destroy old list, if any */
9039    destroy_list(ctx, ctx->ListState.CurrentList->Name);
9040
9041    /* Install the new list */
9042    _mesa_HashInsert(ctx->Shared->DisplayList,
9043                     ctx->ListState.CurrentList->Name,
9044                     ctx->ListState.CurrentList);
9045
9046
9047    if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
9048       mesa_print_display_list(ctx->ListState.CurrentList->Name);
9049
9050    ctx->ListState.CurrentList = NULL;
9051    ctx->ExecuteFlag = GL_TRUE;
9052    ctx->CompileFlag = GL_FALSE;
9053
9054    ctx->CurrentDispatch = ctx->Exec;
9055    _glapi_set_dispatch(ctx->CurrentDispatch);
9056 }
9057
9058
9059 void GLAPIENTRY
9060 _mesa_CallList(GLuint list)
9061 {
9062    GLboolean save_compile_flag;
9063    GET_CURRENT_CONTEXT(ctx);
9064    FLUSH_CURRENT(ctx, 0);
9065
9066    if (MESA_VERBOSE & VERBOSE_API)
9067       _mesa_debug(ctx, "glCallList %d\n", list);
9068
9069    if (list == 0) {
9070       _mesa_error(ctx, GL_INVALID_VALUE, "glCallList(list==0)");
9071       return;
9072    }
9073
9074    if (0)
9075       mesa_print_display_list( list );
9076
9077    /* VERY IMPORTANT:  Save the CompileFlag status, turn it off,
9078     * execute the display list, and restore the CompileFlag.
9079     */
9080    save_compile_flag = ctx->CompileFlag;
9081    if (save_compile_flag) {
9082       ctx->CompileFlag = GL_FALSE;
9083    }
9084
9085    execute_list(ctx, list);
9086    ctx->CompileFlag = save_compile_flag;
9087
9088    /* also restore API function pointers to point to "save" versions */
9089    if (save_compile_flag) {
9090       ctx->CurrentDispatch = ctx->Save;
9091       _glapi_set_dispatch(ctx->CurrentDispatch);
9092    }
9093 }
9094
9095
9096 /**
9097  * Execute glCallLists:  call multiple display lists.
9098  */
9099 void GLAPIENTRY
9100 _mesa_CallLists(GLsizei n, GLenum type, const GLvoid * lists)
9101 {
9102    GET_CURRENT_CONTEXT(ctx);
9103    GLint i;
9104    GLboolean save_compile_flag;
9105
9106    if (MESA_VERBOSE & VERBOSE_API)
9107       _mesa_debug(ctx, "glCallLists %d\n", n);
9108
9109    switch (type) {
9110    case GL_BYTE:
9111    case GL_UNSIGNED_BYTE:
9112    case GL_SHORT:
9113    case GL_UNSIGNED_SHORT:
9114    case GL_INT:
9115    case GL_UNSIGNED_INT:
9116    case GL_FLOAT:
9117    case GL_2_BYTES:
9118    case GL_3_BYTES:
9119    case GL_4_BYTES:
9120       /* OK */
9121       break;
9122    default:
9123       _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)");
9124       return;
9125    }
9126
9127    /* Save the CompileFlag status, turn it off, execute display list,
9128     * and restore the CompileFlag.
9129     */
9130    save_compile_flag = ctx->CompileFlag;
9131    ctx->CompileFlag = GL_FALSE;
9132
9133    for (i = 0; i < n; i++) {
9134       GLuint list = (GLuint) (ctx->List.ListBase + translate_id(i, type, lists));
9135       execute_list(ctx, list);
9136    }
9137
9138    ctx->CompileFlag = save_compile_flag;
9139
9140    /* also restore API function pointers to point to "save" versions */
9141    if (save_compile_flag) {
9142       ctx->CurrentDispatch = ctx->Save;
9143       _glapi_set_dispatch(ctx->CurrentDispatch);
9144    }
9145 }
9146
9147
9148 /**
9149  * Set the offset added to list numbers in glCallLists.
9150  */
9151 static void GLAPIENTRY
9152 _mesa_ListBase(GLuint base)
9153 {
9154    GET_CURRENT_CONTEXT(ctx);
9155    FLUSH_VERTICES(ctx, 0);      /* must be called before assert */
9156    ASSERT_OUTSIDE_BEGIN_END(ctx);
9157    ctx->List.ListBase = base;
9158 }
9159
9160
9161 /* Can no longer assume ctx->Exec->Func is equal to _mesa_Func.
9162  */
9163 static void GLAPIENTRY
9164 exec_Finish(void)
9165 {
9166    GET_CURRENT_CONTEXT(ctx);
9167    FLUSH_VERTICES(ctx, 0);
9168    CALL_Finish(ctx->Exec, ());
9169 }
9170
9171 static void GLAPIENTRY
9172 exec_Flush(void)
9173 {
9174    GET_CURRENT_CONTEXT(ctx);
9175    FLUSH_VERTICES(ctx, 0);
9176    CALL_Flush(ctx->Exec, ());
9177 }
9178
9179 static void GLAPIENTRY
9180 exec_GetBooleanv(GLenum pname, GLboolean *params)
9181 {
9182    GET_CURRENT_CONTEXT(ctx);
9183    FLUSH_VERTICES(ctx, 0);
9184    CALL_GetBooleanv(ctx->Exec, (pname, params));
9185 }
9186
9187 static void GLAPIENTRY
9188 exec_GetClipPlane(GLenum plane, GLdouble * equation)
9189 {
9190    GET_CURRENT_CONTEXT(ctx);
9191    FLUSH_VERTICES(ctx, 0);
9192    CALL_GetClipPlane(ctx->Exec, (plane, equation));
9193 }
9194
9195 static void GLAPIENTRY
9196 exec_GetDoublev(GLenum pname, GLdouble *params)
9197 {
9198    GET_CURRENT_CONTEXT(ctx);
9199    FLUSH_VERTICES(ctx, 0);
9200    CALL_GetDoublev(ctx->Exec, (pname, params));
9201 }
9202
9203 static GLenum GLAPIENTRY
9204 exec_GetError(void)
9205 {
9206    GET_CURRENT_CONTEXT(ctx);
9207    FLUSH_VERTICES(ctx, 0);
9208    return CALL_GetError(ctx->Exec, ());
9209 }
9210
9211 static void GLAPIENTRY
9212 exec_GetFloatv(GLenum pname, GLfloat *params)
9213 {
9214    GET_CURRENT_CONTEXT(ctx);
9215    FLUSH_VERTICES(ctx, 0);
9216    CALL_GetFloatv(ctx->Exec, (pname, params));
9217 }
9218
9219 static void GLAPIENTRY
9220 exec_GetIntegerv(GLenum pname, GLint *params)
9221 {
9222    GET_CURRENT_CONTEXT(ctx);
9223    FLUSH_VERTICES(ctx, 0);
9224    CALL_GetIntegerv(ctx->Exec, (pname, params));
9225 }
9226
9227 static void GLAPIENTRY
9228 exec_GetLightfv(GLenum light, GLenum pname, GLfloat *params)
9229 {
9230    GET_CURRENT_CONTEXT(ctx);
9231    FLUSH_VERTICES(ctx, 0);
9232    CALL_GetLightfv(ctx->Exec, (light, pname, params));
9233 }
9234
9235 static void GLAPIENTRY
9236 exec_GetLightiv(GLenum light, GLenum pname, GLint *params)
9237 {
9238    GET_CURRENT_CONTEXT(ctx);
9239    FLUSH_VERTICES(ctx, 0);
9240    CALL_GetLightiv(ctx->Exec, (light, pname, params));
9241 }
9242
9243 static void GLAPIENTRY
9244 exec_GetMapdv(GLenum target, GLenum query, GLdouble * v)
9245 {
9246    GET_CURRENT_CONTEXT(ctx);
9247    FLUSH_VERTICES(ctx, 0);
9248    CALL_GetMapdv(ctx->Exec, (target, query, v));
9249 }
9250
9251 static void GLAPIENTRY
9252 exec_GetMapfv(GLenum target, GLenum query, GLfloat * v)
9253 {
9254    GET_CURRENT_CONTEXT(ctx);
9255    FLUSH_VERTICES(ctx, 0);
9256    CALL_GetMapfv(ctx->Exec, (target, query, v));
9257 }
9258
9259 static void GLAPIENTRY
9260 exec_GetMapiv(GLenum target, GLenum query, GLint * v)
9261 {
9262    GET_CURRENT_CONTEXT(ctx);
9263    FLUSH_VERTICES(ctx, 0);
9264    CALL_GetMapiv(ctx->Exec, (target, query, v));
9265 }
9266
9267 static void GLAPIENTRY
9268 exec_GetMaterialfv(GLenum face, GLenum pname, GLfloat *params)
9269 {
9270    GET_CURRENT_CONTEXT(ctx);
9271    FLUSH_VERTICES(ctx, 0);
9272    CALL_GetMaterialfv(ctx->Exec, (face, pname, params));
9273 }
9274
9275 static void GLAPIENTRY
9276 exec_GetMaterialiv(GLenum face, GLenum pname, GLint *params)
9277 {
9278    GET_CURRENT_CONTEXT(ctx);
9279    FLUSH_VERTICES(ctx, 0);
9280    CALL_GetMaterialiv(ctx->Exec, (face, pname, params));
9281 }
9282
9283 static void GLAPIENTRY
9284 exec_GetPixelMapfv(GLenum map, GLfloat *values)
9285 {
9286    GET_CURRENT_CONTEXT(ctx);
9287    FLUSH_VERTICES(ctx, 0);
9288    CALL_GetPixelMapfv(ctx->Exec, (map, values));
9289 }
9290
9291 static void GLAPIENTRY
9292 exec_GetPixelMapuiv(GLenum map, GLuint *values)
9293 {
9294    GET_CURRENT_CONTEXT(ctx);
9295    FLUSH_VERTICES(ctx, 0);
9296    CALL_GetPixelMapuiv(ctx->Exec, (map, values));
9297 }
9298
9299 static void GLAPIENTRY
9300 exec_GetPixelMapusv(GLenum map, GLushort *values)
9301 {
9302    GET_CURRENT_CONTEXT(ctx);
9303    FLUSH_VERTICES(ctx, 0);
9304    CALL_GetPixelMapusv(ctx->Exec, (map, values));
9305 }
9306
9307 static void GLAPIENTRY
9308 exec_GetPolygonStipple(GLubyte * dest)
9309 {
9310    GET_CURRENT_CONTEXT(ctx);
9311    FLUSH_VERTICES(ctx, 0);
9312    CALL_GetPolygonStipple(ctx->Exec, (dest));
9313 }
9314
9315 static const GLubyte *GLAPIENTRY
9316 exec_GetString(GLenum name)
9317 {
9318    GET_CURRENT_CONTEXT(ctx);
9319    FLUSH_VERTICES(ctx, 0);
9320    return CALL_GetString(ctx->Exec, (name));
9321 }
9322
9323 static void GLAPIENTRY
9324 exec_GetTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
9325 {
9326    GET_CURRENT_CONTEXT(ctx);
9327    FLUSH_VERTICES(ctx, 0);
9328    CALL_GetTexEnvfv(ctx->Exec, (target, pname, params));
9329 }
9330
9331 static void GLAPIENTRY
9332 exec_GetTexEnviv(GLenum target, GLenum pname, GLint *params)
9333 {
9334    GET_CURRENT_CONTEXT(ctx);
9335    FLUSH_VERTICES(ctx, 0);
9336    CALL_GetTexEnviv(ctx->Exec, (target, pname, params));
9337 }
9338
9339 static void GLAPIENTRY
9340 exec_GetTexGendv(GLenum coord, GLenum pname, GLdouble *params)
9341 {
9342    GET_CURRENT_CONTEXT(ctx);
9343    FLUSH_VERTICES(ctx, 0);
9344    CALL_GetTexGendv(ctx->Exec, (coord, pname, params));
9345 }
9346
9347 static void GLAPIENTRY
9348 exec_GetTexGenfv(GLenum coord, GLenum pname, GLfloat *params)
9349 {
9350    GET_CURRENT_CONTEXT(ctx);
9351    FLUSH_VERTICES(ctx, 0);
9352    CALL_GetTexGenfv(ctx->Exec, (coord, pname, params));
9353 }
9354
9355 static void GLAPIENTRY
9356 exec_GetTexGeniv(GLenum coord, GLenum pname, GLint *params)
9357 {
9358    GET_CURRENT_CONTEXT(ctx);
9359    FLUSH_VERTICES(ctx, 0);
9360    CALL_GetTexGeniv(ctx->Exec, (coord, pname, params));
9361 }
9362
9363 static void GLAPIENTRY
9364 exec_GetTexImage(GLenum target, GLint level, GLenum format,
9365                  GLenum type, GLvoid * pixels)
9366 {
9367    GET_CURRENT_CONTEXT(ctx);
9368    FLUSH_VERTICES(ctx, 0);
9369    CALL_GetTexImage(ctx->Exec, (target, level, format, type, pixels));
9370 }
9371
9372 static void GLAPIENTRY
9373 exec_GetTexLevelParameterfv(GLenum target, GLint level,
9374                             GLenum pname, GLfloat *params)
9375 {
9376    GET_CURRENT_CONTEXT(ctx);
9377    FLUSH_VERTICES(ctx, 0);
9378    CALL_GetTexLevelParameterfv(ctx->Exec, (target, level, pname, params));
9379 }
9380
9381 static void GLAPIENTRY
9382 exec_GetTexLevelParameteriv(GLenum target, GLint level,
9383                             GLenum pname, GLint *params)
9384 {
9385    GET_CURRENT_CONTEXT(ctx);
9386    FLUSH_VERTICES(ctx, 0);
9387    CALL_GetTexLevelParameteriv(ctx->Exec, (target, level, pname, params));
9388 }
9389
9390 static void GLAPIENTRY
9391 exec_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
9392 {
9393    GET_CURRENT_CONTEXT(ctx);
9394    FLUSH_VERTICES(ctx, 0);
9395    CALL_GetTexParameterfv(ctx->Exec, (target, pname, params));
9396 }
9397
9398 static void GLAPIENTRY
9399 exec_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
9400 {
9401    GET_CURRENT_CONTEXT(ctx);
9402    FLUSH_VERTICES(ctx, 0);
9403    CALL_GetTexParameteriv(ctx->Exec, (target, pname, params));
9404 }
9405
9406 static GLboolean GLAPIENTRY
9407 exec_IsEnabled(GLenum cap)
9408 {
9409    GET_CURRENT_CONTEXT(ctx);
9410    FLUSH_VERTICES(ctx, 0);
9411    return CALL_IsEnabled(ctx->Exec, (cap));
9412 }
9413
9414 static void GLAPIENTRY
9415 exec_PixelStoref(GLenum pname, GLfloat param)
9416 {
9417    GET_CURRENT_CONTEXT(ctx);
9418    FLUSH_VERTICES(ctx, 0);
9419    CALL_PixelStoref(ctx->Exec, (pname, param));
9420 }
9421
9422 static void GLAPIENTRY
9423 exec_PixelStorei(GLenum pname, GLint param)
9424 {
9425    GET_CURRENT_CONTEXT(ctx);
9426    FLUSH_VERTICES(ctx, 0);
9427    CALL_PixelStorei(ctx->Exec, (pname, param));
9428 }
9429
9430 static void GLAPIENTRY
9431 exec_ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
9432                 GLenum format, GLenum type, GLvoid * pixels)
9433 {
9434    GET_CURRENT_CONTEXT(ctx);
9435    FLUSH_VERTICES(ctx, 0);
9436    CALL_ReadPixels(ctx->Exec, (x, y, width, height, format, type, pixels));
9437 }
9438
9439 static GLint GLAPIENTRY
9440 exec_RenderMode(GLenum mode)
9441 {
9442    GET_CURRENT_CONTEXT(ctx);
9443    FLUSH_VERTICES(ctx, 0);
9444    return CALL_RenderMode(ctx->Exec, (mode));
9445 }
9446
9447 static void GLAPIENTRY
9448 exec_FeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer)
9449 {
9450    GET_CURRENT_CONTEXT(ctx);
9451    FLUSH_VERTICES(ctx, 0);
9452    CALL_FeedbackBuffer(ctx->Exec, (size, type, buffer));
9453 }
9454
9455 static void GLAPIENTRY
9456 exec_SelectBuffer(GLsizei size, GLuint * buffer)
9457 {
9458    GET_CURRENT_CONTEXT(ctx);
9459    FLUSH_VERTICES(ctx, 0);
9460    CALL_SelectBuffer(ctx->Exec, (size, buffer));
9461 }
9462
9463 static GLboolean GLAPIENTRY
9464 exec_AreTexturesResident(GLsizei n, const GLuint * texName,
9465                          GLboolean * residences)
9466 {
9467    GET_CURRENT_CONTEXT(ctx);
9468    FLUSH_VERTICES(ctx, 0);
9469    return CALL_AreTexturesResident(ctx->Exec, (n, texName, residences));
9470 }
9471
9472 static void GLAPIENTRY
9473 exec_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
9474 {
9475    GET_CURRENT_CONTEXT(ctx);
9476    FLUSH_VERTICES(ctx, 0);
9477    CALL_ColorPointer(ctx->Exec, (size, type, stride, ptr));
9478 }
9479
9480 static void GLAPIENTRY
9481 exec_DeleteTextures(GLsizei n, const GLuint * texName)
9482 {
9483    GET_CURRENT_CONTEXT(ctx);
9484    FLUSH_VERTICES(ctx, 0);
9485    CALL_DeleteTextures(ctx->Exec, (n, texName));
9486 }
9487
9488 static void GLAPIENTRY
9489 exec_DisableClientState(GLenum cap)
9490 {
9491    GET_CURRENT_CONTEXT(ctx);
9492    FLUSH_VERTICES(ctx, 0);
9493    CALL_DisableClientState(ctx->Exec, (cap));
9494 }
9495
9496 static void GLAPIENTRY
9497 exec_EdgeFlagPointer(GLsizei stride, const GLvoid * vptr)
9498 {
9499    GET_CURRENT_CONTEXT(ctx);
9500    FLUSH_VERTICES(ctx, 0);
9501    CALL_EdgeFlagPointer(ctx->Exec, (stride, vptr));
9502 }
9503
9504 static void GLAPIENTRY
9505 exec_EnableClientState(GLenum cap)
9506 {
9507    GET_CURRENT_CONTEXT(ctx);
9508    FLUSH_VERTICES(ctx, 0);
9509    CALL_EnableClientState(ctx->Exec, (cap));
9510 }
9511
9512 static void GLAPIENTRY
9513 exec_GenTextures(GLsizei n, GLuint * texName)
9514 {
9515    GET_CURRENT_CONTEXT(ctx);
9516    FLUSH_VERTICES(ctx, 0);
9517    CALL_GenTextures(ctx->Exec, (n, texName));
9518 }
9519
9520 static void GLAPIENTRY
9521 exec_GetPointerv(GLenum pname, GLvoid **params)
9522 {
9523    GET_CURRENT_CONTEXT(ctx);
9524    FLUSH_VERTICES(ctx, 0);
9525    CALL_GetPointerv(ctx->Exec, (pname, params));
9526 }
9527
9528 static void GLAPIENTRY
9529 exec_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
9530 {
9531    GET_CURRENT_CONTEXT(ctx);
9532    FLUSH_VERTICES(ctx, 0);
9533    CALL_IndexPointer(ctx->Exec, (type, stride, ptr));
9534 }
9535
9536 static void GLAPIENTRY
9537 exec_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid * pointer)
9538 {
9539    GET_CURRENT_CONTEXT(ctx);
9540    FLUSH_VERTICES(ctx, 0);
9541    CALL_InterleavedArrays(ctx->Exec, (format, stride, pointer));
9542 }
9543
9544 static GLboolean GLAPIENTRY
9545 exec_IsTexture(GLuint texture)
9546 {
9547    GET_CURRENT_CONTEXT(ctx);
9548    FLUSH_VERTICES(ctx, 0);
9549    return CALL_IsTexture(ctx->Exec, (texture));
9550 }
9551
9552 static void GLAPIENTRY
9553 exec_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
9554 {
9555    GET_CURRENT_CONTEXT(ctx);
9556    FLUSH_VERTICES(ctx, 0);
9557    CALL_NormalPointer(ctx->Exec, (type, stride, ptr));
9558 }
9559
9560 static void GLAPIENTRY
9561 exec_PopClientAttrib(void)
9562 {
9563    GET_CURRENT_CONTEXT(ctx);
9564    FLUSH_VERTICES(ctx, 0);
9565    CALL_PopClientAttrib(ctx->Exec, ());
9566 }
9567
9568 static void GLAPIENTRY
9569 exec_PushClientAttrib(GLbitfield mask)
9570 {
9571    GET_CURRENT_CONTEXT(ctx);
9572    FLUSH_VERTICES(ctx, 0);
9573    CALL_PushClientAttrib(ctx->Exec, (mask));
9574 }
9575
9576 static void GLAPIENTRY
9577 exec_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
9578                      const GLvoid *ptr)
9579 {
9580    GET_CURRENT_CONTEXT(ctx);
9581    FLUSH_VERTICES(ctx, 0);
9582    CALL_TexCoordPointer(ctx->Exec, (size, type, stride, ptr));
9583 }
9584
9585 static void GLAPIENTRY
9586 exec_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img)
9587 {
9588    GET_CURRENT_CONTEXT(ctx);
9589    FLUSH_VERTICES(ctx, 0);
9590    CALL_GetCompressedTexImageARB(ctx->Exec, (target, level, img));
9591 }
9592
9593 static void GLAPIENTRY
9594 exec_VertexPointer(GLint size, GLenum type, GLsizei stride,
9595                    const GLvoid *ptr)
9596 {
9597    GET_CURRENT_CONTEXT(ctx);
9598    FLUSH_VERTICES(ctx, 0);
9599    CALL_VertexPointer(ctx->Exec, (size, type, stride, ptr));
9600 }
9601
9602 static void GLAPIENTRY
9603 exec_CopyConvolutionFilter1D(GLenum target, GLenum internalFormat,
9604                              GLint x, GLint y, GLsizei width)
9605 {
9606    GET_CURRENT_CONTEXT(ctx);
9607    FLUSH_VERTICES(ctx, 0);
9608    CALL_CopyConvolutionFilter1D(ctx->Exec,
9609                                 (target, internalFormat, x, y, width));
9610 }
9611
9612 static void GLAPIENTRY
9613 exec_CopyConvolutionFilter2D(GLenum target, GLenum internalFormat,
9614                              GLint x, GLint y, GLsizei width, GLsizei height)
9615 {
9616    GET_CURRENT_CONTEXT(ctx);
9617    FLUSH_VERTICES(ctx, 0);
9618    CALL_CopyConvolutionFilter2D(ctx->Exec,
9619                                 (target, internalFormat, x, y, width,
9620                                  height));
9621 }
9622
9623 static void GLAPIENTRY
9624 exec_GetColorTable(GLenum target, GLenum format, GLenum type, GLvoid * data)
9625 {
9626    GET_CURRENT_CONTEXT(ctx);
9627    FLUSH_VERTICES(ctx, 0);
9628    CALL_GetColorTable(ctx->Exec, (target, format, type, data));
9629 }
9630
9631 static void GLAPIENTRY
9632 exec_GetColorTableParameterfv(GLenum target, GLenum pname, GLfloat *params)
9633 {
9634    GET_CURRENT_CONTEXT(ctx);
9635    FLUSH_VERTICES(ctx, 0);
9636    CALL_GetColorTableParameterfv(ctx->Exec, (target, pname, params));
9637 }
9638
9639 static void GLAPIENTRY
9640 exec_GetColorTableParameteriv(GLenum target, GLenum pname, GLint *params)
9641 {
9642    GET_CURRENT_CONTEXT(ctx);
9643    FLUSH_VERTICES(ctx, 0);
9644    CALL_GetColorTableParameteriv(ctx->Exec, (target, pname, params));
9645 }
9646
9647 static void GLAPIENTRY
9648 exec_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
9649                           GLvoid * image)
9650 {
9651    GET_CURRENT_CONTEXT(ctx);
9652    FLUSH_VERTICES(ctx, 0);
9653    CALL_GetConvolutionFilter(ctx->Exec, (target, format, type, image));
9654 }
9655
9656 static void GLAPIENTRY
9657 exec_GetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat *params)
9658 {
9659    GET_CURRENT_CONTEXT(ctx);
9660    FLUSH_VERTICES(ctx, 0);
9661    CALL_GetConvolutionParameterfv(ctx->Exec, (target, pname, params));
9662 }
9663
9664 static void GLAPIENTRY
9665 exec_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params)
9666 {
9667    GET_CURRENT_CONTEXT(ctx);
9668    FLUSH_VERTICES(ctx, 0);
9669    CALL_GetConvolutionParameteriv(ctx->Exec, (target, pname, params));
9670 }
9671
9672 static void GLAPIENTRY
9673 exec_GetHistogram(GLenum target, GLboolean reset, GLenum format,
9674                   GLenum type, GLvoid *values)
9675 {
9676    GET_CURRENT_CONTEXT(ctx);
9677    FLUSH_VERTICES(ctx, 0);
9678    CALL_GetHistogram(ctx->Exec, (target, reset, format, type, values));
9679 }
9680
9681 static void GLAPIENTRY
9682 exec_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
9683 {
9684    GET_CURRENT_CONTEXT(ctx);
9685    FLUSH_VERTICES(ctx, 0);
9686    CALL_GetHistogramParameterfv(ctx->Exec, (target, pname, params));
9687 }
9688
9689 static void GLAPIENTRY
9690 exec_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
9691 {
9692    GET_CURRENT_CONTEXT(ctx);
9693    FLUSH_VERTICES(ctx, 0);
9694    CALL_GetHistogramParameteriv(ctx->Exec, (target, pname, params));
9695 }
9696
9697 static void GLAPIENTRY
9698 exec_GetMinmax(GLenum target, GLboolean reset, GLenum format,
9699                GLenum type, GLvoid *values)
9700 {
9701    GET_CURRENT_CONTEXT(ctx);
9702    FLUSH_VERTICES(ctx, 0);
9703    CALL_GetMinmax(ctx->Exec, (target, reset, format, type, values));
9704 }
9705
9706 static void GLAPIENTRY
9707 exec_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
9708 {
9709    GET_CURRENT_CONTEXT(ctx);
9710    FLUSH_VERTICES(ctx, 0);
9711    CALL_GetMinmaxParameterfv(ctx->Exec, (target, pname, params));
9712 }
9713
9714 static void GLAPIENTRY
9715 exec_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
9716 {
9717    GET_CURRENT_CONTEXT(ctx);
9718    FLUSH_VERTICES(ctx, 0);
9719    CALL_GetMinmaxParameteriv(ctx->Exec, (target, pname, params));
9720 }
9721
9722 static void GLAPIENTRY
9723 exec_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
9724                         GLvoid *row, GLvoid *column, GLvoid *span)
9725 {
9726    GET_CURRENT_CONTEXT(ctx);
9727    FLUSH_VERTICES(ctx, 0);
9728    CALL_GetSeparableFilter(ctx->Exec,
9729                            (target, format, type, row, column, span));
9730 }
9731
9732 static void GLAPIENTRY
9733 exec_SeparableFilter2D(GLenum target, GLenum internalFormat,
9734                        GLsizei width, GLsizei height, GLenum format,
9735                        GLenum type, const GLvoid *row, const GLvoid *column)
9736 {
9737    GET_CURRENT_CONTEXT(ctx);
9738    FLUSH_VERTICES(ctx, 0);
9739    CALL_SeparableFilter2D(ctx->Exec,
9740                           (target, internalFormat, width, height, format,
9741                            type, row, column));
9742 }
9743
9744 static void GLAPIENTRY
9745 exec_ColorPointerEXT(GLint size, GLenum type, GLsizei stride,
9746                      GLsizei count, const GLvoid *ptr)
9747 {
9748    GET_CURRENT_CONTEXT(ctx);
9749    FLUSH_VERTICES(ctx, 0);
9750    CALL_ColorPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
9751 }
9752
9753 static void GLAPIENTRY
9754 exec_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
9755 {
9756    GET_CURRENT_CONTEXT(ctx);
9757    FLUSH_VERTICES(ctx, 0);
9758    CALL_EdgeFlagPointerEXT(ctx->Exec, (stride, count, ptr));
9759 }
9760
9761 static void GLAPIENTRY
9762 exec_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
9763                      const GLvoid *ptr)
9764 {
9765    GET_CURRENT_CONTEXT(ctx);
9766    FLUSH_VERTICES(ctx, 0);
9767    CALL_IndexPointerEXT(ctx->Exec, (type, stride, count, ptr));
9768 }
9769
9770 static void GLAPIENTRY
9771 exec_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
9772                       const GLvoid *ptr)
9773 {
9774    GET_CURRENT_CONTEXT(ctx);
9775    FLUSH_VERTICES(ctx, 0);
9776    CALL_NormalPointerEXT(ctx->Exec, (type, stride, count, ptr));
9777 }
9778
9779 static void GLAPIENTRY
9780 exec_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
9781                         GLsizei count, const GLvoid *ptr)
9782 {
9783    GET_CURRENT_CONTEXT(ctx);
9784    FLUSH_VERTICES(ctx, 0);
9785    CALL_TexCoordPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
9786 }
9787
9788 static void GLAPIENTRY
9789 exec_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
9790                       GLsizei count, const GLvoid *ptr)
9791 {
9792    GET_CURRENT_CONTEXT(ctx);
9793    FLUSH_VERTICES(ctx, 0);
9794    CALL_VertexPointerEXT(ctx->Exec, (size, type, stride, count, ptr));
9795 }
9796
9797 static void GLAPIENTRY
9798 exec_LockArraysEXT(GLint first, GLsizei count)
9799 {
9800    GET_CURRENT_CONTEXT(ctx);
9801    FLUSH_VERTICES(ctx, 0);
9802    CALL_LockArraysEXT(ctx->Exec, (first, count));
9803 }
9804
9805 static void GLAPIENTRY
9806 exec_UnlockArraysEXT(void)
9807 {
9808    GET_CURRENT_CONTEXT(ctx);
9809    FLUSH_VERTICES(ctx, 0);
9810    CALL_UnlockArraysEXT(ctx->Exec, ());
9811 }
9812
9813 static void GLAPIENTRY
9814 exec_ClientActiveTextureARB(GLenum target)
9815 {
9816    GET_CURRENT_CONTEXT(ctx);
9817    FLUSH_VERTICES(ctx, 0);
9818    CALL_ClientActiveTextureARB(ctx->Exec, (target));
9819 }
9820
9821 static void GLAPIENTRY
9822 exec_SecondaryColorPointerEXT(GLint size, GLenum type,
9823                               GLsizei stride, const GLvoid *ptr)
9824 {
9825    GET_CURRENT_CONTEXT(ctx);
9826    FLUSH_VERTICES(ctx, 0);
9827    CALL_SecondaryColorPointerEXT(ctx->Exec, (size, type, stride, ptr));
9828 }
9829
9830 static void GLAPIENTRY
9831 exec_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
9832 {
9833    GET_CURRENT_CONTEXT(ctx);
9834    FLUSH_VERTICES(ctx, 0);
9835    CALL_FogCoordPointerEXT(ctx->Exec, (type, stride, ptr));
9836 }
9837
9838 /* GL_EXT_multi_draw_arrays */
9839 static void GLAPIENTRY
9840 exec_MultiDrawArraysEXT(GLenum mode, const GLint *first,
9841                         const GLsizei *count, GLsizei primcount)
9842 {
9843    GET_CURRENT_CONTEXT(ctx);
9844    FLUSH_VERTICES(ctx, 0);
9845    CALL_MultiDrawArraysEXT(ctx->Exec, (mode, first, count, primcount));
9846 }
9847
9848 /* GL_IBM_multimode_draw_arrays */
9849 static void GLAPIENTRY
9850 exec_MultiModeDrawArraysIBM(const GLenum * mode, const GLint * first,
9851                             const GLsizei * count, GLsizei primcount,
9852                             GLint modestride)
9853 {
9854    GET_CURRENT_CONTEXT(ctx);
9855    FLUSH_VERTICES(ctx, 0);
9856    CALL_MultiModeDrawArraysIBM(ctx->Exec,
9857                                (mode, first, count, primcount, modestride));
9858 }
9859
9860 /* GL_IBM_multimode_draw_arrays */
9861 static void GLAPIENTRY
9862 exec_MultiModeDrawElementsIBM(const GLenum * mode,
9863                               const GLsizei * count,
9864                               GLenum type,
9865                               const GLvoid * const *indices,
9866                               GLsizei primcount, GLint modestride)
9867 {
9868    GET_CURRENT_CONTEXT(ctx);
9869    FLUSH_VERTICES(ctx, 0);
9870    CALL_MultiModeDrawElementsIBM(ctx->Exec,
9871                                  (mode, count, type, indices, primcount,
9872                                   modestride));
9873 }
9874
9875 /**
9876  * Setup the given dispatch table to point to Mesa's display list
9877  * building functions.
9878  *
9879  * This does not include any of the tnl functions - they are
9880  * initialized from _mesa_init_api_defaults and from the active vtxfmt
9881  * struct.
9882  */
9883 struct _glapi_table *
9884 _mesa_create_save_table(void)
9885 {
9886    struct _glapi_table *table;
9887
9888    table = _mesa_alloc_dispatch_table(_gloffset_COUNT);
9889    if (table == NULL)
9890       return NULL;
9891
9892    _mesa_loopback_init_api_table(table);
9893
9894    /* GL 1.0 */
9895    SET_Accum(table, save_Accum);
9896    SET_AlphaFunc(table, save_AlphaFunc);
9897    SET_Bitmap(table, save_Bitmap);
9898    SET_BlendFunc(table, save_BlendFunc);
9899    SET_CallList(table, save_CallList);
9900    SET_CallLists(table, save_CallLists);
9901    SET_Clear(table, save_Clear);
9902    SET_ClearAccum(table, save_ClearAccum);
9903    SET_ClearColor(table, save_ClearColor);
9904    SET_ClearDepth(table, save_ClearDepth);
9905    SET_ClearIndex(table, save_ClearIndex);
9906    SET_ClearStencil(table, save_ClearStencil);
9907    SET_ClipPlane(table, save_ClipPlane);
9908    SET_ColorMask(table, save_ColorMask);
9909    SET_ColorMaskIndexedEXT(table, save_ColorMaskIndexed);
9910    SET_ColorMaterial(table, save_ColorMaterial);
9911    SET_CopyPixels(table, save_CopyPixels);
9912    SET_CullFace(table, save_CullFace);
9913    SET_DeleteLists(table, _mesa_DeleteLists);
9914    SET_DepthFunc(table, save_DepthFunc);
9915    SET_DepthMask(table, save_DepthMask);
9916    SET_DepthRange(table, save_DepthRange);
9917    SET_Disable(table, save_Disable);
9918    SET_DisableIndexedEXT(table, save_DisableIndexed);
9919    SET_DrawBuffer(table, save_DrawBuffer);
9920    SET_DrawPixels(table, save_DrawPixels);
9921    SET_Enable(table, save_Enable);
9922    SET_EnableIndexedEXT(table, save_EnableIndexed);
9923    SET_EndList(table, _mesa_EndList);
9924    SET_EvalMesh1(table, save_EvalMesh1);
9925    SET_EvalMesh2(table, save_EvalMesh2);
9926    SET_Finish(table, exec_Finish);
9927    SET_Flush(table, exec_Flush);
9928    SET_Fogf(table, save_Fogf);
9929    SET_Fogfv(table, save_Fogfv);
9930    SET_Fogi(table, save_Fogi);
9931    SET_Fogiv(table, save_Fogiv);
9932    SET_FrontFace(table, save_FrontFace);
9933    SET_Frustum(table, save_Frustum);
9934    SET_GenLists(table, _mesa_GenLists);
9935    SET_GetBooleanv(table, exec_GetBooleanv);
9936    SET_GetClipPlane(table, exec_GetClipPlane);
9937    SET_GetDoublev(table, exec_GetDoublev);
9938    SET_GetError(table, exec_GetError);
9939    SET_GetFloatv(table, exec_GetFloatv);
9940    SET_GetIntegerv(table, exec_GetIntegerv);
9941    SET_GetLightfv(table, exec_GetLightfv);
9942    SET_GetLightiv(table, exec_GetLightiv);
9943    SET_GetMapdv(table, exec_GetMapdv);
9944    SET_GetMapfv(table, exec_GetMapfv);
9945    SET_GetMapiv(table, exec_GetMapiv);
9946    SET_GetMaterialfv(table, exec_GetMaterialfv);
9947    SET_GetMaterialiv(table, exec_GetMaterialiv);
9948    SET_GetPixelMapfv(table, exec_GetPixelMapfv);
9949    SET_GetPixelMapuiv(table, exec_GetPixelMapuiv);
9950    SET_GetPixelMapusv(table, exec_GetPixelMapusv);
9951    SET_GetPolygonStipple(table, exec_GetPolygonStipple);
9952    SET_GetString(table, exec_GetString);
9953    SET_GetTexEnvfv(table, exec_GetTexEnvfv);
9954    SET_GetTexEnviv(table, exec_GetTexEnviv);
9955    SET_GetTexGendv(table, exec_GetTexGendv);
9956    SET_GetTexGenfv(table, exec_GetTexGenfv);
9957    SET_GetTexGeniv(table, exec_GetTexGeniv);
9958    SET_GetTexImage(table, exec_GetTexImage);
9959    SET_GetTexLevelParameterfv(table, exec_GetTexLevelParameterfv);
9960    SET_GetTexLevelParameteriv(table, exec_GetTexLevelParameteriv);
9961    SET_GetTexParameterfv(table, exec_GetTexParameterfv);
9962    SET_GetTexParameteriv(table, exec_GetTexParameteriv);
9963    SET_Hint(table, save_Hint);
9964    SET_IndexMask(table, save_IndexMask);
9965    SET_InitNames(table, save_InitNames);
9966    SET_IsEnabled(table, exec_IsEnabled);
9967    SET_IsList(table, _mesa_IsList);
9968    SET_LightModelf(table, save_LightModelf);
9969    SET_LightModelfv(table, save_LightModelfv);
9970    SET_LightModeli(table, save_LightModeli);
9971    SET_LightModeliv(table, save_LightModeliv);
9972    SET_Lightf(table, save_Lightf);
9973    SET_Lightfv(table, save_Lightfv);
9974    SET_Lighti(table, save_Lighti);
9975    SET_Lightiv(table, save_Lightiv);
9976    SET_LineStipple(table, save_LineStipple);
9977    SET_LineWidth(table, save_LineWidth);
9978    SET_ListBase(table, save_ListBase);
9979    SET_LoadIdentity(table, save_LoadIdentity);
9980    SET_LoadMatrixd(table, save_LoadMatrixd);
9981    SET_LoadMatrixf(table, save_LoadMatrixf);
9982    SET_LoadName(table, save_LoadName);
9983    SET_LogicOp(table, save_LogicOp);
9984    SET_Map1d(table, save_Map1d);
9985    SET_Map1f(table, save_Map1f);
9986    SET_Map2d(table, save_Map2d);
9987    SET_Map2f(table, save_Map2f);
9988    SET_MapGrid1d(table, save_MapGrid1d);
9989    SET_MapGrid1f(table, save_MapGrid1f);
9990    SET_MapGrid2d(table, save_MapGrid2d);
9991    SET_MapGrid2f(table, save_MapGrid2f);
9992    SET_MatrixMode(table, save_MatrixMode);
9993    SET_MultMatrixd(table, save_MultMatrixd);
9994    SET_MultMatrixf(table, save_MultMatrixf);
9995    SET_NewList(table, save_NewList);
9996    SET_Ortho(table, save_Ortho);
9997    SET_PassThrough(table, save_PassThrough);
9998    SET_PixelMapfv(table, save_PixelMapfv);
9999    SET_PixelMapuiv(table, save_PixelMapuiv);
10000    SET_PixelMapusv(table, save_PixelMapusv);
10001    SET_PixelStoref(table, exec_PixelStoref);
10002    SET_PixelStorei(table, exec_PixelStorei);
10003    SET_PixelTransferf(table, save_PixelTransferf);
10004    SET_PixelTransferi(table, save_PixelTransferi);
10005    SET_PixelZoom(table, save_PixelZoom);
10006    SET_PointSize(table, save_PointSize);
10007    SET_PolygonMode(table, save_PolygonMode);
10008    SET_PolygonOffset(table, save_PolygonOffset);
10009    SET_PolygonStipple(table, save_PolygonStipple);
10010    SET_PopAttrib(table, save_PopAttrib);
10011    SET_PopMatrix(table, save_PopMatrix);
10012    SET_PopName(table, save_PopName);
10013    SET_PushAttrib(table, save_PushAttrib);
10014    SET_PushMatrix(table, save_PushMatrix);
10015    SET_PushName(table, save_PushName);
10016    SET_RasterPos2d(table, save_RasterPos2d);
10017    SET_RasterPos2dv(table, save_RasterPos2dv);
10018    SET_RasterPos2f(table, save_RasterPos2f);
10019    SET_RasterPos2fv(table, save_RasterPos2fv);
10020    SET_RasterPos2i(table, save_RasterPos2i);
10021    SET_RasterPos2iv(table, save_RasterPos2iv);
10022    SET_RasterPos2s(table, save_RasterPos2s);
10023    SET_RasterPos2sv(table, save_RasterPos2sv);
10024    SET_RasterPos3d(table, save_RasterPos3d);
10025    SET_RasterPos3dv(table, save_RasterPos3dv);
10026    SET_RasterPos3f(table, save_RasterPos3f);
10027    SET_RasterPos3fv(table, save_RasterPos3fv);
10028    SET_RasterPos3i(table, save_RasterPos3i);
10029    SET_RasterPos3iv(table, save_RasterPos3iv);
10030    SET_RasterPos3s(table, save_RasterPos3s);
10031    SET_RasterPos3sv(table, save_RasterPos3sv);
10032    SET_RasterPos4d(table, save_RasterPos4d);
10033    SET_RasterPos4dv(table, save_RasterPos4dv);
10034    SET_RasterPos4f(table, save_RasterPos4f);
10035    SET_RasterPos4fv(table, save_RasterPos4fv);
10036    SET_RasterPos4i(table, save_RasterPos4i);
10037    SET_RasterPos4iv(table, save_RasterPos4iv);
10038    SET_RasterPos4s(table, save_RasterPos4s);
10039    SET_RasterPos4sv(table, save_RasterPos4sv);
10040    SET_ReadBuffer(table, save_ReadBuffer);
10041    SET_ReadPixels(table, exec_ReadPixels);
10042    SET_RenderMode(table, exec_RenderMode);
10043    SET_Rotated(table, save_Rotated);
10044    SET_Rotatef(table, save_Rotatef);
10045    SET_Scaled(table, save_Scaled);
10046    SET_Scalef(table, save_Scalef);
10047    SET_Scissor(table, save_Scissor);
10048    SET_FeedbackBuffer(table, exec_FeedbackBuffer);
10049    SET_SelectBuffer(table, exec_SelectBuffer);
10050    SET_ShadeModel(table, save_ShadeModel);
10051    SET_StencilFunc(table, save_StencilFunc);
10052    SET_StencilMask(table, save_StencilMask);
10053    SET_StencilOp(table, save_StencilOp);
10054    SET_TexEnvf(table, save_TexEnvf);
10055    SET_TexEnvfv(table, save_TexEnvfv);
10056    SET_TexEnvi(table, save_TexEnvi);
10057    SET_TexEnviv(table, save_TexEnviv);
10058    SET_TexGend(table, save_TexGend);
10059    SET_TexGendv(table, save_TexGendv);
10060    SET_TexGenf(table, save_TexGenf);
10061    SET_TexGenfv(table, save_TexGenfv);
10062    SET_TexGeni(table, save_TexGeni);
10063    SET_TexGeniv(table, save_TexGeniv);
10064    SET_TexImage1D(table, save_TexImage1D);
10065    SET_TexImage2D(table, save_TexImage2D);
10066    SET_TexParameterf(table, save_TexParameterf);
10067    SET_TexParameterfv(table, save_TexParameterfv);
10068    SET_TexParameteri(table, save_TexParameteri);
10069    SET_TexParameteriv(table, save_TexParameteriv);
10070    SET_Translated(table, save_Translated);
10071    SET_Translatef(table, save_Translatef);
10072    SET_Viewport(table, save_Viewport);
10073
10074    /* GL 1.1 */
10075    SET_AreTexturesResident(table, exec_AreTexturesResident);
10076    SET_BindTexture(table, save_BindTexture);
10077    SET_ColorPointer(table, exec_ColorPointer);
10078    SET_CopyTexImage1D(table, save_CopyTexImage1D);
10079    SET_CopyTexImage2D(table, save_CopyTexImage2D);
10080    SET_CopyTexSubImage1D(table, save_CopyTexSubImage1D);
10081    SET_CopyTexSubImage2D(table, save_CopyTexSubImage2D);
10082    SET_DeleteTextures(table, exec_DeleteTextures);
10083    SET_DisableClientState(table, exec_DisableClientState);
10084    SET_EdgeFlagPointer(table, exec_EdgeFlagPointer);
10085    SET_EnableClientState(table, exec_EnableClientState);
10086    SET_GenTextures(table, exec_GenTextures);
10087    SET_GetPointerv(table, exec_GetPointerv);
10088    SET_IndexPointer(table, exec_IndexPointer);
10089    SET_InterleavedArrays(table, exec_InterleavedArrays);
10090    SET_IsTexture(table, exec_IsTexture);
10091    SET_NormalPointer(table, exec_NormalPointer);
10092    SET_PopClientAttrib(table, exec_PopClientAttrib);
10093    SET_PrioritizeTextures(table, save_PrioritizeTextures);
10094    SET_PushClientAttrib(table, exec_PushClientAttrib);
10095    SET_TexCoordPointer(table, exec_TexCoordPointer);
10096    SET_TexSubImage1D(table, save_TexSubImage1D);
10097    SET_TexSubImage2D(table, save_TexSubImage2D);
10098    SET_VertexPointer(table, exec_VertexPointer);
10099
10100    /* GL 1.2 */
10101    SET_CopyTexSubImage3D(table, save_CopyTexSubImage3D);
10102    SET_TexImage3D(table, save_TexImage3D);
10103    SET_TexSubImage3D(table, save_TexSubImage3D);
10104
10105    /* GL 2.0 */
10106    SET_StencilFuncSeparate(table, save_StencilFuncSeparate);
10107    SET_StencilMaskSeparate(table, save_StencilMaskSeparate);
10108    SET_StencilOpSeparate(table, save_StencilOpSeparate);
10109
10110    /* ATI_separate_stencil */ 
10111    SET_StencilFuncSeparateATI(table, save_StencilFuncSeparateATI);
10112
10113    /* GL_ARB_imaging */
10114    /* Not all are supported */
10115    SET_BlendColor(table, save_BlendColor);
10116    SET_BlendEquation(table, save_BlendEquation);
10117    SET_ColorSubTable(table, save_ColorSubTable);
10118    SET_ColorTable(table, save_ColorTable);
10119    SET_ColorTableParameterfv(table, save_ColorTableParameterfv);
10120    SET_ColorTableParameteriv(table, save_ColorTableParameteriv);
10121    SET_ConvolutionFilter1D(table, save_ConvolutionFilter1D);
10122    SET_ConvolutionFilter2D(table, save_ConvolutionFilter2D);
10123    SET_ConvolutionParameterf(table, save_ConvolutionParameterf);
10124    SET_ConvolutionParameterfv(table, save_ConvolutionParameterfv);
10125    SET_ConvolutionParameteri(table, save_ConvolutionParameteri);
10126    SET_ConvolutionParameteriv(table, save_ConvolutionParameteriv);
10127    SET_CopyColorSubTable(table, save_CopyColorSubTable);
10128    SET_CopyColorTable(table, save_CopyColorTable);
10129    SET_CopyConvolutionFilter1D(table, exec_CopyConvolutionFilter1D);
10130    SET_CopyConvolutionFilter2D(table, exec_CopyConvolutionFilter2D);
10131    SET_GetColorTable(table, exec_GetColorTable);
10132    SET_GetColorTableParameterfv(table, exec_GetColorTableParameterfv);
10133    SET_GetColorTableParameteriv(table, exec_GetColorTableParameteriv);
10134    SET_GetConvolutionFilter(table, exec_GetConvolutionFilter);
10135    SET_GetConvolutionParameterfv(table, exec_GetConvolutionParameterfv);
10136    SET_GetConvolutionParameteriv(table, exec_GetConvolutionParameteriv);
10137    SET_GetHistogram(table, exec_GetHistogram);
10138    SET_GetHistogramParameterfv(table, exec_GetHistogramParameterfv);
10139    SET_GetHistogramParameteriv(table, exec_GetHistogramParameteriv);
10140    SET_GetMinmax(table, exec_GetMinmax);
10141    SET_GetMinmaxParameterfv(table, exec_GetMinmaxParameterfv);
10142    SET_GetMinmaxParameteriv(table, exec_GetMinmaxParameteriv);
10143    SET_GetSeparableFilter(table, exec_GetSeparableFilter);
10144    SET_Histogram(table, save_Histogram);
10145    SET_Minmax(table, save_Minmax);
10146    SET_ResetHistogram(table, save_ResetHistogram);
10147    SET_ResetMinmax(table, save_ResetMinmax);
10148    SET_SeparableFilter2D(table, exec_SeparableFilter2D);
10149
10150    /* 2. GL_EXT_blend_color */
10151 #if 0
10152    SET_BlendColorEXT(table, save_BlendColorEXT);
10153 #endif
10154
10155    /* 3. GL_EXT_polygon_offset */
10156    SET_PolygonOffsetEXT(table, save_PolygonOffsetEXT);
10157
10158    /* 6. GL_EXT_texture3d */
10159 #if 0
10160    SET_CopyTexSubImage3DEXT(table, save_CopyTexSubImage3D);
10161    SET_TexImage3DEXT(table, save_TexImage3DEXT);
10162    SET_TexSubImage3DEXT(table, save_TexSubImage3D);
10163 #endif
10164
10165    /* 14. GL_SGI_color_table */
10166 #if 0
10167    SET_ColorTableSGI(table, save_ColorTable);
10168    SET_ColorSubTableSGI(table, save_ColorSubTable);
10169    SET_GetColorTableSGI(table, exec_GetColorTable);
10170    SET_GetColorTableParameterfvSGI(table, exec_GetColorTableParameterfv);
10171    SET_GetColorTableParameterivSGI(table, exec_GetColorTableParameteriv);
10172 #endif
10173
10174    /* 30. GL_EXT_vertex_array */
10175    SET_ColorPointerEXT(table, exec_ColorPointerEXT);
10176    SET_EdgeFlagPointerEXT(table, exec_EdgeFlagPointerEXT);
10177    SET_IndexPointerEXT(table, exec_IndexPointerEXT);
10178    SET_NormalPointerEXT(table, exec_NormalPointerEXT);
10179    SET_TexCoordPointerEXT(table, exec_TexCoordPointerEXT);
10180    SET_VertexPointerEXT(table, exec_VertexPointerEXT);
10181
10182    /* 37. GL_EXT_blend_minmax */
10183 #if 0
10184    SET_BlendEquationEXT(table, save_BlendEquationEXT);
10185 #endif
10186
10187    /* 54. GL_EXT_point_parameters */
10188    SET_PointParameterfEXT(table, save_PointParameterfEXT);
10189    SET_PointParameterfvEXT(table, save_PointParameterfvEXT);
10190
10191    /* 97. GL_EXT_compiled_vertex_array */
10192    SET_LockArraysEXT(table, exec_LockArraysEXT);
10193    SET_UnlockArraysEXT(table, exec_UnlockArraysEXT);
10194
10195    /* 145. GL_EXT_secondary_color */
10196    SET_SecondaryColorPointerEXT(table, exec_SecondaryColorPointerEXT);
10197
10198    /* 148. GL_EXT_multi_draw_arrays */
10199    SET_MultiDrawArraysEXT(table, exec_MultiDrawArraysEXT);
10200
10201    /* 149. GL_EXT_fog_coord */
10202    SET_FogCoordPointerEXT(table, exec_FogCoordPointerEXT);
10203
10204    /* 173. GL_EXT_blend_func_separate */
10205    SET_BlendFuncSeparateEXT(table, save_BlendFuncSeparateEXT);
10206
10207    /* 196. GL_MESA_resize_buffers */
10208    SET_ResizeBuffersMESA(table, _mesa_ResizeBuffersMESA);
10209
10210    /* 197. GL_MESA_window_pos */
10211    SET_WindowPos2dMESA(table, save_WindowPos2dMESA);
10212    SET_WindowPos2dvMESA(table, save_WindowPos2dvMESA);
10213    SET_WindowPos2fMESA(table, save_WindowPos2fMESA);
10214    SET_WindowPos2fvMESA(table, save_WindowPos2fvMESA);
10215    SET_WindowPos2iMESA(table, save_WindowPos2iMESA);
10216    SET_WindowPos2ivMESA(table, save_WindowPos2ivMESA);
10217    SET_WindowPos2sMESA(table, save_WindowPos2sMESA);
10218    SET_WindowPos2svMESA(table, save_WindowPos2svMESA);
10219    SET_WindowPos3dMESA(table, save_WindowPos3dMESA);
10220    SET_WindowPos3dvMESA(table, save_WindowPos3dvMESA);
10221    SET_WindowPos3fMESA(table, save_WindowPos3fMESA);
10222    SET_WindowPos3fvMESA(table, save_WindowPos3fvMESA);
10223    SET_WindowPos3iMESA(table, save_WindowPos3iMESA);
10224    SET_WindowPos3ivMESA(table, save_WindowPos3ivMESA);
10225    SET_WindowPos3sMESA(table, save_WindowPos3sMESA);
10226    SET_WindowPos3svMESA(table, save_WindowPos3svMESA);
10227    SET_WindowPos4dMESA(table, save_WindowPos4dMESA);
10228    SET_WindowPos4dvMESA(table, save_WindowPos4dvMESA);
10229    SET_WindowPos4fMESA(table, save_WindowPos4fMESA);
10230    SET_WindowPos4fvMESA(table, save_WindowPos4fvMESA);
10231    SET_WindowPos4iMESA(table, save_WindowPos4iMESA);
10232    SET_WindowPos4ivMESA(table, save_WindowPos4ivMESA);
10233    SET_WindowPos4sMESA(table, save_WindowPos4sMESA);
10234    SET_WindowPos4svMESA(table, save_WindowPos4svMESA);
10235
10236    /* 200. GL_IBM_multimode_draw_arrays */
10237    SET_MultiModeDrawArraysIBM(table, exec_MultiModeDrawArraysIBM);
10238    SET_MultiModeDrawElementsIBM(table, exec_MultiModeDrawElementsIBM);
10239
10240    /* 233. GL_NV_vertex_program */
10241    /* The following commands DO NOT go into display lists:
10242     * AreProgramsResidentNV, IsProgramNV, GenProgramsNV, DeleteProgramsNV,
10243     * VertexAttribPointerNV, GetProgram*, GetVertexAttrib*
10244     */
10245    SET_BindProgramNV(table, save_BindProgramNV);
10246    SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
10247    SET_ExecuteProgramNV(table, save_ExecuteProgramNV);
10248    SET_GenProgramsNV(table, _mesa_GenPrograms);
10249    SET_AreProgramsResidentNV(table, _mesa_AreProgramsResidentNV);
10250    SET_RequestResidentProgramsNV(table, save_RequestResidentProgramsNV);
10251    SET_GetProgramParameterfvNV(table, _mesa_GetProgramParameterfvNV);
10252    SET_GetProgramParameterdvNV(table, _mesa_GetProgramParameterdvNV);
10253    SET_GetProgramivNV(table, _mesa_GetProgramivNV);
10254    SET_GetProgramStringNV(table, _mesa_GetProgramStringNV);
10255    SET_GetTrackMatrixivNV(table, _mesa_GetTrackMatrixivNV);
10256    SET_GetVertexAttribdvNV(table, _mesa_GetVertexAttribdvNV);
10257    SET_GetVertexAttribfvNV(table, _mesa_GetVertexAttribfvNV);
10258    SET_GetVertexAttribivNV(table, _mesa_GetVertexAttribivNV);
10259    SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
10260    SET_IsProgramNV(table, _mesa_IsProgramARB);
10261    SET_LoadProgramNV(table, save_LoadProgramNV);
10262    SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
10263    SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
10264    SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
10265    SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
10266    SET_ProgramParameters4dvNV(table, save_ProgramParameters4dvNV);
10267    SET_ProgramParameters4fvNV(table, save_ProgramParameters4fvNV);
10268    SET_TrackMatrixNV(table, save_TrackMatrixNV);
10269    SET_VertexAttribPointerNV(table, _mesa_VertexAttribPointerNV);
10270
10271    /* 244. GL_ATI_envmap_bumpmap */
10272    SET_TexBumpParameterivATI(table, save_TexBumpParameterivATI);
10273    SET_TexBumpParameterfvATI(table, save_TexBumpParameterfvATI);
10274
10275    /* 245. GL_ATI_fragment_shader */
10276 #if FEATURE_ATI_fragment_shader
10277    SET_BindFragmentShaderATI(table, save_BindFragmentShaderATI);
10278    SET_SetFragmentShaderConstantATI(table, save_SetFragmentShaderConstantATI);
10279 #endif
10280
10281    /* 282. GL_NV_fragment_program */
10282    SET_ProgramNamedParameter4fNV(table, save_ProgramNamedParameter4fNV);
10283    SET_ProgramNamedParameter4dNV(table, save_ProgramNamedParameter4dNV);
10284    SET_ProgramNamedParameter4fvNV(table, save_ProgramNamedParameter4fvNV);
10285    SET_ProgramNamedParameter4dvNV(table, save_ProgramNamedParameter4dvNV);
10286    SET_GetProgramNamedParameterfvNV(table,
10287                                     _mesa_GetProgramNamedParameterfvNV);
10288    SET_GetProgramNamedParameterdvNV(table,
10289                                     _mesa_GetProgramNamedParameterdvNV);
10290    SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
10291    SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
10292    SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
10293    SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
10294    SET_GetProgramLocalParameterdvARB(table,
10295                                      _mesa_GetProgramLocalParameterdvARB);
10296    SET_GetProgramLocalParameterfvARB(table,
10297                                      _mesa_GetProgramLocalParameterfvARB);
10298
10299    /* 262. GL_NV_point_sprite */
10300    SET_PointParameteriNV(table, save_PointParameteriNV);
10301    SET_PointParameterivNV(table, save_PointParameterivNV);
10302
10303    /* 268. GL_EXT_stencil_two_side */
10304    SET_ActiveStencilFaceEXT(table, save_ActiveStencilFaceEXT);
10305
10306    /* 273. GL_APPLE_vertex_array_object */
10307    SET_BindVertexArrayAPPLE(table, _mesa_BindVertexArrayAPPLE);
10308    SET_DeleteVertexArraysAPPLE(table, _mesa_DeleteVertexArraysAPPLE);
10309    SET_GenVertexArraysAPPLE(table, _mesa_GenVertexArraysAPPLE);
10310    SET_IsVertexArrayAPPLE(table, _mesa_IsVertexArrayAPPLE);
10311
10312    /* 310. GL_EXT_framebuffer_object */
10313    SET_GenFramebuffersEXT(table, _mesa_GenFramebuffersEXT);
10314    SET_BindFramebufferEXT(table, _mesa_BindFramebufferEXT);
10315    SET_DeleteFramebuffersEXT(table, _mesa_DeleteFramebuffersEXT);
10316    SET_CheckFramebufferStatusEXT(table, _mesa_CheckFramebufferStatusEXT);
10317    SET_GenRenderbuffersEXT(table, _mesa_GenRenderbuffersEXT);
10318    SET_BindRenderbufferEXT(table, _mesa_BindRenderbufferEXT);
10319    SET_DeleteRenderbuffersEXT(table, _mesa_DeleteRenderbuffersEXT);
10320    SET_RenderbufferStorageEXT(table, _mesa_RenderbufferStorageEXT);
10321    SET_FramebufferTexture1DEXT(table, _mesa_FramebufferTexture1DEXT);
10322    SET_FramebufferTexture2DEXT(table, _mesa_FramebufferTexture2DEXT);
10323    SET_FramebufferTexture3DEXT(table, _mesa_FramebufferTexture3DEXT);
10324    SET_FramebufferRenderbufferEXT(table, _mesa_FramebufferRenderbufferEXT);
10325    SET_GenerateMipmapEXT(table, _mesa_GenerateMipmapEXT);
10326
10327    /* 317. GL_EXT_framebuffer_multisample */
10328    SET_RenderbufferStorageMultisample(table, _mesa_RenderbufferStorageMultisample);
10329
10330    /* GL_ARB_vertex_array_object */
10331    SET_BindVertexArray(table, _mesa_BindVertexArray);
10332    SET_GenVertexArrays(table, _mesa_GenVertexArrays);
10333
10334    /* ???. GL_EXT_depth_bounds_test */
10335    SET_DepthBoundsEXT(table, save_DepthBoundsEXT);
10336
10337    /* ARB 1. GL_ARB_multitexture */
10338    SET_ActiveTextureARB(table, save_ActiveTextureARB);
10339    SET_ClientActiveTextureARB(table, exec_ClientActiveTextureARB);
10340
10341    /* ARB 3. GL_ARB_transpose_matrix */
10342    SET_LoadTransposeMatrixdARB(table, save_LoadTransposeMatrixdARB);
10343    SET_LoadTransposeMatrixfARB(table, save_LoadTransposeMatrixfARB);
10344    SET_MultTransposeMatrixdARB(table, save_MultTransposeMatrixdARB);
10345    SET_MultTransposeMatrixfARB(table, save_MultTransposeMatrixfARB);
10346
10347    /* ARB 5. GL_ARB_multisample */
10348    SET_SampleCoverageARB(table, save_SampleCoverageARB);
10349
10350    /* ARB 12. GL_ARB_texture_compression */
10351    SET_CompressedTexImage3DARB(table, save_CompressedTexImage3DARB);
10352    SET_CompressedTexImage2DARB(table, save_CompressedTexImage2DARB);
10353    SET_CompressedTexImage1DARB(table, save_CompressedTexImage1DARB);
10354    SET_CompressedTexSubImage3DARB(table, save_CompressedTexSubImage3DARB);
10355    SET_CompressedTexSubImage2DARB(table, save_CompressedTexSubImage2DARB);
10356    SET_CompressedTexSubImage1DARB(table, save_CompressedTexSubImage1DARB);
10357    SET_GetCompressedTexImageARB(table, exec_GetCompressedTexImageARB);
10358
10359    /* ARB 14. GL_ARB_point_parameters */
10360    /* aliased with EXT_point_parameters functions */
10361
10362    /* ARB 25. GL_ARB_window_pos */
10363    /* aliased with MESA_window_pos functions */
10364
10365    /* ARB 26. GL_ARB_vertex_program */
10366    /* ARB 27. GL_ARB_fragment_program */
10367    /* glVertexAttrib* functions alias the NV ones, handled elsewhere */
10368    SET_VertexAttribPointerARB(table, _mesa_VertexAttribPointerARB);
10369    SET_EnableVertexAttribArrayARB(table, _mesa_EnableVertexAttribArrayARB);
10370    SET_DisableVertexAttribArrayARB(table, _mesa_DisableVertexAttribArrayARB);
10371    SET_ProgramStringARB(table, save_ProgramStringARB);
10372    SET_BindProgramNV(table, save_BindProgramNV);
10373    SET_DeleteProgramsNV(table, _mesa_DeletePrograms);
10374    SET_GenProgramsNV(table, _mesa_GenPrograms);
10375    SET_IsProgramNV(table, _mesa_IsProgramARB);
10376    SET_GetVertexAttribdvARB(table, _mesa_GetVertexAttribdvARB);
10377    SET_GetVertexAttribfvARB(table, _mesa_GetVertexAttribfvARB);
10378    SET_GetVertexAttribivARB(table, _mesa_GetVertexAttribivARB);
10379    SET_GetVertexAttribPointervNV(table, _mesa_GetVertexAttribPointervNV);
10380    SET_ProgramEnvParameter4dARB(table, save_ProgramEnvParameter4dARB);
10381    SET_ProgramEnvParameter4dvARB(table, save_ProgramEnvParameter4dvARB);
10382    SET_ProgramEnvParameter4fARB(table, save_ProgramEnvParameter4fARB);
10383    SET_ProgramEnvParameter4fvARB(table, save_ProgramEnvParameter4fvARB);
10384    SET_ProgramLocalParameter4dARB(table, save_ProgramLocalParameter4dARB);
10385    SET_ProgramLocalParameter4dvARB(table, save_ProgramLocalParameter4dvARB);
10386    SET_ProgramLocalParameter4fARB(table, save_ProgramLocalParameter4fARB);
10387    SET_ProgramLocalParameter4fvARB(table, save_ProgramLocalParameter4fvARB);
10388    SET_GetProgramEnvParameterdvARB(table, _mesa_GetProgramEnvParameterdvARB);
10389    SET_GetProgramEnvParameterfvARB(table, _mesa_GetProgramEnvParameterfvARB);
10390    SET_GetProgramLocalParameterdvARB(table,
10391                                      _mesa_GetProgramLocalParameterdvARB);
10392    SET_GetProgramLocalParameterfvARB(table,
10393                                      _mesa_GetProgramLocalParameterfvARB);
10394    SET_GetProgramivARB(table, _mesa_GetProgramivARB);
10395    SET_GetProgramStringARB(table, _mesa_GetProgramStringARB);
10396
10397    /* ARB 28. GL_ARB_vertex_buffer_object */
10398    /* None of the extension's functions get compiled */
10399    SET_BindBufferARB(table, _mesa_BindBufferARB);
10400    SET_BufferDataARB(table, _mesa_BufferDataARB);
10401    SET_BufferSubDataARB(table, _mesa_BufferSubDataARB);
10402    SET_DeleteBuffersARB(table, _mesa_DeleteBuffersARB);
10403    SET_GenBuffersARB(table, _mesa_GenBuffersARB);
10404    SET_GetBufferParameterivARB(table, _mesa_GetBufferParameterivARB);
10405    SET_GetBufferPointervARB(table, _mesa_GetBufferPointervARB);
10406    SET_GetBufferSubDataARB(table, _mesa_GetBufferSubDataARB);
10407    SET_IsBufferARB(table, _mesa_IsBufferARB);
10408    SET_MapBufferARB(table, _mesa_MapBufferARB);
10409    SET_UnmapBufferARB(table, _mesa_UnmapBufferARB);
10410
10411    _mesa_init_queryobj_dispatch(table); /* glGetQuery, etc */
10412    SET_BeginQueryARB(table, save_BeginQueryARB);
10413    SET_EndQueryARB(table, save_EndQueryARB);
10414    SET_QueryCounter(table, save_QueryCounter);
10415
10416    SET_DrawBuffersARB(table, save_DrawBuffersARB);
10417
10418    SET_BlitFramebufferEXT(table, save_BlitFramebufferEXT);
10419
10420    /* GL_ARB_shader_objects */
10421    _mesa_init_shader_dispatch(table); /* Plug in glCreate/Delete/Get, etc */
10422    SET_UseProgramObjectARB(table, save_UseProgramObjectARB);
10423    SET_Uniform1fARB(table, save_Uniform1fARB);
10424    SET_Uniform2fARB(table, save_Uniform2fARB);
10425    SET_Uniform3fARB(table, save_Uniform3fARB);
10426    SET_Uniform4fARB(table, save_Uniform4fARB);
10427    SET_Uniform1fvARB(table, save_Uniform1fvARB);
10428    SET_Uniform2fvARB(table, save_Uniform2fvARB);
10429    SET_Uniform3fvARB(table, save_Uniform3fvARB);
10430    SET_Uniform4fvARB(table, save_Uniform4fvARB);
10431    SET_Uniform1iARB(table, save_Uniform1iARB);
10432    SET_Uniform2iARB(table, save_Uniform2iARB);
10433    SET_Uniform3iARB(table, save_Uniform3iARB);
10434    SET_Uniform4iARB(table, save_Uniform4iARB);
10435    SET_Uniform1ivARB(table, save_Uniform1ivARB);
10436    SET_Uniform2ivARB(table, save_Uniform2ivARB);
10437    SET_Uniform3ivARB(table, save_Uniform3ivARB);
10438    SET_Uniform4ivARB(table, save_Uniform4ivARB);
10439    SET_UniformMatrix2fvARB(table, save_UniformMatrix2fvARB);
10440    SET_UniformMatrix3fvARB(table, save_UniformMatrix3fvARB);
10441    SET_UniformMatrix4fvARB(table, save_UniformMatrix4fvARB);
10442    SET_UniformMatrix2x3fv(table, save_UniformMatrix2x3fv);
10443    SET_UniformMatrix3x2fv(table, save_UniformMatrix3x2fv);
10444    SET_UniformMatrix2x4fv(table, save_UniformMatrix2x4fv);
10445    SET_UniformMatrix4x2fv(table, save_UniformMatrix4x2fv);
10446    SET_UniformMatrix3x4fv(table, save_UniformMatrix3x4fv);
10447    SET_UniformMatrix4x3fv(table, save_UniformMatrix4x3fv);
10448
10449    /* ARB 30/31/32. GL_ARB_shader_objects, GL_ARB_vertex/fragment_shader */
10450    SET_BindAttribLocationARB(table, exec_BindAttribLocationARB);
10451    SET_GetAttribLocationARB(table, exec_GetAttribLocationARB);
10452    SET_GetUniformLocationARB(table, exec_GetUniformLocationARB);
10453    /* XXX additional functions need to be implemented here! */
10454
10455    /* 299. GL_EXT_blend_equation_separate */
10456    SET_BlendEquationSeparateEXT(table, save_BlendEquationSeparateEXT);
10457
10458    /* GL_EXT_gpu_program_parameters */
10459    SET_ProgramEnvParameters4fvEXT(table, save_ProgramEnvParameters4fvEXT);
10460    SET_ProgramLocalParameters4fvEXT(table, save_ProgramLocalParameters4fvEXT);
10461
10462    /* ARB 50. GL_ARB_map_buffer_range */
10463    SET_MapBufferRange(table, _mesa_MapBufferRange); /* no dlist save */
10464    SET_FlushMappedBufferRange(table, _mesa_FlushMappedBufferRange); /* no dl */
10465
10466    /* ARB 51. GL_ARB_texture_buffer_object */
10467    SET_TexBufferARB(table, _mesa_TexBuffer); /* no dlist save */
10468
10469    /* ARB 59. GL_ARB_copy_buffer */
10470    SET_CopyBufferSubData(table, _mesa_CopyBufferSubData); /* no dlist save */
10471
10472    /* 364. GL_EXT_provoking_vertex */
10473    SET_ProvokingVertexEXT(table, save_ProvokingVertexEXT);
10474
10475    /* 371. GL_APPLE_object_purgeable */
10476    SET_ObjectPurgeableAPPLE(table, _mesa_ObjectPurgeableAPPLE);
10477    SET_ObjectUnpurgeableAPPLE(table, _mesa_ObjectUnpurgeableAPPLE);
10478    SET_GetObjectParameterivAPPLE(table, _mesa_GetObjectParameterivAPPLE);
10479
10480    /* GL_EXT_texture_integer */
10481    SET_ClearColorIiEXT(table, save_ClearColorIi);
10482    SET_ClearColorIuiEXT(table, save_ClearColorIui);
10483    SET_TexParameterIivEXT(table, save_TexParameterIiv);
10484    SET_TexParameterIuivEXT(table, save_TexParameterIuiv);
10485    SET_GetTexParameterIivEXT(table, exec_GetTexParameterIiv);
10486    SET_GetTexParameterIuivEXT(table, exec_GetTexParameterIuiv);
10487
10488    /* 377. GL_EXT_separate_shader_objects */
10489    SET_UseShaderProgramEXT(table, save_UseShaderProgramEXT);
10490    SET_ActiveProgramEXT(table, save_ActiveProgramEXT);
10491
10492    /* GL_ARB_color_buffer_float */
10493    SET_ClampColorARB(table, save_ClampColorARB);
10494    SET_ClampColor(table, save_ClampColorARB);
10495
10496    /* GL 3.0 */
10497    SET_ClearBufferiv(table, save_ClearBufferiv);
10498    SET_ClearBufferuiv(table, save_ClearBufferuiv);
10499    SET_ClearBufferfv(table, save_ClearBufferfv);
10500    SET_ClearBufferfi(table, save_ClearBufferfi);
10501 #if 0
10502    SET_Uniform1ui(table, save_Uniform1ui);
10503    SET_Uniform2ui(table, save_Uniform2ui);
10504    SET_Uniform3ui(table, save_Uniform3ui);
10505    SET_Uniform4ui(table, save_Uniform4ui);
10506    SET_Uniform1uiv(table, save_Uniform1uiv);
10507    SET_Uniform2uiv(table, save_Uniform2uiv);
10508    SET_Uniform3uiv(table, save_Uniform3uiv);
10509    SET_Uniform4uiv(table, save_Uniform4uiv);
10510 #else
10511    (void) save_Uniform1ui;
10512    (void) save_Uniform2ui;
10513    (void) save_Uniform3ui;
10514    (void) save_Uniform4ui;
10515    (void) save_Uniform1uiv;
10516    (void) save_Uniform2uiv;
10517    (void) save_Uniform3uiv;
10518    (void) save_Uniform4uiv;
10519 #endif
10520
10521    /* These are not compiled into display lists: */
10522    SET_BindBufferBaseEXT(table, _mesa_BindBufferBase);
10523    SET_BindBufferOffsetEXT(table, _mesa_BindBufferOffsetEXT);
10524    SET_BindBufferRangeEXT(table, _mesa_BindBufferRange);
10525    SET_TransformFeedbackVaryingsEXT(table, _mesa_TransformFeedbackVaryings);
10526    /* These are: */
10527    SET_BeginTransformFeedbackEXT(table, save_BeginTransformFeedback);
10528    SET_EndTransformFeedbackEXT(table, save_EndTransformFeedback);
10529    SET_BindTransformFeedback(table, save_BindTransformFeedback);
10530    SET_PauseTransformFeedback(table, save_PauseTransformFeedback);
10531    SET_ResumeTransformFeedback(table, save_ResumeTransformFeedback);
10532    SET_DrawTransformFeedback(table, save_DrawTransformFeedback);
10533    SET_DrawTransformFeedbackStream(table, save_DrawTransformFeedbackStream);
10534    SET_DrawTransformFeedbackInstanced(table,
10535                                       save_DrawTransformFeedbackInstanced);
10536    SET_DrawTransformFeedbackStreamInstanced(table,
10537                                 save_DrawTransformFeedbackStreamInstanced);
10538    SET_BeginQueryIndexed(table, save_BeginQueryIndexed);
10539    SET_EndQueryIndexed(table, save_EndQueryIndexed);
10540
10541    /* GL_ARB_instanced_arrays */
10542    SET_VertexAttribDivisorARB(table, save_VertexAttribDivisor);
10543
10544    /* GL_NV_texture_barrier */
10545    SET_TextureBarrierNV(table, save_TextureBarrierNV);
10546
10547    /* GL_ARB_sampler_objects */
10548    _mesa_init_sampler_object_dispatch(table); /* plug in Gen/Get/etc functions */
10549    SET_BindSampler(table, save_BindSampler);
10550    SET_SamplerParameteri(table, save_SamplerParameteri);
10551    SET_SamplerParameterf(table, save_SamplerParameterf);
10552    SET_SamplerParameteriv(table, save_SamplerParameteriv);
10553    SET_SamplerParameterfv(table, save_SamplerParameterfv);
10554    SET_SamplerParameterIiv(table, save_SamplerParameterIiv);
10555    SET_SamplerParameterIuiv(table, save_SamplerParameterIuiv);
10556
10557    /* GL_ARB_draw_buffer_blend */
10558    SET_BlendFunciARB(table, save_BlendFunci);
10559    SET_BlendFuncSeparateiARB(table, save_BlendFuncSeparatei);
10560    SET_BlendEquationiARB(table, save_BlendEquationi);
10561    SET_BlendEquationSeparateiARB(table, save_BlendEquationSeparatei);
10562
10563    /* GL_ARB_geometry_shader4 */
10564    SET_ProgramParameteriARB(table, save_ProgramParameteri);
10565    SET_FramebufferTextureARB(table, save_FramebufferTexture);
10566    SET_FramebufferTextureFaceARB(table, save_FramebufferTextureFace);
10567
10568    /* GL_NV_conditional_render */
10569    SET_BeginConditionalRenderNV(table, save_BeginConditionalRender);
10570    SET_EndConditionalRenderNV(table, save_EndConditionalRender);
10571
10572    /* GL_ARB_sync */
10573    _mesa_init_sync_dispatch(table);
10574    SET_WaitSync(table, save_WaitSync);
10575
10576    /* GL_ARB_texture_storage (no dlist support) */
10577    SET_TexStorage1D(table, _mesa_TexStorage1D);
10578    SET_TexStorage2D(table, _mesa_TexStorage2D);
10579    SET_TexStorage3D(table, _mesa_TexStorage3D);
10580    SET_TextureStorage1DEXT(table, _mesa_TextureStorage1DEXT);
10581    SET_TextureStorage2DEXT(table, _mesa_TextureStorage2DEXT);
10582    SET_TextureStorage3DEXT(table, _mesa_TextureStorage3DEXT);
10583
10584    /* GL_ARB_debug_output (no dlist support) */
10585    _mesa_init_errors_dispatch(table);
10586
10587    /* GL_ARB_uniform_buffer_object */
10588    SET_UniformBlockBinding(table, save_UniformBlockBinding);
10589
10590    /* GL_NV_primitive_restart */
10591    SET_PrimitiveRestartIndexNV(table, _mesa_PrimitiveRestartIndex);
10592
10593    return table;
10594 }
10595
10596
10597
10598 static const char *
10599 enum_string(GLenum k)
10600 {
10601    return _mesa_lookup_enum_by_nr(k);
10602 }
10603
10604
10605 /**
10606  * Print the commands in a display list.  For debugging only.
10607  * TODO: many commands aren't handled yet.
10608  */
10609 static void GLAPIENTRY
10610 print_list(struct gl_context *ctx, GLuint list)
10611 {
10612    struct gl_display_list *dlist;
10613    Node *n;
10614    GLboolean done;
10615
10616    if (!islist(ctx, list)) {
10617       printf("%u is not a display list ID\n", list);
10618       return;
10619    }
10620
10621    dlist = lookup_list(ctx, list);
10622    if (!dlist)
10623       return;
10624
10625    n = dlist->Head;
10626
10627    printf("START-LIST %u, address %p\n", list, (void *) n);
10628
10629    done = n ? GL_FALSE : GL_TRUE;
10630    while (!done) {
10631       const OpCode opcode = n[0].opcode;
10632
10633       if (is_ext_opcode(opcode)) {
10634          n += ext_opcode_print(ctx, n);
10635       }
10636       else {
10637          switch (opcode) {
10638          case OPCODE_ACCUM:
10639             printf("Accum %s %g\n", enum_string(n[1].e), n[2].f);
10640             break;
10641          case OPCODE_BITMAP:
10642             printf("Bitmap %d %d %g %g %g %g %p\n", n[1].i, n[2].i,
10643                          n[3].f, n[4].f, n[5].f, n[6].f, (void *) n[7].data);
10644             break;
10645          case OPCODE_CALL_LIST:
10646             printf("CallList %d\n", (int) n[1].ui);
10647             break;
10648          case OPCODE_CALL_LIST_OFFSET:
10649             printf("CallList %d + offset %u = %u\n", (int) n[1].ui,
10650                          ctx->List.ListBase, ctx->List.ListBase + n[1].ui);
10651             break;
10652          case OPCODE_COLOR_TABLE_PARAMETER_FV:
10653             printf("ColorTableParameterfv %s %s %f %f %f %f\n",
10654                          enum_string(n[1].e), enum_string(n[2].e),
10655                          n[3].f, n[4].f, n[5].f, n[6].f);
10656             break;
10657          case OPCODE_COLOR_TABLE_PARAMETER_IV:
10658             printf("ColorTableParameteriv %s %s %d %d %d %d\n",
10659                          enum_string(n[1].e), enum_string(n[2].e),
10660                          n[3].i, n[4].i, n[5].i, n[6].i);
10661             break;
10662          case OPCODE_DISABLE:
10663             printf("Disable %s\n", enum_string(n[1].e));
10664             break;
10665          case OPCODE_ENABLE:
10666             printf("Enable %s\n", enum_string(n[1].e));
10667             break;
10668          case OPCODE_FRUSTUM:
10669             printf("Frustum %g %g %g %g %g %g\n",
10670                          n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
10671             break;
10672          case OPCODE_LINE_STIPPLE:
10673             printf("LineStipple %d %x\n", n[1].i, (int) n[2].us);
10674             break;
10675          case OPCODE_LOAD_IDENTITY:
10676             printf("LoadIdentity\n");
10677             break;
10678          case OPCODE_LOAD_MATRIX:
10679             printf("LoadMatrix\n");
10680             printf("  %8f %8f %8f %8f\n",
10681                          n[1].f, n[5].f, n[9].f, n[13].f);
10682             printf("  %8f %8f %8f %8f\n",
10683                          n[2].f, n[6].f, n[10].f, n[14].f);
10684             printf("  %8f %8f %8f %8f\n",
10685                          n[3].f, n[7].f, n[11].f, n[15].f);
10686             printf("  %8f %8f %8f %8f\n",
10687                          n[4].f, n[8].f, n[12].f, n[16].f);
10688             break;
10689          case OPCODE_MULT_MATRIX:
10690             printf("MultMatrix (or Rotate)\n");
10691             printf("  %8f %8f %8f %8f\n",
10692                          n[1].f, n[5].f, n[9].f, n[13].f);
10693             printf("  %8f %8f %8f %8f\n",
10694                          n[2].f, n[6].f, n[10].f, n[14].f);
10695             printf("  %8f %8f %8f %8f\n",
10696                          n[3].f, n[7].f, n[11].f, n[15].f);
10697             printf("  %8f %8f %8f %8f\n",
10698                          n[4].f, n[8].f, n[12].f, n[16].f);
10699             break;
10700          case OPCODE_ORTHO:
10701             printf("Ortho %g %g %g %g %g %g\n",
10702                          n[1].f, n[2].f, n[3].f, n[4].f, n[5].f, n[6].f);
10703             break;
10704          case OPCODE_POP_ATTRIB:
10705             printf("PopAttrib\n");
10706             break;
10707          case OPCODE_POP_MATRIX:
10708             printf("PopMatrix\n");
10709             break;
10710          case OPCODE_POP_NAME:
10711             printf("PopName\n");
10712             break;
10713          case OPCODE_PUSH_ATTRIB:
10714             printf("PushAttrib %x\n", n[1].bf);
10715             break;
10716          case OPCODE_PUSH_MATRIX:
10717             printf("PushMatrix\n");
10718             break;
10719          case OPCODE_PUSH_NAME:
10720             printf("PushName %d\n", (int) n[1].ui);
10721             break;
10722          case OPCODE_RASTER_POS:
10723             printf("RasterPos %g %g %g %g\n",
10724                          n[1].f, n[2].f, n[3].f, n[4].f);
10725             break;
10726          case OPCODE_ROTATE:
10727             printf("Rotate %g %g %g %g\n",
10728                          n[1].f, n[2].f, n[3].f, n[4].f);
10729             break;
10730          case OPCODE_SCALE:
10731             printf("Scale %g %g %g\n", n[1].f, n[2].f, n[3].f);
10732             break;
10733          case OPCODE_TRANSLATE:
10734             printf("Translate %g %g %g\n", n[1].f, n[2].f, n[3].f);
10735             break;
10736          case OPCODE_BIND_TEXTURE:
10737             printf("BindTexture %s %d\n",
10738                          _mesa_lookup_enum_by_nr(n[1].ui), n[2].ui);
10739             break;
10740          case OPCODE_SHADE_MODEL:
10741             printf("ShadeModel %s\n", _mesa_lookup_enum_by_nr(n[1].ui));
10742             break;
10743          case OPCODE_MAP1:
10744             printf("Map1 %s %.3f %.3f %d %d\n",
10745                          _mesa_lookup_enum_by_nr(n[1].ui),
10746                          n[2].f, n[3].f, n[4].i, n[5].i);
10747             break;
10748          case OPCODE_MAP2:
10749             printf("Map2 %s %.3f %.3f %.3f %.3f %d %d %d %d\n",
10750                          _mesa_lookup_enum_by_nr(n[1].ui),
10751                          n[2].f, n[3].f, n[4].f, n[5].f,
10752                          n[6].i, n[7].i, n[8].i, n[9].i);
10753             break;
10754          case OPCODE_MAPGRID1:
10755             printf("MapGrid1 %d %.3f %.3f\n", n[1].i, n[2].f, n[3].f);
10756             break;
10757          case OPCODE_MAPGRID2:
10758             printf("MapGrid2 %d %.3f %.3f, %d %.3f %.3f\n",
10759                          n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f);
10760             break;
10761          case OPCODE_EVALMESH1:
10762             printf("EvalMesh1 %d %d\n", n[1].i, n[2].i);
10763             break;
10764          case OPCODE_EVALMESH2:
10765             printf("EvalMesh2 %d %d %d %d\n",
10766                          n[1].i, n[2].i, n[3].i, n[4].i);
10767             break;
10768
10769          case OPCODE_ATTR_1F_NV:
10770             printf("ATTR_1F_NV attr %d: %f\n", n[1].i, n[2].f);
10771             break;
10772          case OPCODE_ATTR_2F_NV:
10773             printf("ATTR_2F_NV attr %d: %f %f\n",
10774                          n[1].i, n[2].f, n[3].f);
10775             break;
10776          case OPCODE_ATTR_3F_NV:
10777             printf("ATTR_3F_NV attr %d: %f %f %f\n",
10778                          n[1].i, n[2].f, n[3].f, n[4].f);
10779             break;
10780          case OPCODE_ATTR_4F_NV:
10781             printf("ATTR_4F_NV attr %d: %f %f %f %f\n",
10782                          n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
10783             break;
10784          case OPCODE_ATTR_1F_ARB:
10785             printf("ATTR_1F_ARB attr %d: %f\n", n[1].i, n[2].f);
10786             break;
10787          case OPCODE_ATTR_2F_ARB:
10788             printf("ATTR_2F_ARB attr %d: %f %f\n",
10789                          n[1].i, n[2].f, n[3].f);
10790             break;
10791          case OPCODE_ATTR_3F_ARB:
10792             printf("ATTR_3F_ARB attr %d: %f %f %f\n",
10793                          n[1].i, n[2].f, n[3].f, n[4].f);
10794             break;
10795          case OPCODE_ATTR_4F_ARB:
10796             printf("ATTR_4F_ARB attr %d: %f %f %f %f\n",
10797                          n[1].i, n[2].f, n[3].f, n[4].f, n[5].f);
10798             break;
10799
10800          case OPCODE_MATERIAL:
10801             printf("MATERIAL %x %x: %f %f %f %f\n",
10802                          n[1].i, n[2].i, n[3].f, n[4].f, n[5].f, n[6].f);
10803             break;
10804          case OPCODE_BEGIN:
10805             printf("BEGIN %x\n", n[1].i);
10806             break;
10807          case OPCODE_END:
10808             printf("END\n");
10809             break;
10810          case OPCODE_RECTF:
10811             printf("RECTF %f %f %f %f\n", n[1].f, n[2].f, n[3].f,
10812                          n[4].f);
10813             break;
10814          case OPCODE_EVAL_C1:
10815             printf("EVAL_C1 %f\n", n[1].f);
10816             break;
10817          case OPCODE_EVAL_C2:
10818             printf("EVAL_C2 %f %f\n", n[1].f, n[2].f);
10819             break;
10820          case OPCODE_EVAL_P1:
10821             printf("EVAL_P1 %d\n", n[1].i);
10822             break;
10823          case OPCODE_EVAL_P2:
10824             printf("EVAL_P2 %d %d\n", n[1].i, n[2].i);
10825             break;
10826
10827          case OPCODE_PROVOKING_VERTEX:
10828             printf("ProvokingVertex %s\n",
10829                          _mesa_lookup_enum_by_nr(n[1].ui));
10830             break;
10831
10832             /*
10833              * meta opcodes/commands
10834              */
10835          case OPCODE_ERROR:
10836             printf("Error: %s %s\n",
10837                          enum_string(n[1].e), (const char *) n[2].data);
10838             break;
10839          case OPCODE_CONTINUE:
10840             printf("DISPLAY-LIST-CONTINUE\n");
10841             n = (Node *) n[1].next;
10842             break;
10843          case OPCODE_END_OF_LIST:
10844             printf("END-LIST %u\n", list);
10845             done = GL_TRUE;
10846             break;
10847          default:
10848             if (opcode < 0 || opcode > OPCODE_END_OF_LIST) {
10849                printf
10850                   ("ERROR IN DISPLAY LIST: opcode = %d, address = %p\n",
10851                    opcode, (void *) n);
10852                return;
10853             }
10854             else {
10855                printf("command %d, %u operands\n", opcode,
10856                             InstSize[opcode]);
10857             }
10858          }
10859          /* increment n to point to next compiled command */
10860          if (opcode != OPCODE_CONTINUE) {
10861             n += InstSize[opcode];
10862          }
10863       }
10864    }
10865 }
10866
10867
10868
10869 /**
10870  * Clients may call this function to help debug display list problems.
10871  * This function is _ONLY_FOR_DEBUGGING_PURPOSES_.  It may be removed,
10872  * changed, or break in the future without notice.
10873  */
10874 void
10875 mesa_print_display_list(GLuint list)
10876 {
10877    GET_CURRENT_CONTEXT(ctx);
10878    print_list(ctx, list);
10879 }
10880
10881
10882 /**********************************************************************/
10883 /*****                      Initialization                        *****/
10884 /**********************************************************************/
10885
10886 void
10887 _mesa_save_vtxfmt_init(GLvertexformat * vfmt)
10888 {
10889    _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
10890
10891    vfmt->Begin = save_Begin;
10892
10893    _MESA_INIT_DLIST_VTXFMT(vfmt, save_);
10894
10895    vfmt->Color3f = save_Color3f;
10896    vfmt->Color3fv = save_Color3fv;
10897    vfmt->Color4f = save_Color4f;
10898    vfmt->Color4fv = save_Color4fv;
10899    vfmt->EdgeFlag = save_EdgeFlag;
10900    vfmt->End = save_End;
10901
10902    _MESA_INIT_EVAL_VTXFMT(vfmt, save_);
10903
10904    vfmt->FogCoordfEXT = save_FogCoordfEXT;
10905    vfmt->FogCoordfvEXT = save_FogCoordfvEXT;
10906    vfmt->Indexf = save_Indexf;
10907    vfmt->Indexfv = save_Indexfv;
10908    vfmt->Materialfv = save_Materialfv;
10909    vfmt->MultiTexCoord1fARB = save_MultiTexCoord1f;
10910    vfmt->MultiTexCoord1fvARB = save_MultiTexCoord1fv;
10911    vfmt->MultiTexCoord2fARB = save_MultiTexCoord2f;
10912    vfmt->MultiTexCoord2fvARB = save_MultiTexCoord2fv;
10913    vfmt->MultiTexCoord3fARB = save_MultiTexCoord3f;
10914    vfmt->MultiTexCoord3fvARB = save_MultiTexCoord3fv;
10915    vfmt->MultiTexCoord4fARB = save_MultiTexCoord4f;
10916    vfmt->MultiTexCoord4fvARB = save_MultiTexCoord4fv;
10917    vfmt->Normal3f = save_Normal3f;
10918    vfmt->Normal3fv = save_Normal3fv;
10919    vfmt->SecondaryColor3fEXT = save_SecondaryColor3fEXT;
10920    vfmt->SecondaryColor3fvEXT = save_SecondaryColor3fvEXT;
10921    vfmt->TexCoord1f = save_TexCoord1f;
10922    vfmt->TexCoord1fv = save_TexCoord1fv;
10923    vfmt->TexCoord2f = save_TexCoord2f;
10924    vfmt->TexCoord2fv = save_TexCoord2fv;
10925    vfmt->TexCoord3f = save_TexCoord3f;
10926    vfmt->TexCoord3fv = save_TexCoord3fv;
10927    vfmt->TexCoord4f = save_TexCoord4f;
10928    vfmt->TexCoord4fv = save_TexCoord4fv;
10929    vfmt->Vertex2f = save_Vertex2f;
10930    vfmt->Vertex2fv = save_Vertex2fv;
10931    vfmt->Vertex3f = save_Vertex3f;
10932    vfmt->Vertex3fv = save_Vertex3fv;
10933    vfmt->Vertex4f = save_Vertex4f;
10934    vfmt->Vertex4fv = save_Vertex4fv;
10935    vfmt->VertexAttrib1fNV = save_VertexAttrib1fNV;
10936    vfmt->VertexAttrib1fvNV = save_VertexAttrib1fvNV;
10937    vfmt->VertexAttrib2fNV = save_VertexAttrib2fNV;
10938    vfmt->VertexAttrib2fvNV = save_VertexAttrib2fvNV;
10939    vfmt->VertexAttrib3fNV = save_VertexAttrib3fNV;
10940    vfmt->VertexAttrib3fvNV = save_VertexAttrib3fvNV;
10941    vfmt->VertexAttrib4fNV = save_VertexAttrib4fNV;
10942    vfmt->VertexAttrib4fvNV = save_VertexAttrib4fvNV;
10943    vfmt->VertexAttrib1fARB = save_VertexAttrib1fARB;
10944    vfmt->VertexAttrib1fvARB = save_VertexAttrib1fvARB;
10945    vfmt->VertexAttrib2fARB = save_VertexAttrib2fARB;
10946    vfmt->VertexAttrib2fvARB = save_VertexAttrib2fvARB;
10947    vfmt->VertexAttrib3fARB = save_VertexAttrib3fARB;
10948    vfmt->VertexAttrib3fvARB = save_VertexAttrib3fvARB;
10949    vfmt->VertexAttrib4fARB = save_VertexAttrib4fARB;
10950    vfmt->VertexAttrib4fvARB = save_VertexAttrib4fvARB;
10951
10952    vfmt->Rectf = save_Rectf;
10953
10954    /* GL_ARB_draw_instanced */
10955    vfmt->DrawArraysInstanced = save_DrawArraysInstancedARB;
10956    vfmt->DrawElementsInstanced = save_DrawElementsInstancedARB;
10957
10958    /* GL_ARB_draw_elements_base_vertex */
10959    vfmt->DrawElementsInstancedBaseVertex = save_DrawElementsInstancedBaseVertexARB;
10960
10961    /* GL_ARB_base_instance */
10962    vfmt->DrawArraysInstancedBaseInstance = save_DrawArraysInstancedBaseInstance;
10963    vfmt->DrawElementsInstancedBaseInstance = save_DrawElementsInstancedBaseInstance;
10964    vfmt->DrawElementsInstancedBaseVertexBaseInstance = save_DrawElementsInstancedBaseVertexBaseInstance;
10965
10966    /* The driver is required to implement these as
10967     * 1) They can probably do a better job.
10968     * 2) A lot of new mechanisms would have to be added to this module
10969     *     to support it.  That code would probably never get used,
10970     *     because of (1).
10971     */
10972 #if 0
10973    vfmt->DrawArrays = 0;
10974    vfmt->DrawElements = 0;
10975    vfmt->DrawRangeElements = 0;
10976    vfmt->MultiDrawElemementsEXT = 0;
10977    vfmt->DrawElementsBaseVertex = 0;
10978    vfmt->DrawRangeElementsBaseVertex = 0;
10979    vfmt->MultiDrawElemementsBaseVertex = 0;
10980 #endif
10981 }
10982
10983
10984 void
10985 _mesa_install_dlist_vtxfmt(struct _glapi_table *disp,
10986                            const GLvertexformat *vfmt)
10987 {
10988    SET_CallList(disp, vfmt->CallList);
10989    SET_CallLists(disp, vfmt->CallLists);
10990 }
10991
10992
10993 void _mesa_init_dlist_dispatch(struct _glapi_table *disp)
10994 {
10995    SET_CallList(disp, _mesa_CallList);
10996    SET_CallLists(disp, _mesa_CallLists);
10997
10998    SET_DeleteLists(disp, _mesa_DeleteLists);
10999    SET_EndList(disp, _mesa_EndList);
11000    SET_GenLists(disp, _mesa_GenLists);
11001    SET_IsList(disp, _mesa_IsList);
11002    SET_ListBase(disp, _mesa_ListBase);
11003    SET_NewList(disp, _mesa_NewList);
11004 }
11005
11006
11007 /**
11008  * Initialize display list state for given context.
11009  */
11010 void
11011 _mesa_init_display_list(struct gl_context *ctx)
11012 {
11013    static GLboolean tableInitialized = GL_FALSE;
11014
11015    /* zero-out the instruction size table, just once */
11016    if (!tableInitialized) {
11017       memset(InstSize, 0, sizeof(InstSize));
11018       tableInitialized = GL_TRUE;
11019    }
11020
11021    /* extension info */
11022    ctx->ListExt = CALLOC_STRUCT(gl_list_extensions);
11023
11024    /* Display list */
11025    ctx->ListState.CallDepth = 0;
11026    ctx->ExecuteFlag = GL_TRUE;
11027    ctx->CompileFlag = GL_FALSE;
11028    ctx->ListState.CurrentBlock = NULL;
11029    ctx->ListState.CurrentPos = 0;
11030
11031    /* Display List group */
11032    ctx->List.ListBase = 0;
11033
11034    _mesa_save_vtxfmt_init(&ctx->ListState.ListVtxfmt);
11035 }
11036
11037
11038 void
11039 _mesa_free_display_list_data(struct gl_context *ctx)
11040 {
11041    free(ctx->ListExt);
11042    ctx->ListExt = NULL;
11043 }