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