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