1 /* $Id: attrib.c,v 1.78 2003/02/05 15:24:28 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2003 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.
46 #include "simple_list.h"
51 #include "math/m_xform.h"
55 * Allocate a new attribute state node. These nodes have a
56 * "kind" value and a pointer to a struct of state data.
58 static struct gl_attrib_node
*
59 new_attrib_node( GLbitfield kind
)
61 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
70 _mesa_PushAttrib(GLbitfield mask
)
72 struct gl_attrib_node
*newnode
;
73 struct gl_attrib_node
*head
;
75 GET_CURRENT_CONTEXT(ctx
);
76 ASSERT_OUTSIDE_BEGIN_END(ctx
);
78 if (MESA_VERBOSE
& VERBOSE_API
)
79 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
81 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
82 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
86 /* Build linked list of attribute nodes which save all attribute */
87 /* groups specified by the mask. */
90 if (mask
& GL_ACCUM_BUFFER_BIT
) {
91 struct gl_accum_attrib
*attr
;
92 attr
= MALLOC_STRUCT( gl_accum_attrib
);
93 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
94 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
100 if (mask
& GL_COLOR_BUFFER_BIT
) {
101 struct gl_colorbuffer_attrib
*attr
;
102 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
103 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
104 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
105 newnode
->data
= attr
;
106 newnode
->next
= head
;
110 if (mask
& GL_CURRENT_BIT
) {
111 struct gl_current_attrib
*attr
;
112 FLUSH_CURRENT( ctx
, 0 );
113 attr
= MALLOC_STRUCT( gl_current_attrib
);
114 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
115 newnode
= new_attrib_node( GL_CURRENT_BIT
);
116 newnode
->data
= attr
;
117 newnode
->next
= head
;
121 if (mask
& GL_DEPTH_BUFFER_BIT
) {
122 struct gl_depthbuffer_attrib
*attr
;
123 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
124 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
125 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
126 newnode
->data
= attr
;
127 newnode
->next
= head
;
131 if (mask
& GL_ENABLE_BIT
) {
132 struct gl_enable_attrib
*attr
;
134 attr
= MALLOC_STRUCT( gl_enable_attrib
);
135 /* Copy enable flags from all other attributes into the enable struct. */
136 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
137 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
138 attr
->Blend
= ctx
->Color
.BlendEnabled
;
139 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
140 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
141 attr
->ColorTable
= ctx
->Pixel
.ColorTableEnabled
;
142 attr
->PostColorMatrixColorTable
= ctx
->Pixel
.PostColorMatrixColorTableEnabled
;
143 attr
->PostConvolutionColorTable
= ctx
->Pixel
.PostConvolutionColorTableEnabled
;
144 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
145 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
146 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
147 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
148 attr
->DepthTest
= ctx
->Depth
.Test
;
149 attr
->Dither
= ctx
->Color
.DitherFlag
;
150 attr
->Fog
= ctx
->Fog
.Enabled
;
151 for (i
=0;i
<MAX_LIGHTS
;i
++) {
152 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
154 attr
->Lighting
= ctx
->Light
.Enabled
;
155 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
156 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
157 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
158 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
159 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
160 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
161 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
162 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
163 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
164 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
165 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
166 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
167 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
168 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
169 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
170 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
171 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
172 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
173 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
174 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
175 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
176 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
177 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
178 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
179 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
180 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
181 attr
->Normalize
= ctx
->Transform
.Normalize
;
182 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
183 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
184 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
185 attr
->PointSprite
= ctx
->Point
.PointSprite
;
186 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
187 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
188 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
189 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
190 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
191 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
192 attr
->Scissor
= ctx
->Scissor
.Enabled
;
193 attr
->Stencil
= ctx
->Stencil
.Enabled
;
194 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
195 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
196 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
197 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
198 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
199 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
200 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
201 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
202 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
204 /* GL_NV_vertex_program */
205 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
206 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
207 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
208 newnode
= new_attrib_node( GL_ENABLE_BIT
);
209 newnode
->data
= attr
;
210 newnode
->next
= head
;
214 if (mask
& GL_EVAL_BIT
) {
215 struct gl_eval_attrib
*attr
;
216 attr
= MALLOC_STRUCT( gl_eval_attrib
);
217 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
218 newnode
= new_attrib_node( GL_EVAL_BIT
);
219 newnode
->data
= attr
;
220 newnode
->next
= head
;
224 if (mask
& GL_FOG_BIT
) {
225 struct gl_fog_attrib
*attr
;
226 attr
= MALLOC_STRUCT( gl_fog_attrib
);
227 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
228 newnode
= new_attrib_node( GL_FOG_BIT
);
229 newnode
->data
= attr
;
230 newnode
->next
= head
;
234 if (mask
& GL_HINT_BIT
) {
235 struct gl_hint_attrib
*attr
;
236 attr
= MALLOC_STRUCT( gl_hint_attrib
);
237 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
238 newnode
= new_attrib_node( GL_HINT_BIT
);
239 newnode
->data
= attr
;
240 newnode
->next
= head
;
244 if (mask
& GL_LIGHTING_BIT
) {
245 struct gl_light_attrib
*attr
;
246 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
247 attr
= MALLOC_STRUCT( gl_light_attrib
);
248 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
249 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
250 newnode
->data
= attr
;
251 newnode
->next
= head
;
255 if (mask
& GL_LINE_BIT
) {
256 struct gl_line_attrib
*attr
;
257 attr
= MALLOC_STRUCT( gl_line_attrib
);
258 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
259 newnode
= new_attrib_node( GL_LINE_BIT
);
260 newnode
->data
= attr
;
261 newnode
->next
= head
;
265 if (mask
& GL_LIST_BIT
) {
266 struct gl_list_attrib
*attr
;
267 attr
= MALLOC_STRUCT( gl_list_attrib
);
268 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
269 newnode
= new_attrib_node( GL_LIST_BIT
);
270 newnode
->data
= attr
;
271 newnode
->next
= head
;
275 if (mask
& GL_PIXEL_MODE_BIT
) {
276 struct gl_pixel_attrib
*attr
;
277 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
278 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
279 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
280 newnode
->data
= attr
;
281 newnode
->next
= head
;
285 if (mask
& GL_POINT_BIT
) {
286 struct gl_point_attrib
*attr
;
287 attr
= MALLOC_STRUCT( gl_point_attrib
);
288 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
289 newnode
= new_attrib_node( GL_POINT_BIT
);
290 newnode
->data
= attr
;
291 newnode
->next
= head
;
295 if (mask
& GL_POLYGON_BIT
) {
296 struct gl_polygon_attrib
*attr
;
297 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
298 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
299 newnode
= new_attrib_node( GL_POLYGON_BIT
);
300 newnode
->data
= attr
;
301 newnode
->next
= head
;
305 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
307 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
308 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
309 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
310 newnode
->data
= stipple
;
311 newnode
->next
= head
;
315 if (mask
& GL_SCISSOR_BIT
) {
316 struct gl_scissor_attrib
*attr
;
317 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
318 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
319 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
320 newnode
->data
= attr
;
321 newnode
->next
= head
;
325 if (mask
& GL_STENCIL_BUFFER_BIT
) {
326 struct gl_stencil_attrib
*attr
;
327 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
328 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
329 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
330 newnode
->data
= attr
;
331 newnode
->next
= head
;
335 if (mask
& GL_TEXTURE_BIT
) {
336 struct gl_texture_attrib
*attr
;
338 /* Bump the texture object reference counts so that they don't
339 * inadvertantly get deleted.
341 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
342 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
343 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
344 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
345 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
346 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
++;
348 attr
= MALLOC_STRUCT( gl_texture_attrib
);
349 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
350 /* copy state of the currently bound texture objects */
351 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
352 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved1D
,
353 attr
->Unit
[u
].Current1D
);
354 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved2D
,
355 attr
->Unit
[u
].Current2D
);
356 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved3D
,
357 attr
->Unit
[u
].Current3D
);
358 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedCubeMap
,
359 attr
->Unit
[u
].CurrentCubeMap
);
360 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedRect
,
361 attr
->Unit
[u
].CurrentRect
);
363 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
364 newnode
->data
= attr
;
365 newnode
->next
= head
;
369 if (mask
& GL_TRANSFORM_BIT
) {
370 struct gl_transform_attrib
*attr
;
371 attr
= MALLOC_STRUCT( gl_transform_attrib
);
372 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
373 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
374 newnode
->data
= attr
;
375 newnode
->next
= head
;
379 if (mask
& GL_VIEWPORT_BIT
) {
380 struct gl_viewport_attrib
*attr
;
381 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
382 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
383 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
384 newnode
->data
= attr
;
385 newnode
->next
= head
;
389 /* GL_ARB_multisample */
390 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
391 struct gl_multisample_attrib
*attr
;
392 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
393 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
394 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
395 newnode
->data
= attr
;
396 newnode
->next
= head
;
400 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
401 ctx
->AttribStackDepth
++;
407 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
411 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
412 if ((VALUE) != (NEWVALUE)) { \
413 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
416 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
417 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
419 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
420 const GLuint mask
= 1 << i
;
421 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
422 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
423 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
426 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
428 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
, enable
->ColorTable
,
430 TEST_AND_UPDATE(ctx
->Pixel
.PostColorMatrixColorTableEnabled
,
431 enable
->PostColorMatrixColorTable
,
432 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
433 TEST_AND_UPDATE(ctx
->Pixel
.PostConvolutionColorTableEnabled
,
434 enable
->PostConvolutionColorTable
,
435 GL_POST_CONVOLUTION_COLOR_TABLE
);
436 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
437 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
438 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
439 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
441 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
443 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
445 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
446 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
447 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
448 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
450 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
452 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
455 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
456 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
457 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
458 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
459 GL_MAP1_TEXTURE_COORD_1
);
460 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
461 GL_MAP1_TEXTURE_COORD_2
);
462 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
463 GL_MAP1_TEXTURE_COORD_3
);
464 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
465 GL_MAP1_TEXTURE_COORD_4
);
466 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
468 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
470 for (i
= 0; i
< 16; i
++) {
471 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
472 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
475 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
476 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
477 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
478 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
479 GL_MAP2_TEXTURE_COORD_1
);
480 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
481 GL_MAP2_TEXTURE_COORD_2
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
483 GL_MAP2_TEXTURE_COORD_3
);
484 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
485 GL_MAP2_TEXTURE_COORD_4
);
486 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
488 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
490 for (i
= 0; i
< 16; i
++) {
491 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
492 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
495 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
496 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
497 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
498 GL_RESCALE_NORMAL_EXT
);
499 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
500 enable
->RasterPositionUnclipped
,
501 GL_RASTER_POSITION_UNCLIPPED_IBM
);
502 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
504 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
506 if (ctx
->Extensions
.NV_point_sprite
) {
507 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
510 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
511 GL_POLYGON_OFFSET_POINT
);
512 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
513 GL_POLYGON_OFFSET_LINE
);
514 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
515 GL_POLYGON_OFFSET_FILL
);
516 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
518 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
520 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
521 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
522 /* XXX two-sided stencil */
523 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
525 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
526 enable
->SampleAlphaToCoverage
,
527 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
528 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
529 enable
->SampleAlphaToOne
,
530 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
531 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
532 enable
->SampleCoverage
,
533 GL_SAMPLE_COVERAGE_ARB
);
534 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
535 enable
->SampleCoverageInvert
,
536 GL_SAMPLE_COVERAGE_INVERT_ARB
);
537 /* GL_NV_vertex_program */
538 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
539 enable
->VertexProgram
,
540 GL_VERTEX_PROGRAM_NV
);
541 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
542 enable
->VertexProgramPointSize
,
543 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
544 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
545 enable
->VertexProgramTwoSide
,
546 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
548 #undef TEST_AND_UPDATE
550 /* texture unit enables */
551 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
552 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
553 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
554 if (ctx
->Driver
.Enable
) {
555 if (ctx
->Driver
.ActiveTexture
) {
556 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
558 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
559 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
560 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
561 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
562 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
563 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
564 if (ctx
->Extensions
.ARB_texture_cube_map
)
565 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
566 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
567 if (ctx
->Extensions
.NV_texture_rectangle
)
568 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
569 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
573 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
574 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
575 if (ctx
->Driver
.Enable
) {
576 if (ctx
->Driver
.ActiveTexture
) {
577 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
579 if (enable
->TexGen
[i
] & S_BIT
)
580 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
582 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
583 if (enable
->TexGen
[i
] & T_BIT
)
584 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
586 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
587 if (enable
->TexGen
[i
] & R_BIT
)
588 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
590 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
591 if (enable
->TexGen
[i
] & Q_BIT
)
592 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
594 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
598 /* GL_SGI_texture_color_table */
599 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
602 if (ctx
->Driver
.ActiveTexture
) {
603 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
609 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
613 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
614 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
617 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
618 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
619 (GLboolean
) (unit
->Enabled
& TEXTURE_1D_BIT
? GL_TRUE
: GL_FALSE
));
620 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
621 (GLboolean
) (unit
->Enabled
& TEXTURE_2D_BIT
? GL_TRUE
: GL_FALSE
));
622 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
623 (GLboolean
) (unit
->Enabled
& TEXTURE_3D_BIT
? GL_TRUE
: GL_FALSE
));
624 if (ctx
->Extensions
.ARB_texture_cube_map
) {
625 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
626 (GLboolean
) (unit
->Enabled
& TEXTURE_CUBE_BIT
? GL_TRUE
: GL_FALSE
));
628 if (ctx
->Extensions
.NV_texture_rectangle
) {
629 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
630 (GLboolean
) (unit
->Enabled
& TEXTURE_RECT_BIT
? GL_TRUE
: GL_FALSE
));
632 if (ctx
->Extensions
.SGI_texture_color_table
) {
633 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
634 unit
->ColorTableEnabled
);
636 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
637 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
638 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
639 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
640 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
641 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
642 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
643 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
644 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
645 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
646 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
647 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
648 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
649 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
650 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
651 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
652 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
654 if (ctx
->Extensions
.EXT_texture_env_combine
||
655 ctx
->Extensions
.ARB_texture_env_combine
) {
656 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB_EXT
,
657 unit
->CombineModeRGB
);
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA_EXT
,
660 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB_EXT
,
661 unit
->CombineSourceRGB
[0]);
662 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB_EXT
,
663 unit
->CombineSourceRGB
[1]);
664 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB_EXT
,
665 unit
->CombineSourceRGB
[2]);
666 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA_EXT
,
667 unit
->CombineSourceA
[0]);
668 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA_EXT
,
669 unit
->CombineSourceA
[1]);
670 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA_EXT
,
671 unit
->CombineSourceA
[2]);
672 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB_EXT
,
673 unit
->CombineOperandRGB
[0]);
674 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB_EXT
,
675 unit
->CombineOperandRGB
[1]);
676 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB_EXT
,
677 unit
->CombineOperandRGB
[2]);
678 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA_EXT
,
679 unit
->CombineOperandA
[0]);
680 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA_EXT
,
681 unit
->CombineOperandA
[1]);
682 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA_EXT
,
683 unit
->CombineOperandA
[2]);
684 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE_EXT
,
685 1 << unit
->CombineScaleShiftRGB
);
686 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
687 1 << unit
->CombineScaleShiftA
);
690 /* Restore texture object state */
691 for (i
= 0; i
< NUM_TEXTURE_TARGETS
; i
++) {
693 const struct gl_texture_object
*obj
= NULL
;
694 GLfloat bordColor
[4];
698 target
= GL_TEXTURE_1D
;
699 obj
= &unit
->Saved1D
;
702 target
= GL_TEXTURE_2D
;
703 obj
= &unit
->Saved2D
;
706 target
= GL_TEXTURE_3D
;
707 obj
= &unit
->Saved3D
;
710 if (!ctx
->Extensions
.ARB_texture_cube_map
)
712 target
= GL_TEXTURE_CUBE_MAP_ARB
;
713 obj
= &unit
->SavedCubeMap
;
716 if (!ctx
->Extensions
.NV_texture_rectangle
)
718 target
= GL_TEXTURE_RECTANGLE_NV
;
719 obj
= &unit
->SavedRect
;
722 ; /* silence warnings */
725 _mesa_BindTexture(target
, obj
->Name
);
727 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
728 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
729 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
730 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
732 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
733 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
735 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
736 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
737 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
738 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
739 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
740 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
741 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
742 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
743 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
744 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
747 if (ctx
->Extensions
.SGIX_shadow
) {
748 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
750 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
751 obj
->CompareOperator
);
753 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
754 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
760 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
761 + texAttrib
->CurrentUnit
);
763 /* "un-bump" the texture object reference counts. We did that so they
764 * wouldn't inadvertantly get deleted while they were still referenced
765 * inside the attribute state stack.
767 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
768 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
769 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
770 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
771 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
772 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
--;
778 * This function is kind of long just because we have to call a lot
779 * of device driver functions to update device driver state.
781 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
782 * in order to restore GL state. This isn't terribly efficient but it
783 * ensures that dirty flags and any derived state gets updated correctly.
784 * We could at least check if the value to restore equals the current value
785 * and then skip the Mesa call.
788 _mesa_PopAttrib(void)
790 struct gl_attrib_node
*attr
, *next
;
791 GET_CURRENT_CONTEXT(ctx
);
792 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
794 if (ctx
->AttribStackDepth
== 0) {
795 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
799 ctx
->AttribStackDepth
--;
800 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
804 if (MESA_VERBOSE
& VERBOSE_API
) {
805 _mesa_debug(ctx
, "glPopAttrib %s\n",
806 _mesa_lookup_enum_by_nr(attr
->kind
));
809 switch (attr
->kind
) {
810 case GL_ACCUM_BUFFER_BIT
:
812 const struct gl_accum_attrib
*accum
;
813 accum
= (const struct gl_accum_attrib
*) attr
->data
;
814 _mesa_ClearAccum(accum
->ClearColor
[0],
815 accum
->ClearColor
[1],
816 accum
->ClearColor
[2],
817 accum
->ClearColor
[3]);
820 case GL_COLOR_BUFFER_BIT
:
822 const struct gl_colorbuffer_attrib
*color
;
823 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
824 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
825 _mesa_ClearColor(color
->ClearColor
[0],
826 color
->ClearColor
[1],
827 color
->ClearColor
[2],
828 color
->ClearColor
[3]);
829 _mesa_IndexMask(color
->IndexMask
);
830 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
831 (GLboolean
) (color
->ColorMask
[1] != 0),
832 (GLboolean
) (color
->ColorMask
[2] != 0),
833 (GLboolean
) (color
->ColorMask
[3] != 0));
834 _mesa_DrawBuffer(color
->DrawBuffer
);
835 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
836 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
837 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
838 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
842 _mesa_BlendEquation(color
->BlendEquation
);
843 _mesa_BlendColor(color
->BlendColor
[0],
844 color
->BlendColor
[1],
845 color
->BlendColor
[2],
846 color
->BlendColor
[3]);
847 _mesa_LogicOp(color
->LogicOp
);
848 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
849 color
->ColorLogicOpEnabled
);
850 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
851 color
->IndexLogicOpEnabled
);
852 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
856 FLUSH_CURRENT( ctx
, 0 );
857 MEMCPY( &ctx
->Current
, attr
->data
,
858 sizeof(struct gl_current_attrib
) );
860 case GL_DEPTH_BUFFER_BIT
:
862 const struct gl_depthbuffer_attrib
*depth
;
863 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
864 _mesa_DepthFunc(depth
->Func
);
865 _mesa_ClearDepth(depth
->Clear
);
866 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
867 _mesa_DepthMask(depth
->Mask
);
868 if (ctx
->Extensions
.HP_occlusion_test
)
869 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
870 depth
->OcclusionTest
);
875 const struct gl_enable_attrib
*enable
;
876 enable
= (const struct gl_enable_attrib
*) attr
->data
;
877 pop_enable_group(ctx
, enable
);
878 ctx
->NewState
|= _NEW_ALL
;
882 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
883 ctx
->NewState
|= _NEW_EVAL
;
887 const struct gl_fog_attrib
*fog
;
888 fog
= (const struct gl_fog_attrib
*) attr
->data
;
889 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
890 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
891 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
892 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
893 _mesa_Fogf(GL_FOG_END
, fog
->End
);
894 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
895 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
900 const struct gl_hint_attrib
*hint
;
901 hint
= (const struct gl_hint_attrib
*) attr
->data
;
902 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
903 hint
->PerspectiveCorrection
);
904 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
905 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
906 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
907 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
908 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
909 hint
->ClipVolumeClipping
);
910 if (ctx
->Extensions
.ARB_texture_compression
)
911 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
912 hint
->TextureCompression
);
915 case GL_LIGHTING_BIT
:
918 const struct gl_light_attrib
*light
;
919 light
= (const struct gl_light_attrib
*) attr
->data
;
920 /* lighting enable */
921 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
922 /* per-light state */
924 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
)
925 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
927 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
928 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
929 const struct gl_light
*l
= &light
->Light
[i
];
931 _mesa_set_enable(ctx
, lgt
, l
->Enabled
);
932 _mesa_Lightfv( lgt
, GL_AMBIENT
, l
->Ambient
);
933 _mesa_Lightfv( lgt
, GL_DIFFUSE
, l
->Diffuse
);
934 _mesa_Lightfv( lgt
, GL_SPECULAR
, l
->Specular
);
935 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->inv
, l
->EyePosition
);
936 _mesa_Lightfv( lgt
, GL_POSITION
, tmp
);
937 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->m
, l
->EyeDirection
);
938 _mesa_Lightfv( lgt
, GL_SPOT_DIRECTION
, tmp
);
939 _mesa_Lightfv( lgt
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
940 _mesa_Lightfv( lgt
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
941 _mesa_Lightfv( lgt
, GL_CONSTANT_ATTENUATION
,
942 &l
->ConstantAttenuation
);
943 _mesa_Lightfv( lgt
, GL_LINEAR_ATTENUATION
,
944 &l
->LinearAttenuation
);
945 _mesa_Lightfv( lgt
, GL_QUADRATIC_ATTENUATION
,
946 &l
->QuadraticAttenuation
);
949 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
950 light
->Model
.Ambient
);
951 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
952 (GLfloat
) light
->Model
.LocalViewer
);
953 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
954 (GLfloat
) light
->Model
.TwoSide
);
955 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
956 (GLfloat
) light
->Model
.ColorControl
);
958 MEMCPY(ctx
->Light
.Material
, light
->Material
,
959 2 * sizeof(struct gl_material
));
961 _mesa_ShadeModel(light
->ShadeModel
);
963 _mesa_ColorMaterial(light
->ColorMaterialFace
,
964 light
->ColorMaterialMode
);
965 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
966 light
->ColorMaterialEnabled
);
971 const struct gl_line_attrib
*line
;
972 line
= (const struct gl_line_attrib
*) attr
->data
;
973 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
974 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
975 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
976 _mesa_LineWidth(line
->Width
);
980 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
982 case GL_PIXEL_MODE_BIT
:
983 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
984 ctx
->NewState
|= _NEW_PIXEL
;
988 const struct gl_point_attrib
*point
;
989 point
= (const struct gl_point_attrib
*) attr
->data
;
990 _mesa_PointSize(point
->Size
);
991 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
992 if (ctx
->Extensions
.EXT_point_parameters
) {
993 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
995 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
997 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
999 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1002 if (ctx
->Extensions
.NV_point_sprite
) {
1004 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1005 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1006 (GLint
) point
->CoordReplace
[u
]);
1008 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1009 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1010 ctx
->Point
.SpriteRMode
);
1014 case GL_POLYGON_BIT
:
1016 const struct gl_polygon_attrib
*polygon
;
1017 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1018 _mesa_CullFace(polygon
->CullFaceMode
);
1019 _mesa_FrontFace(polygon
->FrontFace
);
1020 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1021 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1022 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1023 polygon
->OffsetUnits
);
1024 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1025 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1026 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1027 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1028 polygon
->OffsetPoint
);
1029 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1030 polygon
->OffsetLine
);
1031 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1032 polygon
->OffsetFill
);
1035 case GL_POLYGON_STIPPLE_BIT
:
1036 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1037 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1038 if (ctx
->Driver
.PolygonStipple
)
1039 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1041 case GL_SCISSOR_BIT
:
1043 const struct gl_scissor_attrib
*scissor
;
1044 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1045 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1046 scissor
->Width
, scissor
->Height
);
1047 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1050 case GL_STENCIL_BUFFER_BIT
:
1052 const GLint face
= 0; /* XXX stencil two side */
1053 const struct gl_stencil_attrib
*stencil
;
1054 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1055 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1056 _mesa_ClearStencil(stencil
->Clear
);
1057 _mesa_StencilFunc(stencil
->Function
[face
], stencil
->Ref
[face
],
1058 stencil
->ValueMask
[face
]);
1059 _mesa_StencilMask(stencil
->WriteMask
[face
]);
1060 _mesa_StencilOp(stencil
->FailFunc
[face
],
1061 stencil
->ZFailFunc
[face
],
1062 stencil
->ZPassFunc
[face
]);
1065 case GL_TRANSFORM_BIT
:
1068 const struct gl_transform_attrib
*xform
;
1069 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1070 _mesa_MatrixMode(xform
->MatrixMode
);
1072 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
1073 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1075 /* restore clip planes */
1076 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1077 const GLuint mask
= 1 << 1;
1078 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1079 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1080 if (xform
->ClipPlanesEnabled
& mask
) {
1081 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1084 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1086 if (ctx
->Driver
.ClipPlane
)
1087 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1090 /* normalize/rescale */
1091 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1092 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1093 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1094 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1095 ctx
->Transform
.RescaleNormals
);
1098 case GL_TEXTURE_BIT
:
1099 /* Take care of texture object reference counters */
1101 const struct gl_texture_attrib
*texture
;
1102 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1103 pop_texture_group(ctx
, texture
);
1104 ctx
->NewState
|= _NEW_TEXTURE
;
1107 case GL_VIEWPORT_BIT
:
1109 const struct gl_viewport_attrib
*vp
;
1110 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1111 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1112 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1115 case GL_MULTISAMPLE_BIT_ARB
:
1117 const struct gl_multisample_attrib
*ms
;
1118 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1119 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1120 ms
->SampleCoverageInvert
);
1125 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1137 #define GL_CLIENT_PACK_BIT (1<<20)
1138 #define GL_CLIENT_UNPACK_BIT (1<<21)
1142 _mesa_PushClientAttrib(GLbitfield mask
)
1144 struct gl_attrib_node
*newnode
;
1145 struct gl_attrib_node
*head
;
1147 GET_CURRENT_CONTEXT(ctx
);
1148 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1150 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1151 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1155 /* Build linked list of attribute nodes which save all attribute */
1156 /* groups specified by the mask. */
1159 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1160 struct gl_pixelstore_attrib
*attr
;
1161 /* packing attribs */
1162 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1163 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1164 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1165 newnode
->data
= attr
;
1166 newnode
->next
= head
;
1168 /* unpacking attribs */
1169 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1170 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1171 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1172 newnode
->data
= attr
;
1173 newnode
->next
= head
;
1176 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1177 struct gl_array_attrib
*attr
;
1178 attr
= MALLOC_STRUCT( gl_array_attrib
);
1179 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1180 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1181 newnode
->data
= attr
;
1182 newnode
->next
= head
;
1186 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1187 ctx
->ClientAttribStackDepth
++;
1194 _mesa_PopClientAttrib(void)
1196 struct gl_attrib_node
*attr
, *next
;
1198 GET_CURRENT_CONTEXT(ctx
);
1199 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1201 if (ctx
->ClientAttribStackDepth
== 0) {
1202 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1206 ctx
->ClientAttribStackDepth
--;
1207 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1210 switch (attr
->kind
) {
1211 case GL_CLIENT_PACK_BIT
:
1212 MEMCPY( &ctx
->Pack
, attr
->data
,
1213 sizeof(struct gl_pixelstore_attrib
) );
1214 ctx
->NewState
|= _NEW_PACKUNPACK
;
1216 case GL_CLIENT_UNPACK_BIT
:
1217 MEMCPY( &ctx
->Unpack
, attr
->data
,
1218 sizeof(struct gl_pixelstore_attrib
) );
1219 ctx
->NewState
|= _NEW_PACKUNPACK
;
1221 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1222 MEMCPY( &ctx
->Array
, attr
->data
,
1223 sizeof(struct gl_array_attrib
) );
1224 ctx
->NewState
|= _NEW_ARRAY
;
1227 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");