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