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