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