2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 #include "simple_list.h"
49 #include "math/m_xform.h"
53 * Allocate a new attribute state node. These nodes have a
54 * "kind" value and a pointer to a struct of state data.
56 static struct gl_attrib_node
*
57 new_attrib_node( GLbitfield kind
)
59 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
68 _mesa_PushAttrib(GLbitfield mask
)
70 struct gl_attrib_node
*newnode
;
71 struct gl_attrib_node
*head
;
73 GET_CURRENT_CONTEXT(ctx
);
74 ASSERT_OUTSIDE_BEGIN_END(ctx
);
76 if (MESA_VERBOSE
& VERBOSE_API
)
77 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
79 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
80 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
84 /* Build linked list of attribute nodes which save all attribute */
85 /* groups specified by the mask. */
88 if (mask
& GL_ACCUM_BUFFER_BIT
) {
89 struct gl_accum_attrib
*attr
;
90 attr
= MALLOC_STRUCT( gl_accum_attrib
);
91 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
92 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
98 if (mask
& GL_COLOR_BUFFER_BIT
) {
99 struct gl_colorbuffer_attrib
*attr
;
100 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
101 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
102 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
103 newnode
->data
= attr
;
104 newnode
->next
= head
;
108 if (mask
& GL_CURRENT_BIT
) {
109 struct gl_current_attrib
*attr
;
110 FLUSH_CURRENT( ctx
, 0 );
111 attr
= MALLOC_STRUCT( gl_current_attrib
);
112 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
113 newnode
= new_attrib_node( GL_CURRENT_BIT
);
114 newnode
->data
= attr
;
115 newnode
->next
= head
;
119 if (mask
& GL_DEPTH_BUFFER_BIT
) {
120 struct gl_depthbuffer_attrib
*attr
;
121 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
122 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
123 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
124 newnode
->data
= attr
;
125 newnode
->next
= head
;
129 if (mask
& GL_ENABLE_BIT
) {
130 struct gl_enable_attrib
*attr
;
132 attr
= MALLOC_STRUCT( gl_enable_attrib
);
133 /* Copy enable flags from all other attributes into the enable struct. */
134 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
135 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
136 attr
->Blend
= ctx
->Color
.BlendEnabled
;
137 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
138 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
139 attr
->ColorTable
= ctx
->Pixel
.ColorTableEnabled
;
140 attr
->PostColorMatrixColorTable
= ctx
->Pixel
.PostColorMatrixColorTableEnabled
;
141 attr
->PostConvolutionColorTable
= ctx
->Pixel
.PostConvolutionColorTableEnabled
;
142 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
143 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
144 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
145 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
146 attr
->DepthTest
= ctx
->Depth
.Test
;
147 attr
->Dither
= ctx
->Color
.DitherFlag
;
148 attr
->Fog
= ctx
->Fog
.Enabled
;
149 for (i
=0;i
<MAX_LIGHTS
;i
++) {
150 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
152 attr
->Lighting
= ctx
->Light
.Enabled
;
153 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
154 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
155 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
156 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
157 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
158 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
159 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
160 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
161 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
162 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
163 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
164 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
165 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
166 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
167 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
168 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
169 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
170 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
171 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
172 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
173 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
174 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
175 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
176 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
177 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
178 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
179 attr
->Normalize
= ctx
->Transform
.Normalize
;
180 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
181 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
182 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
183 attr
->PointSprite
= ctx
->Point
.PointSprite
;
184 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
185 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
186 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
187 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
188 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
189 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
190 attr
->Scissor
= ctx
->Scissor
.Enabled
;
191 attr
->Stencil
= ctx
->Stencil
.Enabled
;
192 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
193 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
194 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
195 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
196 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
197 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
198 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
199 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
200 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
202 /* GL_NV_vertex_program */
203 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
204 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
205 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
206 newnode
= new_attrib_node( GL_ENABLE_BIT
);
207 newnode
->data
= attr
;
208 newnode
->next
= head
;
212 if (mask
& GL_EVAL_BIT
) {
213 struct gl_eval_attrib
*attr
;
214 attr
= MALLOC_STRUCT( gl_eval_attrib
);
215 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
216 newnode
= new_attrib_node( GL_EVAL_BIT
);
217 newnode
->data
= attr
;
218 newnode
->next
= head
;
222 if (mask
& GL_FOG_BIT
) {
223 struct gl_fog_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_fog_attrib
);
225 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
226 newnode
= new_attrib_node( GL_FOG_BIT
);
227 newnode
->data
= attr
;
228 newnode
->next
= head
;
232 if (mask
& GL_HINT_BIT
) {
233 struct gl_hint_attrib
*attr
;
234 attr
= MALLOC_STRUCT( gl_hint_attrib
);
235 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
236 newnode
= new_attrib_node( GL_HINT_BIT
);
237 newnode
->data
= attr
;
238 newnode
->next
= head
;
242 if (mask
& GL_LIGHTING_BIT
) {
243 struct gl_light_attrib
*attr
;
244 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
245 attr
= MALLOC_STRUCT( gl_light_attrib
);
246 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
247 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
248 newnode
->data
= attr
;
249 newnode
->next
= head
;
253 if (mask
& GL_LINE_BIT
) {
254 struct gl_line_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_line_attrib
);
256 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
257 newnode
= new_attrib_node( GL_LINE_BIT
);
258 newnode
->data
= attr
;
259 newnode
->next
= head
;
263 if (mask
& GL_LIST_BIT
) {
264 struct gl_list_attrib
*attr
;
265 attr
= MALLOC_STRUCT( gl_list_attrib
);
266 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
267 newnode
= new_attrib_node( GL_LIST_BIT
);
268 newnode
->data
= attr
;
269 newnode
->next
= head
;
273 if (mask
& GL_PIXEL_MODE_BIT
) {
274 struct gl_pixel_attrib
*attr
;
275 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
276 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
277 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
278 newnode
->data
= attr
;
279 newnode
->next
= head
;
283 if (mask
& GL_POINT_BIT
) {
284 struct gl_point_attrib
*attr
;
285 attr
= MALLOC_STRUCT( gl_point_attrib
);
286 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
287 newnode
= new_attrib_node( GL_POINT_BIT
);
288 newnode
->data
= attr
;
289 newnode
->next
= head
;
293 if (mask
& GL_POLYGON_BIT
) {
294 struct gl_polygon_attrib
*attr
;
295 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
296 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
297 newnode
= new_attrib_node( GL_POLYGON_BIT
);
298 newnode
->data
= attr
;
299 newnode
->next
= head
;
303 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
305 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
306 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
307 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
308 newnode
->data
= stipple
;
309 newnode
->next
= head
;
313 if (mask
& GL_SCISSOR_BIT
) {
314 struct gl_scissor_attrib
*attr
;
315 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
316 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
317 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
318 newnode
->data
= attr
;
319 newnode
->next
= head
;
323 if (mask
& GL_STENCIL_BUFFER_BIT
) {
324 struct gl_stencil_attrib
*attr
;
325 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
326 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
327 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
328 newnode
->data
= attr
;
329 newnode
->next
= head
;
333 if (mask
& GL_TEXTURE_BIT
) {
334 struct gl_texture_attrib
*attr
;
336 /* Bump the texture object reference counts so that they don't
337 * inadvertantly get deleted.
339 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
340 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
341 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
342 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
343 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
344 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
++;
346 attr
= MALLOC_STRUCT( gl_texture_attrib
);
347 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
348 /* copy state of the currently bound texture objects */
349 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
350 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved1D
,
351 attr
->Unit
[u
].Current1D
);
352 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved2D
,
353 attr
->Unit
[u
].Current2D
);
354 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved3D
,
355 attr
->Unit
[u
].Current3D
);
356 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedCubeMap
,
357 attr
->Unit
[u
].CurrentCubeMap
);
358 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedRect
,
359 attr
->Unit
[u
].CurrentRect
);
361 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
362 newnode
->data
= attr
;
363 newnode
->next
= head
;
367 if (mask
& GL_TRANSFORM_BIT
) {
368 struct gl_transform_attrib
*attr
;
369 attr
= MALLOC_STRUCT( gl_transform_attrib
);
370 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
371 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
372 newnode
->data
= attr
;
373 newnode
->next
= head
;
377 if (mask
& GL_VIEWPORT_BIT
) {
378 struct gl_viewport_attrib
*attr
;
379 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
380 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
381 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
382 newnode
->data
= attr
;
383 newnode
->next
= head
;
387 /* GL_ARB_multisample */
388 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
389 struct gl_multisample_attrib
*attr
;
390 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
391 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
392 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
393 newnode
->data
= attr
;
394 newnode
->next
= head
;
398 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
399 ctx
->AttribStackDepth
++;
405 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
409 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
410 if ((VALUE) != (NEWVALUE)) { \
411 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
414 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
415 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
417 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
418 const GLuint mask
= 1 << i
;
419 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
420 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
421 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
424 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
426 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
, enable
->ColorTable
,
428 TEST_AND_UPDATE(ctx
->Pixel
.PostColorMatrixColorTableEnabled
,
429 enable
->PostColorMatrixColorTable
,
430 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
431 TEST_AND_UPDATE(ctx
->Pixel
.PostConvolutionColorTableEnabled
,
432 enable
->PostConvolutionColorTable
,
433 GL_POST_CONVOLUTION_COLOR_TABLE
);
434 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
435 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
436 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
437 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
439 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
441 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
443 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
444 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
445 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
446 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
448 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
450 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
453 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
454 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
455 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
456 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
457 GL_MAP1_TEXTURE_COORD_1
);
458 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
459 GL_MAP1_TEXTURE_COORD_2
);
460 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
461 GL_MAP1_TEXTURE_COORD_3
);
462 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
463 GL_MAP1_TEXTURE_COORD_4
);
464 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
466 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
468 for (i
= 0; i
< 16; i
++) {
469 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
470 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
473 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
474 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
475 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
476 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
477 GL_MAP2_TEXTURE_COORD_1
);
478 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
479 GL_MAP2_TEXTURE_COORD_2
);
480 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
481 GL_MAP2_TEXTURE_COORD_3
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
483 GL_MAP2_TEXTURE_COORD_4
);
484 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
486 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
488 for (i
= 0; i
< 16; i
++) {
489 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
490 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
493 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
494 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
495 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
496 GL_RESCALE_NORMAL_EXT
);
497 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
498 enable
->RasterPositionUnclipped
,
499 GL_RASTER_POSITION_UNCLIPPED_IBM
);
500 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
502 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
504 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
505 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
508 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
509 GL_POLYGON_OFFSET_POINT
);
510 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
511 GL_POLYGON_OFFSET_LINE
);
512 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
513 GL_POLYGON_OFFSET_FILL
);
514 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
516 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
518 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
519 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
520 /* XXX two-sided stencil */
521 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
523 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
524 enable
->SampleAlphaToCoverage
,
525 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
526 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
527 enable
->SampleAlphaToOne
,
528 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
529 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
530 enable
->SampleCoverage
,
531 GL_SAMPLE_COVERAGE_ARB
);
532 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
533 enable
->SampleCoverageInvert
,
534 GL_SAMPLE_COVERAGE_INVERT_ARB
);
535 /* GL_NV_vertex_program */
536 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
537 enable
->VertexProgram
,
538 GL_VERTEX_PROGRAM_NV
);
539 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
540 enable
->VertexProgramPointSize
,
541 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
542 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
543 enable
->VertexProgramTwoSide
,
544 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
546 #undef TEST_AND_UPDATE
548 /* texture unit enables */
549 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
550 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
551 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
552 if (ctx
->Driver
.Enable
) {
553 if (ctx
->Driver
.ActiveTexture
) {
554 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
556 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
557 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
558 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
559 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
560 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
561 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
562 if (ctx
->Extensions
.ARB_texture_cube_map
)
563 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
564 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
565 if (ctx
->Extensions
.NV_texture_rectangle
)
566 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
567 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
571 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
572 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
573 if (ctx
->Driver
.Enable
) {
574 if (ctx
->Driver
.ActiveTexture
) {
575 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
577 if (enable
->TexGen
[i
] & S_BIT
)
578 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
580 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
581 if (enable
->TexGen
[i
] & T_BIT
)
582 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
584 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
585 if (enable
->TexGen
[i
] & R_BIT
)
586 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
588 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
589 if (enable
->TexGen
[i
] & Q_BIT
)
590 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
592 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
596 /* GL_SGI_texture_color_table */
597 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
600 if (ctx
->Driver
.ActiveTexture
) {
601 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
607 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
611 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
612 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
615 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
616 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
617 (GLboolean
) (unit
->Enabled
& TEXTURE_1D_BIT
? GL_TRUE
: GL_FALSE
));
618 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
619 (GLboolean
) (unit
->Enabled
& TEXTURE_2D_BIT
? GL_TRUE
: GL_FALSE
));
620 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
621 (GLboolean
) (unit
->Enabled
& TEXTURE_3D_BIT
? GL_TRUE
: GL_FALSE
));
622 if (ctx
->Extensions
.ARB_texture_cube_map
) {
623 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
624 (GLboolean
) (unit
->Enabled
& TEXTURE_CUBE_BIT
? GL_TRUE
: GL_FALSE
));
626 if (ctx
->Extensions
.NV_texture_rectangle
) {
627 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
628 (GLboolean
) (unit
->Enabled
& TEXTURE_RECT_BIT
? GL_TRUE
: GL_FALSE
));
630 if (ctx
->Extensions
.SGI_texture_color_table
) {
631 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
632 unit
->ColorTableEnabled
);
634 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
635 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
636 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
637 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
638 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
639 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
640 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
641 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
642 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
643 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
644 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
645 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
646 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
647 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
648 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
649 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
650 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
652 if (ctx
->Extensions
.EXT_texture_env_combine
||
653 ctx
->Extensions
.ARB_texture_env_combine
) {
654 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
655 unit
->Combine
.ModeRGB
);
656 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
657 unit
->Combine
.ModeA
);
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
659 unit
->Combine
.SourceRGB
[0]);
660 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
661 unit
->Combine
.SourceRGB
[1]);
662 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
663 unit
->Combine
.SourceRGB
[2]);
664 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
665 unit
->Combine
.SourceA
[0]);
666 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
667 unit
->Combine
.SourceA
[1]);
668 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
669 unit
->Combine
.SourceA
[2]);
670 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
671 unit
->Combine
.OperandRGB
[0]);
672 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
673 unit
->Combine
.OperandRGB
[1]);
674 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
675 unit
->Combine
.OperandRGB
[2]);
676 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
677 unit
->Combine
.OperandA
[0]);
678 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
679 unit
->Combine
.OperandA
[1]);
680 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
681 unit
->Combine
.OperandA
[2]);
682 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
683 1 << unit
->Combine
.ScaleShiftRGB
);
684 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
685 1 << unit
->Combine
.ScaleShiftA
);
688 /* Restore texture object state */
689 for (i
= 0; i
< NUM_TEXTURE_TARGETS
; i
++) {
691 const struct gl_texture_object
*obj
= NULL
;
692 GLfloat bordColor
[4];
696 target
= GL_TEXTURE_1D
;
697 obj
= &unit
->Saved1D
;
700 target
= GL_TEXTURE_2D
;
701 obj
= &unit
->Saved2D
;
704 target
= GL_TEXTURE_3D
;
705 obj
= &unit
->Saved3D
;
708 if (!ctx
->Extensions
.ARB_texture_cube_map
)
710 target
= GL_TEXTURE_CUBE_MAP_ARB
;
711 obj
= &unit
->SavedCubeMap
;
714 if (!ctx
->Extensions
.NV_texture_rectangle
)
716 target
= GL_TEXTURE_RECTANGLE_NV
;
717 obj
= &unit
->SavedRect
;
720 ; /* silence warnings */
723 _mesa_BindTexture(target
, obj
->Name
);
725 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
726 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
727 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
728 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
730 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
731 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
732 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
733 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
735 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
736 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
737 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
738 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
739 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
740 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
741 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
742 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
745 if (ctx
->Extensions
.SGIX_shadow
) {
746 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
748 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
749 obj
->CompareOperator
);
751 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
752 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
758 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
759 + texAttrib
->CurrentUnit
);
761 /* "un-bump" the texture object reference counts. We did that so they
762 * wouldn't inadvertantly get deleted while they were still referenced
763 * inside the attribute state stack.
765 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
766 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
767 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
768 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
769 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
770 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
--;
776 * This function is kind of long just because we have to call a lot
777 * of device driver functions to update device driver state.
779 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
780 * in order to restore GL state. This isn't terribly efficient but it
781 * ensures that dirty flags and any derived state gets updated correctly.
782 * We could at least check if the value to restore equals the current value
783 * and then skip the Mesa call.
786 _mesa_PopAttrib(void)
788 struct gl_attrib_node
*attr
, *next
;
789 GET_CURRENT_CONTEXT(ctx
);
790 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
792 if (ctx
->AttribStackDepth
== 0) {
793 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
797 ctx
->AttribStackDepth
--;
798 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
802 if (MESA_VERBOSE
& VERBOSE_API
) {
803 _mesa_debug(ctx
, "glPopAttrib %s\n",
804 _mesa_lookup_enum_by_nr(attr
->kind
));
807 switch (attr
->kind
) {
808 case GL_ACCUM_BUFFER_BIT
:
810 const struct gl_accum_attrib
*accum
;
811 accum
= (const struct gl_accum_attrib
*) attr
->data
;
812 _mesa_ClearAccum(accum
->ClearColor
[0],
813 accum
->ClearColor
[1],
814 accum
->ClearColor
[2],
815 accum
->ClearColor
[3]);
818 case GL_COLOR_BUFFER_BIT
:
820 const struct gl_colorbuffer_attrib
*color
;
821 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
822 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
823 _mesa_ClearColor(color
->ClearColor
[0],
824 color
->ClearColor
[1],
825 color
->ClearColor
[2],
826 color
->ClearColor
[3]);
827 _mesa_IndexMask(color
->IndexMask
);
828 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
829 (GLboolean
) (color
->ColorMask
[1] != 0),
830 (GLboolean
) (color
->ColorMask
[2] != 0),
831 (GLboolean
) (color
->ColorMask
[3] != 0));
832 _mesa_DrawBuffer(color
->DrawBuffer
);
833 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
834 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
835 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
836 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
840 /* This special case is because glBlendEquationSeparateEXT
841 * cannot take GL_LOGIC_OP as a parameter.
843 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
844 _mesa_BlendEquation(color
->BlendEquationRGB
);
847 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
848 color
->BlendEquationA
);
850 _mesa_BlendColor(color
->BlendColor
[0],
851 color
->BlendColor
[1],
852 color
->BlendColor
[2],
853 color
->BlendColor
[3]);
854 _mesa_LogicOp(color
->LogicOp
);
855 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
856 color
->ColorLogicOpEnabled
);
857 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
858 color
->IndexLogicOpEnabled
);
859 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
863 FLUSH_CURRENT( ctx
, 0 );
864 MEMCPY( &ctx
->Current
, attr
->data
,
865 sizeof(struct gl_current_attrib
) );
867 case GL_DEPTH_BUFFER_BIT
:
869 const struct gl_depthbuffer_attrib
*depth
;
870 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
871 _mesa_DepthFunc(depth
->Func
);
872 _mesa_ClearDepth(depth
->Clear
);
873 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
874 _mesa_DepthMask(depth
->Mask
);
875 if (ctx
->Extensions
.HP_occlusion_test
)
876 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
877 depth
->OcclusionTest
);
882 const struct gl_enable_attrib
*enable
;
883 enable
= (const struct gl_enable_attrib
*) attr
->data
;
884 pop_enable_group(ctx
, enable
);
885 ctx
->NewState
|= _NEW_ALL
;
889 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
890 ctx
->NewState
|= _NEW_EVAL
;
894 const struct gl_fog_attrib
*fog
;
895 fog
= (const struct gl_fog_attrib
*) attr
->data
;
896 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
897 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
898 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
899 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
900 _mesa_Fogf(GL_FOG_END
, fog
->End
);
901 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
902 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
907 const struct gl_hint_attrib
*hint
;
908 hint
= (const struct gl_hint_attrib
*) attr
->data
;
909 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
910 hint
->PerspectiveCorrection
);
911 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
912 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
913 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
914 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
915 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
916 hint
->ClipVolumeClipping
);
917 if (ctx
->Extensions
.ARB_texture_compression
)
918 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
919 hint
->TextureCompression
);
922 case GL_LIGHTING_BIT
:
925 const struct gl_light_attrib
*light
;
926 light
= (const struct gl_light_attrib
*) attr
->data
;
927 /* lighting enable */
928 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
929 /* per-light state */
931 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
)
932 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
934 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
935 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
936 const struct gl_light
*l
= &light
->Light
[i
];
938 _mesa_set_enable(ctx
, lgt
, l
->Enabled
);
939 _mesa_Lightfv( lgt
, GL_AMBIENT
, l
->Ambient
);
940 _mesa_Lightfv( lgt
, GL_DIFFUSE
, l
->Diffuse
);
941 _mesa_Lightfv( lgt
, GL_SPECULAR
, l
->Specular
);
942 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->inv
, l
->EyePosition
);
943 _mesa_Lightfv( lgt
, GL_POSITION
, tmp
);
944 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->m
, l
->EyeDirection
);
945 _mesa_Lightfv( lgt
, GL_SPOT_DIRECTION
, tmp
);
946 _mesa_Lightfv( lgt
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
947 _mesa_Lightfv( lgt
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
948 _mesa_Lightfv( lgt
, GL_CONSTANT_ATTENUATION
,
949 &l
->ConstantAttenuation
);
950 _mesa_Lightfv( lgt
, GL_LINEAR_ATTENUATION
,
951 &l
->LinearAttenuation
);
952 _mesa_Lightfv( lgt
, GL_QUADRATIC_ATTENUATION
,
953 &l
->QuadraticAttenuation
);
956 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
957 light
->Model
.Ambient
);
958 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
959 (GLfloat
) light
->Model
.LocalViewer
);
960 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
961 (GLfloat
) light
->Model
.TwoSide
);
962 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
963 (GLfloat
) light
->Model
.ColorControl
);
965 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
966 sizeof(struct gl_material
));
968 _mesa_ShadeModel(light
->ShadeModel
);
970 _mesa_ColorMaterial(light
->ColorMaterialFace
,
971 light
->ColorMaterialMode
);
972 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
973 light
->ColorMaterialEnabled
);
978 const struct gl_line_attrib
*line
;
979 line
= (const struct gl_line_attrib
*) attr
->data
;
980 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
981 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
982 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
983 _mesa_LineWidth(line
->Width
);
987 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
989 case GL_PIXEL_MODE_BIT
:
990 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
991 ctx
->NewState
|= _NEW_PIXEL
;
995 const struct gl_point_attrib
*point
;
996 point
= (const struct gl_point_attrib
*) attr
->data
;
997 _mesa_PointSize(point
->Size
);
998 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
999 if (ctx
->Extensions
.EXT_point_parameters
) {
1000 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
1002 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
1004 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
1006 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1009 if (ctx
->Extensions
.NV_point_sprite
1010 || ctx
->Extensions
.ARB_point_sprite
) {
1012 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1013 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1014 (GLint
) point
->CoordReplace
[u
]);
1016 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1017 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1018 ctx
->Point
.SpriteRMode
);
1022 case GL_POLYGON_BIT
:
1024 const struct gl_polygon_attrib
*polygon
;
1025 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1026 _mesa_CullFace(polygon
->CullFaceMode
);
1027 _mesa_FrontFace(polygon
->FrontFace
);
1028 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1029 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1030 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1031 polygon
->OffsetUnits
);
1032 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1033 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1034 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1035 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1036 polygon
->OffsetPoint
);
1037 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1038 polygon
->OffsetLine
);
1039 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1040 polygon
->OffsetFill
);
1043 case GL_POLYGON_STIPPLE_BIT
:
1044 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1045 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1046 if (ctx
->Driver
.PolygonStipple
)
1047 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1049 case GL_SCISSOR_BIT
:
1051 const struct gl_scissor_attrib
*scissor
;
1052 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1053 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1054 scissor
->Width
, scissor
->Height
);
1055 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1058 case GL_STENCIL_BUFFER_BIT
:
1060 const GLint face
= 0; /* XXX stencil two side */
1061 const struct gl_stencil_attrib
*stencil
;
1062 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1063 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1064 _mesa_ClearStencil(stencil
->Clear
);
1065 _mesa_StencilFunc(stencil
->Function
[face
], stencil
->Ref
[face
],
1066 stencil
->ValueMask
[face
]);
1067 _mesa_StencilMask(stencil
->WriteMask
[face
]);
1068 _mesa_StencilOp(stencil
->FailFunc
[face
],
1069 stencil
->ZFailFunc
[face
],
1070 stencil
->ZPassFunc
[face
]);
1073 case GL_TRANSFORM_BIT
:
1076 const struct gl_transform_attrib
*xform
;
1077 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1078 _mesa_MatrixMode(xform
->MatrixMode
);
1080 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
1081 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1083 /* restore clip planes */
1084 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1085 const GLuint mask
= 1 << 1;
1086 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1087 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1088 if (xform
->ClipPlanesEnabled
& mask
) {
1089 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1092 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1094 if (ctx
->Driver
.ClipPlane
)
1095 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1098 /* normalize/rescale */
1099 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1100 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1101 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1102 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1103 ctx
->Transform
.RescaleNormals
);
1106 case GL_TEXTURE_BIT
:
1107 /* Take care of texture object reference counters */
1109 const struct gl_texture_attrib
*texture
;
1110 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1111 pop_texture_group(ctx
, texture
);
1112 ctx
->NewState
|= _NEW_TEXTURE
;
1115 case GL_VIEWPORT_BIT
:
1117 const struct gl_viewport_attrib
*vp
;
1118 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1119 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1120 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1123 case GL_MULTISAMPLE_BIT_ARB
:
1125 const struct gl_multisample_attrib
*ms
;
1126 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1127 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1128 ms
->SampleCoverageInvert
);
1133 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1146 * Helper for incrementing/decrementing vertex buffer object reference
1147 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1150 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1153 array
->Vertex
.BufferObj
->RefCount
+= step
;
1154 array
->Normal
.BufferObj
->RefCount
+= step
;
1155 array
->Color
.BufferObj
->RefCount
+= step
;
1156 array
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1157 array
->FogCoord
.BufferObj
->RefCount
+= step
;
1158 array
->Index
.BufferObj
->RefCount
+= step
;
1159 array
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1160 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1161 array
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1162 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1163 array
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1165 array
->ArrayBufferObj
->RefCount
+= step
;
1166 array
->ElementArrayBufferObj
->RefCount
+= step
;
1170 #define GL_CLIENT_PACK_BIT (1<<20)
1171 #define GL_CLIENT_UNPACK_BIT (1<<21)
1175 _mesa_PushClientAttrib(GLbitfield mask
)
1177 struct gl_attrib_node
*newnode
;
1178 struct gl_attrib_node
*head
;
1180 GET_CURRENT_CONTEXT(ctx
);
1181 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1183 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1184 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1188 /* Build linked list of attribute nodes which save all attribute */
1189 /* groups specified by the mask. */
1192 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1193 struct gl_pixelstore_attrib
*attr
;
1194 /* packing attribs */
1195 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1196 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1197 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1198 newnode
->data
= attr
;
1199 newnode
->next
= head
;
1201 /* unpacking attribs */
1202 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1203 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1204 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1205 newnode
->data
= attr
;
1206 newnode
->next
= head
;
1209 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1210 struct gl_array_attrib
*attr
;
1211 attr
= MALLOC_STRUCT( gl_array_attrib
);
1212 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1213 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1214 newnode
->data
= attr
;
1215 newnode
->next
= head
;
1217 /* bump reference counts on buffer objects */
1218 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1221 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1222 ctx
->ClientAttribStackDepth
++;
1229 _mesa_PopClientAttrib(void)
1231 struct gl_attrib_node
*attr
, *next
;
1233 GET_CURRENT_CONTEXT(ctx
);
1234 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1236 if (ctx
->ClientAttribStackDepth
== 0) {
1237 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1241 ctx
->ClientAttribStackDepth
--;
1242 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1245 switch (attr
->kind
) {
1246 case GL_CLIENT_PACK_BIT
:
1247 MEMCPY( &ctx
->Pack
, attr
->data
,
1248 sizeof(struct gl_pixelstore_attrib
) );
1249 ctx
->NewState
|= _NEW_PACKUNPACK
;
1251 case GL_CLIENT_UNPACK_BIT
:
1252 MEMCPY( &ctx
->Unpack
, attr
->data
,
1253 sizeof(struct gl_pixelstore_attrib
) );
1254 ctx
->NewState
|= _NEW_PACKUNPACK
;
1256 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1257 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1258 MEMCPY( &ctx
->Array
, attr
->data
,
1259 sizeof(struct gl_array_attrib
) );
1260 /* decrement reference counts on buffer objects */
1261 ctx
->NewState
|= _NEW_ARRAY
;
1264 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1276 void _mesa_init_attrib( GLcontext
*ctx
)
1278 /* Renderer and client attribute stacks */
1279 ctx
->AttribStackDepth
= 0;
1280 ctx
->ClientAttribStackDepth
= 0;