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