home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / attrib.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  36KB  |  870 lines

  1. /* $Id: attrib.c,v 1.10.2.3 1999/12/12 18:30:47 keithw Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  * 
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  * 
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  * 
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26.  
  27.  
  28.  
  29. #include <stdlib.h>
  30.  
  31. #ifdef PC_HEADER
  32. #include "all.h"
  33. #else
  34. #ifndef XFree86Server
  35. #include <stdio.h>
  36. #else
  37. #include "GL/xf86glx.h"
  38. #endif
  39. #include "attrib.h"
  40. #include "context.h"
  41. #include "glmisc.h"
  42. #include "enable.h"
  43. #include "enums.h"
  44. #include "macros.h"
  45. #include "simple_list.h"
  46. #include "texstate.h"
  47. #include "types.h"
  48. #endif
  49.  
  50.  
  51.  
  52.  
  53. /*
  54.  * Allocate a new attribute state node.  These nodes have a
  55.  * "kind" value and a pointer to a struct of state data.
  56.  */
  57. static struct gl_attrib_node *new_attrib_node( GLbitfield kind )
  58. {
  59.    struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
  60.    if (an) {
  61.       an->kind = kind;
  62.    }
  63.    return an;
  64. }
  65.  
  66.  
  67.  
  68. /*
  69.  * Copy texture object state from one texture object to another.
  70.  */
  71. static void copy_texobj_state( struct gl_texture_object *dest,
  72.                                const struct gl_texture_object *src )
  73. {
  74.    /*
  75.    dest->Name = src->Name;
  76.    dest->Dimensions = src->Dimensions;
  77.    */
  78.    dest->Priority = src->Priority;
  79.    dest->BorderColor[0] = src->BorderColor[0];
  80.    dest->BorderColor[1] = src->BorderColor[1];
  81.    dest->BorderColor[2] = src->BorderColor[2];
  82.    dest->BorderColor[3] = src->BorderColor[3];
  83.    dest->WrapS = src->WrapS;
  84.    dest->WrapT = src->WrapT;
  85.    dest->WrapR = src->WrapR;
  86.    dest->MinFilter = src->MinFilter;
  87.    dest->MagFilter = src->MagFilter;
  88.    dest->MinLod = src->MinLod;
  89.    dest->MaxLod = src->MaxLod;
  90.    dest->BaseLevel = src->BaseLevel;
  91.    dest->MaxLevel = src->MaxLevel;
  92.    dest->P = src->P;
  93.    dest->M = src->M;
  94.    dest->MinMagThresh = src->MinMagThresh;
  95.    memcpy( dest->Palette, src->Palette,
  96.            sizeof(GLubyte) * MAX_TEXTURE_PALETTE_SIZE * 4 );
  97.    dest->PaletteSize = src->PaletteSize;
  98.    dest->PaletteIntFormat = src->PaletteIntFormat;
  99.    dest->PaletteFormat = src->PaletteFormat;
  100.    dest->Complete = src->Complete;
  101.    dest->SampleFunc = src->SampleFunc;
  102. }
  103.  
  104.  
  105.  
  106. void gl_PushAttrib( GLcontext* ctx, GLbitfield mask )
  107. {
  108.    struct gl_attrib_node *newnode;
  109.    struct gl_attrib_node *head;
  110.  
  111.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
  112.  
  113.    if (MESA_VERBOSE&VERBOSE_API)
  114.       fprintf(stderr, "glPushAttrib %x\n", mask);
  115.  
  116.    if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
  117.       gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
  118.       return;
  119.    }
  120.  
  121.    /* Build linked list of attribute nodes which save all attribute */
  122.    /* groups specified by the mask. */
  123.    head = NULL;
  124.  
  125.    if (mask & GL_ACCUM_BUFFER_BIT) {
  126.       struct gl_accum_attrib *attr;
  127.       attr = MALLOC_STRUCT( gl_accum_attrib );
  128.       MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
  129.       newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
  130.       newnode->data = attr;
  131.       newnode->next = head;
  132.       head = newnode;
  133.    }
  134.  
  135.    if (mask & GL_COLOR_BUFFER_BIT) {
  136.       struct gl_colorbuffer_attrib *attr;
  137.       attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
  138.       MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
  139.       newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
  140.       newnode->data = attr;
  141.       newnode->next = head;
  142.       head = newnode;
  143.    }
  144.  
  145.    if (mask & GL_CURRENT_BIT) {
  146.       struct gl_current_attrib *attr;
  147.       attr = MALLOC_STRUCT( gl_current_attrib );
  148.       MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
  149.       newnode = new_attrib_node( GL_CURRENT_BIT );
  150.       newnode->data = attr;
  151.       newnode->next = head;
  152.       head = newnode;
  153.    }
  154.  
  155.    if (mask & GL_DEPTH_BUFFER_BIT) {
  156.       struct gl_depthbuffer_attrib *attr;
  157.       attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
  158.       MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
  159.       newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
  160.       newnode->data = attr;
  161.       newnode->next = head;
  162.       head = newnode;
  163.    }
  164.  
  165.    if (mask & GL_ENABLE_BIT) {
  166.       struct gl_enable_attrib *attr;
  167.       GLuint i;
  168.       attr = MALLOC_STRUCT( gl_enable_attrib );
  169.       /* Copy enable flags from all other attributes into the enable struct. */
  170.       attr->AlphaTest = ctx->Color.AlphaEnabled;
  171.       attr->AutoNormal = ctx->Eval.AutoNormal;
  172.       attr->Blend = ctx->Color.BlendEnabled;
  173.       for (i=0;i<MAX_CLIP_PLANES;i++) {
  174.          attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
  175.       }
  176.       attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
  177.       attr->CullFace = ctx->Polygon.CullFlag;
  178.       attr->DepthTest = ctx->Depth.Test;
  179.       attr->Dither = ctx->Color.DitherFlag;
  180.       attr->Fog = ctx->Fog.Enabled;
  181.       for (i=0;i<MAX_LIGHTS;i++) {
  182.          attr->Light[i] = ctx->Light.Light[i].Enabled;
  183.       }
  184.       attr->Lighting = ctx->Light.Enabled;
  185.       attr->LineSmooth = ctx->Line.SmoothFlag;
  186.       attr->LineStipple = ctx->Line.StippleFlag;
  187.       attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
  188.       attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
  189.       attr->Map1Color4 = ctx->Eval.Map1Color4;
  190.       attr->Map1Index = ctx->Eval.Map1Index;
  191.       attr->Map1Normal = ctx->Eval.Map1Normal;
  192.       attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
  193.       attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
  194.       attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
  195.       attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
  196.       attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
  197.       attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
  198.       attr->Map2Color4 = ctx->Eval.Map2Color4;
  199.       attr->Map2Index = ctx->Eval.Map2Index;
  200.       attr->Map2Normal = ctx->Eval.Map2Normal;
  201.       attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
  202.       attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
  203.       attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
  204.       attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
  205.       attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
  206.       attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
  207.       attr->Normalize = ctx->Transform.Normalize;
  208.       attr->PointSmooth = ctx->Point.SmoothFlag;
  209.       attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
  210.       attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
  211.       attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
  212.       attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
  213.       attr->PolygonStipple = ctx->Polygon.StippleFlag;
  214.       attr->RescaleNormals = ctx->Transform.RescaleNormals;
  215.       attr->Scissor = ctx->Scissor.Enabled;
  216.       attr->Stencil = ctx->Stencil.Enabled;
  217.       attr->Texture = ctx->Texture.Enabled;
  218.       for (i=0; i<MAX_TEXTURE_UNITS; i++) {
  219.          attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
  220.       }
  221.       newnode = new_attrib_node( GL_ENABLE_BIT );
  222.       newnode->data = attr;
  223.       newnode->next = head;
  224.       head = newnode;
  225.    }
  226.  
  227.    if (mask & GL_EVAL_BIT) {
  228.       struct gl_eval_attrib *attr;
  229.       attr = MALLOC_STRUCT( gl_eval_attrib );
  230.       MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
  231.       newnode = new_attrib_node( GL_EVAL_BIT );
  232.       newnode->data = attr;
  233.       newnode->next = head;
  234.       head = newnode;
  235.    }
  236.  
  237.    if (mask & GL_FOG_BIT) {
  238.       struct gl_fog_attrib *attr;
  239.       attr = MALLOC_STRUCT( gl_fog_attrib );
  240.       MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
  241.       newnode = new_attrib_node( GL_FOG_BIT );
  242.       newnode->data = attr;
  243.       newnode->next = head;
  244.       head = newnode;
  245.    }
  246.  
  247.    if (mask & GL_HINT_BIT) {
  248.       struct gl_hint_attrib *attr;
  249.       attr = MALLOC_STRUCT( gl_hint_attrib );
  250.       MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
  251.       newnode = new_attrib_node( GL_HINT_BIT );
  252.       newnode->data = attr;
  253.       newnode->next = head;
  254.       head = newnode;
  255.    }
  256.  
  257.    if (mask & GL_LIGHTING_BIT) {
  258.       struct gl_light_attrib *attr;
  259.       attr = MALLOC_STRUCT( gl_light_attrib );
  260.       MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
  261.       newnode = new_attrib_node( GL_LIGHTING_BIT );
  262.       newnode->data = attr;
  263.       newnode->next = head;
  264.       head = newnode;
  265.    }
  266.  
  267.    if (mask & GL_LINE_BIT) {
  268.       struct gl_line_attrib *attr;
  269.       attr = MALLOC_STRUCT( gl_line_attrib );
  270.       MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
  271.       newnode = new_attrib_node( GL_LINE_BIT );
  272.       newnode->data = attr;
  273.       newnode->next = head;
  274.       head = newnode;
  275.    }
  276.  
  277.    if (mask & GL_LIST_BIT) {
  278.       struct gl_list_attrib *attr;
  279.       attr = MALLOC_STRUCT( gl_list_attrib );
  280.       MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
  281.       newnode = new_attrib_node( GL_LIST_BIT );
  282.       newnode->data = attr;
  283.       newnode->next = head;
  284.       head = newnode;
  285.    }
  286.  
  287.    if (mask & GL_PIXEL_MODE_BIT) {
  288.       struct gl_pixel_attrib *attr;
  289.       attr = MALLOC_STRUCT( gl_pixel_attrib );
  290.       MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
  291.       newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
  292.       newnode->data = attr;
  293.       newnode->next = head;
  294.       head = newnode;
  295.    }
  296.  
  297.    if (mask & GL_POINT_BIT) {
  298.       struct gl_point_attrib *attr;
  299.       attr = MALLOC_STRUCT( gl_point_attrib );
  300.       MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
  301.       newnode = new_attrib_node( GL_POINT_BIT );
  302.       newnode->data = attr;
  303.       newnode->next = head;
  304.       head = newnode;
  305.    }
  306.  
  307.    if (mask & GL_POLYGON_BIT) {
  308.       struct gl_polygon_attrib *attr;
  309.       attr = MALLOC_STRUCT( gl_polygon_attrib );
  310.       MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
  311.       newnode = new_attrib_node( GL_POLYGON_BIT );
  312.       newnode->data = attr;
  313.       newnode->next = head;
  314.       head = newnode;
  315.    }
  316.  
  317.    if (mask & GL_POLYGON_STIPPLE_BIT) {
  318.       GLuint *stipple;
  319.       stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
  320.       MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
  321.       newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
  322.       newnode->data = stipple;
  323.       newnode->next = head;
  324.       head = newnode;
  325.    }
  326.  
  327.    if (mask & GL_SCISSOR_BIT) {
  328.       struct gl_scissor_attrib *attr;
  329.       attr = MALLOC_STRUCT( gl_scissor_attrib );
  330.       MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
  331.       newnode = new_attrib_node( GL_SCISSOR_BIT );
  332.       newnode->data = attr;
  333.       newnode->next = head;
  334.       head = newnode;
  335.    }
  336.  
  337.    if (mask & GL_STENCIL_BUFFER_BIT) {
  338.       struct gl_stencil_attrib *attr;
  339.       attr = MALLOC_STRUCT( gl_stencil_attrib );
  340.       MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
  341.       newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
  342.       newnode->data = attr;
  343.       newnode->next = head;
  344.       head = newnode;
  345.    }
  346.  
  347.    if (mask & GL_TEXTURE_BIT) {
  348.       struct gl_texture_attrib *attr;
  349.       GLuint u;
  350.       /* Take care of texture object reference counters */
  351.       for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  352.      ctx->Texture.Unit[u].CurrentD[1]->RefCount++;
  353.      ctx->Texture.Unit[u].CurrentD[2]->RefCount++;
  354.      ctx->Texture.Unit[u].CurrentD[3]->RefCount++;
  355.       }
  356.       attr = MALLOC_STRUCT( gl_texture_attrib );
  357.       MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
  358.       /* copy state of the currently bound texture objects */
  359.       for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  360.          copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]);
  361.          copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]);
  362.          copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]);
  363.       }
  364.       newnode = new_attrib_node( GL_TEXTURE_BIT );
  365.       newnode->data = attr;
  366.       newnode->next = head;
  367.       head = newnode;
  368.    }
  369.  
  370.    if (mask & GL_TRANSFORM_BIT) {
  371.       struct gl_transform_attrib *attr;
  372.       attr = MALLOC_STRUCT( gl_transform_attrib );
  373.       MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
  374.       newnode = new_attrib_node( GL_TRANSFORM_BIT );
  375.       newnode->data = attr;
  376.       newnode->next = head;
  377.       head = newnode;
  378.    }
  379.  
  380.    if (mask & GL_VIEWPORT_BIT) {
  381.       struct gl_viewport_attrib *attr;
  382.       attr = MALLOC_STRUCT( gl_viewport_attrib );
  383.       MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
  384.       newnode = new_attrib_node( GL_VIEWPORT_BIT );
  385.       newnode->data = attr;
  386.       newnode->next = head;
  387.       head = newnode;
  388.    }
  389.  
  390.    ctx->AttribStack[ctx->AttribStackDepth] = head;
  391.    ctx->AttribStackDepth++;
  392. }
  393.  
  394.  
  395.  
  396. /*
  397.  * This function is kind of long just because we have to call a lot
  398.  * of device driver functions to update device driver state.
  399.  */
  400. void gl_PopAttrib( GLcontext* ctx )
  401. {
  402.    struct gl_attrib_node *attr, *next;
  403.  
  404.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
  405.  
  406.  
  407.    if (ctx->AttribStackDepth==0) {
  408.       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
  409.       return;
  410.    }
  411.  
  412.    ctx->AttribStackDepth--;
  413.    attr = ctx->AttribStack[ctx->AttribStackDepth];
  414.  
  415.    while (attr) {
  416.  
  417.       if (MESA_VERBOSE&VERBOSE_API)
  418.      fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind));
  419.  
  420.       switch (attr->kind) {
  421.          case GL_ACCUM_BUFFER_BIT:
  422.             MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
  423.             break;
  424.          case GL_COLOR_BUFFER_BIT:
  425.             {
  426.                GLenum oldDrawBuffer = ctx->Color.DrawBuffer;
  427.                GLenum oldAlphaFunc = ctx->Color.AlphaFunc;
  428.                GLubyte oldAlphaRef = ctx->Color.AlphaRef;
  429.                GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
  430.                GLenum oldBlendDst = ctx->Color.BlendDstRGB;
  431.            GLenum oldLogicOp = ctx->Color.LogicOp;
  432.                MEMCPY( &ctx->Color, attr->data,
  433.                        sizeof(struct gl_colorbuffer_attrib) );
  434.                if (ctx->Color.DrawBuffer != oldDrawBuffer) {
  435.                   gl_DrawBuffer(ctx, ctx->Color.DrawBuffer);
  436.                }
  437.                if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
  438.                     ctx->Color.AlphaRef != oldAlphaRef) &&
  439.                    ctx->Driver.AlphaFunc)
  440.                   (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
  441.                                             ctx->Color.AlphaRef / 255.0F);
  442.                if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
  443.                     ctx->Color.BlendSrcRGB != oldBlendDst) &&
  444.                    ctx->Driver.BlendFunc)
  445.                   (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
  446.                                             ctx->Color.BlendDstRGB);
  447.            if (ctx->Color.LogicOp != oldLogicOp &&
  448.            ctx->Driver.LogicOpcode)
  449.           ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
  450.             }
  451.             break;
  452.          case GL_CURRENT_BIT:
  453.             MEMCPY( &ctx->Current, attr->data,
  454.             sizeof(struct gl_current_attrib) );
  455.             break;
  456.          case GL_DEPTH_BUFFER_BIT:
  457.             {
  458.                GLenum oldDepthFunc = ctx->Depth.Func;
  459.                GLboolean oldDepthMask = ctx->Depth.Mask;
  460.                GLfloat oldDepthClear = ctx->Depth.Clear;
  461.                MEMCPY( &ctx->Depth, attr->data,
  462.                        sizeof(struct gl_depthbuffer_attrib) );
  463.                if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
  464.                   (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func );
  465.                if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask)
  466.                   (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask );
  467.                if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth)
  468.                   (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
  469.             }
  470.             break;
  471.          case GL_ENABLE_BIT:
  472.             {
  473.                const struct gl_enable_attrib *enable;
  474.                enable = (const struct gl_enable_attrib *) attr->data;
  475.  
  476. #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM)        \
  477.     if ((VALUE) != (NEWVALUE)) {            \
  478.        gl_set_enable( ctx, ENUM, (NEWVALUE) );    \
  479.     }
  480.  
  481.                TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
  482.                TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
  483.                TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
  484.                {
  485.                   GLuint i;
  486.                   for (i=0;i<MAX_CLIP_PLANES;i++) {
  487.                      if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
  488.                         gl_set_enable( ctx, (GLenum) (GL_CLIP_PLANE0 + i), enable->ClipPlane[i] );
  489.                   }
  490.                }
  491.                TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, GL_COLOR_MATERIAL);
  492.                TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
  493.                TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
  494.                TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
  495.                TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
  496.                TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
  497.                TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
  498.                TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, GL_LINE_STIPPLE);
  499.                TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, GL_INDEX_LOGIC_OP);
  500.                TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, GL_COLOR_LOGIC_OP);
  501.                TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
  502.                TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
  503.                TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
  504.                TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, GL_MAP1_TEXTURE_COORD_1);
  505.                TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, GL_MAP1_TEXTURE_COORD_2);
  506.                TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, GL_MAP1_TEXTURE_COORD_3);
  507.                TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, GL_MAP1_TEXTURE_COORD_4);
  508.                TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, GL_MAP1_VERTEX_3);
  509.                TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, GL_MAP1_VERTEX_4);
  510.                TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
  511.                TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
  512.                TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
  513.                TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, GL_MAP2_TEXTURE_COORD_1);
  514.                TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, GL_MAP2_TEXTURE_COORD_2);
  515.                TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, GL_MAP2_TEXTURE_COORD_3);
  516.                TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, GL_MAP2_TEXTURE_COORD_4);
  517.                TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, GL_MAP2_VERTEX_3);
  518.                TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, GL_MAP2_VERTEX_4);
  519.                TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
  520.                TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, GL_RESCALE_NORMAL_EXT);
  521.                TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, GL_POINT_SMOOTH);
  522.                TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, GL_POLYGON_OFFSET_POINT);
  523.                TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, GL_POLYGON_OFFSET_LINE);
  524.                TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, GL_POLYGON_OFFSET_FILL);
  525.                TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, GL_POLYGON_SMOOTH);
  526.                TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, GL_POLYGON_STIPPLE);
  527.                TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
  528.                TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
  529.                if (ctx->Texture.Enabled != enable->Texture) {
  530.                   ctx->Texture.Enabled = enable->Texture;
  531.                   if (ctx->Driver.Enable) {
  532.                      if (ctx->Driver.ActiveTexture)
  533.                         (*ctx->Driver.ActiveTexture)( ctx, 0 );
  534.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE0_1D) );
  535.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE0_2D) );
  536.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE0_3D) );
  537.                      if (ctx->Driver.ActiveTexture)
  538.                         (*ctx->Driver.ActiveTexture)( ctx, 1 );
  539.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE1_1D) );
  540.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE1_2D) );
  541.                      (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE1_3D) );
  542.                      if (ctx->Driver.ActiveTexture)
  543.                         (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
  544.                   }
  545.                }
  546. #undef TEST_AND_UPDATE
  547.                {
  548.                   GLuint i;
  549.                   for (i=0; i<MAX_TEXTURE_UNITS; i++) {
  550.                      if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
  551.                         ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
  552.  
  553.             /* ctx->Enabled recalculated in state change
  554.                            processing */
  555.             
  556.                         if (ctx->Driver.Enable) {
  557.                            if (ctx->Driver.ActiveTexture)
  558.                               (*ctx->Driver.ActiveTexture)( ctx, i );
  559.                            if (enable->TexGen[i] & S_BIT)
  560.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
  561.                            else
  562.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
  563.                            if (enable->TexGen[i] & T_BIT)
  564.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
  565.                            else
  566.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
  567.                            if (enable->TexGen[i] & R_BIT)
  568.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
  569.                            else
  570.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
  571.                            if (enable->TexGen[i] & Q_BIT)
  572.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
  573.                            else
  574.                               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
  575.                         }
  576.                      }
  577.                   }
  578.                   if (ctx->Driver.ActiveTexture)
  579.                      (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
  580.                }
  581.             }
  582.             break;
  583.          case GL_EVAL_BIT:
  584.             MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
  585.             break;
  586.          case GL_FOG_BIT:
  587.             {
  588.                GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
  589.                MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
  590.                if (anyChange && ctx->Driver.Fogfv) {
  591.                   const GLfloat mode = (GLfloat) ctx->Fog.Mode;
  592.                   const GLfloat density = ctx->Fog.Density;
  593.                   const GLfloat start = ctx->Fog.Start;
  594.                   const GLfloat end = ctx->Fog.End;
  595.                   const GLfloat index = ctx->Fog.Index;
  596.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode);
  597.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density );
  598.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start );
  599.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end );
  600.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
  601.                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
  602.                }
  603.            ctx->Enabled &= ~ENABLE_FOG;
  604.            if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
  605.             }
  606.             break;
  607.          case GL_HINT_BIT:
  608.             MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
  609.             if (ctx->Driver.Hint) {
  610.                (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
  611.                                     ctx->Hint.PerspectiveCorrection );
  612.                (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT,
  613.                                     ctx->Hint.PointSmooth);
  614.                (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT,
  615.                                     ctx->Hint.LineSmooth );
  616.                (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT,
  617.                                     ctx->Hint.PolygonSmooth );
  618.                (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog );
  619.             }
  620.             break;
  621.          case GL_LIGHTING_BIT:
  622.             MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
  623.             if (ctx->Driver.Enable) {
  624.                GLuint i;
  625.                for (i = 0; i < MAX_LIGHTS; i++) {
  626.                   GLenum light = (GLenum) (GL_LIGHT0 + i);
  627.                   (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled );
  628.                }
  629.                (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
  630.             }
  631.             if (ctx->Light.ShadeModel == GL_FLAT)
  632.                ctx->TriangleCaps |= DD_FLATSHADE;
  633.             else
  634.                ctx->TriangleCaps &= ~DD_FLATSHADE;
  635.             if (ctx->Driver.ShadeModel)
  636.                (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
  637.         ctx->Enabled &= ~ENABLE_LIGHT;
  638.         if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
  639.            ctx->Enabled |= ENABLE_LIGHT;
  640.             break;
  641.          case GL_LINE_BIT:
  642.             MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
  643.             if (ctx->Driver.Enable) {
  644.                (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
  645.                (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
  646.             }
  647.             break;
  648.          case GL_LIST_BIT:
  649.             MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
  650.             break;
  651.          case GL_PIXEL_MODE_BIT:
  652.             MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
  653.             break;
  654.          case GL_POINT_BIT:
  655.             MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
  656.             if (ctx->Driver.Enable)
  657.                (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag );
  658.             break;
  659.          case GL_POLYGON_BIT:
  660.             {
  661.                GLenum oldFrontMode = ctx->Polygon.FrontMode;
  662.                GLenum oldBackMode = ctx->Polygon.BackMode;
  663.                MEMCPY( &ctx->Polygon, attr->data,
  664.                        sizeof(struct gl_polygon_attrib) );
  665.                if ((ctx->Polygon.FrontMode != oldFrontMode ||
  666.                     ctx->Polygon.BackMode != oldBackMode) &&
  667.                    ctx->Driver.PolygonMode) {
  668.                   (*ctx->Driver.PolygonMode)( ctx, GL_FRONT, ctx->Polygon.FrontMode);
  669.                   (*ctx->Driver.PolygonMode)( ctx, GL_BACK, ctx->Polygon.BackMode);
  670.                }
  671.            if (ctx->Driver.CullFace)
  672.           ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
  673.  
  674.            if (ctx->Driver.FrontFace)
  675.           ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
  676.  
  677.                if (ctx->Driver.Enable)
  678.                   (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag );
  679.             }
  680.             break;
  681.      case GL_POLYGON_STIPPLE_BIT:
  682.         MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
  683.         break;
  684.          case GL_SCISSOR_BIT:
  685.             MEMCPY( &ctx->Scissor, attr->data,
  686.             sizeof(struct gl_scissor_attrib) );
  687.             if (ctx->Driver.Enable)
  688.                (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
  689.         if (ctx->Driver.Scissor)
  690.            ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
  691.                     ctx->Scissor.Width, ctx->Scissor.Height );
  692.             break;
  693.          case GL_STENCIL_BUFFER_BIT:
  694.             MEMCPY( &ctx->Stencil, attr->data,
  695.             sizeof(struct gl_stencil_attrib) );
  696.             if (ctx->Driver.StencilFunc)
  697.                (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
  698.                                    ctx->Stencil.Ref, ctx->Stencil.ValueMask);
  699.             if (ctx->Driver.StencilMask)
  700.                (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask );
  701.             if (ctx->Driver.StencilOp)
  702.                (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc,
  703.                               ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc);
  704.             if (ctx->Driver.ClearStencil)
  705.                (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
  706.             if (ctx->Driver.Enable)
  707.                (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
  708.         ctx->TriangleCaps &= ~DD_STENCIL;
  709.         if (ctx->Stencil.Enabled)
  710.            ctx->TriangleCaps |= DD_STENCIL;
  711.  
  712.             break;
  713.          case GL_TRANSFORM_BIT:
  714.             MEMCPY( &ctx->Transform, attr->data,
  715.             sizeof(struct gl_transform_attrib) );
  716.             if (ctx->Driver.Enable) {
  717.                (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
  718.                (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
  719.             }
  720.         ctx->Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
  721.         if (ctx->Transform.Normalize) ctx->Enabled |= ENABLE_NORMALIZE;
  722.         if (ctx->Transform.RescaleNormals) ctx->Enabled |= ENABLE_RESCALE;
  723.             break;
  724.          case GL_TEXTURE_BIT:
  725.             /* Take care of texture object reference counters */
  726.             {
  727.                GLuint u;
  728.                for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  729.           ctx->Texture.Unit[u].CurrentD[1]->RefCount--;
  730.           ctx->Texture.Unit[u].CurrentD[2]->RefCount--;
  731.           ctx->Texture.Unit[u].CurrentD[3]->RefCount--;
  732.                }
  733.                MEMCPY( &ctx->Texture, attr->data,
  734.                        sizeof(struct gl_texture_attrib) );
  735.                /* restore state of the currently bound texture objects */
  736.                for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  737.                   copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1],
  738.                                      &(ctx->Texture.Unit[u].Saved1D) );
  739.                   copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2],
  740.                                      &(ctx->Texture.Unit[u].Saved2D) );
  741.                   copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3],
  742.                                      &(ctx->Texture.Unit[u].Saved3D) );
  743.                   gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] );
  744.                   gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] );
  745.                   gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] );
  746.  
  747.                }
  748.             }
  749.             break;
  750.          case GL_VIEWPORT_BIT: 
  751.      {
  752.         struct gl_viewport_attrib *v = 
  753.            (struct gl_viewport_attrib *)attr->data;
  754.         
  755.         gl_Viewport( ctx, v->X, v->Y, v->Width, v->Height );
  756.         gl_DepthRange( ctx, v->Near, v->Far );
  757.         break;
  758.      }
  759.          default:
  760.             gl_problem( ctx, "Bad attrib flag in PopAttrib");
  761.             break;
  762.       }
  763.  
  764.       next = attr->next;
  765.       FREE( attr->data );
  766.       FREE( attr );
  767.       attr = next;
  768.    }
  769.  
  770.    ctx->NewState = NEW_ALL;
  771. }
  772.  
  773.  
  774. #define GL_CLIENT_PACK_BIT (1<<20)
  775. #define GL_CLIENT_UNPACK_BIT (1<<21)
  776.  
  777.  
  778. void gl_PushClientAttrib( GLcontext *ctx, GLbitfield mask )
  779. {
  780.    struct gl_attrib_node *newnode;
  781.    struct gl_attrib_node *head;
  782.  
  783.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
  784.  
  785.    if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
  786.       gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
  787.       return;
  788.    }
  789.  
  790.    /* Build linked list of attribute nodes which save all attribute */
  791.    /* groups specified by the mask. */
  792.    head = NULL;
  793.  
  794.    if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
  795.       struct gl_pixelstore_attrib *attr;
  796.       /* packing attribs */
  797.       attr = MALLOC_STRUCT( gl_pixelstore_attrib );
  798.       MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
  799.       newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
  800.       newnode->data = attr;
  801.       newnode->next = head;
  802.       head = newnode;
  803.       /* unpacking attribs */
  804.       attr = MALLOC_STRUCT( gl_pixelstore_attrib );
  805.       MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
  806.       newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
  807.       newnode->data = attr;
  808.       newnode->next = head;
  809.       head = newnode;
  810.    }
  811.    if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
  812.       struct gl_array_attrib *attr;
  813.       attr = MALLOC_STRUCT( gl_array_attrib );
  814.       MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
  815.       newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
  816.       newnode->data = attr;
  817.       newnode->next = head;
  818.       head = newnode;
  819.    }
  820.  
  821.    ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
  822.    ctx->ClientAttribStackDepth++;
  823. }
  824.  
  825.  
  826.  
  827.  
  828. void gl_PopClientAttrib( GLcontext *ctx )
  829. {
  830.    struct gl_attrib_node *attr, *next;
  831.  
  832.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
  833.  
  834.    if (ctx->ClientAttribStackDepth==0) {
  835.       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
  836.       return;
  837.    }
  838.  
  839.    ctx->ClientAttribStackDepth--;
  840.    attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
  841.  
  842.    while (attr) {
  843.       switch (attr->kind) {
  844.          case GL_CLIENT_PACK_BIT:
  845.             MEMCPY( &ctx->Pack, attr->data,
  846.                     sizeof(struct gl_pixelstore_attrib) );
  847.             break;
  848.          case GL_CLIENT_UNPACK_BIT:
  849.             MEMCPY( &ctx->Unpack, attr->data,
  850.                     sizeof(struct gl_pixelstore_attrib) );
  851.             break;
  852.          case GL_CLIENT_VERTEX_ARRAY_BIT:
  853.             MEMCPY( &ctx->Array, attr->data,
  854.             sizeof(struct gl_array_attrib) );
  855.             break;
  856.          default:
  857.             gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
  858.             break;
  859.       }
  860.  
  861.       next = attr->next;
  862.       FREE( attr->data );
  863.       FREE( attr );
  864.       attr = next;
  865.    }
  866.  
  867.    ctx->NewState = NEW_ALL;
  868. }
  869.  
  870.