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