1 /* $Id: attrib.c,v 1.75 2002/10/24 23:57:19 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
141 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
142 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
143 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
144 attr
->DepthTest
= ctx
->Depth
.Test
;
145 attr
->Dither
= ctx
->Color
.DitherFlag
;
146 attr
->Fog
= ctx
->Fog
.Enabled
;
147 for (i
=0;i
<MAX_LIGHTS
;i
++) {
148 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
150 attr
->Lighting
= ctx
->Light
.Enabled
;
151 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
152 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
153 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
154 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
155 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
156 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
157 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
158 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
159 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
160 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
161 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
162 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
163 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
164 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
165 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
166 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
167 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
168 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
169 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
170 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
171 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
172 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
173 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
174 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
175 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
176 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
177 attr
->Normalize
= ctx
->Transform
.Normalize
;
178 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
179 attr
->PixelTexture
= ctx
->Pixel
.PixelTextureEnabled
;
180 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
181 attr
->PointSprite
= ctx
->Point
.PointSprite
;
182 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
183 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
184 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
185 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
186 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
187 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
188 attr
->Scissor
= ctx
->Scissor
.Enabled
;
189 attr
->Stencil
= ctx
->Stencil
.Enabled
;
190 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
191 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
192 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
193 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
194 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
195 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
196 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
197 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
199 /* GL_NV_vertex_program */
200 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
201 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
202 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
203 newnode
= new_attrib_node( GL_ENABLE_BIT
);
204 newnode
->data
= attr
;
205 newnode
->next
= head
;
209 if (mask
& GL_EVAL_BIT
) {
210 struct gl_eval_attrib
*attr
;
211 attr
= MALLOC_STRUCT( gl_eval_attrib
);
212 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
213 newnode
= new_attrib_node( GL_EVAL_BIT
);
214 newnode
->data
= attr
;
215 newnode
->next
= head
;
219 if (mask
& GL_FOG_BIT
) {
220 struct gl_fog_attrib
*attr
;
221 attr
= MALLOC_STRUCT( gl_fog_attrib
);
222 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
223 newnode
= new_attrib_node( GL_FOG_BIT
);
224 newnode
->data
= attr
;
225 newnode
->next
= head
;
229 if (mask
& GL_HINT_BIT
) {
230 struct gl_hint_attrib
*attr
;
231 attr
= MALLOC_STRUCT( gl_hint_attrib
);
232 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
233 newnode
= new_attrib_node( GL_HINT_BIT
);
234 newnode
->data
= attr
;
235 newnode
->next
= head
;
239 if (mask
& GL_LIGHTING_BIT
) {
240 struct gl_light_attrib
*attr
;
241 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
242 attr
= MALLOC_STRUCT( gl_light_attrib
);
243 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
244 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
245 newnode
->data
= attr
;
246 newnode
->next
= head
;
250 if (mask
& GL_LINE_BIT
) {
251 struct gl_line_attrib
*attr
;
252 attr
= MALLOC_STRUCT( gl_line_attrib
);
253 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
254 newnode
= new_attrib_node( GL_LINE_BIT
);
255 newnode
->data
= attr
;
256 newnode
->next
= head
;
260 if (mask
& GL_LIST_BIT
) {
261 struct gl_list_attrib
*attr
;
262 attr
= MALLOC_STRUCT( gl_list_attrib
);
263 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
264 newnode
= new_attrib_node( GL_LIST_BIT
);
265 newnode
->data
= attr
;
266 newnode
->next
= head
;
270 if (mask
& GL_PIXEL_MODE_BIT
) {
271 struct gl_pixel_attrib
*attr
;
272 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
273 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
274 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
275 newnode
->data
= attr
;
276 newnode
->next
= head
;
280 if (mask
& GL_POINT_BIT
) {
281 struct gl_point_attrib
*attr
;
282 attr
= MALLOC_STRUCT( gl_point_attrib
);
283 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
284 newnode
= new_attrib_node( GL_POINT_BIT
);
285 newnode
->data
= attr
;
286 newnode
->next
= head
;
290 if (mask
& GL_POLYGON_BIT
) {
291 struct gl_polygon_attrib
*attr
;
292 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
293 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
294 newnode
= new_attrib_node( GL_POLYGON_BIT
);
295 newnode
->data
= attr
;
296 newnode
->next
= head
;
300 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
302 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
303 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
304 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
305 newnode
->data
= stipple
;
306 newnode
->next
= head
;
310 if (mask
& GL_SCISSOR_BIT
) {
311 struct gl_scissor_attrib
*attr
;
312 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
313 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
314 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
315 newnode
->data
= attr
;
316 newnode
->next
= head
;
320 if (mask
& GL_STENCIL_BUFFER_BIT
) {
321 struct gl_stencil_attrib
*attr
;
322 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
323 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
324 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
325 newnode
->data
= attr
;
326 newnode
->next
= head
;
330 if (mask
& GL_TEXTURE_BIT
) {
331 struct gl_texture_attrib
*attr
;
333 /* Bump the texture object reference counts so that they don't
334 * inadvertantly get deleted.
336 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
337 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
++;
338 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
++;
339 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
++;
340 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
++;
341 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
++;
343 attr
= MALLOC_STRUCT( gl_texture_attrib
);
344 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
345 /* copy state of the currently bound texture objects */
346 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
347 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved1D
,
348 attr
->Unit
[u
].Current1D
);
349 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved2D
,
350 attr
->Unit
[u
].Current2D
);
351 _mesa_copy_texture_object(&attr
->Unit
[u
].Saved3D
,
352 attr
->Unit
[u
].Current3D
);
353 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedCubeMap
,
354 attr
->Unit
[u
].CurrentCubeMap
);
355 _mesa_copy_texture_object(&attr
->Unit
[u
].SavedRect
,
356 attr
->Unit
[u
].CurrentRect
);
358 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
359 newnode
->data
= attr
;
360 newnode
->next
= head
;
364 if (mask
& GL_TRANSFORM_BIT
) {
365 struct gl_transform_attrib
*attr
;
366 attr
= MALLOC_STRUCT( gl_transform_attrib
);
367 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
368 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
369 newnode
->data
= attr
;
370 newnode
->next
= head
;
374 if (mask
& GL_VIEWPORT_BIT
) {
375 struct gl_viewport_attrib
*attr
;
376 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
377 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
378 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
379 newnode
->data
= attr
;
380 newnode
->next
= head
;
384 /* GL_ARB_multisample */
385 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
386 struct gl_multisample_attrib
*attr
;
387 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
388 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
389 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
390 newnode
->data
= attr
;
391 newnode
->next
= head
;
395 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
396 ctx
->AttribStackDepth
++;
402 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
406 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
407 if ((VALUE) != (NEWVALUE)) { \
408 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
411 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
412 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
414 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
415 const GLuint mask
= 1 << i
;
416 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
417 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
418 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
421 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
423 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
424 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
425 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
426 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
428 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
430 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
432 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
433 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
434 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
435 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
437 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
439 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
442 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
443 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
444 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
445 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
446 GL_MAP1_TEXTURE_COORD_1
);
447 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
448 GL_MAP1_TEXTURE_COORD_2
);
449 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
450 GL_MAP1_TEXTURE_COORD_3
);
451 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
452 GL_MAP1_TEXTURE_COORD_4
);
453 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
455 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
457 for (i
= 0; i
< 16; i
++) {
458 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
459 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
462 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
463 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
464 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
465 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
466 GL_MAP2_TEXTURE_COORD_1
);
467 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
468 GL_MAP2_TEXTURE_COORD_2
);
469 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
470 GL_MAP2_TEXTURE_COORD_3
);
471 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
472 GL_MAP2_TEXTURE_COORD_4
);
473 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
475 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
477 for (i
= 0; i
< 16; i
++) {
478 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
479 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
482 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
483 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
484 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
485 GL_RESCALE_NORMAL_EXT
);
486 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
487 enable
->RasterPositionUnclipped
,
488 GL_RASTER_POSITION_UNCLIPPED_IBM
);
489 TEST_AND_UPDATE(ctx
->Pixel
.PixelTextureEnabled
, enable
->PixelTexture
,
491 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
493 if (ctx
->Extensions
.NV_point_sprite
) {
494 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
497 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
498 GL_POLYGON_OFFSET_POINT
);
499 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
500 GL_POLYGON_OFFSET_LINE
);
501 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
502 GL_POLYGON_OFFSET_FILL
);
503 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
505 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
507 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
508 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
509 /* XXX two-sided stencil */
510 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
512 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
513 enable
->SampleAlphaToCoverage
,
514 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
515 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
516 enable
->SampleAlphaToOne
,
517 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
518 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
519 enable
->SampleCoverage
,
520 GL_SAMPLE_COVERAGE_ARB
);
521 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
522 enable
->SampleCoverageInvert
,
523 GL_SAMPLE_COVERAGE_INVERT_ARB
);
524 /* GL_NV_vertex_program */
525 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
526 enable
->VertexProgram
,
527 GL_VERTEX_PROGRAM_NV
);
528 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
529 enable
->VertexProgramPointSize
,
530 GL_VERTEX_PROGRAM_POINT_SIZE_NV
);
531 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
532 enable
->VertexProgramTwoSide
,
533 GL_VERTEX_PROGRAM_TWO_SIDE_NV
);
535 #undef TEST_AND_UPDATE
537 /* texture unit enables */
538 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
539 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
540 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
541 if (ctx
->Driver
.Enable
) {
542 if (ctx
->Driver
.ActiveTexture
) {
543 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
545 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
546 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
547 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
548 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
549 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
550 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
551 if (ctx
->Extensions
.ARB_texture_cube_map
)
552 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
553 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
554 if (ctx
->Extensions
.NV_texture_rectangle
)
555 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
556 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
560 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
561 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
562 if (ctx
->Driver
.Enable
) {
563 if (ctx
->Driver
.ActiveTexture
) {
564 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
566 if (enable
->TexGen
[i
] & S_BIT
)
567 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
569 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
570 if (enable
->TexGen
[i
] & T_BIT
)
571 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
573 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
574 if (enable
->TexGen
[i
] & R_BIT
)
575 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
577 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
578 if (enable
->TexGen
[i
] & Q_BIT
)
579 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
581 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
586 if (ctx
->Driver
.ActiveTexture
) {
587 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
593 pop_texture_group(GLcontext
*ctx
, const struct gl_texture_attrib
*texAttrib
)
597 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
598 const struct gl_texture_unit
*unit
= &texAttrib
->Unit
[u
];
601 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
602 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
603 (GLboolean
) (unit
->Enabled
& TEXTURE_1D_BIT
? GL_TRUE
: GL_FALSE
));
604 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
605 (GLboolean
) (unit
->Enabled
& TEXTURE_2D_BIT
? GL_TRUE
: GL_FALSE
));
606 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
607 (GLboolean
) (unit
->Enabled
& TEXTURE_3D_BIT
? GL_TRUE
: GL_FALSE
));
608 if (ctx
->Extensions
.ARB_texture_cube_map
) {
609 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
610 (GLboolean
) (unit
->Enabled
& TEXTURE_CUBE_BIT
? GL_TRUE
: GL_FALSE
));
612 if (ctx
->Extensions
.NV_texture_rectangle
) {
613 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
614 (GLboolean
) (unit
->Enabled
& TEXTURE_RECT_BIT
? GL_TRUE
: GL_FALSE
));
616 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
617 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
618 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
619 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
620 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
621 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
622 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
623 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
624 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
625 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
626 _mesa_TexGenfv(GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
627 _mesa_TexGenfv(GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
628 _mesa_TexGenfv(GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
629 _mesa_TexGenfv(GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
630 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
631 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
632 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
634 if (ctx
->Extensions
.EXT_texture_env_combine
||
635 ctx
->Extensions
.ARB_texture_env_combine
) {
636 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB_EXT
,
637 unit
->CombineModeRGB
);
638 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA_EXT
,
640 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB_EXT
,
641 unit
->CombineSourceRGB
[0]);
642 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB_EXT
,
643 unit
->CombineSourceRGB
[1]);
644 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB_EXT
,
645 unit
->CombineSourceRGB
[2]);
646 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA_EXT
,
647 unit
->CombineSourceA
[0]);
648 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA_EXT
,
649 unit
->CombineSourceA
[1]);
650 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA_EXT
,
651 unit
->CombineSourceA
[2]);
652 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB_EXT
,
653 unit
->CombineOperandRGB
[0]);
654 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB_EXT
,
655 unit
->CombineOperandRGB
[1]);
656 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB_EXT
,
657 unit
->CombineOperandRGB
[2]);
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA_EXT
,
659 unit
->CombineOperandA
[0]);
660 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA_EXT
,
661 unit
->CombineOperandA
[1]);
662 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA_EXT
,
663 unit
->CombineOperandA
[2]);
664 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE_EXT
,
665 1 << unit
->CombineScaleShiftRGB
);
666 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
667 1 << unit
->CombineScaleShiftA
);
670 /* Restore texture object state */
671 for (i
= 0; i
< NUM_TEXTURE_TARGETS
; i
++) {
673 const struct gl_texture_object
*obj
= NULL
;
674 GLfloat bordColor
[4];
678 target
= GL_TEXTURE_1D
;
679 obj
= &unit
->Saved1D
;
682 target
= GL_TEXTURE_2D
;
683 obj
= &unit
->Saved2D
;
686 target
= GL_TEXTURE_3D
;
687 obj
= &unit
->Saved3D
;
690 if (!ctx
->Extensions
.ARB_texture_cube_map
)
692 target
= GL_TEXTURE_CUBE_MAP_ARB
;
693 obj
= &unit
->SavedCubeMap
;
696 if (!ctx
->Extensions
.NV_texture_rectangle
)
698 target
= GL_TEXTURE_RECTANGLE_NV
;
699 obj
= &unit
->SavedRect
;
702 ; /* silence warnings */
705 _mesa_BindTexture(target
, obj
->Name
);
707 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
708 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
709 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
710 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
712 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
713 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
714 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
715 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
716 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
717 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
718 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
719 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
720 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
721 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
722 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
723 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
724 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
727 if (ctx
->Extensions
.SGIX_shadow
) {
728 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
730 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
731 obj
->CompareOperator
);
733 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
734 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
740 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
741 + texAttrib
->CurrentUnit
);
743 /* "un-bump" the texture object reference counts. We did that so they
744 * wouldn't inadvertantly get deleted while they were still referenced
745 * inside the attribute state stack.
747 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
748 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
749 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
750 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
751 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
752 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
--;
758 * This function is kind of long just because we have to call a lot
759 * of device driver functions to update device driver state.
761 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
762 * in order to restore GL state. This isn't terribly efficient but it
763 * ensures that dirty flags and any derived state gets updated correctly.
764 * We could at least check if the value to restore equals the current value
765 * and then skip the Mesa call.
768 _mesa_PopAttrib(void)
770 struct gl_attrib_node
*attr
, *next
;
771 GET_CURRENT_CONTEXT(ctx
);
772 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
774 if (ctx
->AttribStackDepth
== 0) {
775 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
779 ctx
->AttribStackDepth
--;
780 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
784 if (MESA_VERBOSE
& VERBOSE_API
) {
785 _mesa_debug(ctx
, "glPopAttrib %s\n",
786 _mesa_lookup_enum_by_nr(attr
->kind
));
789 switch (attr
->kind
) {
790 case GL_ACCUM_BUFFER_BIT
:
792 const struct gl_accum_attrib
*accum
;
793 accum
= (const struct gl_accum_attrib
*) attr
->data
;
794 _mesa_ClearAccum(accum
->ClearColor
[0],
795 accum
->ClearColor
[1],
796 accum
->ClearColor
[2],
797 accum
->ClearColor
[3]);
800 case GL_COLOR_BUFFER_BIT
:
802 const struct gl_colorbuffer_attrib
*color
;
803 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
804 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
805 _mesa_ClearColor(color
->ClearColor
[0],
806 color
->ClearColor
[1],
807 color
->ClearColor
[2],
808 color
->ClearColor
[3]);
809 _mesa_IndexMask(color
->IndexMask
);
810 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
811 (GLboolean
) (color
->ColorMask
[1] != 0),
812 (GLboolean
) (color
->ColorMask
[2] != 0),
813 (GLboolean
) (color
->ColorMask
[3] != 0));
814 _mesa_DrawBuffer(color
->DrawBuffer
);
815 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
816 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
817 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
818 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
822 _mesa_BlendEquation(color
->BlendEquation
);
823 _mesa_BlendColor(color
->BlendColor
[0],
824 color
->BlendColor
[1],
825 color
->BlendColor
[2],
826 color
->BlendColor
[3]);
827 _mesa_LogicOp(color
->LogicOp
);
828 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
829 color
->ColorLogicOpEnabled
);
830 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
831 color
->IndexLogicOpEnabled
);
832 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
836 FLUSH_CURRENT( ctx
, 0 );
837 MEMCPY( &ctx
->Current
, attr
->data
,
838 sizeof(struct gl_current_attrib
) );
840 case GL_DEPTH_BUFFER_BIT
:
842 const struct gl_depthbuffer_attrib
*depth
;
843 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
844 _mesa_DepthFunc(depth
->Func
);
845 _mesa_ClearDepth(depth
->Clear
);
846 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
847 _mesa_DepthMask(depth
->Mask
);
848 if (ctx
->Extensions
.HP_occlusion_test
)
849 _mesa_set_enable(ctx
, GL_OCCLUSION_TEST_HP
,
850 depth
->OcclusionTest
);
855 const struct gl_enable_attrib
*enable
;
856 enable
= (const struct gl_enable_attrib
*) attr
->data
;
857 pop_enable_group(ctx
, enable
);
858 ctx
->NewState
|= _NEW_ALL
;
862 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
863 ctx
->NewState
|= _NEW_EVAL
;
867 const struct gl_fog_attrib
*fog
;
868 fog
= (const struct gl_fog_attrib
*) attr
->data
;
869 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
870 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
871 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
872 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
873 _mesa_Fogf(GL_FOG_END
, fog
->End
);
874 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
875 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
880 const struct gl_hint_attrib
*hint
;
881 hint
= (const struct gl_hint_attrib
*) attr
->data
;
882 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
883 hint
->PerspectiveCorrection
);
884 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
885 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
886 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
887 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
888 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
889 hint
->ClipVolumeClipping
);
890 if (ctx
->Extensions
.ARB_texture_compression
)
891 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
892 hint
->TextureCompression
);
895 case GL_LIGHTING_BIT
:
898 const struct gl_light_attrib
*light
;
899 light
= (const struct gl_light_attrib
*) attr
->data
;
900 /* lighting enable */
901 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
902 /* per-light state */
904 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
)
905 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
907 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
908 GLenum lgt
= (GLenum
) (GL_LIGHT0
+ i
);
909 const struct gl_light
*l
= &light
->Light
[i
];
911 _mesa_set_enable(ctx
, lgt
, l
->Enabled
);
912 _mesa_Lightfv( lgt
, GL_AMBIENT
, l
->Ambient
);
913 _mesa_Lightfv( lgt
, GL_DIFFUSE
, l
->Diffuse
);
914 _mesa_Lightfv( lgt
, GL_SPECULAR
, l
->Specular
);
915 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->inv
, l
->EyePosition
);
916 _mesa_Lightfv( lgt
, GL_POSITION
, tmp
);
917 TRANSFORM_POINT( tmp
, ctx
->ModelviewMatrixStack
.Top
->m
, l
->EyeDirection
);
918 _mesa_Lightfv( lgt
, GL_SPOT_DIRECTION
, tmp
);
919 _mesa_Lightfv( lgt
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
920 _mesa_Lightfv( lgt
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
921 _mesa_Lightfv( lgt
, GL_CONSTANT_ATTENUATION
,
922 &l
->ConstantAttenuation
);
923 _mesa_Lightfv( lgt
, GL_LINEAR_ATTENUATION
,
924 &l
->LinearAttenuation
);
925 _mesa_Lightfv( lgt
, GL_QUADRATIC_ATTENUATION
,
926 &l
->QuadraticAttenuation
);
929 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
930 light
->Model
.Ambient
);
931 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
932 (GLfloat
) light
->Model
.LocalViewer
);
933 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
934 (GLfloat
) light
->Model
.TwoSide
);
935 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
936 (GLfloat
) light
->Model
.ColorControl
);
938 MEMCPY(ctx
->Light
.Material
, light
->Material
,
939 2 * sizeof(struct gl_material
));
941 _mesa_ShadeModel(light
->ShadeModel
);
943 _mesa_ColorMaterial(light
->ColorMaterialFace
,
944 light
->ColorMaterialMode
);
945 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
946 light
->ColorMaterialEnabled
);
951 const struct gl_line_attrib
*line
;
952 line
= (const struct gl_line_attrib
*) attr
->data
;
953 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
954 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
955 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
956 _mesa_LineWidth(line
->Width
);
960 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
962 case GL_PIXEL_MODE_BIT
:
963 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
964 ctx
->NewState
|= _NEW_PIXEL
;
968 const struct gl_point_attrib
*point
;
969 point
= (const struct gl_point_attrib
*) attr
->data
;
970 _mesa_PointSize(point
->Size
);
971 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
972 if (ctx
->Extensions
.EXT_point_parameters
) {
973 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
975 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
977 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
979 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
982 if (ctx
->Extensions
.NV_point_sprite
) {
984 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
985 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
986 (GLint
) point
->CoordReplace
[u
]);
988 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
989 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
990 ctx
->Point
.SpriteRMode
);
996 const struct gl_polygon_attrib
*polygon
;
997 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
998 _mesa_CullFace(polygon
->CullFaceMode
);
999 _mesa_FrontFace(polygon
->FrontFace
);
1000 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1001 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1002 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1003 polygon
->OffsetUnits
);
1004 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1005 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1006 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1007 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1008 polygon
->OffsetPoint
);
1009 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1010 polygon
->OffsetLine
);
1011 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1012 polygon
->OffsetFill
);
1015 case GL_POLYGON_STIPPLE_BIT
:
1016 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1017 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1018 if (ctx
->Driver
.PolygonStipple
)
1019 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1021 case GL_SCISSOR_BIT
:
1023 const struct gl_scissor_attrib
*scissor
;
1024 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1025 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1026 scissor
->Width
, scissor
->Height
);
1027 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1030 case GL_STENCIL_BUFFER_BIT
:
1032 const GLint face
= 0; /* XXX stencil two side */
1033 const struct gl_stencil_attrib
*stencil
;
1034 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1035 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1036 _mesa_ClearStencil(stencil
->Clear
);
1037 _mesa_StencilFunc(stencil
->Function
[face
], stencil
->Ref
[face
],
1038 stencil
->ValueMask
[face
]);
1039 _mesa_StencilMask(stencil
->WriteMask
[face
]);
1040 _mesa_StencilOp(stencil
->FailFunc
[face
],
1041 stencil
->ZFailFunc
[face
],
1042 stencil
->ZPassFunc
[face
]);
1045 case GL_TRANSFORM_BIT
:
1048 const struct gl_transform_attrib
*xform
;
1049 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1050 _mesa_MatrixMode(xform
->MatrixMode
);
1052 if (ctx
->ProjectionMatrixStack
.Top
->flags
& MAT_DIRTY
)
1053 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1055 /* restore clip planes */
1056 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1057 const GLuint mask
= 1 << 1;
1058 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1059 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1060 if (xform
->ClipPlanesEnabled
& mask
) {
1061 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1064 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1066 if (ctx
->Driver
.ClipPlane
)
1067 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1070 /* normalize/rescale */
1071 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1072 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1073 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1074 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1075 ctx
->Transform
.RescaleNormals
);
1078 case GL_TEXTURE_BIT
:
1079 /* Take care of texture object reference counters */
1081 const struct gl_texture_attrib
*texture
;
1082 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1083 pop_texture_group(ctx
, texture
);
1084 ctx
->NewState
|= _NEW_TEXTURE
;
1087 case GL_VIEWPORT_BIT
:
1089 const struct gl_viewport_attrib
*vp
;
1090 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1091 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1092 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1095 case GL_MULTISAMPLE_BIT_ARB
:
1097 const struct gl_multisample_attrib
*ms
;
1098 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1099 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1100 ms
->SampleCoverageInvert
);
1105 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1117 #define GL_CLIENT_PACK_BIT (1<<20)
1118 #define GL_CLIENT_UNPACK_BIT (1<<21)
1122 _mesa_PushClientAttrib(GLbitfield mask
)
1124 struct gl_attrib_node
*newnode
;
1125 struct gl_attrib_node
*head
;
1127 GET_CURRENT_CONTEXT(ctx
);
1128 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1130 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1131 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1135 /* Build linked list of attribute nodes which save all attribute */
1136 /* groups specified by the mask. */
1139 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1140 struct gl_pixelstore_attrib
*attr
;
1141 /* packing attribs */
1142 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1143 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1144 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1145 newnode
->data
= attr
;
1146 newnode
->next
= head
;
1148 /* unpacking attribs */
1149 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1150 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1151 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1152 newnode
->data
= attr
;
1153 newnode
->next
= head
;
1156 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1157 struct gl_array_attrib
*attr
;
1158 attr
= MALLOC_STRUCT( gl_array_attrib
);
1159 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1160 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1161 newnode
->data
= attr
;
1162 newnode
->next
= head
;
1166 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1167 ctx
->ClientAttribStackDepth
++;
1174 _mesa_PopClientAttrib(void)
1176 struct gl_attrib_node
*attr
, *next
;
1178 GET_CURRENT_CONTEXT(ctx
);
1179 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1181 if (ctx
->ClientAttribStackDepth
== 0) {
1182 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1186 ctx
->ClientAttribStackDepth
--;
1187 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1190 switch (attr
->kind
) {
1191 case GL_CLIENT_PACK_BIT
:
1192 MEMCPY( &ctx
->Pack
, attr
->data
,
1193 sizeof(struct gl_pixelstore_attrib
) );
1194 ctx
->NewState
|= _NEW_PACKUNPACK
;
1196 case GL_CLIENT_UNPACK_BIT
:
1197 MEMCPY( &ctx
->Unpack
, attr
->data
,
1198 sizeof(struct gl_pixelstore_attrib
) );
1199 ctx
->NewState
|= _NEW_PACKUNPACK
;
1201 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1202 MEMCPY( &ctx
->Array
, attr
->data
,
1203 sizeof(struct gl_array_attrib
) );
1204 ctx
->NewState
|= _NEW_ARRAY
;
1207 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");