attrib.c revision 7117f1b4
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.0.2 4 * 5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25#include "glheader.h" 26#include "imports.h" 27#include "accum.h" 28#include "arrayobj.h" 29#include "attrib.h" 30#include "blend.h" 31#include "buffers.h" 32#include "bufferobj.h" 33#include "colormac.h" 34#include "colortab.h" 35#include "context.h" 36#include "depth.h" 37#include "enable.h" 38#include "enums.h" 39#include "fog.h" 40#include "hint.h" 41#include "light.h" 42#include "lines.h" 43#include "matrix.h" 44#include "points.h" 45#include "polygon.h" 46#include "simple_list.h" 47#include "stencil.h" 48#include "texobj.h" 49#include "texstate.h" 50#include "mtypes.h" 51#include "math/m_xform.h" 52 53 54/** 55 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT) 56 */ 57struct texture_state 58{ 59 struct gl_texture_attrib Texture; /**< The usual context state */ 60 61 /** to save per texture object state (wrap modes, filters, etc): */ 62 struct gl_texture_object Saved1D[MAX_TEXTURE_UNITS]; 63 struct gl_texture_object Saved2D[MAX_TEXTURE_UNITS]; 64 struct gl_texture_object Saved3D[MAX_TEXTURE_UNITS]; 65 struct gl_texture_object SavedCube[MAX_TEXTURE_UNITS]; 66 struct gl_texture_object SavedRect[MAX_TEXTURE_UNITS]; 67 68 /** 69 * To save references to texture objects (so they don't get accidentally 70 * deleted while saved in the attribute stack). 71 */ 72 struct gl_texture_object *SavedRef1D[MAX_TEXTURE_UNITS]; 73 struct gl_texture_object *SavedRef2D[MAX_TEXTURE_UNITS]; 74 struct gl_texture_object *SavedRef3D[MAX_TEXTURE_UNITS]; 75 struct gl_texture_object *SavedRefCube[MAX_TEXTURE_UNITS]; 76 struct gl_texture_object *SavedRefRect[MAX_TEXTURE_UNITS]; 77}; 78 79 80/** 81 * Allocate a new attribute state node. These nodes have a 82 * "kind" value and a pointer to a struct of state data. 83 */ 84static struct gl_attrib_node * 85new_attrib_node( GLbitfield kind ) 86{ 87 struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node); 88 if (an) { 89 an->kind = kind; 90 } 91 return an; 92} 93 94 95void GLAPIENTRY 96_mesa_PushAttrib(GLbitfield mask) 97{ 98 struct gl_attrib_node *newnode; 99 struct gl_attrib_node *head; 100 101 GET_CURRENT_CONTEXT(ctx); 102 ASSERT_OUTSIDE_BEGIN_END(ctx); 103 104 if (MESA_VERBOSE & VERBOSE_API) 105 _mesa_debug(ctx, "glPushAttrib %x\n", (int) mask); 106 107 if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) { 108 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" ); 109 return; 110 } 111 112 /* Build linked list of attribute nodes which save all attribute */ 113 /* groups specified by the mask. */ 114 head = NULL; 115 116 if (mask & GL_ACCUM_BUFFER_BIT) { 117 struct gl_accum_attrib *attr; 118 attr = MALLOC_STRUCT( gl_accum_attrib ); 119 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) ); 120 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT ); 121 newnode->data = attr; 122 newnode->next = head; 123 head = newnode; 124 } 125 126 if (mask & GL_COLOR_BUFFER_BIT) { 127 struct gl_colorbuffer_attrib *attr; 128 attr = MALLOC_STRUCT( gl_colorbuffer_attrib ); 129 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) ); 130 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT ); 131 newnode->data = attr; 132 newnode->next = head; 133 head = newnode; 134 } 135 136 if (mask & GL_CURRENT_BIT) { 137 struct gl_current_attrib *attr; 138 FLUSH_CURRENT( ctx, 0 ); 139 attr = MALLOC_STRUCT( gl_current_attrib ); 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; 149 attr = MALLOC_STRUCT( gl_depthbuffer_attrib ); 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; 160 attr = MALLOC_STRUCT( gl_enable_attrib ); 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 attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled; 166 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled; 167 for (i = 0; i < COLORTABLE_MAX; i++) { 168 attr->ColorTable[i] = ctx->Pixel.ColorTableEnabled[i]; 169 } 170 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled; 171 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled; 172 attr->Separable2D = ctx->Pixel.Separable2DEnabled; 173 attr->CullFace = ctx->Polygon.CullFlag; 174 attr->DepthTest = ctx->Depth.Test; 175 attr->Dither = ctx->Color.DitherFlag; 176 attr->Fog = ctx->Fog.Enabled; 177 for (i = 0; i < ctx->Const.MaxLights; i++) { 178 attr->Light[i] = ctx->Light.Light[i].Enabled; 179 } 180 attr->Lighting = ctx->Light.Enabled; 181 attr->LineSmooth = ctx->Line.SmoothFlag; 182 attr->LineStipple = ctx->Line.StippleFlag; 183 attr->Histogram = ctx->Pixel.HistogramEnabled; 184 attr->MinMax = ctx->Pixel.MinMaxEnabled; 185 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled; 186 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled; 187 attr->Map1Color4 = ctx->Eval.Map1Color4; 188 attr->Map1Index = ctx->Eval.Map1Index; 189 attr->Map1Normal = ctx->Eval.Map1Normal; 190 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1; 191 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2; 192 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3; 193 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4; 194 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3; 195 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4; 196 MEMCPY(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib)); 197 attr->Map2Color4 = ctx->Eval.Map2Color4; 198 attr->Map2Index = ctx->Eval.Map2Index; 199 attr->Map2Normal = ctx->Eval.Map2Normal; 200 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1; 201 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2; 202 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3; 203 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4; 204 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3; 205 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4; 206 MEMCPY(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib)); 207 attr->Normalize = ctx->Transform.Normalize; 208 attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped; 209 attr->PointSmooth = ctx->Point.SmoothFlag; 210 attr->PointSprite = ctx->Point.PointSprite; 211 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint; 212 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine; 213 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill; 214 attr->PolygonSmooth = ctx->Polygon.SmoothFlag; 215 attr->PolygonStipple = ctx->Polygon.StippleFlag; 216 attr->RescaleNormals = ctx->Transform.RescaleNormals; 217 attr->Scissor = ctx->Scissor.Enabled; 218 attr->Stencil = ctx->Stencil.Enabled; 219 attr->StencilTwoSide = ctx->Stencil.TestTwoSide; 220 attr->MultisampleEnabled = ctx->Multisample.Enabled; 221 attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage; 222 attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne; 223 attr->SampleCoverage = ctx->Multisample.SampleCoverage; 224 attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert; 225 for (i=0; i<MAX_TEXTURE_UNITS; i++) { 226 attr->Texture[i] = ctx->Texture.Unit[i].Enabled; 227 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled; 228 attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled; 229 } 230 /* GL_NV_vertex_program */ 231 attr->VertexProgram = ctx->VertexProgram.Enabled; 232 attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled; 233 attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled; 234 newnode = new_attrib_node( GL_ENABLE_BIT ); 235 newnode->data = attr; 236 newnode->next = head; 237 head = newnode; 238 } 239 240 if (mask & GL_EVAL_BIT) { 241 struct gl_eval_attrib *attr; 242 attr = MALLOC_STRUCT( gl_eval_attrib ); 243 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) ); 244 newnode = new_attrib_node( GL_EVAL_BIT ); 245 newnode->data = attr; 246 newnode->next = head; 247 head = newnode; 248 } 249 250 if (mask & GL_FOG_BIT) { 251 struct gl_fog_attrib *attr; 252 attr = MALLOC_STRUCT( gl_fog_attrib ); 253 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) ); 254 newnode = new_attrib_node( GL_FOG_BIT ); 255 newnode->data = attr; 256 newnode->next = head; 257 head = newnode; 258 } 259 260 if (mask & GL_HINT_BIT) { 261 struct gl_hint_attrib *attr; 262 attr = MALLOC_STRUCT( gl_hint_attrib ); 263 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) ); 264 newnode = new_attrib_node( GL_HINT_BIT ); 265 newnode->data = attr; 266 newnode->next = head; 267 head = newnode; 268 } 269 270 if (mask & GL_LIGHTING_BIT) { 271 struct gl_light_attrib *attr; 272 FLUSH_CURRENT(ctx, 0); /* flush material changes */ 273 attr = MALLOC_STRUCT( gl_light_attrib ); 274 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) ); 275 newnode = new_attrib_node( GL_LIGHTING_BIT ); 276 newnode->data = attr; 277 newnode->next = head; 278 head = newnode; 279 } 280 281 if (mask & GL_LINE_BIT) { 282 struct gl_line_attrib *attr; 283 attr = MALLOC_STRUCT( gl_line_attrib ); 284 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) ); 285 newnode = new_attrib_node( GL_LINE_BIT ); 286 newnode->data = attr; 287 newnode->next = head; 288 head = newnode; 289 } 290 291 if (mask & GL_LIST_BIT) { 292 struct gl_list_attrib *attr; 293 attr = MALLOC_STRUCT( gl_list_attrib ); 294 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) ); 295 newnode = new_attrib_node( GL_LIST_BIT ); 296 newnode->data = attr; 297 newnode->next = head; 298 head = newnode; 299 } 300 301 if (mask & GL_PIXEL_MODE_BIT) { 302 struct gl_pixel_attrib *attr; 303 attr = MALLOC_STRUCT( gl_pixel_attrib ); 304 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) ); 305 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */ 306 attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer; 307 newnode = new_attrib_node( GL_PIXEL_MODE_BIT ); 308 newnode->data = attr; 309 newnode->next = head; 310 head = newnode; 311 } 312 313 if (mask & GL_POINT_BIT) { 314 struct gl_point_attrib *attr; 315 attr = MALLOC_STRUCT( gl_point_attrib ); 316 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) ); 317 newnode = new_attrib_node( GL_POINT_BIT ); 318 newnode->data = attr; 319 newnode->next = head; 320 head = newnode; 321 } 322 323 if (mask & GL_POLYGON_BIT) { 324 struct gl_polygon_attrib *attr; 325 attr = MALLOC_STRUCT( gl_polygon_attrib ); 326 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) ); 327 newnode = new_attrib_node( GL_POLYGON_BIT ); 328 newnode->data = attr; 329 newnode->next = head; 330 head = newnode; 331 } 332 333 if (mask & GL_POLYGON_STIPPLE_BIT) { 334 GLuint *stipple; 335 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) ); 336 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) ); 337 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT ); 338 newnode->data = stipple; 339 newnode->next = head; 340 head = newnode; 341 } 342 343 if (mask & GL_SCISSOR_BIT) { 344 struct gl_scissor_attrib *attr; 345 attr = MALLOC_STRUCT( gl_scissor_attrib ); 346 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) ); 347 newnode = new_attrib_node( GL_SCISSOR_BIT ); 348 newnode->data = attr; 349 newnode->next = head; 350 head = newnode; 351 } 352 353 if (mask & GL_STENCIL_BUFFER_BIT) { 354 struct gl_stencil_attrib *attr; 355 attr = MALLOC_STRUCT( gl_stencil_attrib ); 356 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) ); 357 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT ); 358 newnode->data = attr; 359 newnode->next = head; 360 head = newnode; 361 } 362 363 if (mask & GL_TEXTURE_BIT) { 364 struct texture_state *texstate = CALLOC_STRUCT( texture_state ); 365 GLuint u; 366 367 if (!texstate) { 368 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)"); 369 goto end; 370 } 371 372 _mesa_lock_context_textures(ctx); 373 374 /* copy/save the bulk of texture state here */ 375 _mesa_memcpy(&texstate->Texture, &ctx->Texture, sizeof(ctx->Texture)); 376 377 /* Save references to the currently bound texture objects so they don't 378 * accidentally get deleted while referenced in the attribute stack. 379 */ 380 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 381 _mesa_reference_texobj(&texstate->SavedRef1D[u], ctx->Texture.Unit[u].Current1D); 382 _mesa_reference_texobj(&texstate->SavedRef2D[u], ctx->Texture.Unit[u].Current2D); 383 _mesa_reference_texobj(&texstate->SavedRef3D[u], ctx->Texture.Unit[u].Current3D); 384 _mesa_reference_texobj(&texstate->SavedRefCube[u], ctx->Texture.Unit[u].CurrentCubeMap); 385 _mesa_reference_texobj(&texstate->SavedRefRect[u], ctx->Texture.Unit[u].CurrentRect); 386 } 387 388 /* copy state/contents of the currently bound texture objects */ 389 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 390 _mesa_copy_texture_object(&texstate->Saved1D[u], 391 ctx->Texture.Unit[u].Current1D); 392 _mesa_copy_texture_object(&texstate->Saved2D[u], 393 ctx->Texture.Unit[u].Current2D); 394 _mesa_copy_texture_object(&texstate->Saved3D[u], 395 ctx->Texture.Unit[u].Current3D); 396 _mesa_copy_texture_object(&texstate->SavedCube[u], 397 ctx->Texture.Unit[u].CurrentCubeMap); 398 _mesa_copy_texture_object(&texstate->SavedRect[u], 399 ctx->Texture.Unit[u].CurrentRect); 400 } 401 402 _mesa_unlock_context_textures(ctx); 403 404 newnode = new_attrib_node( GL_TEXTURE_BIT ); 405 newnode->data = texstate; 406 newnode->next = head; 407 head = newnode; 408 } 409 410 if (mask & GL_TRANSFORM_BIT) { 411 struct gl_transform_attrib *attr; 412 attr = MALLOC_STRUCT( gl_transform_attrib ); 413 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) ); 414 newnode = new_attrib_node( GL_TRANSFORM_BIT ); 415 newnode->data = attr; 416 newnode->next = head; 417 head = newnode; 418 } 419 420 if (mask & GL_VIEWPORT_BIT) { 421 struct gl_viewport_attrib *attr; 422 attr = MALLOC_STRUCT( gl_viewport_attrib ); 423 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) ); 424 newnode = new_attrib_node( GL_VIEWPORT_BIT ); 425 newnode->data = attr; 426 newnode->next = head; 427 head = newnode; 428 } 429 430 /* GL_ARB_multisample */ 431 if (mask & GL_MULTISAMPLE_BIT_ARB) { 432 struct gl_multisample_attrib *attr; 433 attr = MALLOC_STRUCT( gl_multisample_attrib ); 434 MEMCPY( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) ); 435 newnode = new_attrib_node( GL_MULTISAMPLE_BIT_ARB ); 436 newnode->data = attr; 437 newnode->next = head; 438 head = newnode; 439 } 440 441end: 442 ctx->AttribStack[ctx->AttribStackDepth] = head; 443 ctx->AttribStackDepth++; 444} 445 446 447 448static void 449pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable) 450{ 451 GLuint i; 452 453#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \ 454 if ((VALUE) != (NEWVALUE)) { \ 455 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \ 456 } 457 458 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST); 459 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND); 460 461 for (i=0;i<MAX_CLIP_PLANES;i++) { 462 const GLuint mask = 1 << i; 463 if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask)) 464 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i), 465 (GLboolean) ((enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE)); 466 } 467 468 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, 469 GL_COLOR_MATERIAL); 470 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION], 471 enable->ColorTable[COLORTABLE_PRECONVOLUTION], 472 GL_COLOR_TABLE); 473 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION], 474 enable->ColorTable[COLORTABLE_POSTCONVOLUTION], 475 GL_POST_CONVOLUTION_COLOR_TABLE); 476 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX], 477 enable->ColorTable[COLORTABLE_POSTCOLORMATRIX], 478 GL_POST_COLOR_MATRIX_COLOR_TABLE); 479 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE); 480 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST); 481 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER); 482 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D, 483 GL_CONVOLUTION_1D); 484 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D, 485 GL_CONVOLUTION_2D); 486 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D, 487 GL_SEPARABLE_2D); 488 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG); 489 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING); 490 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH); 491 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, 492 GL_LINE_STIPPLE); 493 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, 494 GL_INDEX_LOGIC_OP); 495 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, 496 GL_COLOR_LOGIC_OP); 497 498 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4); 499 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX); 500 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL); 501 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, 502 GL_MAP1_TEXTURE_COORD_1); 503 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, 504 GL_MAP1_TEXTURE_COORD_2); 505 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, 506 GL_MAP1_TEXTURE_COORD_3); 507 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, 508 GL_MAP1_TEXTURE_COORD_4); 509 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, 510 GL_MAP1_VERTEX_3); 511 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, 512 GL_MAP1_VERTEX_4); 513 for (i = 0; i < 16; i++) { 514 TEST_AND_UPDATE(ctx->Eval.Map1Attrib[i], enable->Map1Attrib[i], 515 GL_MAP1_VERTEX_ATTRIB0_4_NV + i); 516 } 517 518 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4); 519 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX); 520 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL); 521 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, 522 GL_MAP2_TEXTURE_COORD_1); 523 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, 524 GL_MAP2_TEXTURE_COORD_2); 525 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, 526 GL_MAP2_TEXTURE_COORD_3); 527 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, 528 GL_MAP2_TEXTURE_COORD_4); 529 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, 530 GL_MAP2_VERTEX_3); 531 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, 532 GL_MAP2_VERTEX_4); 533 for (i = 0; i < 16; i++) { 534 TEST_AND_UPDATE(ctx->Eval.Map2Attrib[i], enable->Map2Attrib[i], 535 GL_MAP2_VERTEX_ATTRIB0_4_NV + i); 536 } 537 538 TEST_AND_UPDATE(ctx->Eval.AutoNormal, enable->AutoNormal, GL_AUTO_NORMAL); 539 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE); 540 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, 541 GL_RESCALE_NORMAL_EXT); 542 TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped, 543 enable->RasterPositionUnclipped, 544 GL_RASTER_POSITION_UNCLIPPED_IBM); 545 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, 546 GL_POINT_SMOOTH); 547 if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) { 548 TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite, 549 GL_POINT_SPRITE_NV); 550 } 551 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, 552 GL_POLYGON_OFFSET_POINT); 553 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, 554 GL_POLYGON_OFFSET_LINE); 555 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, 556 GL_POLYGON_OFFSET_FILL); 557 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, 558 GL_POLYGON_SMOOTH); 559 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, 560 GL_POLYGON_STIPPLE); 561 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST); 562 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST); 563 if (ctx->Extensions.EXT_stencil_two_side) { 564 TEST_AND_UPDATE(ctx->Stencil.TestTwoSide, enable->StencilTwoSide, GL_STENCIL_TEST_TWO_SIDE_EXT); 565 } 566 TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled, 567 GL_MULTISAMPLE_ARB); 568 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage, 569 enable->SampleAlphaToCoverage, 570 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 571 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne, 572 enable->SampleAlphaToOne, 573 GL_SAMPLE_ALPHA_TO_ONE_ARB); 574 TEST_AND_UPDATE(ctx->Multisample.SampleCoverage, 575 enable->SampleCoverage, 576 GL_SAMPLE_COVERAGE_ARB); 577 TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert, 578 enable->SampleCoverageInvert, 579 GL_SAMPLE_COVERAGE_INVERT_ARB); 580 /* GL_ARB_vertex_program, GL_NV_vertex_program */ 581 TEST_AND_UPDATE(ctx->VertexProgram.Enabled, 582 enable->VertexProgram, 583 GL_VERTEX_PROGRAM_ARB); 584 TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled, 585 enable->VertexProgramPointSize, 586 GL_VERTEX_PROGRAM_POINT_SIZE_ARB); 587 TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled, 588 enable->VertexProgramTwoSide, 589 GL_VERTEX_PROGRAM_TWO_SIDE_ARB); 590 591#undef TEST_AND_UPDATE 592 593 /* texture unit enables */ 594 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { 595 if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) { 596 ctx->Texture.Unit[i].Enabled = enable->Texture[i]; 597 if (ctx->Driver.Enable) { 598 if (ctx->Driver.ActiveTexture) { 599 (*ctx->Driver.ActiveTexture)(ctx, i); 600 } 601 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, 602 (GLboolean) (enable->Texture[i] & TEXTURE_1D_BIT) ); 603 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, 604 (GLboolean) (enable->Texture[i] & TEXTURE_2D_BIT) ); 605 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, 606 (GLboolean) (enable->Texture[i] & TEXTURE_3D_BIT) ); 607 if (ctx->Extensions.ARB_texture_cube_map) 608 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_CUBE_MAP_ARB, 609 (GLboolean) (enable->Texture[i] & TEXTURE_CUBE_BIT) ); 610 if (ctx->Extensions.NV_texture_rectangle) 611 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_RECTANGLE_NV, 612 (GLboolean) (enable->Texture[i] & TEXTURE_RECT_BIT) ); 613 } 614 } 615 616 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) { 617 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i]; 618 if (ctx->Driver.Enable) { 619 if (ctx->Driver.ActiveTexture) { 620 (*ctx->Driver.ActiveTexture)(ctx, i); 621 } 622 if (enable->TexGen[i] & S_BIT) 623 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE); 624 else 625 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE); 626 if (enable->TexGen[i] & T_BIT) 627 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE); 628 else 629 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE); 630 if (enable->TexGen[i] & R_BIT) 631 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE); 632 else 633 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE); 634 if (enable->TexGen[i] & Q_BIT) 635 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE); 636 else 637 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE); 638 } 639 } 640 641 /* GL_SGI_texture_color_table */ 642 ctx->Texture.Unit[i].ColorTableEnabled = enable->TextureColorTable[i]; 643 } 644 645 if (ctx->Driver.ActiveTexture) { 646 (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit); 647 } 648} 649 650 651/** 652 * Pop/restore texture attribute/group state. 653 */ 654static void 655pop_texture_group(GLcontext *ctx, struct texture_state *texstate) 656{ 657 GLuint u; 658 659 _mesa_lock_context_textures(ctx); 660 661 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 662 const struct gl_texture_unit *unit = &texstate->Texture.Unit[u]; 663 GLuint tgt; 664 665 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u); 666 _mesa_set_enable(ctx, GL_TEXTURE_1D, 667 (unit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE); 668 _mesa_set_enable(ctx, GL_TEXTURE_2D, 669 (unit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE); 670 _mesa_set_enable(ctx, GL_TEXTURE_3D, 671 (unit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE); 672 if (ctx->Extensions.ARB_texture_cube_map) { 673 _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB, 674 (unit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE); 675 } 676 if (ctx->Extensions.NV_texture_rectangle) { 677 _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV, 678 (unit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE); 679 } 680 if (ctx->Extensions.SGI_texture_color_table) { 681 _mesa_set_enable(ctx, GL_TEXTURE_COLOR_TABLE_SGI, 682 unit->ColorTableEnabled); 683 } 684 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode); 685 _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor); 686 _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenModeS); 687 _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenModeT); 688 _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenModeR); 689 _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenModeQ); 690 _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->ObjectPlaneS); 691 _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->ObjectPlaneT); 692 _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->ObjectPlaneR); 693 _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->ObjectPlaneQ); 694 /* Eye plane done differently to avoid re-transformation */ 695 { 696 struct gl_texture_unit *destUnit = &ctx->Texture.Unit[u]; 697 COPY_4FV(destUnit->EyePlaneS, unit->EyePlaneS); 698 COPY_4FV(destUnit->EyePlaneT, unit->EyePlaneT); 699 COPY_4FV(destUnit->EyePlaneR, unit->EyePlaneR); 700 COPY_4FV(destUnit->EyePlaneQ, unit->EyePlaneQ); 701 if (ctx->Driver.TexGen) { 702 ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->EyePlaneS); 703 ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->EyePlaneT); 704 ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->EyePlaneR); 705 ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->EyePlaneQ); 706 } 707 } 708 _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, 709 ((unit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE)); 710 _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, 711 ((unit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE)); 712 _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, 713 ((unit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE)); 714 _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, 715 ((unit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE)); 716 if (ctx->Extensions.EXT_texture_lod_bias) { 717 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, 718 GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias); 719 } 720 if (ctx->Extensions.EXT_texture_env_combine || 721 ctx->Extensions.ARB_texture_env_combine) { 722 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, 723 unit->Combine.ModeRGB); 724 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, 725 unit->Combine.ModeA); 726 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, 727 unit->Combine.SourceRGB[0]); 728 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, 729 unit->Combine.SourceRGB[1]); 730 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, 731 unit->Combine.SourceRGB[2]); 732 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, 733 unit->Combine.SourceA[0]); 734 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, 735 unit->Combine.SourceA[1]); 736 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, 737 unit->Combine.SourceA[2]); 738 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, 739 unit->Combine.OperandRGB[0]); 740 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, 741 unit->Combine.OperandRGB[1]); 742 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, 743 unit->Combine.OperandRGB[2]); 744 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, 745 unit->Combine.OperandA[0]); 746 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, 747 unit->Combine.OperandA[1]); 748 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, 749 unit->Combine.OperandA[2]); 750 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 751 1 << unit->Combine.ScaleShiftRGB); 752 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 753 1 << unit->Combine.ScaleShiftA); 754 } 755 756 /* Restore texture object state for each target */ 757 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { 758 const struct gl_texture_object *obj = NULL; 759 GLfloat bordColor[4]; 760 GLenum target; 761 762 switch (tgt) { 763 case TEXTURE_1D_INDEX: 764 obj = &texstate->Saved1D[u]; 765 ASSERT(obj->Target == GL_TEXTURE_1D); 766 break; 767 case TEXTURE_2D_INDEX: 768 obj = &texstate->Saved2D[u]; 769 ASSERT(obj->Target == GL_TEXTURE_2D); 770 break; 771 case TEXTURE_3D_INDEX: 772 obj = &texstate->Saved3D[u]; 773 ASSERT(obj->Target == GL_TEXTURE_3D); 774 break; 775 case TEXTURE_CUBE_INDEX: 776 if (!ctx->Extensions.ARB_texture_cube_map) 777 continue; 778 obj = &texstate->SavedCube[u]; 779 ASSERT(obj->Target == GL_TEXTURE_CUBE_MAP_ARB); 780 break; 781 case TEXTURE_RECT_INDEX: 782 if (!ctx->Extensions.NV_texture_rectangle) 783 continue; 784 obj = &texstate->SavedRect[u]; 785 ASSERT(obj->Target == GL_TEXTURE_RECTANGLE_NV); 786 break; 787 default: 788 _mesa_problem(ctx, "bad texture index in pop_texture_group"); 789 continue; 790 } 791 792 target = obj->Target; 793 794 _mesa_BindTexture(target, obj->Name); 795 796 bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]); 797 bordColor[1] = CHAN_TO_FLOAT(obj->BorderColor[1]); 798 bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]); 799 bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]); 800 801 _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority); 802 _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor); 803 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS); 804 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT); 805 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR); 806 _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter); 807 _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter); 808 _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod); 809 _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod); 810 _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, obj->LodBias); 811 _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel); 812 if (target != GL_TEXTURE_RECTANGLE_ARB) 813 _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel); 814 if (ctx->Extensions.EXT_texture_filter_anisotropic) { 815 _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 816 obj->MaxAnisotropy); 817 } 818 if (ctx->Extensions.SGIX_shadow) { 819 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_SGIX, 820 obj->CompareFlag); 821 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_OPERATOR_SGIX, 822 obj->CompareOperator); 823 } 824 if (ctx->Extensions.SGIX_shadow_ambient) { 825 _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX, 826 obj->ShadowAmbient); 827 } 828 } 829 830 /* remove saved references to the texture objects */ 831 _mesa_reference_texobj(&texstate->SavedRef1D[u], NULL); 832 _mesa_reference_texobj(&texstate->SavedRef2D[u], NULL); 833 _mesa_reference_texobj(&texstate->SavedRef3D[u], NULL); 834 _mesa_reference_texobj(&texstate->SavedRefCube[u], NULL); 835 _mesa_reference_texobj(&texstate->SavedRefRect[u], NULL); 836 } 837 838 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit); 839 840 _mesa_unlock_context_textures(ctx); 841} 842 843 844/* 845 * This function is kind of long just because we have to call a lot 846 * of device driver functions to update device driver state. 847 * 848 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions 849 * in order to restore GL state. This isn't terribly efficient but it 850 * ensures that dirty flags and any derived state gets updated correctly. 851 * We could at least check if the value to restore equals the current value 852 * and then skip the Mesa call. 853 */ 854void GLAPIENTRY 855_mesa_PopAttrib(void) 856{ 857 struct gl_attrib_node *attr, *next; 858 GET_CURRENT_CONTEXT(ctx); 859 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 860 861 if (ctx->AttribStackDepth == 0) { 862 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" ); 863 return; 864 } 865 866 ctx->AttribStackDepth--; 867 attr = ctx->AttribStack[ctx->AttribStackDepth]; 868 869 while (attr) { 870 871 if (MESA_VERBOSE & VERBOSE_API) { 872 _mesa_debug(ctx, "glPopAttrib %s\n", 873 _mesa_lookup_enum_by_nr(attr->kind)); 874 } 875 876 switch (attr->kind) { 877 case GL_ACCUM_BUFFER_BIT: 878 { 879 const struct gl_accum_attrib *accum; 880 accum = (const struct gl_accum_attrib *) attr->data; 881 _mesa_ClearAccum(accum->ClearColor[0], 882 accum->ClearColor[1], 883 accum->ClearColor[2], 884 accum->ClearColor[3]); 885 } 886 break; 887 case GL_COLOR_BUFFER_BIT: 888 { 889 const struct gl_colorbuffer_attrib *color; 890 color = (const struct gl_colorbuffer_attrib *) attr->data; 891 _mesa_ClearIndex((GLfloat) color->ClearIndex); 892 _mesa_ClearColor(color->ClearColor[0], 893 color->ClearColor[1], 894 color->ClearColor[2], 895 color->ClearColor[3]); 896 _mesa_IndexMask(color->IndexMask); 897 _mesa_ColorMask((GLboolean) (color->ColorMask[0] != 0), 898 (GLboolean) (color->ColorMask[1] != 0), 899 (GLboolean) (color->ColorMask[2] != 0), 900 (GLboolean) (color->ColorMask[3] != 0)); 901 { 902 /* Need to determine if more than one color output is 903 * specified. If so, call glDrawBuffersARB, else call 904 * glDrawBuffer(). This is a subtle, but essential point 905 * since GL_FRONT (for example) is illegal for the former 906 * function, but legal for the later. 907 */ 908 GLboolean multipleBuffers = GL_FALSE; 909 if (ctx->Extensions.ARB_draw_buffers) { 910 GLuint i; 911 for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) { 912 if (color->DrawBuffer[i] != GL_NONE) { 913 multipleBuffers = GL_TRUE; 914 break; 915 } 916 } 917 } 918 /* Call the API_level functions, not _mesa_drawbuffers() 919 * since we need to do error checking on the pop'd 920 * GL_DRAW_BUFFER. 921 * Ex: if GL_FRONT were pushed, but we're popping with a 922 * user FBO bound, GL_FRONT will be illegal and we'll need 923 * to record that error. Per OpenGL ARB decision. 924 */ 925 if (multipleBuffers) 926 _mesa_DrawBuffersARB(ctx->Const.MaxDrawBuffers, 927 color->DrawBuffer); 928 else 929 _mesa_DrawBuffer(color->DrawBuffer[0]); 930 } 931 _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled); 932 _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef); 933 _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled); 934 _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB, 935 color->BlendDstRGB, 936 color->BlendSrcA, 937 color->BlendDstA); 938 /* This special case is because glBlendEquationSeparateEXT 939 * cannot take GL_LOGIC_OP as a parameter. 940 */ 941 if ( color->BlendEquationRGB == color->BlendEquationA ) { 942 _mesa_BlendEquation(color->BlendEquationRGB); 943 } 944 else { 945 _mesa_BlendEquationSeparateEXT(color->BlendEquationRGB, 946 color->BlendEquationA); 947 } 948 _mesa_BlendColor(color->BlendColor[0], 949 color->BlendColor[1], 950 color->BlendColor[2], 951 color->BlendColor[3]); 952 _mesa_LogicOp(color->LogicOp); 953 _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, 954 color->ColorLogicOpEnabled); 955 _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP, 956 color->IndexLogicOpEnabled); 957 _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag); 958 } 959 break; 960 case GL_CURRENT_BIT: 961 FLUSH_CURRENT( ctx, 0 ); 962 MEMCPY( &ctx->Current, attr->data, 963 sizeof(struct gl_current_attrib) ); 964 break; 965 case GL_DEPTH_BUFFER_BIT: 966 { 967 const struct gl_depthbuffer_attrib *depth; 968 depth = (const struct gl_depthbuffer_attrib *) attr->data; 969 _mesa_DepthFunc(depth->Func); 970 _mesa_ClearDepth(depth->Clear); 971 _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test); 972 _mesa_DepthMask(depth->Mask); 973 } 974 break; 975 case GL_ENABLE_BIT: 976 { 977 const struct gl_enable_attrib *enable; 978 enable = (const struct gl_enable_attrib *) attr->data; 979 pop_enable_group(ctx, enable); 980 ctx->NewState |= _NEW_ALL; 981 } 982 break; 983 case GL_EVAL_BIT: 984 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) ); 985 ctx->NewState |= _NEW_EVAL; 986 break; 987 case GL_FOG_BIT: 988 { 989 const struct gl_fog_attrib *fog; 990 fog = (const struct gl_fog_attrib *) attr->data; 991 _mesa_set_enable(ctx, GL_FOG, fog->Enabled); 992 _mesa_Fogfv(GL_FOG_COLOR, fog->Color); 993 _mesa_Fogf(GL_FOG_DENSITY, fog->Density); 994 _mesa_Fogf(GL_FOG_START, fog->Start); 995 _mesa_Fogf(GL_FOG_END, fog->End); 996 _mesa_Fogf(GL_FOG_INDEX, fog->Index); 997 _mesa_Fogi(GL_FOG_MODE, fog->Mode); 998 } 999 break; 1000 case GL_HINT_BIT: 1001 { 1002 const struct gl_hint_attrib *hint; 1003 hint = (const struct gl_hint_attrib *) attr->data; 1004 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT, 1005 hint->PerspectiveCorrection ); 1006 _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth); 1007 _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth); 1008 _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth); 1009 _mesa_Hint(GL_FOG_HINT, hint->Fog); 1010 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, 1011 hint->ClipVolumeClipping); 1012 if (ctx->Extensions.ARB_texture_compression) 1013 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB, 1014 hint->TextureCompression); 1015 } 1016 break; 1017 case GL_LIGHTING_BIT: 1018 { 1019 GLuint i; 1020 const struct gl_light_attrib *light; 1021 light = (const struct gl_light_attrib *) attr->data; 1022 /* lighting enable */ 1023 _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled); 1024 /* per-light state */ 1025 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) 1026 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top ); 1027 1028 for (i = 0; i < ctx->Const.MaxLights; i++) { 1029 const struct gl_light *l = &light->Light[i]; 1030 _mesa_set_enable(ctx, GL_LIGHT0 + i, l->Enabled); 1031 _mesa_light(ctx, i, GL_AMBIENT, l->Ambient); 1032 _mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse); 1033 _mesa_light(ctx, i, GL_SPECULAR, l->Specular ); 1034 _mesa_light(ctx, i, GL_POSITION, l->EyePosition); 1035 _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->EyeDirection); 1036 _mesa_light(ctx, i, GL_SPOT_EXPONENT, &l->SpotExponent); 1037 _mesa_light(ctx, i, GL_SPOT_CUTOFF, &l->SpotCutoff); 1038 _mesa_light(ctx, i, GL_CONSTANT_ATTENUATION, 1039 &l->ConstantAttenuation); 1040 _mesa_light(ctx, i, GL_LINEAR_ATTENUATION, 1041 &l->LinearAttenuation); 1042 _mesa_light(ctx, i, GL_QUADRATIC_ATTENUATION, 1043 &l->QuadraticAttenuation); 1044 } 1045 /* light model */ 1046 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT, 1047 light->Model.Ambient); 1048 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1049 (GLfloat) light->Model.LocalViewer); 1050 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1051 (GLfloat) light->Model.TwoSide); 1052 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL, 1053 (GLfloat) light->Model.ColorControl); 1054 /* shade model */ 1055 _mesa_ShadeModel(light->ShadeModel); 1056 /* color material */ 1057 _mesa_ColorMaterial(light->ColorMaterialFace, 1058 light->ColorMaterialMode); 1059 _mesa_set_enable(ctx, GL_COLOR_MATERIAL, 1060 light->ColorMaterialEnabled); 1061 /* materials */ 1062 MEMCPY(&ctx->Light.Material, &light->Material, 1063 sizeof(struct gl_material)); 1064 } 1065 break; 1066 case GL_LINE_BIT: 1067 { 1068 const struct gl_line_attrib *line; 1069 line = (const struct gl_line_attrib *) attr->data; 1070 _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag); 1071 _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag); 1072 _mesa_LineStipple(line->StippleFactor, line->StipplePattern); 1073 _mesa_LineWidth(line->Width); 1074 } 1075 break; 1076 case GL_LIST_BIT: 1077 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) ); 1078 break; 1079 case GL_PIXEL_MODE_BIT: 1080 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) ); 1081 /* XXX what other pixel state needs to be set by function calls? */ 1082 _mesa_ReadBuffer(ctx->Pixel.ReadBuffer); 1083 ctx->NewState |= _NEW_PIXEL; 1084 break; 1085 case GL_POINT_BIT: 1086 { 1087 const struct gl_point_attrib *point; 1088 point = (const struct gl_point_attrib *) attr->data; 1089 _mesa_PointSize(point->Size); 1090 _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag); 1091 if (ctx->Extensions.EXT_point_parameters) { 1092 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, 1093 point->Params); 1094 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1095 point->MinSize); 1096 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT, 1097 point->MaxSize); 1098 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1099 point->Threshold); 1100 } 1101 if (ctx->Extensions.NV_point_sprite 1102 || ctx->Extensions.ARB_point_sprite) { 1103 GLuint u; 1104 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 1105 _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, 1106 (GLint) point->CoordReplace[u]); 1107 } 1108 _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite); 1109 if (ctx->Extensions.NV_point_sprite) 1110 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV, 1111 ctx->Point.SpriteRMode); 1112 _mesa_PointParameterfEXT(GL_POINT_SPRITE_COORD_ORIGIN, 1113 (GLfloat)ctx->Point.SpriteOrigin); 1114 } 1115 } 1116 break; 1117 case GL_POLYGON_BIT: 1118 { 1119 const struct gl_polygon_attrib *polygon; 1120 polygon = (const struct gl_polygon_attrib *) attr->data; 1121 _mesa_CullFace(polygon->CullFaceMode); 1122 _mesa_FrontFace(polygon->FrontFace); 1123 _mesa_PolygonMode(GL_FRONT, polygon->FrontMode); 1124 _mesa_PolygonMode(GL_BACK, polygon->BackMode); 1125 _mesa_PolygonOffset(polygon->OffsetFactor, 1126 polygon->OffsetUnits); 1127 _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag); 1128 _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag); 1129 _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag); 1130 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT, 1131 polygon->OffsetPoint); 1132 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE, 1133 polygon->OffsetLine); 1134 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, 1135 polygon->OffsetFill); 1136 } 1137 break; 1138 case GL_POLYGON_STIPPLE_BIT: 1139 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) ); 1140 ctx->NewState |= _NEW_POLYGONSTIPPLE; 1141 if (ctx->Driver.PolygonStipple) 1142 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data ); 1143 break; 1144 case GL_SCISSOR_BIT: 1145 { 1146 const struct gl_scissor_attrib *scissor; 1147 scissor = (const struct gl_scissor_attrib *) attr->data; 1148 _mesa_Scissor(scissor->X, scissor->Y, 1149 scissor->Width, scissor->Height); 1150 _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled); 1151 } 1152 break; 1153 case GL_STENCIL_BUFFER_BIT: 1154 { 1155 const struct gl_stencil_attrib *stencil; 1156 stencil = (const struct gl_stencil_attrib *) attr->data; 1157 _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled); 1158 _mesa_ClearStencil(stencil->Clear); 1159 if (ctx->Extensions.EXT_stencil_two_side) { 1160 _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT, 1161 stencil->TestTwoSide); 1162 _mesa_ActiveStencilFaceEXT(stencil->ActiveFace 1163 ? GL_BACK : GL_FRONT); 1164 } 1165 /* front state */ 1166 _mesa_StencilFuncSeparate(GL_FRONT, 1167 stencil->Function[0], 1168 stencil->Ref[0], 1169 stencil->ValueMask[0]); 1170 _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]); 1171 _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0], 1172 stencil->ZFailFunc[0], 1173 stencil->ZPassFunc[0]); 1174 /* back state */ 1175 _mesa_StencilFuncSeparate(GL_BACK, 1176 stencil->Function[1], 1177 stencil->Ref[1], 1178 stencil->ValueMask[1]); 1179 _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]); 1180 _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1], 1181 stencil->ZFailFunc[1], 1182 stencil->ZPassFunc[1]); 1183 } 1184 break; 1185 case GL_TRANSFORM_BIT: 1186 { 1187 GLuint i; 1188 const struct gl_transform_attrib *xform; 1189 xform = (const struct gl_transform_attrib *) attr->data; 1190 _mesa_MatrixMode(xform->MatrixMode); 1191 if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top)) 1192 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); 1193 1194 /* restore clip planes */ 1195 for (i = 0; i < MAX_CLIP_PLANES; i++) { 1196 const GLuint mask = 1 << 1; 1197 const GLfloat *eyePlane = xform->EyeUserPlane[i]; 1198 COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane); 1199 if (xform->ClipPlanesEnabled & mask) { 1200 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE); 1201 } 1202 else { 1203 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE); 1204 } 1205 if (ctx->Driver.ClipPlane) 1206 ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, eyePlane ); 1207 } 1208 1209 /* normalize/rescale */ 1210 if (xform->Normalize != ctx->Transform.Normalize) 1211 _mesa_set_enable(ctx, GL_NORMALIZE,ctx->Transform.Normalize); 1212 if (xform->RescaleNormals != ctx->Transform.RescaleNormals) 1213 _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT, 1214 ctx->Transform.RescaleNormals); 1215 } 1216 break; 1217 case GL_TEXTURE_BIT: 1218 /* Take care of texture object reference counters */ 1219 { 1220 struct texture_state *texstate 1221 = (struct texture_state *) attr->data; 1222 pop_texture_group(ctx, texstate); 1223 ctx->NewState |= _NEW_TEXTURE; 1224 } 1225 break; 1226 case GL_VIEWPORT_BIT: 1227 { 1228 const struct gl_viewport_attrib *vp; 1229 vp = (const struct gl_viewport_attrib *) attr->data; 1230 _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height); 1231 _mesa_DepthRange(vp->Near, vp->Far); 1232 } 1233 break; 1234 case GL_MULTISAMPLE_BIT_ARB: 1235 { 1236 const struct gl_multisample_attrib *ms; 1237 ms = (const struct gl_multisample_attrib *) attr->data; 1238 _mesa_SampleCoverageARB(ms->SampleCoverageValue, 1239 ms->SampleCoverageInvert); 1240 } 1241 break; 1242 1243 default: 1244 _mesa_problem( ctx, "Bad attrib flag in PopAttrib"); 1245 break; 1246 } 1247 1248 next = attr->next; 1249 FREE( attr->data ); 1250 FREE( attr ); 1251 attr = next; 1252 } 1253} 1254 1255 1256/** 1257 * Helper for incrementing/decrementing vertex buffer object reference 1258 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group. 1259 */ 1260static void 1261adjust_buffer_object_ref_counts(struct gl_array_attrib *array, GLint step) 1262{ 1263 GLuint i; 1264 array->ArrayObj->Vertex.BufferObj->RefCount += step; 1265 array->ArrayObj->Normal.BufferObj->RefCount += step; 1266 array->ArrayObj->Color.BufferObj->RefCount += step; 1267 array->ArrayObj->SecondaryColor.BufferObj->RefCount += step; 1268 array->ArrayObj->FogCoord.BufferObj->RefCount += step; 1269 array->ArrayObj->Index.BufferObj->RefCount += step; 1270 array->ArrayObj->EdgeFlag.BufferObj->RefCount += step; 1271 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) 1272 array->ArrayObj->TexCoord[i].BufferObj->RefCount += step; 1273 for (i = 0; i < VERT_ATTRIB_MAX; i++) 1274 array->ArrayObj->VertexAttrib[i].BufferObj->RefCount += step; 1275 1276 array->ArrayBufferObj->RefCount += step; 1277 array->ElementArrayBufferObj->RefCount += step; 1278} 1279 1280 1281#define GL_CLIENT_PACK_BIT (1<<20) 1282#define GL_CLIENT_UNPACK_BIT (1<<21) 1283 1284 1285void GLAPIENTRY 1286_mesa_PushClientAttrib(GLbitfield mask) 1287{ 1288 struct gl_attrib_node *newnode; 1289 struct gl_attrib_node *head; 1290 1291 GET_CURRENT_CONTEXT(ctx); 1292 ASSERT_OUTSIDE_BEGIN_END(ctx); 1293 1294 if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) { 1295 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" ); 1296 return; 1297 } 1298 1299 /* Build linked list of attribute nodes which save all attribute */ 1300 /* groups specified by the mask. */ 1301 head = NULL; 1302 1303 if (mask & GL_CLIENT_PIXEL_STORE_BIT) { 1304 struct gl_pixelstore_attrib *attr; 1305#if FEATURE_EXT_pixel_buffer_object 1306 ctx->Pack.BufferObj->RefCount++; 1307 ctx->Unpack.BufferObj->RefCount++; 1308#endif 1309 /* packing attribs */ 1310 attr = MALLOC_STRUCT( gl_pixelstore_attrib ); 1311 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) ); 1312 newnode = new_attrib_node( GL_CLIENT_PACK_BIT ); 1313 newnode->data = attr; 1314 newnode->next = head; 1315 head = newnode; 1316 /* unpacking attribs */ 1317 attr = MALLOC_STRUCT( gl_pixelstore_attrib ); 1318 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) ); 1319 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT ); 1320 newnode->data = attr; 1321 newnode->next = head; 1322 head = newnode; 1323 } 1324 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { 1325 struct gl_array_attrib *attr; 1326 struct gl_array_object *obj; 1327 1328 attr = MALLOC_STRUCT( gl_array_attrib ); 1329 obj = MALLOC_STRUCT( gl_array_object ); 1330 1331#if FEATURE_ARB_vertex_buffer_object 1332 /* increment ref counts since we're copying pointers to these objects */ 1333 ctx->Array.ArrayBufferObj->RefCount++; 1334 ctx->Array.ElementArrayBufferObj->RefCount++; 1335#endif 1336 1337 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) ); 1338 MEMCPY( obj, ctx->Array.ArrayObj, sizeof(struct gl_array_object) ); 1339 1340 attr->ArrayObj = obj; 1341 1342 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT ); 1343 newnode->data = attr; 1344 newnode->next = head; 1345 head = newnode; 1346 /* bump reference counts on buffer objects */ 1347 adjust_buffer_object_ref_counts(&ctx->Array, 1); 1348 } 1349 1350 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head; 1351 ctx->ClientAttribStackDepth++; 1352} 1353 1354 1355 1356 1357void GLAPIENTRY 1358_mesa_PopClientAttrib(void) 1359{ 1360 struct gl_attrib_node *attr, *next; 1361 1362 GET_CURRENT_CONTEXT(ctx); 1363 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1364 1365 if (ctx->ClientAttribStackDepth == 0) { 1366 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" ); 1367 return; 1368 } 1369 1370 ctx->ClientAttribStackDepth--; 1371 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth]; 1372 1373 while (attr) { 1374 switch (attr->kind) { 1375 case GL_CLIENT_PACK_BIT: 1376#if FEATURE_EXT_pixel_buffer_object 1377 ctx->Pack.BufferObj->RefCount--; 1378 if (ctx->Pack.BufferObj->RefCount <= 0) { 1379 _mesa_remove_buffer_object( ctx, ctx->Pack.BufferObj ); 1380 (*ctx->Driver.DeleteBuffer)( ctx, ctx->Pack.BufferObj ); 1381 } 1382#endif 1383 MEMCPY( &ctx->Pack, attr->data, 1384 sizeof(struct gl_pixelstore_attrib) ); 1385 ctx->NewState |= _NEW_PACKUNPACK; 1386 break; 1387 case GL_CLIENT_UNPACK_BIT: 1388#if FEATURE_EXT_pixel_buffer_object 1389 ctx->Unpack.BufferObj->RefCount--; 1390 if (ctx->Unpack.BufferObj->RefCount <= 0) { 1391 _mesa_remove_buffer_object( ctx, ctx->Unpack.BufferObj ); 1392 (*ctx->Driver.DeleteBuffer)( ctx, ctx->Unpack.BufferObj ); 1393 } 1394#endif 1395 MEMCPY( &ctx->Unpack, attr->data, 1396 sizeof(struct gl_pixelstore_attrib) ); 1397 ctx->NewState |= _NEW_PACKUNPACK; 1398 break; 1399 case GL_CLIENT_VERTEX_ARRAY_BIT: { 1400 struct gl_array_attrib * data = 1401 (struct gl_array_attrib *) attr->data; 1402 1403 adjust_buffer_object_ref_counts(&ctx->Array, -1); 1404 1405 ctx->Array.ActiveTexture = data->ActiveTexture; 1406 ctx->Array.LockFirst = data->LockFirst; 1407 ctx->Array.LockCount = data->LockCount; 1408 1409 _mesa_BindVertexArrayAPPLE( data->ArrayObj->Name ); 1410 1411#if FEATURE_ARB_vertex_buffer_object 1412 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, 1413 data->ArrayBufferObj->Name); 1414 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 1415 data->ElementArrayBufferObj->Name); 1416#endif 1417 1418 MEMCPY( ctx->Array.ArrayObj, data->ArrayObj, 1419 sizeof( struct gl_array_object ) ); 1420 1421 FREE( data->ArrayObj ); 1422 1423 /* FIXME: Should some bits in ctx->Array->NewState also be set 1424 * FIXME: here? It seems like it should be set to inclusive-or 1425 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled. 1426 */ 1427 1428 ctx->NewState |= _NEW_ARRAY; 1429 break; 1430 } 1431 default: 1432 _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib"); 1433 break; 1434 } 1435 1436 next = attr->next; 1437 FREE( attr->data ); 1438 FREE( attr ); 1439 attr = next; 1440 } 1441} 1442 1443 1444void 1445_mesa_free_attrib_data(GLcontext *ctx) 1446{ 1447 while (ctx->AttribStackDepth > 0) { 1448 struct gl_attrib_node *attr, *next; 1449 1450 ctx->AttribStackDepth--; 1451 attr = ctx->AttribStack[ctx->AttribStackDepth]; 1452 1453 while (attr) { 1454 if (attr->kind == GL_TEXTURE_BIT) { 1455 struct texture_state *texstate = (struct texture_state*)attr->data; 1456 GLuint u; 1457 /* clear references to the saved texture objects */ 1458 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { 1459 _mesa_reference_texobj(&texstate->SavedRef1D[u], NULL); 1460 _mesa_reference_texobj(&texstate->SavedRef2D[u], NULL); 1461 _mesa_reference_texobj(&texstate->SavedRef3D[u], NULL); 1462 _mesa_reference_texobj(&texstate->SavedRefCube[u], NULL); 1463 _mesa_reference_texobj(&texstate->SavedRefRect[u], NULL); 1464 } 1465 } 1466 else { 1467 /* any other chunks of state that requires special handling? */ 1468 } 1469 1470 next = attr->next; 1471 _mesa_free(attr->data); 1472 _mesa_free(attr); 1473 attr = next; 1474 } 1475 } 1476} 1477 1478 1479void _mesa_init_attrib( GLcontext *ctx ) 1480{ 1481 /* Renderer and client attribute stacks */ 1482 ctx->AttribStackDepth = 0; 1483 ctx->ClientAttribStackDepth = 0; 1484} 1485