3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #include "simple_list.h"
50 #include "math/m_xform.h"
54 * Allocate a new attribute state node. These nodes have a
55 * "kind" value and a pointer to a struct of state data.
57 static struct gl_attrib_node
*
58 new_attrib_node( GLbitfield kind
)
60 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
69 _mesa_PushAttrib(GLbitfield mask
)
71 struct gl_attrib_node
*newnode
;
72 struct gl_attrib_node
*head
;
74 GET_CURRENT_CONTEXT(ctx
);
75 ASSERT_OUTSIDE_BEGIN_END(ctx
);
77 if (MESA_VERBOSE
& VERBOSE_API
)
78 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
80 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
81 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
85 /* Build linked list of attribute nodes which save all attribute */
86 /* groups specified by the mask. */
89 if (mask
& GL_ACCUM_BUFFER_BIT
) {
90 struct gl_accum_attrib
*attr
;
91 attr
= MALLOC_STRUCT( gl_accum_attrib
);
92 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
93 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
99 if (mask
& GL_COLOR_BUFFER_BIT
) {
100 struct gl_colorbuffer_attrib
*attr
;
101 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
102 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
103 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
104 newnode
->data
= attr
;
105 newnode
->next
= head
;
109 if (mask
& GL_CURRENT_BIT
) {
110 struct gl_current_attrib
*attr
;
111 FLUSH_CURRENT( ctx
, 0 );
112 attr
= MALLOC_STRUCT( gl_current_attrib
);
113 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
114 newnode
= new_attrib_node( GL_CURRENT_BIT
);
115 newnode
->data
= attr
;
116 newnode
->next
= head
;
120 if (mask
& GL_DEPTH_BUFFER_BIT
) {
121 struct gl_depthbuffer_attrib
*attr
;
122 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
123 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
124 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
125 newnode
->data
= attr
;
126 newnode
->next
= head
;
130 if (mask
& GL_ENABLE_BIT
) {
131 struct gl_enable_attrib
*attr
;
133 attr
= MALLOC_STRUCT( gl_enable_attrib
);
134 /* Copy enable flags from all other attributes into the enable struct. */
135 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
136 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
137 attr
->Blend
= ctx
->Color
.BlendEnabled
;
138 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
139 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
140 attr
->ColorTable
= ctx
->Pixel
.ColorTableEnabled
;
141 attr
->PostColorMatrixColorTable
= ctx
->Pixel
.PostColorMatrixColorTableEnabled
;
142 attr
->PostConvolutionColorTable
= ctx
->Pixel
.PostConvolutionColorTableEnabled
;
143 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
144 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
145 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
146 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
147 attr
->DepthTest
= ctx
->Depth
.Test
;
148 attr
->Dither
= ctx
->Color
.DitherFlag
;
149 attr
->Fog
= ctx
->Fog
.Enabled
;
150 for (i
=0;i
<MAX_LIGHTS
;i
++) {
151 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
153 attr
->Lighting
= ctx
->Light
.Enabled
;
154 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
155 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
156 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
157 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
158 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
159 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
160 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
161 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
162 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
163 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
164 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
165 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
166 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
167 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
168 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
169 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
170 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
171 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
172 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
173 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
174 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
175 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
176 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
177 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
178 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
179 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
180 attr
->Normalize
= ctx
->Transform
.Normalize
;
181 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
182 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
183 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
184 attr
->PointSprite
= ctx
->Point
.PointSprite
;
185 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
186 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
187 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
188 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
189 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
190 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
191 attr
->Scissor
= ctx
->Scissor
.Enabled
;
192 attr
->Stencil
= ctx
->Stencil
.Enabled
;
193 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
194 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
195 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
196 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
197 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
198 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
199 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
200 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
201 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
203 /* GL_NV_vertex_program */
204 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
205 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
206 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
207 newnode
= new_attrib_node( GL_ENABLE_BIT
);
208 newnode
->data
= attr
;
209 newnode
->next
= head
;
213 if (mask
& GL_EVAL_BIT
) {
214 struct gl_eval_attrib
*attr
;
215 attr
= MALLOC_STRUCT( gl_eval_attrib
);
216 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
217 newnode
= new_attrib_node( GL_EVAL_BIT
);
218 newnode
->data
= attr
;
219 newnode
->next
= head
;
223 if (mask
& GL_FOG_BIT
) {
224 struct gl_fog_attrib
*attr
;
225 attr
= MALLOC_STRUCT( gl_fog_attrib
);
226 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
227 newnode
= new_attrib_node( GL_FOG_BIT
);
228 newnode
->data
= attr
;
229 newnode
->next
= head
;
233 if (mask
& GL_HINT_BIT
) {
234 struct gl_hint_attrib
*attr
;
235 attr
= MALLOC_STRUCT( gl_hint_attrib
);
236 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
237 newnode
= new_attrib_node( GL_HINT_BIT
);
238 newnode
->data
= attr
;
239 newnode
->next
= head
;
243 if (mask
& GL_LIGHTING_BIT
) {
244 struct gl_light_attrib
*attr
;
245 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
246 attr
= MALLOC_STRUCT( gl_light_attrib
);
247 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
248 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
249 newnode
->data
= attr
;
250 newnode
->next
= head
;
254 if (mask
& GL_LINE_BIT
) {
255 struct gl_line_attrib
*attr
;
256 attr
= MALLOC_STRUCT( gl_line_attrib
);
257 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
258 newnode
= new_attrib_node( GL_LINE_BIT
);
259 newnode
->data
= attr
;
260 newnode
->next
= head
;
264 if (mask
& GL_LIST_BIT
) {
265 struct gl_list_attrib
*attr
;
266 attr
= MALLOC_STRUCT( gl_list_attrib
);
267 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
268 newnode
= new_attrib_node( GL_LIST_BIT
);
269 newnode
->data
= attr
;
270 newnode
->next
= head
;
274 if (mask
& GL_PIXEL_MODE_BIT
) {
275 struct gl_pixel_attrib
*attr
;
276 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
277 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
278 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
279 newnode
->data
= attr
;
280 newnode
->next
= head
;
284 if (mask
& GL_POINT_BIT
) {
285 struct gl_point_attrib
*attr
;
286 attr
= MALLOC_STRUCT( gl_point_attrib
);
287 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
288 newnode
= new_attrib_node( GL_POINT_BIT
);
289 newnode
->data
= attr
;
290 newnode
->next
= head
;
294 if (mask
& GL_POLYGON_BIT
) {
295 struct gl_polygon_attrib
*attr
;
296 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
297 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
298 newnode
= new_attrib_node( GL_POLYGON_BIT
);
299 newnode
->data
= attr
;
300 newnode
->next
= head
;
304 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
306 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
307 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
308 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
309 newnode
->data
= stipple
;
310 newnode
->next
= head
;
314 if (mask
& GL_SCISSOR_BIT
) {
315 struct gl_scissor_attrib
*attr
;
316 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
317 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
318 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
319 newnode
->data
= attr
;
320 newnode
->next
= head
;
324 if (mask
& GL_STENCIL_BUFFER_BIT
) {
325 struct gl_stencil_attrib
*attr
;
326 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
327 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
328 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
329 newnode
->data
= attr
;
330 newnode
->next
= head
;
334 if (mask
& GL_TEXTURE_BIT
) {
335 struct gl_texture_attrib
*attr
;
337 /* Bump the texture object reference counts so that they don't
338 * inadvertantly get deleted.
340 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
341 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
342 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
343 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
344 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
345 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
++;
347 attr
= MALLOC_STRUCT( gl_texture_attrib
);
348 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
349 /* copy state of the currently bound texture objects */
350 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
351 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved1D
,
352 attr
->Unit
[u
].Current1D
);
353 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved2D
,
354 attr
->Unit
[u
].Current2D
);
355 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved3D
,
356 attr
->Unit
[u
].Current3D
);
357 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedCubeMap
,
358 attr
->Unit
[u
].CurrentCubeMap
);
359 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedRect
,
360 attr
->Unit
[u
].CurrentRect
);
362 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
363 newnode
->data
= attr
;
364 newnode
->next
= head
;
368 if (mask
& GL_TRANSFORM_BIT
) {
369 struct gl_transform_attrib
*attr
;
370 attr
= MALLOC_STRUCT( gl_transform_attrib
);
371 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
372 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
373 newnode
->data
= attr
;
374 newnode
->next
= head
;
378 if (mask
& GL_VIEWPORT_BIT
) {
379 struct gl_viewport_attrib
*attr
;
380 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
381 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
382 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
383 newnode
->data
= attr
;
384 newnode
->next
= head
;
388 /* GL_ARB_multisample */
389 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
390 struct gl_multisample_attrib
*attr
;
391 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
392 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
393 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
394 newnode
->data
= attr
;
395 newnode
->next
= head
;
399 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
400 ctx
->AttribStackDepth
++;
406 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
410 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
411 if ((VALUE) != (NEWVALUE)) { \
412 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
415 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
416 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
418 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
419 const GLuint mask
= 1 << i
;
420 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
421 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
422 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
425 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
427 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
, enable
->ColorTable
,
429 TEST_AND_UPDATE(ctx
->Pixel
.PostColorMatrixColorTableEnabled
,
430 enable
->PostColorMatrixColorTable
,
431 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
432 TEST_AND_UPDATE(ctx
->Pixel
.PostConvolutionColorTableEnabled
,
433 enable
->PostConvolutionColorTable
,
434 GL_POST_CONVOLUTION_COLOR_TABLE
);
435 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
436 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
437 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
438 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
440 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
442 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
444 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
445 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
446 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
447 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
449 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
451 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
454 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
455 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
456 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
457 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
458 GL_MAP1_TEXTURE_COORD_1
);
459 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
460 GL_MAP1_TEXTURE_COORD_2
);
461 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
462 GL_MAP1_TEXTURE_COORD_3
);
463 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
464 GL_MAP1_TEXTURE_COORD_4
);
465 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
467 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
469 for (i
= 0; i
< 16; i
++) {
470 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
471 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
474 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
475 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
476 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
477 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
478 GL_MAP2_TEXTURE_COORD_1
);
479 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
480 GL_MAP2_TEXTURE_COORD_2
);
481 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
482 GL_MAP2_TEXTURE_COORD_3
);
483 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
484 GL_MAP2_TEXTURE_COORD_4
);
485 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
487 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
489 for (i
= 0; i
< 16; i
++) {
490 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
491 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
494 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
495 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
496 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
497 GL_RESCALE_NORMAL_EXT
);
498 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
499 enable
->RasterPositionUnclipped
,
500 GL_RASTER_POSITION_UNCLIPPED_IBM
);
501 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
503 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
505 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
506 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
509 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
510 GL_POLYGON_OFFSET_POINT
);
511 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
512 GL_POLYGON_OFFSET_LINE
);
513 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
514 GL_POLYGON_OFFSET_FILL
);
515 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
517 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
519 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
520 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
521 /* XXX two-sided stencil */
522 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
524 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
525 enable
->SampleAlphaToCoverage
,
526 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
527 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
528 enable
->SampleAlphaToOne
,
529 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
530 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
531 enable
->SampleCoverage
,
532 GL_SAMPLE_COVERAGE_ARB
);
533 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
534 enable
->SampleCoverageInvert
,
535 GL_SAMPLE_COVERAGE_INVERT_ARB
);
536 /* GL_NV_vertex_program */
537 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
538 enable
->VertexProgram
,
539 GL_VERTEX_PROGRAM_NV
);
540 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
541 enable
->VertexProgramPointSize
,
542 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
543 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
544 enable
->VertexProgramTwoSide
,
545 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
547 #undef TEST_AND_UPDATE
549 /* texture unit enables */
550 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
551 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
552 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
553 if (ctx
->Driver
.Enable
) {
554 if (ctx
->Driver
.ActiveTexture
) {
555 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
557 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
558 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
559 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
560 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
561 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
562 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
563 if (ctx
->Extensions
.ARB_texture_cube_map
)
564 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
565 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
566 if (ctx
->Extensions
.NV_texture_rectangle
)
567 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
568 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
572 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
573 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
574 if (ctx
->Driver
.Enable
) {
575 if (ctx
->Driver
.ActiveTexture
) {
576 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
578 if (enable
->TexGen
[i
] & S_BIT
)
579 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
581 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
582 if (enable
->TexGen
[i
] & T_BIT
)
583 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
585 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
586 if (enable
->TexGen
[i
] & R_BIT
)
587 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
589 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
590 if (enable
->TexGen
[i
] & Q_BIT
)
591 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
593 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
597 /* GL_SGI_texture_color_table */
598 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
601 if (ctx
->Driver
.ActiveTexture
) {
602 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
608 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
612 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
613 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
616 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
617 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
618 (GLboolean
) (unit
->Enabled
& TEXTURE_1D_BIT
? GL_TRUE
: GL_FALSE
));
619 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
620 (GLboolean
) (unit
->Enabled
& TEXTURE_2D_BIT
? GL_TRUE
: GL_FALSE
));
621 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
622 (GLboolean
) (unit
->Enabled
& TEXTURE_3D_BIT
? GL_TRUE
: GL_FALSE
));
623 if (ctx
->Extensions
.ARB_texture_cube_map
) {
624 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
625 (GLboolean
) (unit
->Enabled
& TEXTURE_CUBE_BIT
? GL_TRUE
: GL_FALSE
));
627 if (ctx
->Extensions
.NV_texture_rectangle
) {
628 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
629 (GLboolean
) (unit
->Enabled
& TEXTURE_RECT_BIT
? GL_TRUE
: GL_FALSE
));
631 if (ctx
->Extensions
.SGI_texture_color_table
) {
632 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
633 unit
->ColorTableEnabled
);
635 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
636 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
637 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
638 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
639 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
640 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
641 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
642 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
643 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
644 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
645 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
646 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
647 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
648 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
649 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
650 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
651 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
653 if (ctx
->Extensions
.EXT_texture_env_combine
||
654 ctx
->Extensions
.ARB_texture_env_combine
) {
655 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
656 unit
->Combine
.ModeRGB
);
657 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
658 unit
->Combine
.ModeA
);
659 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
660 unit
->Combine
.SourceRGB
[0]);
661 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
662 unit
->Combine
.SourceRGB
[1]);
663 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
664 unit
->Combine
.SourceRGB
[2]);
665 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
666 unit
->Combine
.SourceA
[0]);
667 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
668 unit
->Combine
.SourceA
[1]);
669 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
670 unit
->Combine
.SourceA
[2]);
671 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
672 unit
->Combine
.OperandRGB
[0]);
673 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
674 unit
->Combine
.OperandRGB
[1]);
675 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
676 unit
->Combine
.OperandRGB
[2]);
677 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
678 unit
->Combine
.OperandA
[0]);
679 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
680 unit
->Combine
.OperandA
[1]);
681 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
682 unit
->Combine
.OperandA
[2]);
683 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
684 1 << unit
->Combine
.ScaleShiftRGB
);
685 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
686 1 << unit
->Combine
.ScaleShiftA
);
689 /* Restore texture object state */
690 for (i
= 0; i
< NUM_TEXTURE_TARGETS
; i
++) {
692 const struct gl_texture_object
*obj
= NULL
;
693 GLfloat bordColor
[4];
697 target
= GL_TEXTURE_1D
;
698 obj
= &unit
->Saved1D
;
701 target
= GL_TEXTURE_2D
;
702 obj
= &unit
->Saved2D
;
705 target
= GL_TEXTURE_3D
;
706 obj
= &unit
->Saved3D
;
709 if (!ctx
->Extensions
.ARB_texture_cube_map
)
711 target
= GL_TEXTURE_CUBE_MAP_ARB
;
712 obj
= &unit
->SavedCubeMap
;
715 if (!ctx
->Extensions
.NV_texture_rectangle
)
717 target
= GL_TEXTURE_RECTANGLE_NV
;
718 obj
= &unit
->SavedRect
;
721 ; /* silence warnings */
724 _mesa_BindTexture(target
, obj
->Name
);
726 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
727 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
728 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
729 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
731 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
732 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
733 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
735 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
736 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
737 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
738 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
739 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
740 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
741 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
742 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
743 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
746 if (ctx
->Extensions
.SGIX_shadow
) {
747 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
749 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
750 obj
->CompareOperator
);
752 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
753 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
759 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
760 + texAttrib
->CurrentUnit
);
762 /* "un-bump" the texture object reference counts. We did that so they
763 * wouldn't inadvertantly get deleted while they were still referenced
764 * inside the attribute state stack.
766 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
767 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
768 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
769 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
770 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
771 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
--;
777 * This function is kind of long just because we have to call a lot
778 * of device driver functions to update device driver state.
780 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
781 * in order to restore GL state. This isn't terribly efficient but it
782 * ensures that dirty flags and any derived state gets updated correctly.
783 * We could at least check if the value to restore equals the current value
784 * and then skip the Mesa call.
787 _mesa_PopAttrib(void)
789 struct gl_attrib_node
*attr
, *next
;
790 GET_CURRENT_CONTEXT(ctx
);
791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
793 if (ctx
->AttribStackDepth
== 0) {
794 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
798 ctx
->AttribStackDepth
--;
799 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
803 if (MESA_VERBOSE
& VERBOSE_API
) {
804 _mesa_debug(ctx
, "glPopAttrib %s\n",
805 _mesa_lookup_enum_by_nr(attr
->kind
));
808 switch (attr
->kind
) {
809 case GL_ACCUM_BUFFER_BIT
:
811 const struct gl_accum_attrib
*accum
;
812 accum
= (const struct gl_accum_attrib
*) attr
->data
;
813 _mesa_ClearAccum(accum
->ClearColor
[0],
814 accum
->ClearColor
[1],
815 accum
->ClearColor
[2],
816 accum
->ClearColor
[3]);
819 case GL_COLOR_BUFFER_BIT
:
821 const struct gl_colorbuffer_attrib
*color
;
822 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
823 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
824 _mesa_ClearColor(color
->ClearColor
[0],
825 color
->ClearColor
[1],
826 color
->ClearColor
[2],
827 color
->ClearColor
[3]);
828 _mesa_IndexMask(color
->IndexMask
);
829 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
830 (GLboolean
) (color
->ColorMask
[1] != 0),
831 (GLboolean
) (color
->ColorMask
[2] != 0),
832 (GLboolean
) (color
->ColorMask
[3] != 0));
833 _mesa_DrawBuffer(color
->DrawBuffer
);
834 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
835 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
836 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
837 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
841 /* This special case is because glBlendEquationSeparateEXT
842 * cannot take GL_LOGIC_OP as a parameter.
844 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
845 _mesa_BlendEquation(color
->BlendEquationRGB
);
848 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
849 color
->BlendEquationA
);
851 _mesa_BlendColor(color
->BlendColor
[0],
852 color
->BlendColor
[1],
853 color
->BlendColor
[2],
854 color
->BlendColor
[3]);
855 _mesa_LogicOp(color
->LogicOp
);
856 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
857 color
->ColorLogicOpEnabled
);
858 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
859 color
->IndexLogicOpEnabled
);
860 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
864 FLUSH_CURRENT( ctx
, 0 );
865 MEMCPY( &ctx
->Current
, attr
->data
,
866 sizeof(struct gl_current_attrib
) );
868 case GL_DEPTH_BUFFER_BIT
:
870 const struct gl_depthbuffer_attrib
*depth
;
871 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
872 _mesa_DepthFunc(depth
->Func
);
873 _mesa_ClearDepth(depth
->Clear
);
874 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
875 _mesa_DepthMask(depth
->Mask
);
876 if (ctx
->Extensions
.HP_occlusion_test
)
877 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
878 depth
->OcclusionTest
);
883 const struct gl_enable_attrib
*enable
;
884 enable
= (const struct gl_enable_attrib
*) attr
->data
;
885 pop_enable_group(ctx
, enable
);
886 ctx
->NewState
|= _NEW_ALL
;
890 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
891 ctx
->NewState
|= _NEW_EVAL
;
895 const struct gl_fog_attrib
*fog
;
896 fog
= (const struct gl_fog_attrib
*) attr
->data
;
897 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
898 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
899 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
900 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
901 _mesa_Fogf(GL_FOG_END
, fog
->End
);
902 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
903 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
908 const struct gl_hint_attrib
*hint
;
909 hint
= (const struct gl_hint_attrib
*) attr
->data
;
910 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
911 hint
->PerspectiveCorrection
);
912 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
913 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
914 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
915 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
916 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
917 hint
->ClipVolumeClipping
);
918 if (ctx
->Extensions
.ARB_texture_compression
)
919 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
920 hint
->TextureCompression
);
923 case GL_LIGHTING_BIT
:
926 const struct gl_light_attrib
*light
;
927 light
= (const struct gl_light_attrib
*) attr
->data
;
928 /* lighting enable */
929 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
930 /* per-light state */
932 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
)
933 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
935 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
936 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
937 const struct gl_light
*l
= &light
->Light
[i
];
939 _mesa_set_enable(ctx
, lgt
, l
->Enabled
);
940 _mesa_Lightfv( lgt
, GL_AMBIENT
, l
->Ambient
);
941 _mesa_Lightfv( lgt
, GL_DIFFUSE
, l
->Diffuse
);
942 _mesa_Lightfv( lgt
, GL_SPECULAR
, l
->Specular
);
943 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->inv
, l
->EyePosition
);
944 _mesa_Lightfv( lgt
, GL_POSITION
, tmp
);
945 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->m
, l
->EyeDirection
);
946 _mesa_Lightfv( lgt
, GL_SPOT_DIRECTION
, tmp
);
947 _mesa_Lightfv( lgt
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
948 _mesa_Lightfv( lgt
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
949 _mesa_Lightfv( lgt
, GL_CONSTANT_ATTENUATION
,
950 &l
->ConstantAttenuation
);
951 _mesa_Lightfv( lgt
, GL_LINEAR_ATTENUATION
,
952 &l
->LinearAttenuation
);
953 _mesa_Lightfv( lgt
, GL_QUADRATIC_ATTENUATION
,
954 &l
->QuadraticAttenuation
);
957 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
958 light
->Model
.Ambient
);
959 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
960 (GLfloat
) light
->Model
.LocalViewer
);
961 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
962 (GLfloat
) light
->Model
.TwoSide
);
963 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
964 (GLfloat
) light
->Model
.ColorControl
);
966 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
967 sizeof(struct gl_material
));
969 _mesa_ShadeModel(light
->ShadeModel
);
971 _mesa_ColorMaterial(light
->ColorMaterialFace
,
972 light
->ColorMaterialMode
);
973 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
974 light
->ColorMaterialEnabled
);
979 const struct gl_line_attrib
*line
;
980 line
= (const struct gl_line_attrib
*) attr
->data
;
981 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
982 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
983 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
984 _mesa_LineWidth(line
->Width
);
988 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
990 case GL_PIXEL_MODE_BIT
:
991 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
992 ctx
->NewState
|= _NEW_PIXEL
;
996 const struct gl_point_attrib
*point
;
997 point
= (const struct gl_point_attrib
*) attr
->data
;
998 _mesa_PointSize(point
->Size
);
999 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1000 if (ctx
->Extensions
.EXT_point_parameters
) {
1001 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
1003 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
1005 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
1007 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1010 if (ctx
->Extensions
.NV_point_sprite
1011 || ctx
->Extensions
.ARB_point_sprite
) {
1013 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1014 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1015 (GLint
) point
->CoordReplace
[u
]);
1017 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1018 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1019 ctx
->Point
.SpriteRMode
);
1023 case GL_POLYGON_BIT
:
1025 const struct gl_polygon_attrib
*polygon
;
1026 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1027 _mesa_CullFace(polygon
->CullFaceMode
);
1028 _mesa_FrontFace(polygon
->FrontFace
);
1029 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1030 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1031 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1032 polygon
->OffsetUnits
);
1033 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1034 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1035 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1036 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1037 polygon
->OffsetPoint
);
1038 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1039 polygon
->OffsetLine
);
1040 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1041 polygon
->OffsetFill
);
1044 case GL_POLYGON_STIPPLE_BIT
:
1045 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1046 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1047 if (ctx
->Driver
.PolygonStipple
)
1048 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1050 case GL_SCISSOR_BIT
:
1052 const struct gl_scissor_attrib
*scissor
;
1053 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1054 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1055 scissor
->Width
, scissor
->Height
);
1056 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1059 case GL_STENCIL_BUFFER_BIT
:
1061 const GLint face
= 0; /* XXX stencil two side */
1062 const struct gl_stencil_attrib
*stencil
;
1063 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1064 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1065 _mesa_ClearStencil(stencil
->Clear
);
1066 _mesa_StencilFunc(stencil
->Function
[face
], stencil
->Ref
[face
],
1067 stencil
->ValueMask
[face
]);
1068 _mesa_StencilMask(stencil
->WriteMask
[face
]);
1069 _mesa_StencilOp(stencil
->FailFunc
[face
],
1070 stencil
->ZFailFunc
[face
],
1071 stencil
->ZPassFunc
[face
]);
1074 case GL_TRANSFORM_BIT
:
1077 const struct gl_transform_attrib
*xform
;
1078 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1079 _mesa_MatrixMode(xform
->MatrixMode
);
1081 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
1082 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1084 /* restore clip planes */
1085 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1086 const GLuint mask
= 1 << 1;
1087 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1088 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1089 if (xform
->ClipPlanesEnabled
& mask
) {
1090 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1093 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1095 if (ctx
->Driver
.ClipPlane
)
1096 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1099 /* normalize/rescale */
1100 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1101 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1102 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1103 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1104 ctx
->Transform
.RescaleNormals
);
1107 case GL_TEXTURE_BIT
:
1108 /* Take care of texture object reference counters */
1110 const struct gl_texture_attrib
*texture
;
1111 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1112 pop_texture_group(ctx
, texture
);
1113 ctx
->NewState
|= _NEW_TEXTURE
;
1116 case GL_VIEWPORT_BIT
:
1118 const struct gl_viewport_attrib
*vp
;
1119 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1120 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1121 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1124 case GL_MULTISAMPLE_BIT_ARB
:
1126 const struct gl_multisample_attrib
*ms
;
1127 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1128 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1129 ms
->SampleCoverageInvert
);
1134 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1146 #define GL_CLIENT_PACK_BIT (1<<20)
1147 #define GL_CLIENT_UNPACK_BIT (1<<21)
1151 _mesa_PushClientAttrib(GLbitfield mask
)
1153 struct gl_attrib_node
*newnode
;
1154 struct gl_attrib_node
*head
;
1156 GET_CURRENT_CONTEXT(ctx
);
1157 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1159 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1160 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1164 /* Build linked list of attribute nodes which save all attribute */
1165 /* groups specified by the mask. */
1168 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1169 struct gl_pixelstore_attrib
*attr
;
1170 /* packing attribs */
1171 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1172 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1173 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1174 newnode
->data
= attr
;
1175 newnode
->next
= head
;
1177 /* unpacking attribs */
1178 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1179 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1180 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1181 newnode
->data
= attr
;
1182 newnode
->next
= head
;
1185 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1186 struct gl_array_attrib
*attr
;
1187 attr
= MALLOC_STRUCT( gl_array_attrib
);
1188 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1189 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1190 newnode
->data
= attr
;
1191 newnode
->next
= head
;
1195 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1196 ctx
->ClientAttribStackDepth
++;
1203 _mesa_PopClientAttrib(void)
1205 struct gl_attrib_node
*attr
, *next
;
1207 GET_CURRENT_CONTEXT(ctx
);
1208 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1210 if (ctx
->ClientAttribStackDepth
== 0) {
1211 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1215 ctx
->ClientAttribStackDepth
--;
1216 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1219 switch (attr
->kind
) {
1220 case GL_CLIENT_PACK_BIT
:
1221 MEMCPY( &ctx
->Pack
, attr
->data
,
1222 sizeof(struct gl_pixelstore_attrib
) );
1223 ctx
->NewState
|= _NEW_PACKUNPACK
;
1225 case GL_CLIENT_UNPACK_BIT
:
1226 MEMCPY( &ctx
->Unpack
, attr
->data
,
1227 sizeof(struct gl_pixelstore_attrib
) );
1228 ctx
->NewState
|= _NEW_PACKUNPACK
;
1230 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1231 MEMCPY( &ctx
->Array
, attr
->data
,
1232 sizeof(struct gl_array_attrib
) );
1233 ctx
->NewState
|= _NEW_ARRAY
;
1236 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1248 void _mesa_init_attrib( GLcontext
*ctx
)
1250 /* Renderer and client attribute stacks */
1251 ctx
->AttribStackDepth
= 0;
1252 ctx
->ClientAttribStackDepth
= 0;