1 /* $Id: attrib.c,v 1.46 2001/03/12 00:48:37 gareth 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.
54 #include "simple_list.h"
64 * Allocate a new attribute state node. These nodes have a
65 * "kind" value and a pointer to a struct of state data.
67 static struct gl_attrib_node
*
68 new_attrib_node( GLbitfield kind
)
70 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
80 * Copy texture object state from one texture object to another.
83 copy_texobj_state( struct gl_texture_object
*dest
,
84 const struct gl_texture_object
*src
)
87 dest->Name = src->Name;
88 dest->Dimensions = src->Dimensions;
90 dest
->Priority
= src
->Priority
;
91 dest
->BorderColor
[0] = src
->BorderColor
[0];
92 dest
->BorderColor
[1] = src
->BorderColor
[1];
93 dest
->BorderColor
[2] = src
->BorderColor
[2];
94 dest
->BorderColor
[3] = src
->BorderColor
[3];
95 dest
->WrapS
= src
->WrapS
;
96 dest
->WrapT
= src
->WrapT
;
97 dest
->WrapR
= src
->WrapR
;
98 dest
->MinFilter
= src
->MinFilter
;
99 dest
->MagFilter
= src
->MagFilter
;
100 dest
->MinLod
= src
->MinLod
;
101 dest
->MaxLod
= src
->MaxLod
;
102 dest
->BaseLevel
= src
->BaseLevel
;
103 dest
->MaxLevel
= src
->MaxLevel
;
104 dest
->CompareFlag
= src
->CompareFlag
;
105 dest
->CompareOperator
= src
->CompareOperator
;
106 dest
->ShadowAmbient
= src
->ShadowAmbient
;
107 dest
->_MaxLevel
= src
->_MaxLevel
;
108 dest
->_MaxLambda
= src
->_MaxLambda
;
109 dest
->Palette
= src
->Palette
;
110 dest
->Complete
= src
->Complete
;
116 _mesa_PushAttrib(GLbitfield mask
)
118 struct gl_attrib_node
*newnode
;
119 struct gl_attrib_node
*head
;
121 GET_CURRENT_CONTEXT(ctx
);
122 ASSERT_OUTSIDE_BEGIN_END(ctx
);
124 if (MESA_VERBOSE
&VERBOSE_API
)
125 fprintf(stderr
, "glPushAttrib %x\n", (int)mask
);
127 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
128 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
132 /* Build linked list of attribute nodes which save all attribute */
133 /* groups specified by the mask. */
136 if (mask
& GL_ACCUM_BUFFER_BIT
) {
137 struct gl_accum_attrib
*attr
;
138 attr
= MALLOC_STRUCT( gl_accum_attrib
);
139 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
140 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
141 newnode
->data
= attr
;
142 newnode
->next
= head
;
146 if (mask
& GL_COLOR_BUFFER_BIT
) {
147 struct gl_colorbuffer_attrib
*attr
;
148 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
149 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
150 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
151 newnode
->data
= attr
;
152 newnode
->next
= head
;
156 if (mask
& GL_CURRENT_BIT
) {
157 struct gl_current_attrib
*attr
;
158 FLUSH_CURRENT( ctx
, 0 );
159 attr
= MALLOC_STRUCT( gl_current_attrib
);
160 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
161 newnode
= new_attrib_node( GL_CURRENT_BIT
);
162 newnode
->data
= attr
;
163 newnode
->next
= head
;
167 if (mask
& GL_DEPTH_BUFFER_BIT
) {
168 struct gl_depthbuffer_attrib
*attr
;
169 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
170 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
171 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
172 newnode
->data
= attr
;
173 newnode
->next
= head
;
177 if (mask
& GL_ENABLE_BIT
) {
178 struct gl_enable_attrib
*attr
;
180 attr
= MALLOC_STRUCT( gl_enable_attrib
);
181 /* Copy enable flags from all other attributes into the enable struct. */
182 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
183 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
184 attr
->Blend
= ctx
->Color
.BlendEnabled
;
185 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
186 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
188 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
189 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
190 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
191 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
192 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
193 attr
->DepthTest
= ctx
->Depth
.Test
;
194 attr
->Dither
= ctx
->Color
.DitherFlag
;
195 attr
->Fog
= ctx
->Fog
.Enabled
;
196 for (i
=0;i
<MAX_LIGHTS
;i
++) {
197 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
199 attr
->Lighting
= ctx
->Light
.Enabled
;
200 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
201 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
202 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
203 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
204 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
205 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
206 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
207 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
208 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
209 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
210 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
211 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
212 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
213 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
214 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
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 attr
->Normalize
= ctx
->Transform
.Normalize
;
225 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
226 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
227 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
228 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
229 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
230 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
231 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
232 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
233 attr
->Scissor
= ctx
->Scissor
.Enabled
;
234 attr
->Stencil
= ctx
->Stencil
.Enabled
;
235 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
236 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
237 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
239 newnode
= new_attrib_node( GL_ENABLE_BIT
);
240 newnode
->data
= attr
;
241 newnode
->next
= head
;
245 if (mask
& GL_EVAL_BIT
) {
246 struct gl_eval_attrib
*attr
;
247 attr
= MALLOC_STRUCT( gl_eval_attrib
);
248 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
249 newnode
= new_attrib_node( GL_EVAL_BIT
);
250 newnode
->data
= attr
;
251 newnode
->next
= head
;
255 if (mask
& GL_FOG_BIT
) {
256 struct gl_fog_attrib
*attr
;
257 attr
= MALLOC_STRUCT( gl_fog_attrib
);
258 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
259 newnode
= new_attrib_node( GL_FOG_BIT
);
260 newnode
->data
= attr
;
261 newnode
->next
= head
;
265 if (mask
& GL_HINT_BIT
) {
266 struct gl_hint_attrib
*attr
;
267 attr
= MALLOC_STRUCT( gl_hint_attrib
);
268 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
269 newnode
= new_attrib_node( GL_HINT_BIT
);
270 newnode
->data
= attr
;
271 newnode
->next
= head
;
275 if (mask
& GL_LIGHTING_BIT
) {
276 struct gl_light_attrib
*attr
;
277 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
278 attr
= MALLOC_STRUCT( gl_light_attrib
);
279 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
280 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
281 newnode
->data
= attr
;
282 newnode
->next
= head
;
286 if (mask
& GL_LINE_BIT
) {
287 struct gl_line_attrib
*attr
;
288 attr
= MALLOC_STRUCT( gl_line_attrib
);
289 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
290 newnode
= new_attrib_node( GL_LINE_BIT
);
291 newnode
->data
= attr
;
292 newnode
->next
= head
;
296 if (mask
& GL_LIST_BIT
) {
297 struct gl_list_attrib
*attr
;
298 attr
= MALLOC_STRUCT( gl_list_attrib
);
299 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
300 newnode
= new_attrib_node( GL_LIST_BIT
);
301 newnode
->data
= attr
;
302 newnode
->next
= head
;
306 if (mask
& GL_PIXEL_MODE_BIT
) {
307 struct gl_pixel_attrib
*attr
;
308 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
309 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
310 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
311 newnode
->data
= attr
;
312 newnode
->next
= head
;
316 if (mask
& GL_POINT_BIT
) {
317 struct gl_point_attrib
*attr
;
318 attr
= MALLOC_STRUCT( gl_point_attrib
);
319 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
320 newnode
= new_attrib_node( GL_POINT_BIT
);
321 newnode
->data
= attr
;
322 newnode
->next
= head
;
326 if (mask
& GL_POLYGON_BIT
) {
327 struct gl_polygon_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
329 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
330 newnode
= new_attrib_node( GL_POLYGON_BIT
);
331 newnode
->data
= attr
;
332 newnode
->next
= head
;
336 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
338 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
339 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
340 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
341 newnode
->data
= stipple
;
342 newnode
->next
= head
;
346 if (mask
& GL_SCISSOR_BIT
) {
347 struct gl_scissor_attrib
*attr
;
348 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
349 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
350 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
351 newnode
->data
= attr
;
352 newnode
->next
= head
;
356 if (mask
& GL_STENCIL_BUFFER_BIT
) {
357 struct gl_stencil_attrib
*attr
;
358 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
359 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
360 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
361 newnode
->data
= attr
;
362 newnode
->next
= head
;
366 if (mask
& GL_TEXTURE_BIT
) {
367 struct gl_texture_attrib
*attr
;
369 /* Take care of texture object reference counters */
370 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
371 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
372 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
373 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
374 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
376 attr
= MALLOC_STRUCT( gl_texture_attrib
);
377 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
378 /* copy state of the currently bound texture objects */
379 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
380 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].Current1D
);
381 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].Current2D
);
382 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].Current3D
);
383 copy_texobj_state(&attr
->Unit
[u
].SavedCubeMap
, attr
->Unit
[u
].CurrentCubeMap
);
385 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
386 newnode
->data
= attr
;
387 newnode
->next
= head
;
391 if (mask
& GL_TRANSFORM_BIT
) {
392 struct gl_transform_attrib
*attr
;
393 attr
= MALLOC_STRUCT( gl_transform_attrib
);
394 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
395 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
396 newnode
->data
= attr
;
397 newnode
->next
= head
;
401 if (mask
& GL_VIEWPORT_BIT
) {
402 struct gl_viewport_attrib
*attr
;
403 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
404 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
405 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
406 newnode
->data
= attr
;
407 newnode
->next
= head
;
411 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
412 ctx
->AttribStackDepth
++;
418 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
422 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
423 if ((VALUE) != (NEWVALUE)) { \
424 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
427 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
428 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->AutoNormal
, GL_NORMALIZE
);
429 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
431 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
432 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
433 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
434 enable
->ClipPlane
[i
]);
437 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
439 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
440 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
441 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
442 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
444 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
446 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
448 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
449 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
450 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
451 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
453 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
455 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
457 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
458 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
459 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
460 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
461 GL_MAP1_TEXTURE_COORD_1
);
462 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
463 GL_MAP1_TEXTURE_COORD_2
);
464 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
465 GL_MAP1_TEXTURE_COORD_3
);
466 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
467 GL_MAP1_TEXTURE_COORD_4
);
468 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
470 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
472 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
473 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
474 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
475 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
476 GL_MAP2_TEXTURE_COORD_1
);
477 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
478 GL_MAP2_TEXTURE_COORD_2
);
479 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
480 GL_MAP2_TEXTURE_COORD_3
);
481 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
482 GL_MAP2_TEXTURE_COORD_4
);
483 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
485 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
487 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
488 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
489 GL_RESCALE_NORMAL_EXT
);
490 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
492 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
494 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
495 GL_POLYGON_OFFSET_POINT
);
496 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
497 GL_POLYGON_OFFSET_LINE
);
498 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
499 GL_POLYGON_OFFSET_FILL
);
500 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
502 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
504 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
505 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
506 #undef TEST_AND_UPDATE
508 /* texture unit enables */
509 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
510 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
511 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
512 if (ctx
->Driver
.Enable
) {
513 if (ctx
->Driver
.ActiveTexture
) {
514 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
516 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
517 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_1D
) );
518 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
519 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_2D
) );
520 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
521 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_3D
) );
525 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
526 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
527 if (ctx
->Driver
.Enable
) {
528 if (ctx
->Driver
.ActiveTexture
) {
529 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
531 if (enable
->TexGen
[i
] & S_BIT
)
532 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
534 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
535 if (enable
->TexGen
[i
] & T_BIT
)
536 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
538 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
539 if (enable
->TexGen
[i
] & R_BIT
)
540 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
542 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
543 if (enable
->TexGen
[i
] & Q_BIT
)
544 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
546 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
551 if (ctx
->Driver
.ActiveTexture
) {
552 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
559 * This function is kind of long just because we have to call a lot
560 * of device driver functions to update device driver state.
562 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
563 * in order to restore GL state. This isn't terribly efficient but it
564 * ensures that dirty flags and any derived state gets updated correctly.
565 * We could at least check if the value to restore equals the current value
566 * and then skip the Mesa call.
569 _mesa_PopAttrib(void)
571 struct gl_attrib_node
*attr
, *next
;
572 GET_CURRENT_CONTEXT(ctx
);
573 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
575 if (ctx
->AttribStackDepth
== 0) {
576 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
580 ctx
->AttribStackDepth
--;
581 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
585 if (MESA_VERBOSE
&VERBOSE_API
)
586 fprintf(stderr
, "glPopAttrib %s\n", _mesa_lookup_enum_by_nr(attr
->kind
));
588 switch (attr
->kind
) {
589 case GL_ACCUM_BUFFER_BIT
:
591 const struct gl_accum_attrib
*accum
;
592 accum
= (const struct gl_accum_attrib
*) attr
->data
;
593 _mesa_ClearAccum(accum
->ClearColor
[0],
594 accum
->ClearColor
[1],
595 accum
->ClearColor
[2],
596 accum
->ClearColor
[3]);
599 case GL_COLOR_BUFFER_BIT
:
601 const struct gl_colorbuffer_attrib
*color
;
602 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
603 _mesa_ClearIndex(color
->ClearIndex
);
604 _mesa_ClearColor(CHAN_TO_FLOAT(color
->ClearColor
[0]),
605 CHAN_TO_FLOAT(color
->ClearColor
[1]),
606 CHAN_TO_FLOAT(color
->ClearColor
[2]),
607 CHAN_TO_FLOAT(color
->ClearColor
[3]));
608 _mesa_IndexMask(color
->IndexMask
);
609 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
610 (GLboolean
) (color
->ColorMask
[1] != 0),
611 (GLboolean
) (color
->ColorMask
[2] != 0),
612 (GLboolean
) (color
->ColorMask
[3] != 0));
613 _mesa_DrawBuffer(color
->DrawBuffer
);
614 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
615 _mesa_AlphaFunc(color
->AlphaFunc
,
616 CHAN_TO_FLOAT(color
->AlphaRef
));
617 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
618 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
622 _mesa_BlendEquation(color
->BlendEquation
);
623 _mesa_BlendColor(color
->BlendColor
[0],
624 color
->BlendColor
[1],
625 color
->BlendColor
[2],
626 color
->BlendColor
[3]);
627 _mesa_LogicOp(color
->LogicOp
);
628 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
629 color
->ColorLogicOpEnabled
);
630 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
631 color
->IndexLogicOpEnabled
);
632 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
636 FLUSH_CURRENT( ctx
, 0 );
637 MEMCPY( &ctx
->Current
, attr
->data
,
638 sizeof(struct gl_current_attrib
) );
640 case GL_DEPTH_BUFFER_BIT
:
642 const struct gl_depthbuffer_attrib
*depth
;
643 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
644 _mesa_DepthFunc(depth
->Func
);
645 _mesa_ClearDepth(depth
->Clear
);
646 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
647 _mesa_DepthMask(depth
->Mask
);
648 if (ctx
->Extensions
.HP_occlusion_test
)
649 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
650 depth
->OcclusionTest
);
655 const struct gl_enable_attrib
*enable
;
656 enable
= (const struct gl_enable_attrib
*) attr
->data
;
657 pop_enable_group(ctx
, enable
);
658 ctx
->NewState
|= _NEW_ALL
;
662 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
663 ctx
->NewState
|= _NEW_EVAL
;
667 const struct gl_fog_attrib
*fog
;
668 fog
= (const struct gl_fog_attrib
*) attr
->data
;
669 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
670 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
671 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
672 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
673 _mesa_Fogf(GL_FOG_END
, fog
->End
);
674 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
675 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
680 const struct gl_hint_attrib
*hint
;
681 hint
= (const struct gl_hint_attrib
*) attr
->data
;
682 /* XXX this memcpy is temporary: */
683 MEMCPY(&ctx
->Hint
, hint
, sizeof(struct gl_hint_attrib
));
684 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
685 hint
->PerspectiveCorrection
);
686 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
687 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
688 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
689 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
690 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
691 hint
->ClipVolumeClipping
);
692 if (ctx
->Extensions
.ARB_texture_compression
)
693 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
694 hint
->TextureCompression
);
697 case GL_LIGHTING_BIT
:
700 const struct gl_light_attrib
*light
;
701 light
= (const struct gl_light_attrib
*) attr
->data
;
702 /* lighting enable */
703 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
704 /* per-light state */
705 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
706 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
707 _mesa_set_enable(ctx
, lgt
, light
->Light
[i
].Enabled
);
708 MEMCPY(&ctx
->Light
.Light
[i
], &light
->Light
[i
],
709 sizeof(struct gl_light
));
712 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
713 light
->Model
.Ambient
);
714 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
715 (GLfloat
) light
->Model
.LocalViewer
);
716 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
717 (GLfloat
) light
->Model
.TwoSide
);
718 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
719 (GLfloat
) light
->Model
.ColorControl
);
721 MEMCPY(ctx
->Light
.Material
, light
->Material
,
722 2 * sizeof(struct gl_material
));
724 _mesa_ShadeModel(light
->ShadeModel
);
726 _mesa_ColorMaterial(light
->ColorMaterialFace
,
727 light
->ColorMaterialMode
);
728 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
729 light
->ColorMaterialEnabled
);
734 const struct gl_line_attrib
*line
;
735 line
= (const struct gl_line_attrib
*) attr
->data
;
736 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
737 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
738 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
739 _mesa_LineWidth(line
->Width
);
743 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
745 case GL_PIXEL_MODE_BIT
:
746 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
747 ctx
->NewState
|= _NEW_PIXEL
;
751 const struct gl_point_attrib
*point
;
752 point
= (const struct gl_point_attrib
*) attr
->data
;
753 _mesa_PointSize(point
->Size
);
754 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
755 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
757 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
, point
->MinSize
);
758 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
, point
->MaxSize
);
759 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
765 const struct gl_polygon_attrib
*polygon
;
766 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
767 _mesa_CullFace(polygon
->CullFaceMode
);
768 _mesa_FrontFace(polygon
->FrontFace
);
769 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
770 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
771 _mesa_PolygonOffset(polygon
->OffsetFactor
,
772 polygon
->OffsetUnits
);
773 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
774 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
775 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
776 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
777 polygon
->OffsetPoint
);
778 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
779 polygon
->OffsetLine
);
780 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
781 polygon
->OffsetFill
);
784 case GL_POLYGON_STIPPLE_BIT
:
785 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
786 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
787 if (ctx
->Driver
.PolygonStipple
)
788 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
792 const struct gl_scissor_attrib
*scissor
;
793 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
794 _mesa_Scissor(scissor
->X
, scissor
->Y
,
795 scissor
->Width
, scissor
->Height
);
796 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
799 case GL_STENCIL_BUFFER_BIT
:
801 const struct gl_stencil_attrib
*stencil
;
802 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
803 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
804 _mesa_ClearStencil(stencil
->Clear
);
805 _mesa_StencilFunc(stencil
->Function
, stencil
->Ref
,
807 _mesa_StencilMask(stencil
->WriteMask
);
808 _mesa_StencilOp(stencil
->FailFunc
, stencil
->ZFailFunc
,
812 case GL_TRANSFORM_BIT
:
815 const struct gl_transform_attrib
*xform
;
816 xform
= (const struct gl_transform_attrib
*) attr
->data
;
817 _mesa_MatrixMode(xform
->MatrixMode
);
819 MEMCPY(ctx
->Transform
.EyeUserPlane
, xform
->EyeUserPlane
,
820 sizeof(xform
->EyeUserPlane
));
821 MEMCPY(ctx
->Transform
._ClipUserPlane
, xform
->_ClipUserPlane
,
822 sizeof(xform
->EyeUserPlane
));
823 /* clip plane enable flags */
824 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
825 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
826 xform
->ClipEnabled
[i
]);
828 /* normalize/rescale */
829 _mesa_set_enable(ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
830 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
831 ctx
->Transform
.RescaleNormals
);
835 /* Take care of texture object reference counters */
838 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
839 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
840 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
841 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
842 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
844 MEMCPY( &ctx
->Texture
, attr
->data
,
845 sizeof(struct gl_texture_attrib
) );
846 ctx
->NewState
|= _NEW_TEXTURE
;
847 /* restore state of the currently bound texture objects */
848 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
849 copy_texobj_state( ctx
->Texture
.Unit
[u
].Current1D
,
850 &(ctx
->Texture
.Unit
[u
].Saved1D
) );
851 copy_texobj_state( ctx
->Texture
.Unit
[u
].Current2D
,
852 &(ctx
->Texture
.Unit
[u
].Saved2D
) );
853 copy_texobj_state( ctx
->Texture
.Unit
[u
].Current3D
,
854 &(ctx
->Texture
.Unit
[u
].Saved3D
) );
855 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentCubeMap
,
856 &(ctx
->Texture
.Unit
[u
].SavedCubeMap
) );
858 ctx
->Texture
.Unit
[u
].Current1D
->Complete
= GL_FALSE
;
859 ctx
->Texture
.Unit
[u
].Current2D
->Complete
= GL_FALSE
;
860 ctx
->Texture
.Unit
[u
].Current3D
->Complete
= GL_FALSE
;
861 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->Complete
= GL_FALSE
;
865 case GL_VIEWPORT_BIT
:
867 const struct gl_viewport_attrib
*vp
;
868 vp
= (const struct gl_viewport_attrib
*)attr
->data
;
869 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
870 _mesa_DepthRange(vp
->Near
, vp
->Far
);
874 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
886 #define GL_CLIENT_PACK_BIT (1<<20)
887 #define GL_CLIENT_UNPACK_BIT (1<<21)
891 _mesa_PushClientAttrib(GLbitfield mask
)
893 struct gl_attrib_node
*newnode
;
894 struct gl_attrib_node
*head
;
896 GET_CURRENT_CONTEXT(ctx
);
897 ASSERT_OUTSIDE_BEGIN_END(ctx
);
899 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
900 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
904 /* Build linked list of attribute nodes which save all attribute */
905 /* groups specified by the mask. */
908 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
909 struct gl_pixelstore_attrib
*attr
;
910 /* packing attribs */
911 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
912 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
913 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
914 newnode
->data
= attr
;
915 newnode
->next
= head
;
917 /* unpacking attribs */
918 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
919 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
920 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
921 newnode
->data
= attr
;
922 newnode
->next
= head
;
925 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
926 struct gl_array_attrib
*attr
;
927 attr
= MALLOC_STRUCT( gl_array_attrib
);
928 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
929 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
930 newnode
->data
= attr
;
931 newnode
->next
= head
;
935 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
936 ctx
->ClientAttribStackDepth
++;
943 _mesa_PopClientAttrib(void)
945 struct gl_attrib_node
*attr
, *next
;
947 GET_CURRENT_CONTEXT(ctx
);
948 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
950 if (ctx
->ClientAttribStackDepth
== 0) {
951 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
955 ctx
->ClientAttribStackDepth
--;
956 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
959 switch (attr
->kind
) {
960 case GL_CLIENT_PACK_BIT
:
961 MEMCPY( &ctx
->Pack
, attr
->data
,
962 sizeof(struct gl_pixelstore_attrib
) );
963 ctx
->NewState
= _NEW_PACKUNPACK
;
965 case GL_CLIENT_UNPACK_BIT
:
966 MEMCPY( &ctx
->Unpack
, attr
->data
,
967 sizeof(struct gl_pixelstore_attrib
) );
968 ctx
->NewState
= _NEW_PACKUNPACK
;
970 case GL_CLIENT_VERTEX_ARRAY_BIT
:
971 MEMCPY( &ctx
->Array
, attr
->data
,
972 sizeof(struct gl_array_attrib
) );
973 ctx
->NewState
= _NEW_ARRAY
;
976 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");