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