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