1 /* $Id: attrib.c,v 1.63 2002/04/01 17:03:38 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
49 #include "simple_list.h"
54 #include "math/m_xform.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 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
184 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
185 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
186 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
187 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
188 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
189 attr
->DepthTest
= ctx
->Depth
.Test
;
190 attr
->Dither
= ctx
->Color
.DitherFlag
;
191 attr
->Fog
= ctx
->Fog
.Enabled
;
192 for (i
=0;i
<MAX_LIGHTS
;i
++) {
193 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
195 attr
->Lighting
= ctx
->Light
.Enabled
;
196 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
197 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
198 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
199 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
200 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
201 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
202 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
203 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
204 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
205 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
206 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
207 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
208 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
209 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
210 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
211 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
212 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
213 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
214 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
215 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
216 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
217 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
218 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
219 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
220 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
221 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
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 const GLuint mask
= 1 << i
;
453 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
454 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
455 (enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
);
458 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
460 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
461 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
462 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
463 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
465 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
467 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
469 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
470 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
471 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
472 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
474 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
476 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
479 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
480 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
481 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
483 GL_MAP1_TEXTURE_COORD_1
);
484 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
485 GL_MAP1_TEXTURE_COORD_2
);
486 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
487 GL_MAP1_TEXTURE_COORD_3
);
488 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
489 GL_MAP1_TEXTURE_COORD_4
);
490 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
492 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
494 for (i
= 0; i
< 16; i
++) {
495 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
496 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
499 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
500 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
501 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
502 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
503 GL_MAP2_TEXTURE_COORD_1
);
504 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
505 GL_MAP2_TEXTURE_COORD_2
);
506 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
507 GL_MAP2_TEXTURE_COORD_3
);
508 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
509 GL_MAP2_TEXTURE_COORD_4
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
512 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
514 for (i
= 0; i
< 16; i
++) {
515 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
516 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
519 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
520 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
521 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
522 GL_RESCALE_NORMAL_EXT
);
523 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
524 enable
->RasterPositionUnclipped
,
525 GL_RASTER_POSITION_UNCLIPPED_IBM
);
526 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
528 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
530 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
531 GL_POLYGON_OFFSET_POINT
);
532 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
533 GL_POLYGON_OFFSET_LINE
);
534 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
535 GL_POLYGON_OFFSET_FILL
);
536 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
538 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
540 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
541 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
542 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
544 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
545 enable
->SampleAlphaToCoverage
,
546 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
547 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
548 enable
->SampleAlphaToOne
,
549 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
550 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
551 enable
->SampleCoverage
,
552 GL_SAMPLE_COVERAGE_ARB
);
553 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
554 enable
->SampleCoverageInvert
,
555 GL_SAMPLE_COVERAGE_INVERT_ARB
);
556 /* GL_NV_vertex_program */
557 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
558 enable
->VertexProgram
,
559 GL_VERTEX_PROGRAM_NV
);
560 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
561 enable
->VertexProgramPointSize
,
562 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
563 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
564 enable
->VertexProgramTwoSide
,
565 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
567 #undef TEST_AND_UPDATE
569 /* texture unit enables */
570 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
571 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
572 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
573 if (ctx
->Driver
.Enable
) {
574 if (ctx
->Driver
.ActiveTexture
) {
575 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
577 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
578 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_1D
) );
579 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
580 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_2D
) );
581 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
582 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_3D
) );
586 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
587 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
588 if (ctx
->Driver
.Enable
) {
589 if (ctx
->Driver
.ActiveTexture
) {
590 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
592 if (enable
->TexGen
[i
] & S_BIT
)
593 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
595 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
596 if (enable
->TexGen
[i
] & T_BIT
)
597 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
599 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
600 if (enable
->TexGen
[i
] & R_BIT
)
601 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
603 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
604 if (enable
->TexGen
[i
] & Q_BIT
)
605 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
607 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
612 if (ctx
->Driver
.ActiveTexture
) {
613 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
619 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
623 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
624 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
627 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
628 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
629 (GLboolean
) (unit
->Enabled
& TEXTURE0_1D
? GL_TRUE
: GL_FALSE
));
630 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
631 (GLboolean
) (unit
->Enabled
& TEXTURE0_2D
? GL_TRUE
: GL_FALSE
));
632 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
633 (GLboolean
) (unit
->Enabled
& TEXTURE0_3D
? GL_TRUE
: GL_FALSE
));
634 if (ctx
->Extensions
.ARB_texture_cube_map
) {
635 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
636 (GLboolean
) (unit
->Enabled
& TEXTURE0_CUBE
? GL_TRUE
: GL_FALSE
));
638 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
639 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
640 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
641 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
642 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
643 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
644 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
645 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
646 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
647 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
648 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
649 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
650 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
651 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
652 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
653 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
654 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
656 if (ctx
->Extensions
.EXT_texture_env_combine
||
657 ctx
->Extensions
.ARB_texture_env_combine
) {
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB_EXT
,
659 unit
->CombineModeRGB
);
660 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA_EXT
,
662 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB_EXT
,
663 unit
->CombineSourceRGB
[0]);
664 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB_EXT
,
665 unit
->CombineSourceRGB
[1]);
666 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB_EXT
,
667 unit
->CombineSourceRGB
[2]);
668 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA_EXT
,
669 unit
->CombineSourceA
[0]);
670 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA_EXT
,
671 unit
->CombineSourceA
[1]);
672 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA_EXT
,
673 unit
->CombineSourceA
[2]);
674 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB_EXT
,
675 unit
->CombineOperandRGB
[0]);
676 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB_EXT
,
677 unit
->CombineOperandRGB
[1]);
678 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB_EXT
,
679 unit
->CombineOperandRGB
[2]);
680 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA_EXT
,
681 unit
->CombineOperandA
[0]);
682 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA_EXT
,
683 unit
->CombineOperandA
[1]);
684 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA_EXT
,
685 unit
->CombineOperandA
[2]);
686 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE_EXT
,
687 1 << unit
->CombineScaleShiftRGB
);
688 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
689 1 << unit
->CombineScaleShiftA
);
692 /* Restore texture object state */
693 numObjs
= ctx
->Extensions
.ARB_texture_cube_map
? 4 : 3;
695 for (i
= 0; i
< numObjs
; i
++) {
697 const struct gl_texture_object
*obj
= NULL
;
698 GLfloat bordColor
[4];
702 target
= GL_TEXTURE_1D
;
703 obj
= &unit
->Saved1D
;
706 target
= GL_TEXTURE_2D
;
707 obj
= &unit
->Saved2D
;
710 target
= GL_TEXTURE_3D
;
711 obj
= &unit
->Saved3D
;
714 target
= GL_TEXTURE_CUBE_MAP_ARB
;
715 obj
= &unit
->SavedCubeMap
;
718 ; /* silence warnings */
721 _mesa_BindTexture(target
, obj
->Name
);
723 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
724 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
725 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
726 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
728 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
729 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
730 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
731 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
732 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
733 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
735 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
736 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
737 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
738 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
739 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
740 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
743 if (ctx
->Extensions
.SGIX_shadow
) {
744 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
746 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
747 obj
->CompareOperator
);
749 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
750 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
751 CHAN_TO_FLOAT(obj
->ShadowAmbient
));
756 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
757 + texAttrib
->CurrentUnit
);
759 /* "un-bump" the texture object reference counts. We did that so they
760 * wouldn't inadvertantly get deleted while they were still referenced
761 * inside the attribute state stack.
763 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
764 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
765 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
766 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
767 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
773 * This function is kind of long just because we have to call a lot
774 * of device driver functions to update device driver state.
776 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
777 * in order to restore GL state. This isn't terribly efficient but it
778 * ensures that dirty flags and any derived state gets updated correctly.
779 * We could at least check if the value to restore equals the current value
780 * and then skip the Mesa call.
783 _mesa_PopAttrib(void)
785 struct gl_attrib_node
*attr
, *next
;
786 GET_CURRENT_CONTEXT(ctx
);
787 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
789 if (ctx
->AttribStackDepth
== 0) {
790 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
794 ctx
->AttribStackDepth
--;
795 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
799 if (MESA_VERBOSE
&VERBOSE_API
) {
800 fprintf(stderr
, "glPopAttrib %s\n",
801 _mesa_lookup_enum_by_nr(attr
->kind
));
804 switch (attr
->kind
) {
805 case GL_ACCUM_BUFFER_BIT
:
807 const struct gl_accum_attrib
*accum
;
808 accum
= (const struct gl_accum_attrib
*) attr
->data
;
809 _mesa_ClearAccum(accum
->ClearColor
[0],
810 accum
->ClearColor
[1],
811 accum
->ClearColor
[2],
812 accum
->ClearColor
[3]);
815 case GL_COLOR_BUFFER_BIT
:
817 const struct gl_colorbuffer_attrib
*color
;
818 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
819 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
820 _mesa_ClearColor(CHAN_TO_FLOAT(color
->ClearColor
[0]),
821 CHAN_TO_FLOAT(color
->ClearColor
[1]),
822 CHAN_TO_FLOAT(color
->ClearColor
[2]),
823 CHAN_TO_FLOAT(color
->ClearColor
[3]));
824 _mesa_IndexMask(color
->IndexMask
);
825 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
826 (GLboolean
) (color
->ColorMask
[1] != 0),
827 (GLboolean
) (color
->ColorMask
[2] != 0),
828 (GLboolean
) (color
->ColorMask
[3] != 0));
829 _mesa_DrawBuffer(color
->DrawBuffer
);
830 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
831 _mesa_AlphaFunc(color
->AlphaFunc
,
832 CHAN_TO_FLOAT(color
->AlphaRef
));
833 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
834 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
838 _mesa_BlendEquation(color
->BlendEquation
);
839 _mesa_BlendColor(color
->BlendColor
[0],
840 color
->BlendColor
[1],
841 color
->BlendColor
[2],
842 color
->BlendColor
[3]);
843 _mesa_LogicOp(color
->LogicOp
);
844 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
845 color
->ColorLogicOpEnabled
);
846 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
847 color
->IndexLogicOpEnabled
);
848 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
852 FLUSH_CURRENT( ctx
, 0 );
853 MEMCPY( &ctx
->Current
, attr
->data
,
854 sizeof(struct gl_current_attrib
) );
856 case GL_DEPTH_BUFFER_BIT
:
858 const struct gl_depthbuffer_attrib
*depth
;
859 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
860 _mesa_DepthFunc(depth
->Func
);
861 _mesa_ClearDepth(depth
->Clear
);
862 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
863 _mesa_DepthMask(depth
->Mask
);
864 if (ctx
->Extensions
.HP_occlusion_test
)
865 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
866 depth
->OcclusionTest
);
871 const struct gl_enable_attrib
*enable
;
872 enable
= (const struct gl_enable_attrib
*) attr
->data
;
873 pop_enable_group(ctx
, enable
);
874 ctx
->NewState
|= _NEW_ALL
;
878 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
879 ctx
->NewState
|= _NEW_EVAL
;
883 const struct gl_fog_attrib
*fog
;
884 fog
= (const struct gl_fog_attrib
*) attr
->data
;
885 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
886 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
887 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
888 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
889 _mesa_Fogf(GL_FOG_END
, fog
->End
);
890 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
891 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
896 const struct gl_hint_attrib
*hint
;
897 hint
= (const struct gl_hint_attrib
*) attr
->data
;
898 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
899 hint
->PerspectiveCorrection
);
900 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
901 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
902 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
903 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
904 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
905 hint
->ClipVolumeClipping
);
906 if (ctx
->Extensions
.ARB_texture_compression
)
907 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
908 hint
->TextureCompression
);
911 case GL_LIGHTING_BIT
:
914 const struct gl_light_attrib
*light
;
915 light
= (const struct gl_light_attrib
*) attr
->data
;
916 /* lighting enable */
917 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
918 /* per-light state */
920 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
)
921 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
923 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
924 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
925 const struct gl_light
*l
= &light
->Light
[i
];
927 _mesa_set_enable(ctx
, lgt
, l
->Enabled
);
928 _mesa_Lightfv( lgt
, GL_AMBIENT
, l
->Ambient
);
929 _mesa_Lightfv( lgt
, GL_DIFFUSE
, l
->Diffuse
);
930 _mesa_Lightfv( lgt
, GL_SPECULAR
, l
->Specular
);
931 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->inv
, l
->EyePosition
);
932 _mesa_Lightfv( lgt
, GL_POSITION
, tmp
);
933 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->m
, l
->EyeDirection
);
934 _mesa_Lightfv( lgt
, GL_SPOT_DIRECTION
, tmp
);
935 _mesa_Lightfv( lgt
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
936 _mesa_Lightfv( lgt
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
937 _mesa_Lightfv( lgt
, GL_CONSTANT_ATTENUATION
,
938 &l
->ConstantAttenuation
);
939 _mesa_Lightfv( lgt
, GL_LINEAR_ATTENUATION
,
940 &l
->LinearAttenuation
);
941 _mesa_Lightfv( lgt
, GL_QUADRATIC_ATTENUATION
,
942 &l
->QuadraticAttenuation
);
945 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
946 light
->Model
.Ambient
);
947 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
948 (GLfloat
) light
->Model
.LocalViewer
);
949 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
950 (GLfloat
) light
->Model
.TwoSide
);
951 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
952 (GLfloat
) light
->Model
.ColorControl
);
954 MEMCPY(ctx
->Light
.Material
, light
->Material
,
955 2 * sizeof(struct gl_material
));
957 _mesa_ShadeModel(light
->ShadeModel
);
959 _mesa_ColorMaterial(light
->ColorMaterialFace
,
960 light
->ColorMaterialMode
);
961 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
962 light
->ColorMaterialEnabled
);
967 const struct gl_line_attrib
*line
;
968 line
= (const struct gl_line_attrib
*) attr
->data
;
969 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
970 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
971 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
972 _mesa_LineWidth(line
->Width
);
976 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
978 case GL_PIXEL_MODE_BIT
:
979 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
980 ctx
->NewState
|= _NEW_PIXEL
;
984 const struct gl_point_attrib
*point
;
985 point
= (const struct gl_point_attrib
*) attr
->data
;
986 _mesa_PointSize(point
->Size
);
987 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
988 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
990 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
, point
->MinSize
);
991 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
, point
->MaxSize
);
992 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
998 const struct gl_polygon_attrib
*polygon
;
999 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1000 _mesa_CullFace(polygon
->CullFaceMode
);
1001 _mesa_FrontFace(polygon
->FrontFace
);
1002 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1003 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1004 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1005 polygon
->OffsetUnits
);
1006 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1007 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1008 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1009 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1010 polygon
->OffsetPoint
);
1011 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1012 polygon
->OffsetLine
);
1013 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1014 polygon
->OffsetFill
);
1017 case GL_POLYGON_STIPPLE_BIT
:
1018 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1019 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1020 if (ctx
->Driver
.PolygonStipple
)
1021 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1023 case GL_SCISSOR_BIT
:
1025 const struct gl_scissor_attrib
*scissor
;
1026 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1027 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1028 scissor
->Width
, scissor
->Height
);
1029 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1032 case GL_STENCIL_BUFFER_BIT
:
1034 const struct gl_stencil_attrib
*stencil
;
1035 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1036 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1037 _mesa_ClearStencil(stencil
->Clear
);
1038 _mesa_StencilFunc(stencil
->Function
, stencil
->Ref
,
1039 stencil
->ValueMask
);
1040 _mesa_StencilMask(stencil
->WriteMask
);
1041 _mesa_StencilOp(stencil
->FailFunc
, stencil
->ZFailFunc
,
1042 stencil
->ZPassFunc
);
1045 case GL_TRANSFORM_BIT
:
1048 const struct gl_transform_attrib
*xform
;
1049 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1050 _mesa_MatrixMode(xform
->MatrixMode
);
1052 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
1053 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1055 /* restore clip planes */
1056 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1057 const GLuint mask
= 1 << 1;
1058 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1059 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1060 if (xform
->ClipPlanesEnabled
& mask
) {
1061 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1064 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1066 if (ctx
->Driver
.ClipPlane
)
1067 ctx
->Driver
.ClipPlane( ctx
, i
, eyePlane
);
1070 /* normalize/rescale */
1071 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1072 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1073 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1074 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1075 ctx
->Transform
.RescaleNormals
);
1078 case GL_TEXTURE_BIT
:
1079 /* Take care of texture object reference counters */
1081 const struct gl_texture_attrib
*texture
;
1082 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1083 pop_texture_group(ctx
, texture
);
1084 ctx
->NewState
|= _NEW_TEXTURE
;
1087 case GL_VIEWPORT_BIT
:
1089 const struct gl_viewport_attrib
*vp
;
1090 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1091 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1092 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1095 case GL_MULTISAMPLE_BIT_ARB
:
1097 const struct gl_multisample_attrib
*ms
;
1098 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1099 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1100 ms
->SampleCoverageInvert
);
1105 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1117 #define GL_CLIENT_PACK_BIT (1<<20)
1118 #define GL_CLIENT_UNPACK_BIT (1<<21)
1122 _mesa_PushClientAttrib(GLbitfield mask
)
1124 struct gl_attrib_node
*newnode
;
1125 struct gl_attrib_node
*head
;
1127 GET_CURRENT_CONTEXT(ctx
);
1128 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1130 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1131 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1135 /* Build linked list of attribute nodes which save all attribute */
1136 /* groups specified by the mask. */
1139 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1140 struct gl_pixelstore_attrib
*attr
;
1141 /* packing attribs */
1142 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1143 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1144 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1145 newnode
->data
= attr
;
1146 newnode
->next
= head
;
1148 /* unpacking attribs */
1149 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1150 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1151 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1152 newnode
->data
= attr
;
1153 newnode
->next
= head
;
1156 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1157 struct gl_array_attrib
*attr
;
1158 attr
= MALLOC_STRUCT( gl_array_attrib
);
1159 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1160 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1161 newnode
->data
= attr
;
1162 newnode
->next
= head
;
1166 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1167 ctx
->ClientAttribStackDepth
++;
1174 _mesa_PopClientAttrib(void)
1176 struct gl_attrib_node
*attr
, *next
;
1178 GET_CURRENT_CONTEXT(ctx
);
1179 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1181 if (ctx
->ClientAttribStackDepth
== 0) {
1182 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1186 ctx
->ClientAttribStackDepth
--;
1187 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1190 switch (attr
->kind
) {
1191 case GL_CLIENT_PACK_BIT
:
1192 MEMCPY( &ctx
->Pack
, attr
->data
,
1193 sizeof(struct gl_pixelstore_attrib
) );
1194 ctx
->NewState
|= _NEW_PACKUNPACK
;
1196 case GL_CLIENT_UNPACK_BIT
:
1197 MEMCPY( &ctx
->Unpack
, attr
->data
,
1198 sizeof(struct gl_pixelstore_attrib
) );
1199 ctx
->NewState
|= _NEW_PACKUNPACK
;
1201 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1202 MEMCPY( &ctx
->Array
, attr
->data
,
1203 sizeof(struct gl_array_attrib
) );
1204 ctx
->NewState
|= _NEW_ARRAY
;
1207 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");