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