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