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