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