1 /* $Id: attrib.c,v 1.59 2002/01/05 21:53:20 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 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
214 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
215 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
216 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
217 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
218 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
219 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
220 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
221 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
222 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
223 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
224 attr
->Normalize
= ctx
->Transform
.Normalize
;
225 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
226 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
227 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
228 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
229 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
230 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
231 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
232 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
233 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
234 attr
->Scissor
= ctx
->Scissor
.Enabled
;
235 attr
->Stencil
= ctx
->Stencil
.Enabled
;
236 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
237 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
238 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
239 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
240 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
241 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
242 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
243 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
245 /* GL_NV_vertex_program */
246 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
247 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
248 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
249 newnode
= new_attrib_node( GL_ENABLE_BIT
);
250 newnode
->data
= attr
;
251 newnode
->next
= head
;
255 if (mask
& GL_EVAL_BIT
) {
256 struct gl_eval_attrib
*attr
;
257 attr
= MALLOC_STRUCT( gl_eval_attrib
);
258 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
259 newnode
= new_attrib_node( GL_EVAL_BIT
);
260 newnode
->data
= attr
;
261 newnode
->next
= head
;
265 if (mask
& GL_FOG_BIT
) {
266 struct gl_fog_attrib
*attr
;
267 attr
= MALLOC_STRUCT( gl_fog_attrib
);
268 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
269 newnode
= new_attrib_node( GL_FOG_BIT
);
270 newnode
->data
= attr
;
271 newnode
->next
= head
;
275 if (mask
& GL_HINT_BIT
) {
276 struct gl_hint_attrib
*attr
;
277 attr
= MALLOC_STRUCT( gl_hint_attrib
);
278 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
279 newnode
= new_attrib_node( GL_HINT_BIT
);
280 newnode
->data
= attr
;
281 newnode
->next
= head
;
285 if (mask
& GL_LIGHTING_BIT
) {
286 struct gl_light_attrib
*attr
;
287 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
288 attr
= MALLOC_STRUCT( gl_light_attrib
);
289 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
290 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
291 newnode
->data
= attr
;
292 newnode
->next
= head
;
296 if (mask
& GL_LINE_BIT
) {
297 struct gl_line_attrib
*attr
;
298 attr
= MALLOC_STRUCT( gl_line_attrib
);
299 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
300 newnode
= new_attrib_node( GL_LINE_BIT
);
301 newnode
->data
= attr
;
302 newnode
->next
= head
;
306 if (mask
& GL_LIST_BIT
) {
307 struct gl_list_attrib
*attr
;
308 attr
= MALLOC_STRUCT( gl_list_attrib
);
309 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
310 newnode
= new_attrib_node( GL_LIST_BIT
);
311 newnode
->data
= attr
;
312 newnode
->next
= head
;
316 if (mask
& GL_PIXEL_MODE_BIT
) {
317 struct gl_pixel_attrib
*attr
;
318 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
319 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
320 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
321 newnode
->data
= attr
;
322 newnode
->next
= head
;
326 if (mask
& GL_POINT_BIT
) {
327 struct gl_point_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_point_attrib
);
329 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
330 newnode
= new_attrib_node( GL_POINT_BIT
);
331 newnode
->data
= attr
;
332 newnode
->next
= head
;
336 if (mask
& GL_POLYGON_BIT
) {
337 struct gl_polygon_attrib
*attr
;
338 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
339 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
340 newnode
= new_attrib_node( GL_POLYGON_BIT
);
341 newnode
->data
= attr
;
342 newnode
->next
= head
;
346 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
348 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
349 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
350 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
351 newnode
->data
= stipple
;
352 newnode
->next
= head
;
356 if (mask
& GL_SCISSOR_BIT
) {
357 struct gl_scissor_attrib
*attr
;
358 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
359 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
360 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
361 newnode
->data
= attr
;
362 newnode
->next
= head
;
366 if (mask
& GL_STENCIL_BUFFER_BIT
) {
367 struct gl_stencil_attrib
*attr
;
368 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
369 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
370 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
371 newnode
->data
= attr
;
372 newnode
->next
= head
;
376 if (mask
& GL_TEXTURE_BIT
) {
377 struct gl_texture_attrib
*attr
;
379 /* Bump the texture object reference counts so that they don't
380 * inadvertantly get deleted.
382 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
383 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
384 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
385 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
386 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
388 attr
= MALLOC_STRUCT( gl_texture_attrib
);
389 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
390 /* copy state of the currently bound texture objects */
391 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
392 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].Current1D
);
393 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].Current2D
);
394 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].Current3D
);
395 copy_texobj_state(&attr
->Unit
[u
].SavedCubeMap
, attr
->Unit
[u
].CurrentCubeMap
);
397 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
398 newnode
->data
= attr
;
399 newnode
->next
= head
;
403 if (mask
& GL_TRANSFORM_BIT
) {
404 struct gl_transform_attrib
*attr
;
405 attr
= MALLOC_STRUCT( gl_transform_attrib
);
406 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
407 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
408 newnode
->data
= attr
;
409 newnode
->next
= head
;
413 if (mask
& GL_VIEWPORT_BIT
) {
414 struct gl_viewport_attrib
*attr
;
415 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
416 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
417 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
418 newnode
->data
= attr
;
419 newnode
->next
= head
;
423 /* GL_ARB_multisample */
424 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
425 struct gl_multisample_attrib
*attr
;
426 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
427 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
428 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
429 newnode
->data
= attr
;
430 newnode
->next
= head
;
434 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
435 ctx
->AttribStackDepth
++;
441 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
445 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
446 if ((VALUE) != (NEWVALUE)) { \
447 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
450 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
451 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
453 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
454 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
455 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
456 enable
->ClipPlane
[i
]);
459 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
461 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
462 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
463 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
464 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
466 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
468 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
470 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
471 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
472 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
473 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
475 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
477 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
480 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
481 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
483 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
484 GL_MAP1_TEXTURE_COORD_1
);
485 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
486 GL_MAP1_TEXTURE_COORD_2
);
487 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
488 GL_MAP1_TEXTURE_COORD_3
);
489 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
490 GL_MAP1_TEXTURE_COORD_4
);
491 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
493 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
495 for (i
= 0; i
< 16; i
++) {
496 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
497 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
500 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
501 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
502 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
503 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
504 GL_MAP2_TEXTURE_COORD_1
);
505 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
506 GL_MAP2_TEXTURE_COORD_2
);
507 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
508 GL_MAP2_TEXTURE_COORD_3
);
509 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
510 GL_MAP2_TEXTURE_COORD_4
);
511 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
513 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
515 for (i
= 0; i
< 16; i
++) {
516 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
517 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
520 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
521 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
522 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
523 GL_RESCALE_NORMAL_EXT
);
524 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
525 enable
->RasterPositionUnclipped
,
526 GL_RASTER_POSITION_UNCLIPPED_IBM
);
527 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
529 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
531 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
532 GL_POLYGON_OFFSET_POINT
);
533 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
534 GL_POLYGON_OFFSET_LINE
);
535 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
536 GL_POLYGON_OFFSET_FILL
);
537 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
539 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
541 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
542 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
543 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
545 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
546 enable
->SampleAlphaToCoverage
,
547 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
548 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
549 enable
->SampleAlphaToOne
,
550 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
551 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
552 enable
->SampleCoverage
,
553 GL_SAMPLE_COVERAGE_ARB
);
554 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
555 enable
->SampleCoverageInvert
,
556 GL_SAMPLE_COVERAGE_INVERT_ARB
);
557 /* GL_NV_vertex_program */
558 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
559 enable
->VertexProgram
,
560 GL_VERTEX_PROGRAM_NV
);
561 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
562 enable
->VertexProgramPointSize
,
563 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
564 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
565 enable
->VertexProgramTwoSide
,
566 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
568 #undef TEST_AND_UPDATE
570 /* texture unit enables */
571 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
572 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
573 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
574 if (ctx
->Driver
.Enable
) {
575 if (ctx
->Driver
.ActiveTexture
) {
576 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
578 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
579 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_1D
) );
580 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
581 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_2D
) );
582 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
583 (GLboolean
) (enable
->Texture
[i
] & TEXTURE0_3D
) );
587 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
588 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
589 if (ctx
->Driver
.Enable
) {
590 if (ctx
->Driver
.ActiveTexture
) {
591 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
593 if (enable
->TexGen
[i
] & S_BIT
)
594 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
596 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
597 if (enable
->TexGen
[i
] & T_BIT
)
598 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
600 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
601 if (enable
->TexGen
[i
] & R_BIT
)
602 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
604 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
605 if (enable
->TexGen
[i
] & Q_BIT
)
606 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
608 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
613 if (ctx
->Driver
.ActiveTexture
) {
614 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
620 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
624 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
625 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
628 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
629 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
630 (GLboolean
) (unit
->Enabled
& TEXTURE0_1D
? GL_TRUE
: GL_FALSE
));
631 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
632 (GLboolean
) (unit
->Enabled
& TEXTURE0_2D
? GL_TRUE
: GL_FALSE
));
633 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
634 (GLboolean
) (unit
->Enabled
& TEXTURE0_3D
? GL_TRUE
: GL_FALSE
));
635 if (ctx
->Extensions
.ARB_texture_cube_map
) {
636 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
637 (GLboolean
) (unit
->Enabled
& TEXTURE0_CUBE
? GL_TRUE
: GL_FALSE
));
639 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
640 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
641 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
642 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
643 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
644 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
645 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
646 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
647 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
648 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
649 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
650 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
651 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
652 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
653 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
654 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
655 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
657 if (ctx
->Extensions
.EXT_texture_env_combine
||
658 ctx
->Extensions
.ARB_texture_env_combine
) {
659 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB_EXT
,
660 unit
->CombineModeRGB
);
661 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA_EXT
,
663 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB_EXT
,
664 unit
->CombineSourceRGB
[0]);
665 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB_EXT
,
666 unit
->CombineSourceRGB
[1]);
667 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB_EXT
,
668 unit
->CombineSourceRGB
[2]);
669 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA_EXT
,
670 unit
->CombineSourceA
[0]);
671 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA_EXT
,
672 unit
->CombineSourceA
[1]);
673 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA_EXT
,
674 unit
->CombineSourceA
[2]);
675 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB_EXT
,
676 unit
->CombineOperandRGB
[0]);
677 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB_EXT
,
678 unit
->CombineOperandRGB
[1]);
679 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB_EXT
,
680 unit
->CombineOperandRGB
[2]);
681 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA_EXT
,
682 unit
->CombineOperandA
[0]);
683 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA_EXT
,
684 unit
->CombineOperandA
[1]);
685 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA_EXT
,
686 unit
->CombineOperandA
[2]);
687 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE_EXT
,
688 1 << unit
->CombineScaleShiftRGB
);
689 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
690 1 << unit
->CombineScaleShiftA
);
693 /* Restore texture object state */
694 numObjs
= ctx
->Extensions
.ARB_texture_cube_map
? 4 : 3;
696 for (i
= 0; i
< numObjs
; i
++) {
698 const struct gl_texture_object
*obj
= NULL
;
699 GLfloat bordColor
[4];
703 target
= GL_TEXTURE_1D
;
704 obj
= &unit
->Saved1D
;
707 target
= GL_TEXTURE_2D
;
708 obj
= &unit
->Saved2D
;
711 target
= GL_TEXTURE_3D
;
712 obj
= &unit
->Saved3D
;
715 target
= GL_TEXTURE_CUBE_MAP_ARB
;
716 obj
= &unit
->SavedCubeMap
;
719 ; /* silence warnings */
722 _mesa_BindTexture(target
, obj
->Name
);
724 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
725 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
726 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
727 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
729 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
730 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
731 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
732 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
733 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
735 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
736 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
737 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
738 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
739 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
740 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
741 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
744 if (ctx
->Extensions
.SGIX_shadow
) {
745 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
747 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
748 obj
->CompareOperator
);
750 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
751 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
752 CHAN_TO_FLOAT(obj
->ShadowAmbient
));
757 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
758 + texAttrib
->CurrentUnit
);
760 /* "un-bump" the texture object reference counts. We did that so they
761 * wouldn't inadvertantly get deleted while they were still referenced
762 * inside the attribute state stack.
764 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
765 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
766 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
767 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
768 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
774 * This function is kind of long just because we have to call a lot
775 * of device driver functions to update device driver state.
777 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
778 * in order to restore GL state. This isn't terribly efficient but it
779 * ensures that dirty flags and any derived state gets updated correctly.
780 * We could at least check if the value to restore equals the current value
781 * and then skip the Mesa call.
784 _mesa_PopAttrib(void)
786 struct gl_attrib_node
*attr
, *next
;
787 GET_CURRENT_CONTEXT(ctx
);
788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
790 if (ctx
->AttribStackDepth
== 0) {
791 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
795 ctx
->AttribStackDepth
--;
796 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
800 if (MESA_VERBOSE
&VERBOSE_API
) {
801 fprintf(stderr
, "glPopAttrib %s\n",
802 _mesa_lookup_enum_by_nr(attr
->kind
));
805 switch (attr
->kind
) {
806 case GL_ACCUM_BUFFER_BIT
:
808 const struct gl_accum_attrib
*accum
;
809 accum
= (const struct gl_accum_attrib
*) attr
->data
;
810 _mesa_ClearAccum(accum
->ClearColor
[0],
811 accum
->ClearColor
[1],
812 accum
->ClearColor
[2],
813 accum
->ClearColor
[3]);
816 case GL_COLOR_BUFFER_BIT
:
818 const struct gl_colorbuffer_attrib
*color
;
819 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
820 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
821 _mesa_ClearColor(CHAN_TO_FLOAT(color
->ClearColor
[0]),
822 CHAN_TO_FLOAT(color
->ClearColor
[1]),
823 CHAN_TO_FLOAT(color
->ClearColor
[2]),
824 CHAN_TO_FLOAT(color
->ClearColor
[3]));
825 _mesa_IndexMask(color
->IndexMask
);
826 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
827 (GLboolean
) (color
->ColorMask
[1] != 0),
828 (GLboolean
) (color
->ColorMask
[2] != 0),
829 (GLboolean
) (color
->ColorMask
[3] != 0));
830 _mesa_DrawBuffer(color
->DrawBuffer
);
831 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
832 _mesa_AlphaFunc(color
->AlphaFunc
,
833 CHAN_TO_FLOAT(color
->AlphaRef
));
834 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
835 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
839 _mesa_BlendEquation(color
->BlendEquation
);
840 _mesa_BlendColor(color
->BlendColor
[0],
841 color
->BlendColor
[1],
842 color
->BlendColor
[2],
843 color
->BlendColor
[3]);
844 _mesa_LogicOp(color
->LogicOp
);
845 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
846 color
->ColorLogicOpEnabled
);
847 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
848 color
->IndexLogicOpEnabled
);
849 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
853 FLUSH_CURRENT( ctx
, 0 );
854 MEMCPY( &ctx
->Current
, attr
->data
,
855 sizeof(struct gl_current_attrib
) );
857 case GL_DEPTH_BUFFER_BIT
:
859 const struct gl_depthbuffer_attrib
*depth
;
860 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
861 _mesa_DepthFunc(depth
->Func
);
862 _mesa_ClearDepth(depth
->Clear
);
863 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
864 _mesa_DepthMask(depth
->Mask
);
865 if (ctx
->Extensions
.HP_occlusion_test
)
866 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
867 depth
->OcclusionTest
);
872 const struct gl_enable_attrib
*enable
;
873 enable
= (const struct gl_enable_attrib
*) attr
->data
;
874 pop_enable_group(ctx
, enable
);
875 ctx
->NewState
|= _NEW_ALL
;
879 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
880 ctx
->NewState
|= _NEW_EVAL
;
884 const struct gl_fog_attrib
*fog
;
885 fog
= (const struct gl_fog_attrib
*) attr
->data
;
886 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
887 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
888 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
889 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
890 _mesa_Fogf(GL_FOG_END
, fog
->End
);
891 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
892 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
897 const struct gl_hint_attrib
*hint
;
898 hint
= (const struct gl_hint_attrib
*) attr
->data
;
899 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
900 hint
->PerspectiveCorrection
);
901 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
902 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
903 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
904 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
905 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
906 hint
->ClipVolumeClipping
);
907 if (ctx
->Extensions
.ARB_texture_compression
)
908 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
909 hint
->TextureCompression
);
912 case GL_LIGHTING_BIT
:
915 const struct gl_light_attrib
*light
;
916 light
= (const struct gl_light_attrib
*) attr
->data
;
917 /* lighting enable */
918 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
919 /* per-light state */
920 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
921 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
922 _mesa_set_enable(ctx
, lgt
, light
->Light
[i
].Enabled
);
923 MEMCPY(&ctx
->Light
.Light
[i
], &light
->Light
[i
],
924 sizeof(struct gl_light
));
927 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
928 light
->Model
.Ambient
);
929 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
930 (GLfloat
) light
->Model
.LocalViewer
);
931 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
932 (GLfloat
) light
->Model
.TwoSide
);
933 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
934 (GLfloat
) light
->Model
.ColorControl
);
936 MEMCPY(ctx
->Light
.Material
, light
->Material
,
937 2 * sizeof(struct gl_material
));
939 _mesa_ShadeModel(light
->ShadeModel
);
941 _mesa_ColorMaterial(light
->ColorMaterialFace
,
942 light
->ColorMaterialMode
);
943 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
944 light
->ColorMaterialEnabled
);
949 const struct gl_line_attrib
*line
;
950 line
= (const struct gl_line_attrib
*) attr
->data
;
951 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
952 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
953 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
954 _mesa_LineWidth(line
->Width
);
958 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
960 case GL_PIXEL_MODE_BIT
:
961 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
962 ctx
->NewState
|= _NEW_PIXEL
;
966 const struct gl_point_attrib
*point
;
967 point
= (const struct gl_point_attrib
*) attr
->data
;
968 _mesa_PointSize(point
->Size
);
969 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
970 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
972 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
, point
->MinSize
);
973 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
, point
->MaxSize
);
974 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
980 const struct gl_polygon_attrib
*polygon
;
981 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
982 _mesa_CullFace(polygon
->CullFaceMode
);
983 _mesa_FrontFace(polygon
->FrontFace
);
984 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
985 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
986 _mesa_PolygonOffset(polygon
->OffsetFactor
,
987 polygon
->OffsetUnits
);
988 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
989 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
990 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
991 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
992 polygon
->OffsetPoint
);
993 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
994 polygon
->OffsetLine
);
995 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
996 polygon
->OffsetFill
);
999 case GL_POLYGON_STIPPLE_BIT
:
1000 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1001 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1002 if (ctx
->Driver
.PolygonStipple
)
1003 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1005 case GL_SCISSOR_BIT
:
1007 const struct gl_scissor_attrib
*scissor
;
1008 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1009 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1010 scissor
->Width
, scissor
->Height
);
1011 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1014 case GL_STENCIL_BUFFER_BIT
:
1016 const struct gl_stencil_attrib
*stencil
;
1017 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1018 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1019 _mesa_ClearStencil(stencil
->Clear
);
1020 _mesa_StencilFunc(stencil
->Function
, stencil
->Ref
,
1021 stencil
->ValueMask
);
1022 _mesa_StencilMask(stencil
->WriteMask
);
1023 _mesa_StencilOp(stencil
->FailFunc
, stencil
->ZFailFunc
,
1024 stencil
->ZPassFunc
);
1027 case GL_TRANSFORM_BIT
:
1030 const struct gl_transform_attrib
*xform
;
1031 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1032 _mesa_MatrixMode(xform
->MatrixMode
);
1034 MEMCPY(ctx
->Transform
.EyeUserPlane
, xform
->EyeUserPlane
,
1035 sizeof(xform
->EyeUserPlane
));
1036 MEMCPY(ctx
->Transform
._ClipUserPlane
, xform
->_ClipUserPlane
,
1037 sizeof(xform
->EyeUserPlane
));
1038 /* clip plane enable flags */
1039 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1040 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1041 xform
->ClipEnabled
[i
]);
1043 /* normalize/rescale */
1044 _mesa_set_enable(ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
1045 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1046 ctx
->Transform
.RescaleNormals
);
1049 case GL_TEXTURE_BIT
:
1050 /* Take care of texture object reference counters */
1052 const struct gl_texture_attrib
*texture
;
1053 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1054 pop_texture_group(ctx
, texture
);
1055 ctx
->NewState
|= _NEW_TEXTURE
;
1058 case GL_VIEWPORT_BIT
:
1060 const struct gl_viewport_attrib
*vp
;
1061 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1062 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1063 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1066 case GL_MULTISAMPLE_BIT_ARB
:
1068 const struct gl_multisample_attrib
*ms
;
1069 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1070 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1071 ms
->SampleCoverageInvert
);
1076 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1088 #define GL_CLIENT_PACK_BIT (1<<20)
1089 #define GL_CLIENT_UNPACK_BIT (1<<21)
1093 _mesa_PushClientAttrib(GLbitfield mask
)
1095 struct gl_attrib_node
*newnode
;
1096 struct gl_attrib_node
*head
;
1098 GET_CURRENT_CONTEXT(ctx
);
1099 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1101 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1102 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1106 /* Build linked list of attribute nodes which save all attribute */
1107 /* groups specified by the mask. */
1110 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1111 struct gl_pixelstore_attrib
*attr
;
1112 /* packing attribs */
1113 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1114 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1115 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1116 newnode
->data
= attr
;
1117 newnode
->next
= head
;
1119 /* unpacking attribs */
1120 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1121 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1122 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1123 newnode
->data
= attr
;
1124 newnode
->next
= head
;
1127 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1128 struct gl_array_attrib
*attr
;
1129 attr
= MALLOC_STRUCT( gl_array_attrib
);
1130 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1131 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1132 newnode
->data
= attr
;
1133 newnode
->next
= head
;
1137 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1138 ctx
->ClientAttribStackDepth
++;
1145 _mesa_PopClientAttrib(void)
1147 struct gl_attrib_node
*attr
, *next
;
1149 GET_CURRENT_CONTEXT(ctx
);
1150 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1152 if (ctx
->ClientAttribStackDepth
== 0) {
1153 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1157 ctx
->ClientAttribStackDepth
--;
1158 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1161 switch (attr
->kind
) {
1162 case GL_CLIENT_PACK_BIT
:
1163 MEMCPY( &ctx
->Pack
, attr
->data
,
1164 sizeof(struct gl_pixelstore_attrib
) );
1165 ctx
->NewState
|= _NEW_PACKUNPACK
;
1167 case GL_CLIENT_UNPACK_BIT
:
1168 MEMCPY( &ctx
->Unpack
, attr
->data
,
1169 sizeof(struct gl_pixelstore_attrib
) );
1170 ctx
->NewState
|= _NEW_PACKUNPACK
;
1172 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1173 MEMCPY( &ctx
->Array
, attr
->data
,
1174 sizeof(struct gl_array_attrib
) );
1175 ctx
->NewState
|= _NEW_ARRAY
;
1178 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");