1 /* $Id: attrib.c,v 1.58 2001/12/14 02:50:01 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
50 #include "simple_list.h"
61 * Allocate a new attribute state node. These nodes have a
62 * "kind" value and a pointer to a struct of state data.
64 static struct gl_attrib_node
*
65 new_attrib_node( GLbitfield kind
)
67 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
77 * Copy texture object state from one texture object to another.
80 copy_texobj_state( struct gl_texture_object
*dest
,
81 const struct gl_texture_object
*src
)
83 dest
->Name
= src
->Name
;
85 dest->Dimensions = src->Dimensions;
87 dest
->Priority
= src
->Priority
;
88 dest
->BorderColor
[0] = src
->BorderColor
[0];
89 dest
->BorderColor
[1] = src
->BorderColor
[1];
90 dest
->BorderColor
[2] = src
->BorderColor
[2];
91 dest
->BorderColor
[3] = src
->BorderColor
[3];
92 dest
->WrapS
= src
->WrapS
;
93 dest
->WrapT
= src
->WrapT
;
94 dest
->WrapR
= src
->WrapR
;
95 dest
->MinFilter
= src
->MinFilter
;
96 dest
->MagFilter
= src
->MagFilter
;
97 dest
->MinLod
= src
->MinLod
;
98 dest
->MaxLod
= src
->MaxLod
;
99 dest
->BaseLevel
= src
->BaseLevel
;
100 dest
->MaxLevel
= src
->MaxLevel
;
101 dest
->MaxAnisotropy
= src
->MaxAnisotropy
;
102 dest
->CompareFlag
= src
->CompareFlag
;
103 dest
->CompareOperator
= src
->CompareOperator
;
104 dest
->ShadowAmbient
= src
->ShadowAmbient
;
105 dest
->_MaxLevel
= src
->_MaxLevel
;
106 dest
->_MaxLambda
= src
->_MaxLambda
;
107 dest
->Palette
= src
->Palette
;
108 dest
->Complete
= src
->Complete
;
114 _mesa_PushAttrib(GLbitfield mask
)
116 struct gl_attrib_node
*newnode
;
117 struct gl_attrib_node
*head
;
119 GET_CURRENT_CONTEXT(ctx
);
120 ASSERT_OUTSIDE_BEGIN_END(ctx
);
122 if (MESA_VERBOSE
&VERBOSE_API
)
123 fprintf(stderr
, "glPushAttrib %x\n", (int)mask
);
125 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
126 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
130 /* Build linked list of attribute nodes which save all attribute */
131 /* groups specified by the mask. */
134 if (mask
& GL_ACCUM_BUFFER_BIT
) {
135 struct gl_accum_attrib
*attr
;
136 attr
= MALLOC_STRUCT( gl_accum_attrib
);
137 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
138 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
139 newnode
->data
= attr
;
140 newnode
->next
= head
;
144 if (mask
& GL_COLOR_BUFFER_BIT
) {
145 struct gl_colorbuffer_attrib
*attr
;
146 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
147 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
148 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
149 newnode
->data
= attr
;
150 newnode
->next
= head
;
154 if (mask
& GL_CURRENT_BIT
) {
155 struct gl_current_attrib
*attr
;
156 FLUSH_CURRENT( ctx
, 0 );
157 attr
= MALLOC_STRUCT( gl_current_attrib
);
158 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
159 newnode
= new_attrib_node( GL_CURRENT_BIT
);
160 newnode
->data
= attr
;
161 newnode
->next
= head
;
165 if (mask
& GL_DEPTH_BUFFER_BIT
) {
166 struct gl_depthbuffer_attrib
*attr
;
167 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
168 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
169 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
170 newnode
->data
= attr
;
171 newnode
->next
= head
;
175 if (mask
& GL_ENABLE_BIT
) {
176 struct gl_enable_attrib
*attr
;
178 attr
= MALLOC_STRUCT( gl_enable_attrib
);
179 /* Copy enable flags from all other attributes into the enable struct. */
180 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
181 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
182 attr
->Blend
= ctx
->Color
.BlendEnabled
;
183 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
184 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
186 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
187 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
188 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
189 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
190 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
191 attr
->DepthTest
= ctx
->Depth
.Test
;
192 attr
->Dither
= ctx
->Color
.DitherFlag
;
193 attr
->Fog
= ctx
->Fog
.Enabled
;
194 for (i
=0;i
<MAX_LIGHTS
;i
++) {
195 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
197 attr
->Lighting
= ctx
->Light
.Enabled
;
198 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
199 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
200 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
201 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
202 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
203 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
204 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
205 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
206 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
207 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
208 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
209 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
210 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
211 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
212 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
213 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
214 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
215 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
216 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
217 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
218 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
219 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
220 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
221 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
222 attr
->Normalize
= ctx
->Transform
.Normalize
;
223 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
224 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
225 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
226 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
227 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
228 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
229 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
230 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
231 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
232 attr
->Scissor
= ctx
->Scissor
.Enabled
;
233 attr
->Stencil
= ctx
->Stencil
.Enabled
;
234 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
235 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
236 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
237 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
238 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
239 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
240 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
241 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
243 /* GL_NV_vertex_program */
244 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
245 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
246 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
247 newnode
= new_attrib_node( GL_ENABLE_BIT
);
248 newnode
->data
= attr
;
249 newnode
->next
= head
;
253 if (mask
& GL_EVAL_BIT
) {
254 struct gl_eval_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_eval_attrib
);
256 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
257 newnode
= new_attrib_node( GL_EVAL_BIT
);
258 newnode
->data
= attr
;
259 newnode
->next
= head
;
263 if (mask
& GL_FOG_BIT
) {
264 struct gl_fog_attrib
*attr
;
265 attr
= MALLOC_STRUCT( gl_fog_attrib
);
266 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
267 newnode
= new_attrib_node( GL_FOG_BIT
);
268 newnode
->data
= attr
;
269 newnode
->next
= head
;
273 if (mask
& GL_HINT_BIT
) {
274 struct gl_hint_attrib
*attr
;
275 attr
= MALLOC_STRUCT( gl_hint_attrib
);
276 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
277 newnode
= new_attrib_node( GL_HINT_BIT
);
278 newnode
->data
= attr
;
279 newnode
->next
= head
;
283 if (mask
& GL_LIGHTING_BIT
) {
284 struct gl_light_attrib
*attr
;
285 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
286 attr
= MALLOC_STRUCT( gl_light_attrib
);
287 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
288 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
289 newnode
->data
= attr
;
290 newnode
->next
= head
;
294 if (mask
& GL_LINE_BIT
) {
295 struct gl_line_attrib
*attr
;
296 attr
= MALLOC_STRUCT( gl_line_attrib
);
297 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
298 newnode
= new_attrib_node( GL_LINE_BIT
);
299 newnode
->data
= attr
;
300 newnode
->next
= head
;
304 if (mask
& GL_LIST_BIT
) {
305 struct gl_list_attrib
*attr
;
306 attr
= MALLOC_STRUCT( gl_list_attrib
);
307 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
308 newnode
= new_attrib_node( GL_LIST_BIT
);
309 newnode
->data
= attr
;
310 newnode
->next
= head
;
314 if (mask
& GL_PIXEL_MODE_BIT
) {
315 struct gl_pixel_attrib
*attr
;
316 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
317 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
318 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
319 newnode
->data
= attr
;
320 newnode
->next
= head
;
324 if (mask
& GL_POINT_BIT
) {
325 struct gl_point_attrib
*attr
;
326 attr
= MALLOC_STRUCT( gl_point_attrib
);
327 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
328 newnode
= new_attrib_node( GL_POINT_BIT
);
329 newnode
->data
= attr
;
330 newnode
->next
= head
;
334 if (mask
& GL_POLYGON_BIT
) {
335 struct gl_polygon_attrib
*attr
;
336 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
337 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
338 newnode
= new_attrib_node( GL_POLYGON_BIT
);
339 newnode
->data
= attr
;
340 newnode
->next
= head
;
344 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
346 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
347 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
348 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
349 newnode
->data
= stipple
;
350 newnode
->next
= head
;
354 if (mask
& GL_SCISSOR_BIT
) {
355 struct gl_scissor_attrib
*attr
;
356 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
357 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
358 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
359 newnode
->data
= attr
;
360 newnode
->next
= head
;
364 if (mask
& GL_STENCIL_BUFFER_BIT
) {
365 struct gl_stencil_attrib
*attr
;
366 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
367 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
368 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
369 newnode
->data
= attr
;
370 newnode
->next
= head
;
374 if (mask
& GL_TEXTURE_BIT
) {
375 struct gl_texture_attrib
*attr
;
377 /* Bump the texture object reference counts so that they don't
378 * inadvertantly get deleted.
380 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
381 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
382 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
383 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
384 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
386 attr
= MALLOC_STRUCT( gl_texture_attrib
);
387 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
388 /* copy state of the currently bound texture objects */
389 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
390 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].Current1D
);
391 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].Current2D
);
392 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].Current3D
);
393 copy_texobj_state(&attr
->Unit
[u
].SavedCubeMap
, attr
->Unit
[u
].CurrentCubeMap
);
395 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
396 newnode
->data
= attr
;
397 newnode
->next
= head
;
401 if (mask
& GL_TRANSFORM_BIT
) {
402 struct gl_transform_attrib
*attr
;
403 attr
= MALLOC_STRUCT( gl_transform_attrib
);
404 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
405 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
406 newnode
->data
= attr
;
407 newnode
->next
= head
;
411 if (mask
& GL_VIEWPORT_BIT
) {
412 struct gl_viewport_attrib
*attr
;
413 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
414 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
415 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
416 newnode
->data
= attr
;
417 newnode
->next
= head
;
421 /* GL_ARB_multisample */
422 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
423 struct gl_multisample_attrib
*attr
;
424 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
425 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
426 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
427 newnode
->data
= attr
;
428 newnode
->next
= head
;
432 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
433 ctx
->AttribStackDepth
++;
439 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
443 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
444 if ((VALUE) != (NEWVALUE)) { \
445 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
448 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
449 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
451 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
452 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
453 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
454 enable
->ClipPlane
[i
]);
457 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
459 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
460 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
461 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
462 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
464 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
466 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
468 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
469 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
470 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
471 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
473 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
475 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
477 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
478 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
479 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
480 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
481 GL_MAP1_TEXTURE_COORD_1
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
483 GL_MAP1_TEXTURE_COORD_2
);
484 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
485 GL_MAP1_TEXTURE_COORD_3
);
486 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
487 GL_MAP1_TEXTURE_COORD_4
);
488 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
490 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
492 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
493 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
494 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
495 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
496 GL_MAP2_TEXTURE_COORD_1
);
497 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
498 GL_MAP2_TEXTURE_COORD_2
);
499 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
500 GL_MAP2_TEXTURE_COORD_3
);
501 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
502 GL_MAP2_TEXTURE_COORD_4
);
503 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
505 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
507 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
508 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
509 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
510 GL_RESCALE_NORMAL_EXT
);
511 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
512 enable
->RasterPositionUnclipped
,
513 GL_RASTER_POSITION_UNCLIPPED_IBM
);
514 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
516 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
518 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
519 GL_POLYGON_OFFSET_POINT
);
520 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
521 GL_POLYGON_OFFSET_LINE
);
522 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
523 GL_POLYGON_OFFSET_FILL
);
524 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
526 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
528 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
529 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
530 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
532 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
533 enable
->SampleAlphaToCoverage
,
534 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
535 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
536 enable
->SampleAlphaToOne
,
537 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
538 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
539 enable
->SampleCoverage
,
540 GL_SAMPLE_COVERAGE_ARB
);
541 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
542 enable
->SampleCoverageInvert
,
543 GL_SAMPLE_COVERAGE_INVERT_ARB
);
544 /* GL_NV_vertex_program */
545 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
546 enable
->VertexProgram
,
547 GL_VERTEX_PROGRAM_NV
);
548 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
549 enable
->VertexProgramPointSize
,
550 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
551 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
552 enable
->VertexProgramTwoSide
,
553 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
555 #undef TEST_AND_UPDATE
557 /* texture unit enables */
558 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
559 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
560 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
561 if (ctx
->Driver
.Enable
) {
562 if (ctx
->Driver
.ActiveTexture
) {
563 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
565 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
566 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_1D
) );
567 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
568 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_2D
) );
569 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
570 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_3D
) );
574 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
575 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
576 if (ctx
->Driver
.Enable
) {
577 if (ctx
->Driver
.ActiveTexture
) {
578 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
580 if (enable
->TexGen
[i
] & S_BIT
)
581 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
583 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
584 if (enable
->TexGen
[i
] & T_BIT
)
585 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
587 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
588 if (enable
->TexGen
[i
] & R_BIT
)
589 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
591 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
592 if (enable
->TexGen
[i
] & Q_BIT
)
593 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
595 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
600 if (ctx
->Driver
.ActiveTexture
) {
601 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
607 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
611 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
612 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
615 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
616 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
617 (GLboolean
) (unit
->Enabled
& TEXTURE0_1D
? GL_TRUE
: GL_FALSE
));
618 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
619 (GLboolean
) (unit
->Enabled
& TEXTURE0_2D
? GL_TRUE
: GL_FALSE
));
620 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
621 (GLboolean
) (unit
->Enabled
& TEXTURE0_3D
? GL_TRUE
: GL_FALSE
));
622 if (ctx
->Extensions
.ARB_texture_cube_map
) {
623 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
624 (GLboolean
) (unit
->Enabled
& TEXTURE0_CUBE
? GL_TRUE
: GL_FALSE
));
626 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
627 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
628 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
629 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
630 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
631 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
632 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
633 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
634 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
635 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
636 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
637 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
638 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
639 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
640 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
641 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
642 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
644 if (ctx
->Extensions
.EXT_texture_env_combine
||
645 ctx
->Extensions
.ARB_texture_env_combine
) {
646 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB_EXT
,
647 unit
->CombineModeRGB
);
648 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA_EXT
,
650 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB_EXT
,
651 unit
->CombineSourceRGB
[0]);
652 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB_EXT
,
653 unit
->CombineSourceRGB
[1]);
654 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB_EXT
,
655 unit
->CombineSourceRGB
[2]);
656 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA_EXT
,
657 unit
->CombineSourceA
[0]);
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA_EXT
,
659 unit
->CombineSourceA
[1]);
660 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA_EXT
,
661 unit
->CombineSourceA
[2]);
662 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB_EXT
,
663 unit
->CombineOperandRGB
[0]);
664 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB_EXT
,
665 unit
->CombineOperandRGB
[1]);
666 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB_EXT
,
667 unit
->CombineOperandRGB
[2]);
668 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA_EXT
,
669 unit
->CombineOperandA
[0]);
670 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA_EXT
,
671 unit
->CombineOperandA
[1]);
672 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA_EXT
,
673 unit
->CombineOperandA
[2]);
674 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE_EXT
,
675 1 << unit
->CombineScaleShiftRGB
);
676 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
677 1 << unit
->CombineScaleShiftA
);
680 /* Restore texture object state */
681 numObjs
= ctx
->Extensions
.ARB_texture_cube_map
? 4 : 3;
683 for (i
= 0; i
< numObjs
; i
++) {
685 const struct gl_texture_object
*obj
= NULL
;
686 GLfloat bordColor
[4];
690 target
= GL_TEXTURE_1D
;
691 obj
= &unit
->Saved1D
;
694 target
= GL_TEXTURE_2D
;
695 obj
= &unit
->Saved2D
;
698 target
= GL_TEXTURE_3D
;
699 obj
= &unit
->Saved3D
;
702 target
= GL_TEXTURE_CUBE_MAP_ARB
;
703 obj
= &unit
->SavedCubeMap
;
706 ; /* silence warnings */
709 _mesa_BindTexture(target
, obj
->Name
);
711 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
712 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
713 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
714 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
716 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
717 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
718 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
719 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
720 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
721 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
722 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
723 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
724 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
725 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
726 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
727 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
728 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
731 if (ctx
->Extensions
.SGIX_shadow
) {
732 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
734 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
735 obj
->CompareOperator
);
737 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
738 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
739 CHAN_TO_FLOAT(obj
->ShadowAmbient
));
744 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
745 + texAttrib
->CurrentUnit
);
747 /* "un-bump" the texture object reference counts. We did that so they
748 * wouldn't inadvertantly get deleted while they were still referenced
749 * inside the attribute state stack.
751 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
752 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
753 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
754 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
755 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
761 * This function is kind of long just because we have to call a lot
762 * of device driver functions to update device driver state.
764 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
765 * in order to restore GL state. This isn't terribly efficient but it
766 * ensures that dirty flags and any derived state gets updated correctly.
767 * We could at least check if the value to restore equals the current value
768 * and then skip the Mesa call.
771 _mesa_PopAttrib(void)
773 struct gl_attrib_node
*attr
, *next
;
774 GET_CURRENT_CONTEXT(ctx
);
775 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
777 if (ctx
->AttribStackDepth
== 0) {
778 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
782 ctx
->AttribStackDepth
--;
783 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
787 if (MESA_VERBOSE
&VERBOSE_API
) {
788 fprintf(stderr
, "glPopAttrib %s\n",
789 _mesa_lookup_enum_by_nr(attr
->kind
));
792 switch (attr
->kind
) {
793 case GL_ACCUM_BUFFER_BIT
:
795 const struct gl_accum_attrib
*accum
;
796 accum
= (const struct gl_accum_attrib
*) attr
->data
;
797 _mesa_ClearAccum(accum
->ClearColor
[0],
798 accum
->ClearColor
[1],
799 accum
->ClearColor
[2],
800 accum
->ClearColor
[3]);
803 case GL_COLOR_BUFFER_BIT
:
805 const struct gl_colorbuffer_attrib
*color
;
806 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
807 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
808 _mesa_ClearColor(CHAN_TO_FLOAT(color
->ClearColor
[0]),
809 CHAN_TO_FLOAT(color
->ClearColor
[1]),
810 CHAN_TO_FLOAT(color
->ClearColor
[2]),
811 CHAN_TO_FLOAT(color
->ClearColor
[3]));
812 _mesa_IndexMask(color
->IndexMask
);
813 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
814 (GLboolean
) (color
->ColorMask
[1] != 0),
815 (GLboolean
) (color
->ColorMask
[2] != 0),
816 (GLboolean
) (color
->ColorMask
[3] != 0));
817 _mesa_DrawBuffer(color
->DrawBuffer
);
818 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
819 _mesa_AlphaFunc(color
->AlphaFunc
,
820 CHAN_TO_FLOAT(color
->AlphaRef
));
821 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
822 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
826 _mesa_BlendEquation(color
->BlendEquation
);
827 _mesa_BlendColor(color
->BlendColor
[0],
828 color
->BlendColor
[1],
829 color
->BlendColor
[2],
830 color
->BlendColor
[3]);
831 _mesa_LogicOp(color
->LogicOp
);
832 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
833 color
->ColorLogicOpEnabled
);
834 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
835 color
->IndexLogicOpEnabled
);
836 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
840 FLUSH_CURRENT( ctx
, 0 );
841 MEMCPY( &ctx
->Current
, attr
->data
,
842 sizeof(struct gl_current_attrib
) );
844 case GL_DEPTH_BUFFER_BIT
:
846 const struct gl_depthbuffer_attrib
*depth
;
847 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
848 _mesa_DepthFunc(depth
->Func
);
849 _mesa_ClearDepth(depth
->Clear
);
850 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
851 _mesa_DepthMask(depth
->Mask
);
852 if (ctx
->Extensions
.HP_occlusion_test
)
853 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
854 depth
->OcclusionTest
);
859 const struct gl_enable_attrib
*enable
;
860 enable
= (const struct gl_enable_attrib
*) attr
->data
;
861 pop_enable_group(ctx
, enable
);
862 ctx
->NewState
|= _NEW_ALL
;
866 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
867 ctx
->NewState
|= _NEW_EVAL
;
871 const struct gl_fog_attrib
*fog
;
872 fog
= (const struct gl_fog_attrib
*) attr
->data
;
873 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
874 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
875 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
876 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
877 _mesa_Fogf(GL_FOG_END
, fog
->End
);
878 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
879 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
884 const struct gl_hint_attrib
*hint
;
885 hint
= (const struct gl_hint_attrib
*) attr
->data
;
886 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
887 hint
->PerspectiveCorrection
);
888 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
889 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
890 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
891 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
892 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
893 hint
->ClipVolumeClipping
);
894 if (ctx
->Extensions
.ARB_texture_compression
)
895 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
896 hint
->TextureCompression
);
899 case GL_LIGHTING_BIT
:
902 const struct gl_light_attrib
*light
;
903 light
= (const struct gl_light_attrib
*) attr
->data
;
904 /* lighting enable */
905 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
906 /* per-light state */
907 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
908 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
909 _mesa_set_enable(ctx
, lgt
, light
->Light
[i
].Enabled
);
910 MEMCPY(&ctx
->Light
.Light
[i
], &light
->Light
[i
],
911 sizeof(struct gl_light
));
914 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
915 light
->Model
.Ambient
);
916 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
917 (GLfloat
) light
->Model
.LocalViewer
);
918 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
919 (GLfloat
) light
->Model
.TwoSide
);
920 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
921 (GLfloat
) light
->Model
.ColorControl
);
923 MEMCPY(ctx
->Light
.Material
, light
->Material
,
924 2 * sizeof(struct gl_material
));
926 _mesa_ShadeModel(light
->ShadeModel
);
928 _mesa_ColorMaterial(light
->ColorMaterialFace
,
929 light
->ColorMaterialMode
);
930 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
931 light
->ColorMaterialEnabled
);
936 const struct gl_line_attrib
*line
;
937 line
= (const struct gl_line_attrib
*) attr
->data
;
938 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
939 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
940 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
941 _mesa_LineWidth(line
->Width
);
945 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
947 case GL_PIXEL_MODE_BIT
:
948 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
949 ctx
->NewState
|= _NEW_PIXEL
;
953 const struct gl_point_attrib
*point
;
954 point
= (const struct gl_point_attrib
*) attr
->data
;
955 _mesa_PointSize(point
->Size
);
956 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
957 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
959 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
, point
->MinSize
);
960 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
, point
->MaxSize
);
961 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
967 const struct gl_polygon_attrib
*polygon
;
968 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
969 _mesa_CullFace(polygon
->CullFaceMode
);
970 _mesa_FrontFace(polygon
->FrontFace
);
971 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
972 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
973 _mesa_PolygonOffset(polygon
->OffsetFactor
,
974 polygon
->OffsetUnits
);
975 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
976 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
977 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
978 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
979 polygon
->OffsetPoint
);
980 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
981 polygon
->OffsetLine
);
982 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
983 polygon
->OffsetFill
);
986 case GL_POLYGON_STIPPLE_BIT
:
987 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
988 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
989 if (ctx
->Driver
.PolygonStipple
)
990 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
994 const struct gl_scissor_attrib
*scissor
;
995 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
996 _mesa_Scissor(scissor
->X
, scissor
->Y
,
997 scissor
->Width
, scissor
->Height
);
998 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1001 case GL_STENCIL_BUFFER_BIT
:
1003 const struct gl_stencil_attrib
*stencil
;
1004 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1005 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1006 _mesa_ClearStencil(stencil
->Clear
);
1007 _mesa_StencilFunc(stencil
->Function
, stencil
->Ref
,
1008 stencil
->ValueMask
);
1009 _mesa_StencilMask(stencil
->WriteMask
);
1010 _mesa_StencilOp(stencil
->FailFunc
, stencil
->ZFailFunc
,
1011 stencil
->ZPassFunc
);
1014 case GL_TRANSFORM_BIT
:
1017 const struct gl_transform_attrib
*xform
;
1018 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1019 _mesa_MatrixMode(xform
->MatrixMode
);
1021 MEMCPY(ctx
->Transform
.EyeUserPlane
, xform
->EyeUserPlane
,
1022 sizeof(xform
->EyeUserPlane
));
1023 MEMCPY(ctx
->Transform
._ClipUserPlane
, xform
->_ClipUserPlane
,
1024 sizeof(xform
->EyeUserPlane
));
1025 /* clip plane enable flags */
1026 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1027 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1028 xform
->ClipEnabled
[i
]);
1030 /* normalize/rescale */
1031 _mesa_set_enable(ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
1032 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1033 ctx
->Transform
.RescaleNormals
);
1036 case GL_TEXTURE_BIT
:
1037 /* Take care of texture object reference counters */
1039 const struct gl_texture_attrib
*texture
;
1040 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1041 pop_texture_group(ctx
, texture
);
1042 ctx
->NewState
|= _NEW_TEXTURE
;
1045 case GL_VIEWPORT_BIT
:
1047 const struct gl_viewport_attrib
*vp
;
1048 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1049 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1050 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1053 case GL_MULTISAMPLE_BIT_ARB
:
1055 const struct gl_multisample_attrib
*ms
;
1056 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1057 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1058 ms
->SampleCoverageInvert
);
1063 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1075 #define GL_CLIENT_PACK_BIT (1<<20)
1076 #define GL_CLIENT_UNPACK_BIT (1<<21)
1080 _mesa_PushClientAttrib(GLbitfield mask
)
1082 struct gl_attrib_node
*newnode
;
1083 struct gl_attrib_node
*head
;
1085 GET_CURRENT_CONTEXT(ctx
);
1086 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1088 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1089 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1093 /* Build linked list of attribute nodes which save all attribute */
1094 /* groups specified by the mask. */
1097 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1098 struct gl_pixelstore_attrib
*attr
;
1099 /* packing attribs */
1100 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1101 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1102 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1103 newnode
->data
= attr
;
1104 newnode
->next
= head
;
1106 /* unpacking attribs */
1107 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1108 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1109 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1110 newnode
->data
= attr
;
1111 newnode
->next
= head
;
1114 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1115 struct gl_array_attrib
*attr
;
1116 attr
= MALLOC_STRUCT( gl_array_attrib
);
1117 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1118 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1119 newnode
->data
= attr
;
1120 newnode
->next
= head
;
1124 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1125 ctx
->ClientAttribStackDepth
++;
1132 _mesa_PopClientAttrib(void)
1134 struct gl_attrib_node
*attr
, *next
;
1136 GET_CURRENT_CONTEXT(ctx
);
1137 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1139 if (ctx
->ClientAttribStackDepth
== 0) {
1140 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1144 ctx
->ClientAttribStackDepth
--;
1145 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1148 switch (attr
->kind
) {
1149 case GL_CLIENT_PACK_BIT
:
1150 MEMCPY( &ctx
->Pack
, attr
->data
,
1151 sizeof(struct gl_pixelstore_attrib
) );
1152 ctx
->NewState
|= _NEW_PACKUNPACK
;
1154 case GL_CLIENT_UNPACK_BIT
:
1155 MEMCPY( &ctx
->Unpack
, attr
->data
,
1156 sizeof(struct gl_pixelstore_attrib
) );
1157 ctx
->NewState
|= _NEW_PACKUNPACK
;
1159 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1160 MEMCPY( &ctx
->Array
, attr
->data
,
1161 sizeof(struct gl_array_attrib
) );
1162 ctx
->NewState
|= _NEW_ARRAY
;
1165 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");