Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 1 | /* $Id: attrib.c,v 1.33 2000/11/05 18:40:57 keithw Exp $ */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 5 | * Version: 3.5 |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 32 | #include "attrib.h" |
Brian Paul | ea39f04 | 2000-02-02 19:17:57 +0000 | [diff] [blame] | 33 | #include "buffers.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 34 | #include "context.h" |
| 35 | #include "enable.h" |
| 36 | #include "enums.h" |
Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 37 | #include "matrix.h" |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 38 | #include "mem.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 39 | #include "simple_list.h" |
| 40 | #include "texstate.h" |
| 41 | #include "types.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | /* |
| 48 | * Allocate a new attribute state node. These nodes have a |
| 49 | * "kind" value and a pointer to a struct of state data. |
| 50 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 51 | static struct gl_attrib_node * |
| 52 | new_attrib_node( GLbitfield kind ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 53 | { |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 54 | struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 55 | if (an) { |
| 56 | an->kind = kind; |
| 57 | } |
| 58 | return an; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | /* |
| 64 | * Copy texture object state from one texture object to another. |
| 65 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 66 | static void |
| 67 | copy_texobj_state( struct gl_texture_object *dest, |
| 68 | const struct gl_texture_object *src ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 69 | { |
| 70 | /* |
| 71 | dest->Name = src->Name; |
| 72 | dest->Dimensions = src->Dimensions; |
| 73 | */ |
| 74 | dest->Priority = src->Priority; |
| 75 | dest->BorderColor[0] = src->BorderColor[0]; |
| 76 | dest->BorderColor[1] = src->BorderColor[1]; |
| 77 | dest->BorderColor[2] = src->BorderColor[2]; |
| 78 | dest->BorderColor[3] = src->BorderColor[3]; |
| 79 | dest->WrapS = src->WrapS; |
| 80 | dest->WrapT = src->WrapT; |
| 81 | dest->WrapR = src->WrapR; |
| 82 | dest->MinFilter = src->MinFilter; |
| 83 | dest->MagFilter = src->MagFilter; |
| 84 | dest->MinLod = src->MinLod; |
| 85 | dest->MaxLod = src->MaxLod; |
| 86 | dest->BaseLevel = src->BaseLevel; |
| 87 | dest->MaxLevel = src->MaxLevel; |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 88 | dest->_P = src->_P; |
| 89 | dest->_M = src->_M; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 90 | dest->Palette = src->Palette; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 91 | dest->Complete = src->Complete; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | |
| 95 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 96 | void |
| 97 | _mesa_PushAttrib(GLbitfield mask) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 98 | { |
| 99 | struct gl_attrib_node *newnode; |
| 100 | struct gl_attrib_node *head; |
| 101 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 102 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 103 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib"); |
| 104 | |
| 105 | if (MESA_VERBOSE&VERBOSE_API) |
Keith Whitwell | e5ed37f | 2000-02-27 20:38:15 +0000 | [diff] [blame] | 106 | fprintf(stderr, "glPushAttrib %x\n", (int)mask); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 107 | |
| 108 | if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) { |
| 109 | gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" ); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | /* Build linked list of attribute nodes which save all attribute */ |
| 114 | /* groups specified by the mask. */ |
| 115 | head = NULL; |
| 116 | |
| 117 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| 118 | struct gl_accum_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 119 | attr = MALLOC_STRUCT( gl_accum_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 120 | MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) ); |
| 121 | newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT ); |
| 122 | newnode->data = attr; |
| 123 | newnode->next = head; |
| 124 | head = newnode; |
| 125 | } |
| 126 | |
| 127 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 128 | struct gl_colorbuffer_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 129 | attr = MALLOC_STRUCT( gl_colorbuffer_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 130 | MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) ); |
| 131 | newnode = new_attrib_node( GL_COLOR_BUFFER_BIT ); |
| 132 | newnode->data = attr; |
| 133 | newnode->next = head; |
| 134 | head = newnode; |
| 135 | } |
| 136 | |
| 137 | if (mask & GL_CURRENT_BIT) { |
| 138 | struct gl_current_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 139 | attr = MALLOC_STRUCT( gl_current_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 140 | MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) ); |
| 141 | newnode = new_attrib_node( GL_CURRENT_BIT ); |
| 142 | newnode->data = attr; |
| 143 | newnode->next = head; |
| 144 | head = newnode; |
| 145 | } |
| 146 | |
| 147 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| 148 | struct gl_depthbuffer_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 149 | attr = MALLOC_STRUCT( gl_depthbuffer_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 150 | MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) ); |
| 151 | newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT ); |
| 152 | newnode->data = attr; |
| 153 | newnode->next = head; |
| 154 | head = newnode; |
| 155 | } |
| 156 | |
| 157 | if (mask & GL_ENABLE_BIT) { |
| 158 | struct gl_enable_attrib *attr; |
| 159 | GLuint i; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 160 | attr = MALLOC_STRUCT( gl_enable_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 161 | /* Copy enable flags from all other attributes into the enable struct. */ |
| 162 | attr->AlphaTest = ctx->Color.AlphaEnabled; |
| 163 | attr->AutoNormal = ctx->Eval.AutoNormal; |
| 164 | attr->Blend = ctx->Color.BlendEnabled; |
| 165 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 166 | attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i]; |
| 167 | } |
| 168 | attr->ColorMaterial = ctx->Light.ColorMaterialEnabled; |
Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 169 | attr->Convolution1D = ctx->Pixel.Convolution1DEnabled; |
| 170 | attr->Convolution2D = ctx->Pixel.Convolution2DEnabled; |
| 171 | attr->Separable2D = ctx->Pixel.Separable2DEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 172 | attr->CullFace = ctx->Polygon.CullFlag; |
| 173 | attr->DepthTest = ctx->Depth.Test; |
| 174 | attr->Dither = ctx->Color.DitherFlag; |
| 175 | attr->Fog = ctx->Fog.Enabled; |
| 176 | for (i=0;i<MAX_LIGHTS;i++) { |
| 177 | attr->Light[i] = ctx->Light.Light[i].Enabled; |
| 178 | } |
| 179 | attr->Lighting = ctx->Light.Enabled; |
| 180 | attr->LineSmooth = ctx->Line.SmoothFlag; |
| 181 | attr->LineStipple = ctx->Line.StippleFlag; |
Brian Paul | 2b2e925 | 2000-04-07 16:27:26 +0000 | [diff] [blame] | 182 | attr->Histogram = ctx->Pixel.HistogramEnabled; |
| 183 | attr->MinMax = ctx->Pixel.MinMaxEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 184 | attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled; |
| 185 | attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled; |
| 186 | attr->Map1Color4 = ctx->Eval.Map1Color4; |
| 187 | attr->Map1Index = ctx->Eval.Map1Index; |
| 188 | attr->Map1Normal = ctx->Eval.Map1Normal; |
| 189 | attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1; |
| 190 | attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2; |
| 191 | attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3; |
| 192 | attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4; |
| 193 | attr->Map1Vertex3 = ctx->Eval.Map1Vertex3; |
| 194 | attr->Map1Vertex4 = ctx->Eval.Map1Vertex4; |
| 195 | attr->Map2Color4 = ctx->Eval.Map2Color4; |
| 196 | attr->Map2Index = ctx->Eval.Map2Index; |
| 197 | attr->Map2Normal = ctx->Eval.Map2Normal; |
| 198 | attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1; |
| 199 | attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2; |
| 200 | attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3; |
| 201 | attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4; |
| 202 | attr->Map2Vertex3 = ctx->Eval.Map2Vertex3; |
| 203 | attr->Map2Vertex4 = ctx->Eval.Map2Vertex4; |
| 204 | attr->Normalize = ctx->Transform.Normalize; |
Brian Paul | 2b2e925 | 2000-04-07 16:27:26 +0000 | [diff] [blame] | 205 | attr->PixelTexture = ctx->Pixel.PixelTextureEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 206 | attr->PointSmooth = ctx->Point.SmoothFlag; |
| 207 | attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint; |
| 208 | attr->PolygonOffsetLine = ctx->Polygon.OffsetLine; |
| 209 | attr->PolygonOffsetFill = ctx->Polygon.OffsetFill; |
| 210 | attr->PolygonSmooth = ctx->Polygon.SmoothFlag; |
| 211 | attr->PolygonStipple = ctx->Polygon.StippleFlag; |
| 212 | attr->RescaleNormals = ctx->Transform.RescaleNormals; |
| 213 | attr->Scissor = ctx->Scissor.Enabled; |
| 214 | attr->Stencil = ctx->Stencil.Enabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 215 | for (i=0; i<MAX_TEXTURE_UNITS; i++) { |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 216 | attr->Texture[i] = ctx->Texture.Unit[i].Enabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 217 | attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled; |
| 218 | } |
| 219 | newnode = new_attrib_node( GL_ENABLE_BIT ); |
| 220 | newnode->data = attr; |
| 221 | newnode->next = head; |
| 222 | head = newnode; |
| 223 | } |
| 224 | |
| 225 | if (mask & GL_EVAL_BIT) { |
| 226 | struct gl_eval_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 227 | attr = MALLOC_STRUCT( gl_eval_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 228 | MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) ); |
| 229 | newnode = new_attrib_node( GL_EVAL_BIT ); |
| 230 | newnode->data = attr; |
| 231 | newnode->next = head; |
| 232 | head = newnode; |
| 233 | } |
| 234 | |
| 235 | if (mask & GL_FOG_BIT) { |
| 236 | struct gl_fog_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 237 | attr = MALLOC_STRUCT( gl_fog_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 238 | MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) ); |
| 239 | newnode = new_attrib_node( GL_FOG_BIT ); |
| 240 | newnode->data = attr; |
| 241 | newnode->next = head; |
| 242 | head = newnode; |
| 243 | } |
| 244 | |
| 245 | if (mask & GL_HINT_BIT) { |
| 246 | struct gl_hint_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 247 | attr = MALLOC_STRUCT( gl_hint_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 248 | MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) ); |
| 249 | newnode = new_attrib_node( GL_HINT_BIT ); |
| 250 | newnode->data = attr; |
| 251 | newnode->next = head; |
| 252 | head = newnode; |
| 253 | } |
| 254 | |
| 255 | if (mask & GL_LIGHTING_BIT) { |
| 256 | struct gl_light_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 257 | attr = MALLOC_STRUCT( gl_light_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 258 | MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) ); |
| 259 | newnode = new_attrib_node( GL_LIGHTING_BIT ); |
| 260 | newnode->data = attr; |
| 261 | newnode->next = head; |
| 262 | head = newnode; |
| 263 | } |
| 264 | |
| 265 | if (mask & GL_LINE_BIT) { |
| 266 | struct gl_line_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 267 | attr = MALLOC_STRUCT( gl_line_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 268 | MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) ); |
| 269 | newnode = new_attrib_node( GL_LINE_BIT ); |
| 270 | newnode->data = attr; |
| 271 | newnode->next = head; |
| 272 | head = newnode; |
| 273 | } |
| 274 | |
| 275 | if (mask & GL_LIST_BIT) { |
| 276 | struct gl_list_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 277 | attr = MALLOC_STRUCT( gl_list_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 278 | MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) ); |
| 279 | newnode = new_attrib_node( GL_LIST_BIT ); |
| 280 | newnode->data = attr; |
| 281 | newnode->next = head; |
| 282 | head = newnode; |
| 283 | } |
| 284 | |
| 285 | if (mask & GL_PIXEL_MODE_BIT) { |
| 286 | struct gl_pixel_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 287 | attr = MALLOC_STRUCT( gl_pixel_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 288 | MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) ); |
| 289 | newnode = new_attrib_node( GL_PIXEL_MODE_BIT ); |
| 290 | newnode->data = attr; |
| 291 | newnode->next = head; |
| 292 | head = newnode; |
| 293 | } |
| 294 | |
| 295 | if (mask & GL_POINT_BIT) { |
| 296 | struct gl_point_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 297 | attr = MALLOC_STRUCT( gl_point_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 298 | MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) ); |
| 299 | newnode = new_attrib_node( GL_POINT_BIT ); |
| 300 | newnode->data = attr; |
| 301 | newnode->next = head; |
| 302 | head = newnode; |
| 303 | } |
| 304 | |
| 305 | if (mask & GL_POLYGON_BIT) { |
| 306 | struct gl_polygon_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 307 | attr = MALLOC_STRUCT( gl_polygon_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 308 | MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) ); |
| 309 | newnode = new_attrib_node( GL_POLYGON_BIT ); |
| 310 | newnode->data = attr; |
| 311 | newnode->next = head; |
| 312 | head = newnode; |
| 313 | } |
| 314 | |
| 315 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 316 | GLuint *stipple; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 317 | stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 318 | MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) ); |
| 319 | newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT ); |
| 320 | newnode->data = stipple; |
| 321 | newnode->next = head; |
| 322 | head = newnode; |
| 323 | } |
| 324 | |
| 325 | if (mask & GL_SCISSOR_BIT) { |
| 326 | struct gl_scissor_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 327 | attr = MALLOC_STRUCT( gl_scissor_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 328 | MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) ); |
| 329 | newnode = new_attrib_node( GL_SCISSOR_BIT ); |
| 330 | newnode->data = attr; |
| 331 | newnode->next = head; |
| 332 | head = newnode; |
| 333 | } |
| 334 | |
| 335 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| 336 | struct gl_stencil_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 337 | attr = MALLOC_STRUCT( gl_stencil_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 338 | MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) ); |
| 339 | newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT ); |
| 340 | newnode->data = attr; |
| 341 | newnode->next = head; |
| 342 | head = newnode; |
| 343 | } |
| 344 | |
| 345 | if (mask & GL_TEXTURE_BIT) { |
| 346 | struct gl_texture_attrib *attr; |
| 347 | GLuint u; |
| 348 | /* Take care of texture object reference counters */ |
| 349 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 350 | ctx->Texture.Unit[u].CurrentD[1]->RefCount++; |
| 351 | ctx->Texture.Unit[u].CurrentD[2]->RefCount++; |
| 352 | ctx->Texture.Unit[u].CurrentD[3]->RefCount++; |
| 353 | } |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 354 | attr = MALLOC_STRUCT( gl_texture_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 355 | MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) ); |
| 356 | /* copy state of the currently bound texture objects */ |
| 357 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 358 | copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]); |
| 359 | copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]); |
| 360 | copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]); |
Brian Paul | 6479a17 | 2000-07-05 22:26:43 +0000 | [diff] [blame] | 361 | copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 362 | } |
| 363 | newnode = new_attrib_node( GL_TEXTURE_BIT ); |
| 364 | newnode->data = attr; |
| 365 | newnode->next = head; |
| 366 | head = newnode; |
| 367 | } |
| 368 | |
| 369 | if (mask & GL_TRANSFORM_BIT) { |
| 370 | struct gl_transform_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 371 | attr = MALLOC_STRUCT( gl_transform_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 372 | MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) ); |
| 373 | newnode = new_attrib_node( GL_TRANSFORM_BIT ); |
| 374 | newnode->data = attr; |
| 375 | newnode->next = head; |
| 376 | head = newnode; |
| 377 | } |
| 378 | |
| 379 | if (mask & GL_VIEWPORT_BIT) { |
| 380 | struct gl_viewport_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 381 | attr = MALLOC_STRUCT( gl_viewport_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 382 | MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) ); |
| 383 | newnode = new_attrib_node( GL_VIEWPORT_BIT ); |
| 384 | newnode->data = attr; |
| 385 | newnode->next = head; |
| 386 | head = newnode; |
| 387 | } |
| 388 | |
| 389 | ctx->AttribStack[ctx->AttribStackDepth] = head; |
| 390 | ctx->AttribStackDepth++; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 395 | static void |
| 396 | pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable) |
| 397 | { |
| 398 | GLuint i; |
| 399 | |
| 400 | #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \ |
| 401 | if ((VALUE) != (NEWVALUE)) { \ |
| 402 | _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \ |
| 403 | } |
| 404 | |
| 405 | TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST); |
| 406 | TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE); |
| 407 | TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND); |
| 408 | |
| 409 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 410 | if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i]) |
| 411 | _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i), |
| 412 | enable->ClipPlane[i]); |
| 413 | } |
| 414 | |
| 415 | TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, |
| 416 | GL_COLOR_MATERIAL); |
| 417 | TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE); |
| 418 | TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST); |
| 419 | TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER); |
| 420 | TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D, |
| 421 | GL_CONVOLUTION_1D); |
| 422 | TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D, |
| 423 | GL_CONVOLUTION_2D); |
| 424 | TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D, |
| 425 | GL_SEPARABLE_2D); |
| 426 | TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG); |
| 427 | TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING); |
| 428 | TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH); |
| 429 | TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, |
| 430 | GL_LINE_STIPPLE); |
| 431 | TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, |
| 432 | GL_INDEX_LOGIC_OP); |
| 433 | TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, |
| 434 | GL_COLOR_LOGIC_OP); |
| 435 | TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4); |
| 436 | TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX); |
| 437 | TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL); |
| 438 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, |
| 439 | GL_MAP1_TEXTURE_COORD_1); |
| 440 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, |
| 441 | GL_MAP1_TEXTURE_COORD_2); |
| 442 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, |
| 443 | GL_MAP1_TEXTURE_COORD_3); |
| 444 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, |
| 445 | GL_MAP1_TEXTURE_COORD_4); |
| 446 | TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, |
| 447 | GL_MAP1_VERTEX_3); |
| 448 | TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, |
| 449 | GL_MAP1_VERTEX_4); |
| 450 | TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4); |
| 451 | TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX); |
| 452 | TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL); |
| 453 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, |
| 454 | GL_MAP2_TEXTURE_COORD_1); |
| 455 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, |
| 456 | GL_MAP2_TEXTURE_COORD_2); |
| 457 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, |
| 458 | GL_MAP2_TEXTURE_COORD_3); |
| 459 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, |
| 460 | GL_MAP2_TEXTURE_COORD_4); |
| 461 | TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, |
| 462 | GL_MAP2_VERTEX_3); |
| 463 | TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, |
| 464 | GL_MAP2_VERTEX_4); |
| 465 | TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE); |
| 466 | TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, |
| 467 | GL_RESCALE_NORMAL_EXT); |
| 468 | TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture, |
| 469 | GL_POINT_SMOOTH); |
| 470 | TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, |
| 471 | GL_POINT_SMOOTH); |
| 472 | TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, |
| 473 | GL_POLYGON_OFFSET_POINT); |
| 474 | TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, |
| 475 | GL_POLYGON_OFFSET_LINE); |
| 476 | TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, |
| 477 | GL_POLYGON_OFFSET_FILL); |
| 478 | TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, |
| 479 | GL_POLYGON_SMOOTH); |
| 480 | TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, |
| 481 | GL_POLYGON_STIPPLE); |
| 482 | TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST); |
| 483 | TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST); |
| 484 | #undef TEST_AND_UPDATE |
| 485 | |
| 486 | /* texture unit enables */ |
| 487 | for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { |
| 488 | if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) { |
| 489 | ctx->Texture.Unit[i].Enabled = enable->Texture[i]; |
| 490 | if (ctx->Driver.Enable) { |
| 491 | if (ctx->Driver.ActiveTexture) { |
| 492 | (*ctx->Driver.ActiveTexture)(ctx, i); |
| 493 | } |
| 494 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, |
| 495 | (GLboolean) (enable->Texture[i] & TEXTURE0_1D) ); |
| 496 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, |
| 497 | (GLboolean) (enable->Texture[i] & TEXTURE0_2D) ); |
| 498 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, |
| 499 | (GLboolean) (enable->Texture[i] & TEXTURE0_3D) ); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) { |
| 504 | ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i]; |
| 505 | if (ctx->Driver.Enable) { |
| 506 | if (ctx->Driver.ActiveTexture) { |
| 507 | (*ctx->Driver.ActiveTexture)(ctx, i); |
| 508 | } |
| 509 | if (enable->TexGen[i] & S_BIT) |
| 510 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE); |
| 511 | else |
| 512 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE); |
| 513 | if (enable->TexGen[i] & T_BIT) |
| 514 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE); |
| 515 | else |
| 516 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE); |
| 517 | if (enable->TexGen[i] & R_BIT) |
| 518 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE); |
| 519 | else |
| 520 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE); |
| 521 | if (enable->TexGen[i] & Q_BIT) |
| 522 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE); |
| 523 | else |
| 524 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | if (ctx->Driver.ActiveTexture) { |
| 530 | (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | |
| 535 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 536 | /* |
| 537 | * This function is kind of long just because we have to call a lot |
| 538 | * of device driver functions to update device driver state. |
| 539 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 540 | void |
| 541 | _mesa_PopAttrib(void) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 542 | { |
| 543 | struct gl_attrib_node *attr, *next; |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 544 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 545 | |
| 546 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib"); |
| 547 | |
| 548 | |
| 549 | if (ctx->AttribStackDepth==0) { |
| 550 | gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" ); |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | ctx->AttribStackDepth--; |
| 555 | attr = ctx->AttribStack[ctx->AttribStackDepth]; |
| 556 | |
| 557 | while (attr) { |
| 558 | |
| 559 | if (MESA_VERBOSE&VERBOSE_API) |
| 560 | fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind)); |
| 561 | |
| 562 | switch (attr->kind) { |
| 563 | case GL_ACCUM_BUFFER_BIT: |
| 564 | MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 565 | ctx->NewState |= _NEW_ACCUM; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 566 | break; |
| 567 | case GL_COLOR_BUFFER_BIT: |
| 568 | { |
| 569 | GLenum oldDrawBuffer = ctx->Color.DrawBuffer; |
| 570 | GLenum oldAlphaFunc = ctx->Color.AlphaFunc; |
Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 571 | GLchan oldAlphaRef = ctx->Color.AlphaRef; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 572 | GLenum oldBlendSrc = ctx->Color.BlendSrcRGB; |
| 573 | GLenum oldBlendDst = ctx->Color.BlendDstRGB; |
Keith Whitwell | e828bc8 | 2000-02-25 03:55:39 +0000 | [diff] [blame] | 574 | GLenum oldLogicOp = ctx->Color.LogicOp; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 575 | MEMCPY( &ctx->Color, attr->data, |
| 576 | sizeof(struct gl_colorbuffer_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 577 | ctx->NewState |= _NEW_COLOR; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 578 | if (ctx->Color.DrawBuffer != oldDrawBuffer) { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 579 | _mesa_DrawBuffer( ctx->Color.DrawBuffer); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 580 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 581 | if ((ctx->Color.BlendSrcRGB != oldBlendSrc || |
Brian Paul | 516b836 | 2000-03-10 22:12:22 +0000 | [diff] [blame] | 582 | ctx->Color.BlendDstRGB != oldBlendDst) && |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 583 | ctx->Driver.BlendFunc) |
| 584 | (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB, |
| 585 | ctx->Color.BlendDstRGB); |
Keith Whitwell | e828bc8 | 2000-02-25 03:55:39 +0000 | [diff] [blame] | 586 | if (ctx->Color.LogicOp != oldLogicOp && |
Brian Paul | 516b836 | 2000-03-10 22:12:22 +0000 | [diff] [blame] | 587 | ctx->Driver.LogicOpcode) { |
Keith Whitwell | e828bc8 | 2000-02-25 03:55:39 +0000 | [diff] [blame] | 588 | ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp ); |
Brian Paul | 516b836 | 2000-03-10 22:12:22 +0000 | [diff] [blame] | 589 | } |
Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 590 | if (ctx->Visual.RGBAflag) { |
Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 591 | GLchan r = (GLint) (ctx->Color.ClearColor[0] * CHAN_MAXF); |
| 592 | GLchan g = (GLint) (ctx->Color.ClearColor[1] * CHAN_MAXF); |
| 593 | GLchan b = (GLint) (ctx->Color.ClearColor[2] * CHAN_MAXF); |
| 594 | GLchan a = (GLint) (ctx->Color.ClearColor[3] * CHAN_MAXF); |
Brian Paul | 516b836 | 2000-03-10 22:12:22 +0000 | [diff] [blame] | 595 | (*ctx->Driver.ClearColor)( ctx, r, g, b, a ); |
| 596 | if ((ctx->Color.AlphaFunc != oldAlphaFunc || |
| 597 | ctx->Color.AlphaRef != oldAlphaRef) && |
| 598 | ctx->Driver.AlphaFunc) |
| 599 | (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc, |
Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 600 | ctx->Color.AlphaRef / CHAN_MAXF); |
Brian Paul | 516b836 | 2000-03-10 22:12:22 +0000 | [diff] [blame] | 601 | if (ctx->Driver.ColorMask) { |
| 602 | (*ctx->Driver.ColorMask)(ctx, |
| 603 | ctx->Color.ColorMask[0], |
| 604 | ctx->Color.ColorMask[1], |
| 605 | ctx->Color.ColorMask[2], |
| 606 | ctx->Color.ColorMask[3]); |
| 607 | } |
| 608 | } |
| 609 | else { |
| 610 | (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex); |
| 611 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 612 | } |
| 613 | break; |
| 614 | case GL_CURRENT_BIT: |
| 615 | MEMCPY( &ctx->Current, attr->data, |
| 616 | sizeof(struct gl_current_attrib) ); |
| 617 | break; |
| 618 | case GL_DEPTH_BUFFER_BIT: |
| 619 | { |
Brian Paul | d283df6 | 2000-07-19 18:34:00 +0000 | [diff] [blame] | 620 | GLboolean oldDepthTest = ctx->Depth.Test; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 621 | GLenum oldDepthFunc = ctx->Depth.Func; |
| 622 | GLboolean oldDepthMask = ctx->Depth.Mask; |
| 623 | GLfloat oldDepthClear = ctx->Depth.Clear; |
| 624 | MEMCPY( &ctx->Depth, attr->data, |
| 625 | sizeof(struct gl_depthbuffer_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 626 | ctx->NewState |= _NEW_DEPTH; |
Brian Paul | d283df6 | 2000-07-19 18:34:00 +0000 | [diff] [blame] | 627 | if (ctx->Depth.Test != oldDepthTest && ctx->Driver.Enable) |
| 628 | (*ctx->Driver.Enable)( ctx, GL_DEPTH_TEST, ctx->Depth.Test); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 629 | if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc) |
| 630 | (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func ); |
| 631 | if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask) |
| 632 | (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask ); |
| 633 | if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth) |
| 634 | (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear ); |
| 635 | } |
| 636 | break; |
| 637 | case GL_ENABLE_BIT: |
| 638 | { |
| 639 | const struct gl_enable_attrib *enable; |
| 640 | enable = (const struct gl_enable_attrib *) attr->data; |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 641 | pop_enable_group(ctx, enable); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 642 | ctx->NewState |= _NEW_ALL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 643 | } |
| 644 | break; |
| 645 | case GL_EVAL_BIT: |
| 646 | MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 647 | ctx->NewState |= _NEW_EVAL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 648 | break; |
| 649 | case GL_FOG_BIT: |
| 650 | { |
Brian Paul | 99f16d0 | 1999-11-08 15:28:08 +0000 | [diff] [blame] | 651 | GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 652 | MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 653 | ctx->NewState |= _NEW_FOG; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 654 | if (anyChange && ctx->Driver.Fogfv) { |
Brian Paul | 99f16d0 | 1999-11-08 15:28:08 +0000 | [diff] [blame] | 655 | const GLfloat mode = (GLfloat) ctx->Fog.Mode; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 656 | const GLfloat density = ctx->Fog.Density; |
| 657 | const GLfloat start = ctx->Fog.Start; |
| 658 | const GLfloat end = ctx->Fog.End; |
| 659 | const GLfloat index = ctx->Fog.Index; |
| 660 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode); |
| 661 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density ); |
| 662 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start ); |
| 663 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end ); |
| 664 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index ); |
| 665 | (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color ); |
| 666 | } |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 667 | ctx->_Enabled &= ~ENABLE_FOG; |
| 668 | if (ctx->Fog.Enabled) ctx->_Enabled |= ENABLE_FOG; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 669 | } |
| 670 | break; |
| 671 | case GL_HINT_BIT: |
| 672 | MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 673 | ctx->NewState |= _NEW_HINT; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 674 | if (ctx->Driver.Hint) { |
| 675 | (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT, |
| 676 | ctx->Hint.PerspectiveCorrection ); |
| 677 | (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT, |
| 678 | ctx->Hint.PointSmooth); |
| 679 | (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT, |
| 680 | ctx->Hint.LineSmooth ); |
| 681 | (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT, |
| 682 | ctx->Hint.PolygonSmooth ); |
| 683 | (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog ); |
| 684 | } |
| 685 | break; |
| 686 | case GL_LIGHTING_BIT: |
| 687 | MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 688 | ctx->NewState |= _NEW_LIGHT; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 689 | if (ctx->Driver.Enable) { |
| 690 | GLuint i; |
| 691 | for (i = 0; i < MAX_LIGHTS; i++) { |
| 692 | GLenum light = (GLenum) (GL_LIGHT0 + i); |
| 693 | (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled ); |
| 694 | } |
| 695 | (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled ); |
| 696 | } |
Brian Paul | f2db7ed | 1999-11-22 18:28:39 +0000 | [diff] [blame] | 697 | if (ctx->Light.ShadeModel == GL_FLAT) |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 698 | ctx->_TriangleCaps |= DD_FLATSHADE; |
Brian Paul | f2db7ed | 1999-11-22 18:28:39 +0000 | [diff] [blame] | 699 | else |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 700 | ctx->_TriangleCaps &= ~DD_FLATSHADE; |
Brian Paul | f2db7ed | 1999-11-22 18:28:39 +0000 | [diff] [blame] | 701 | if (ctx->Driver.ShadeModel) |
| 702 | (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel); |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 703 | ctx->_Enabled &= ~ENABLE_LIGHT; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 704 | if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList)) |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 705 | ctx->_Enabled |= ENABLE_LIGHT; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 706 | break; |
| 707 | case GL_LINE_BIT: |
| 708 | MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 709 | ctx->NewState |= _NEW_LINE; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 710 | if (ctx->Driver.Enable) { |
| 711 | (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag ); |
| 712 | (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag ); |
| 713 | } |
Brian Paul | 1b6592a | 2000-03-03 18:55:45 +0000 | [diff] [blame] | 714 | if (ctx->Driver.LineStipple) |
| 715 | (*ctx->Driver.LineStipple)(ctx, ctx->Line.StippleFactor, |
| 716 | ctx->Line.StipplePattern); |
| 717 | if (ctx->Driver.LineWidth) |
| 718 | (*ctx->Driver.LineWidth)(ctx, ctx->Line.Width); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 719 | break; |
| 720 | case GL_LIST_BIT: |
| 721 | MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) ); |
| 722 | break; |
| 723 | case GL_PIXEL_MODE_BIT: |
| 724 | MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 725 | ctx->NewState |= _NEW_PIXEL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 726 | break; |
| 727 | case GL_POINT_BIT: |
| 728 | MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 729 | ctx->NewState |= _NEW_POINT; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 730 | if (ctx->Driver.Enable) |
| 731 | (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag ); |
| 732 | break; |
| 733 | case GL_POLYGON_BIT: |
| 734 | { |
| 735 | GLenum oldFrontMode = ctx->Polygon.FrontMode; |
| 736 | GLenum oldBackMode = ctx->Polygon.BackMode; |
| 737 | MEMCPY( &ctx->Polygon, attr->data, |
| 738 | sizeof(struct gl_polygon_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 739 | ctx->NewState |= _NEW_POLYGON; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 740 | if ((ctx->Polygon.FrontMode != oldFrontMode || |
| 741 | ctx->Polygon.BackMode != oldBackMode) && |
| 742 | ctx->Driver.PolygonMode) { |
| 743 | (*ctx->Driver.PolygonMode)( ctx, GL_FRONT, ctx->Polygon.FrontMode); |
| 744 | (*ctx->Driver.PolygonMode)( ctx, GL_BACK, ctx->Polygon.BackMode); |
| 745 | } |
| 746 | if (ctx->Driver.CullFace) |
| 747 | ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode ); |
| 748 | |
| 749 | if (ctx->Driver.FrontFace) |
| 750 | ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace ); |
| 751 | |
| 752 | if (ctx->Driver.Enable) |
| 753 | (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag ); |
| 754 | } |
| 755 | break; |
| 756 | case GL_POLYGON_STIPPLE_BIT: |
| 757 | MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 758 | ctx->NewState |= _NEW_POLYGONSTIPPLE; |
Keith Whitwell | e5ed37f | 2000-02-27 20:38:15 +0000 | [diff] [blame] | 759 | if (ctx->Driver.PolygonStipple) |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 760 | ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 761 | break; |
| 762 | case GL_SCISSOR_BIT: |
| 763 | MEMCPY( &ctx->Scissor, attr->data, |
| 764 | sizeof(struct gl_scissor_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 765 | ctx->NewState |= _NEW_SCISSOR; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 766 | if (ctx->Driver.Enable) |
| 767 | (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled ); |
| 768 | if (ctx->Driver.Scissor) |
| 769 | ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y, |
| 770 | ctx->Scissor.Width, ctx->Scissor.Height ); |
| 771 | break; |
| 772 | case GL_STENCIL_BUFFER_BIT: |
| 773 | MEMCPY( &ctx->Stencil, attr->data, |
| 774 | sizeof(struct gl_stencil_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 775 | ctx->NewState |= _NEW_STENCIL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 776 | if (ctx->Driver.StencilFunc) |
| 777 | (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function, |
| 778 | ctx->Stencil.Ref, ctx->Stencil.ValueMask); |
| 779 | if (ctx->Driver.StencilMask) |
| 780 | (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask ); |
| 781 | if (ctx->Driver.StencilOp) |
| 782 | (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc, |
| 783 | ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc); |
| 784 | if (ctx->Driver.ClearStencil) |
| 785 | (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear ); |
| 786 | if (ctx->Driver.Enable) |
| 787 | (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled ); |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 788 | ctx->_TriangleCaps &= ~DD_STENCIL; |
Keith Whitwell | 1bf9dfa | 1999-09-18 20:41:22 +0000 | [diff] [blame] | 789 | if (ctx->Stencil.Enabled) |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 790 | ctx->_TriangleCaps |= DD_STENCIL; |
Keith Whitwell | e3f3786 | 1999-09-16 11:54:56 +0000 | [diff] [blame] | 791 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 792 | break; |
| 793 | case GL_TRANSFORM_BIT: |
| 794 | MEMCPY( &ctx->Transform, attr->data, |
| 795 | sizeof(struct gl_transform_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 796 | ctx->NewState |= _NEW_TRANSFORM; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 797 | if (ctx->Driver.Enable) { |
| 798 | (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize ); |
| 799 | (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals ); |
| 800 | } |
Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame^] | 801 | ctx->_Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE); |
| 802 | if (ctx->Transform.Normalize) ctx->_Enabled |= ENABLE_NORMALIZE; |
| 803 | if (ctx->Transform.RescaleNormals) ctx->_Enabled |= ENABLE_RESCALE; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 804 | break; |
| 805 | case GL_TEXTURE_BIT: |
| 806 | /* Take care of texture object reference counters */ |
| 807 | { |
| 808 | GLuint u; |
| 809 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 810 | ctx->Texture.Unit[u].CurrentD[1]->RefCount--; |
| 811 | ctx->Texture.Unit[u].CurrentD[2]->RefCount--; |
| 812 | ctx->Texture.Unit[u].CurrentD[3]->RefCount--; |
| 813 | } |
| 814 | MEMCPY( &ctx->Texture, attr->data, |
| 815 | sizeof(struct gl_texture_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 816 | ctx->NewState |= _NEW_TEXTURE; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 817 | /* restore state of the currently bound texture objects */ |
| 818 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 819 | copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1], |
| 820 | &(ctx->Texture.Unit[u].Saved1D) ); |
| 821 | copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2], |
| 822 | &(ctx->Texture.Unit[u].Saved2D) ); |
| 823 | copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3], |
| 824 | &(ctx->Texture.Unit[u].Saved3D) ); |
Brian Paul | 6479a17 | 2000-07-05 22:26:43 +0000 | [diff] [blame] | 825 | copy_texobj_state( ctx->Texture.Unit[u].CurrentCubeMap, |
| 826 | &(ctx->Texture.Unit[u].SavedCubeMap) ); |
| 827 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 828 | gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] ); |
| 829 | gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] ); |
| 830 | gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] ); |
Brian Paul | 6479a17 | 2000-07-05 22:26:43 +0000 | [diff] [blame] | 831 | gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentCubeMap ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 832 | |
| 833 | } |
| 834 | } |
| 835 | break; |
Keith Whitwell | e3f3786 | 1999-09-16 11:54:56 +0000 | [diff] [blame] | 836 | case GL_VIEWPORT_BIT: |
| 837 | { |
| 838 | struct gl_viewport_attrib *v = |
| 839 | (struct gl_viewport_attrib *)attr->data; |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 840 | |
| 841 | ctx->NewState |= _NEW_VIEWPORT; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 842 | _mesa_Viewport( v->X, v->Y, v->Width, v->Height ); |
| 843 | _mesa_DepthRange( v->Near, v->Far ); |
Keith Whitwell | e3f3786 | 1999-09-16 11:54:56 +0000 | [diff] [blame] | 844 | break; |
| 845 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 846 | default: |
| 847 | gl_problem( ctx, "Bad attrib flag in PopAttrib"); |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | next = attr->next; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 852 | FREE( attr->data ); |
| 853 | FREE( attr ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 854 | attr = next; |
| 855 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | |
| 859 | #define GL_CLIENT_PACK_BIT (1<<20) |
| 860 | #define GL_CLIENT_UNPACK_BIT (1<<21) |
| 861 | |
| 862 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 863 | void |
| 864 | _mesa_PushClientAttrib(GLbitfield mask) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 865 | { |
| 866 | struct gl_attrib_node *newnode; |
| 867 | struct gl_attrib_node *head; |
| 868 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 869 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 870 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib"); |
| 871 | |
| 872 | if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) { |
| 873 | gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" ); |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | /* Build linked list of attribute nodes which save all attribute */ |
| 878 | /* groups specified by the mask. */ |
| 879 | head = NULL; |
| 880 | |
| 881 | if (mask & GL_CLIENT_PIXEL_STORE_BIT) { |
| 882 | struct gl_pixelstore_attrib *attr; |
| 883 | /* packing attribs */ |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 884 | attr = MALLOC_STRUCT( gl_pixelstore_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 885 | MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) ); |
| 886 | newnode = new_attrib_node( GL_CLIENT_PACK_BIT ); |
| 887 | newnode->data = attr; |
| 888 | newnode->next = head; |
| 889 | head = newnode; |
| 890 | /* unpacking attribs */ |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 891 | attr = MALLOC_STRUCT( gl_pixelstore_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 892 | MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) ); |
| 893 | newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT ); |
| 894 | newnode->data = attr; |
| 895 | newnode->next = head; |
| 896 | head = newnode; |
| 897 | } |
| 898 | if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { |
| 899 | struct gl_array_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 900 | attr = MALLOC_STRUCT( gl_array_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 901 | MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) ); |
| 902 | newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT ); |
| 903 | newnode->data = attr; |
| 904 | newnode->next = head; |
| 905 | head = newnode; |
| 906 | } |
| 907 | |
| 908 | ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head; |
| 909 | ctx->ClientAttribStackDepth++; |
| 910 | } |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 915 | void |
| 916 | _mesa_PopClientAttrib(void) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 917 | { |
| 918 | struct gl_attrib_node *attr, *next; |
| 919 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 920 | GET_CURRENT_CONTEXT(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 921 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib"); |
| 922 | |
| 923 | if (ctx->ClientAttribStackDepth==0) { |
| 924 | gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" ); |
| 925 | return; |
| 926 | } |
| 927 | |
| 928 | ctx->ClientAttribStackDepth--; |
| 929 | attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth]; |
| 930 | |
| 931 | while (attr) { |
| 932 | switch (attr->kind) { |
| 933 | case GL_CLIENT_PACK_BIT: |
| 934 | MEMCPY( &ctx->Pack, attr->data, |
| 935 | sizeof(struct gl_pixelstore_attrib) ); |
| 936 | break; |
| 937 | case GL_CLIENT_UNPACK_BIT: |
| 938 | MEMCPY( &ctx->Unpack, attr->data, |
| 939 | sizeof(struct gl_pixelstore_attrib) ); |
| 940 | break; |
| 941 | case GL_CLIENT_VERTEX_ARRAY_BIT: |
| 942 | MEMCPY( &ctx->Array, attr->data, |
| 943 | sizeof(struct gl_array_attrib) ); |
| 944 | break; |
| 945 | default: |
| 946 | gl_problem( ctx, "Bad attrib flag in PopClientAttrib"); |
| 947 | break; |
| 948 | } |
| 949 | |
| 950 | next = attr->next; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 951 | FREE( attr->data ); |
| 952 | FREE( attr ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 953 | attr = next; |
| 954 | } |
| 955 | |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 956 | ctx->NewState = _NEW_ARRAY; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 959 | |
| 960 | |