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