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