2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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.
31 #include "bufferobj.h"
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
< ctx
->Const
.MaxLights
; 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
->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
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
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
->Point
.SmoothFlag
, enable
->PointSmooth
,
503 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
504 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
507 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
508 GL_POLYGON_OFFSET_POINT
);
509 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
510 GL_POLYGON_OFFSET_LINE
);
511 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
512 GL_POLYGON_OFFSET_FILL
);
513 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
515 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
517 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
518 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
519 if (ctx
->Extensions
.EXT_stencil_two_side
) {
520 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
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 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
619 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
620 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
621 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
622 (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 (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 (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 /* Eye plane done differently to avoid re-transformation */
647 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
648 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
649 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
650 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
651 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
652 if (ctx
->Driver
.TexGen
) {
653 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
654 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
655 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
656 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
659 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
660 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
661 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
662 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
663 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
664 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
665 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
666 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
667 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
668 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
669 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
671 if (ctx
->Extensions
.EXT_texture_env_combine
||
672 ctx
->Extensions
.ARB_texture_env_combine
) {
673 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
674 unit
->Combine
.ModeRGB
);
675 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
676 unit
->Combine
.ModeA
);
677 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
678 unit
->Combine
.SourceRGB
[0]);
679 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
680 unit
->Combine
.SourceRGB
[1]);
681 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
682 unit
->Combine
.SourceRGB
[2]);
683 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
684 unit
->Combine
.SourceA
[0]);
685 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
686 unit
->Combine
.SourceA
[1]);
687 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
688 unit
->Combine
.SourceA
[2]);
689 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
690 unit
->Combine
.OperandRGB
[0]);
691 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
692 unit
->Combine
.OperandRGB
[1]);
693 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
694 unit
->Combine
.OperandRGB
[2]);
695 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
696 unit
->Combine
.OperandA
[0]);
697 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
698 unit
->Combine
.OperandA
[1]);
699 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
700 unit
->Combine
.OperandA
[2]);
701 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
702 1 << unit
->Combine
.ScaleShiftRGB
);
703 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
704 1 << unit
->Combine
.ScaleShiftA
);
707 /* Restore texture object state */
708 for (i
= 0; i
< NUM_TEXTURE_TARGETS
; i
++) {
710 const struct gl_texture_object
*obj
= NULL
;
711 GLfloat bordColor
[4];
715 target
= GL_TEXTURE_1D
;
716 obj
= &unit
->Saved1D
;
719 target
= GL_TEXTURE_2D
;
720 obj
= &unit
->Saved2D
;
723 target
= GL_TEXTURE_3D
;
724 obj
= &unit
->Saved3D
;
727 if (!ctx
->Extensions
.ARB_texture_cube_map
)
729 target
= GL_TEXTURE_CUBE_MAP_ARB
;
730 obj
= &unit
->SavedCubeMap
;
733 if (!ctx
->Extensions
.NV_texture_rectangle
)
735 target
= GL_TEXTURE_RECTANGLE_NV
;
736 obj
= &unit
->SavedRect
;
739 ; /* silence warnings */
742 _mesa_BindTexture(target
, obj
->Name
);
744 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
745 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
746 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
747 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
749 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
750 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
751 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
752 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
753 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
754 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
755 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
756 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
757 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
758 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
759 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
760 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
761 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
764 if (ctx
->Extensions
.SGIX_shadow
) {
765 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
767 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
768 obj
->CompareOperator
);
770 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
771 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
777 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
778 + texAttrib
->CurrentUnit
);
780 /* "un-bump" the texture object reference counts. We did that so they
781 * wouldn't inadvertantly get deleted while they were still referenced
782 * inside the attribute state stack.
784 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
785 ctx
->Texture
.Unit
[u
].Current1D
->RefCount
--;
786 ctx
->Texture
.Unit
[u
].Current2D
->RefCount
--;
787 ctx
->Texture
.Unit
[u
].Current3D
->RefCount
--;
788 ctx
->Texture
.Unit
[u
].CurrentCubeMap
->RefCount
--;
789 ctx
->Texture
.Unit
[u
].CurrentRect
->RefCount
--;
795 * This function is kind of long just because we have to call a lot
796 * of device driver functions to update device driver state.
798 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
799 * in order to restore GL state. This isn't terribly efficient but it
800 * ensures that dirty flags and any derived state gets updated correctly.
801 * We could at least check if the value to restore equals the current value
802 * and then skip the Mesa call.
805 _mesa_PopAttrib(void)
807 struct gl_attrib_node
*attr
, *next
;
808 GET_CURRENT_CONTEXT(ctx
);
809 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
811 if (ctx
->AttribStackDepth
== 0) {
812 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
816 ctx
->AttribStackDepth
--;
817 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
821 if (MESA_VERBOSE
& VERBOSE_API
) {
822 _mesa_debug(ctx
, "glPopAttrib %s\n",
823 _mesa_lookup_enum_by_nr(attr
->kind
));
826 switch (attr
->kind
) {
827 case GL_ACCUM_BUFFER_BIT
:
829 const struct gl_accum_attrib
*accum
;
830 accum
= (const struct gl_accum_attrib
*) attr
->data
;
831 _mesa_ClearAccum(accum
->ClearColor
[0],
832 accum
->ClearColor
[1],
833 accum
->ClearColor
[2],
834 accum
->ClearColor
[3]);
837 case GL_COLOR_BUFFER_BIT
:
839 const struct gl_colorbuffer_attrib
*color
;
840 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
841 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
842 _mesa_ClearColor(color
->ClearColor
[0],
843 color
->ClearColor
[1],
844 color
->ClearColor
[2],
845 color
->ClearColor
[3]);
846 _mesa_IndexMask(color
->IndexMask
);
847 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
848 (GLboolean
) (color
->ColorMask
[1] != 0),
849 (GLboolean
) (color
->ColorMask
[2] != 0),
850 (GLboolean
) (color
->ColorMask
[3] != 0));
851 _mesa_drawbuffers(ctx
, ctx
->Const
.MaxDrawBuffers
,
852 color
->DrawBuffer
, NULL
);
853 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
854 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
855 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
856 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
860 /* This special case is because glBlendEquationSeparateEXT
861 * cannot take GL_LOGIC_OP as a parameter.
863 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
864 _mesa_BlendEquation(color
->BlendEquationRGB
);
867 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
868 color
->BlendEquationA
);
870 _mesa_BlendColor(color
->BlendColor
[0],
871 color
->BlendColor
[1],
872 color
->BlendColor
[2],
873 color
->BlendColor
[3]);
874 _mesa_LogicOp(color
->LogicOp
);
875 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
876 color
->ColorLogicOpEnabled
);
877 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
878 color
->IndexLogicOpEnabled
);
879 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
883 FLUSH_CURRENT( ctx
, 0 );
884 MEMCPY( &ctx
->Current
, attr
->data
,
885 sizeof(struct gl_current_attrib
) );
887 case GL_DEPTH_BUFFER_BIT
:
889 const struct gl_depthbuffer_attrib
*depth
;
890 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
891 _mesa_DepthFunc(depth
->Func
);
892 _mesa_ClearDepth(depth
->Clear
);
893 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
894 _mesa_DepthMask(depth
->Mask
);
899 const struct gl_enable_attrib
*enable
;
900 enable
= (const struct gl_enable_attrib
*) attr
->data
;
901 pop_enable_group(ctx
, enable
);
902 ctx
->NewState
|= _NEW_ALL
;
906 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
907 ctx
->NewState
|= _NEW_EVAL
;
911 const struct gl_fog_attrib
*fog
;
912 fog
= (const struct gl_fog_attrib
*) attr
->data
;
913 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
914 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
915 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
916 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
917 _mesa_Fogf(GL_FOG_END
, fog
->End
);
918 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
919 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
924 const struct gl_hint_attrib
*hint
;
925 hint
= (const struct gl_hint_attrib
*) attr
->data
;
926 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
927 hint
->PerspectiveCorrection
);
928 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
929 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
930 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
931 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
932 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
933 hint
->ClipVolumeClipping
);
934 if (ctx
->Extensions
.ARB_texture_compression
)
935 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
936 hint
->TextureCompression
);
939 case GL_LIGHTING_BIT
:
942 const struct gl_light_attrib
*light
;
943 light
= (const struct gl_light_attrib
*) attr
->data
;
944 /* lighting enable */
945 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
946 /* per-light state */
947 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
948 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
950 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
951 const struct gl_light
*l
= &light
->Light
[i
];
952 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
953 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
954 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
955 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
956 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
957 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
958 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
959 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
960 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
961 &l
->ConstantAttenuation
);
962 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
963 &l
->LinearAttenuation
);
964 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
965 &l
->QuadraticAttenuation
);
968 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
969 light
->Model
.Ambient
);
970 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
971 (GLfloat
) light
->Model
.LocalViewer
);
972 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
973 (GLfloat
) light
->Model
.TwoSide
);
974 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
975 (GLfloat
) light
->Model
.ColorControl
);
977 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
978 sizeof(struct gl_material
));
980 _mesa_ShadeModel(light
->ShadeModel
);
982 _mesa_ColorMaterial(light
->ColorMaterialFace
,
983 light
->ColorMaterialMode
);
984 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
985 light
->ColorMaterialEnabled
);
990 const struct gl_line_attrib
*line
;
991 line
= (const struct gl_line_attrib
*) attr
->data
;
992 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
993 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
994 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
995 _mesa_LineWidth(line
->Width
);
999 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1001 case GL_PIXEL_MODE_BIT
:
1002 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1003 /* XXX what other pixel state needs to be set by function calls? */
1004 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1005 ctx
->NewState
|= _NEW_PIXEL
;
1009 const struct gl_point_attrib
*point
;
1010 point
= (const struct gl_point_attrib
*) attr
->data
;
1011 _mesa_PointSize(point
->Size
);
1012 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1013 if (ctx
->Extensions
.EXT_point_parameters
) {
1014 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
1016 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
1018 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
1020 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1023 if (ctx
->Extensions
.NV_point_sprite
1024 || ctx
->Extensions
.ARB_point_sprite
) {
1026 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1027 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1028 (GLint
) point
->CoordReplace
[u
]);
1030 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1031 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1032 ctx
->Point
.SpriteRMode
);
1033 _mesa_PointParameterfEXT(GL_POINT_SPRITE_COORD_ORIGIN
,
1034 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1038 case GL_POLYGON_BIT
:
1040 const struct gl_polygon_attrib
*polygon
;
1041 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1042 _mesa_CullFace(polygon
->CullFaceMode
);
1043 _mesa_FrontFace(polygon
->FrontFace
);
1044 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1045 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1046 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1047 polygon
->OffsetUnits
);
1048 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1049 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1050 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1051 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1052 polygon
->OffsetPoint
);
1053 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1054 polygon
->OffsetLine
);
1055 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1056 polygon
->OffsetFill
);
1059 case GL_POLYGON_STIPPLE_BIT
:
1060 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1061 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1062 if (ctx
->Driver
.PolygonStipple
)
1063 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1065 case GL_SCISSOR_BIT
:
1067 const struct gl_scissor_attrib
*scissor
;
1068 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1069 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1070 scissor
->Width
, scissor
->Height
);
1071 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1074 case GL_STENCIL_BUFFER_BIT
:
1076 const struct gl_stencil_attrib
*stencil
;
1077 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1078 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1079 _mesa_ClearStencil(stencil
->Clear
);
1080 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1081 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1082 stencil
->TestTwoSide
);
1083 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1084 ? GL_BACK
: GL_FRONT
);
1087 _mesa_StencilFuncSeparate(GL_FRONT
,
1088 stencil
->Function
[0],
1090 stencil
->ValueMask
[0]);
1091 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1092 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1093 stencil
->ZFailFunc
[0],
1094 stencil
->ZPassFunc
[0]);
1096 _mesa_StencilFuncSeparate(GL_BACK
,
1097 stencil
->Function
[1],
1099 stencil
->ValueMask
[1]);
1100 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1101 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1102 stencil
->ZFailFunc
[1],
1103 stencil
->ZPassFunc
[1]);
1106 case GL_TRANSFORM_BIT
:
1109 const struct gl_transform_attrib
*xform
;
1110 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1111 _mesa_MatrixMode(xform
->MatrixMode
);
1112 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1113 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1115 /* restore clip planes */
1116 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1117 const GLuint mask
= 1 << 1;
1118 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1119 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1120 if (xform
->ClipPlanesEnabled
& mask
) {
1121 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1124 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1126 if (ctx
->Driver
.ClipPlane
)
1127 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1130 /* normalize/rescale */
1131 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1132 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1133 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1134 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1135 ctx
->Transform
.RescaleNormals
);
1138 case GL_TEXTURE_BIT
:
1139 /* Take care of texture object reference counters */
1141 const struct gl_texture_attrib
*texture
;
1142 texture
= (const struct gl_texture_attrib
*) attr
->data
;
1143 pop_texture_group(ctx
, texture
);
1144 ctx
->NewState
|= _NEW_TEXTURE
;
1147 case GL_VIEWPORT_BIT
:
1149 const struct gl_viewport_attrib
*vp
;
1150 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1151 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1152 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1155 case GL_MULTISAMPLE_BIT_ARB
:
1157 const struct gl_multisample_attrib
*ms
;
1158 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1159 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1160 ms
->SampleCoverageInvert
);
1165 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1178 * Helper for incrementing/decrementing vertex buffer object reference
1179 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1182 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1185 array
->Vertex
.BufferObj
->RefCount
+= step
;
1186 array
->Normal
.BufferObj
->RefCount
+= step
;
1187 array
->Color
.BufferObj
->RefCount
+= step
;
1188 array
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1189 array
->FogCoord
.BufferObj
->RefCount
+= step
;
1190 array
->Index
.BufferObj
->RefCount
+= step
;
1191 array
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1192 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1193 array
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1194 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1195 array
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1197 array
->ArrayBufferObj
->RefCount
+= step
;
1198 array
->ElementArrayBufferObj
->RefCount
+= step
;
1202 #define GL_CLIENT_PACK_BIT (1<<20)
1203 #define GL_CLIENT_UNPACK_BIT (1<<21)
1207 _mesa_PushClientAttrib(GLbitfield mask
)
1209 struct gl_attrib_node
*newnode
;
1210 struct gl_attrib_node
*head
;
1212 GET_CURRENT_CONTEXT(ctx
);
1213 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1215 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1216 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1220 /* Build linked list of attribute nodes which save all attribute */
1221 /* groups specified by the mask. */
1224 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1225 struct gl_pixelstore_attrib
*attr
;
1226 #if FEATURE_EXT_pixel_buffer_object
1227 ctx
->Pack
.BufferObj
->RefCount
++;
1228 ctx
->Unpack
.BufferObj
->RefCount
++;
1230 /* packing attribs */
1231 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1232 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1233 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1234 newnode
->data
= attr
;
1235 newnode
->next
= head
;
1237 /* unpacking attribs */
1238 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1239 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1240 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1241 newnode
->data
= attr
;
1242 newnode
->next
= head
;
1245 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1246 struct gl_array_attrib
*attr
;
1247 attr
= MALLOC_STRUCT( gl_array_attrib
);
1248 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1249 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1250 newnode
->data
= attr
;
1251 newnode
->next
= head
;
1253 /* bump reference counts on buffer objects */
1254 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1257 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1258 ctx
->ClientAttribStackDepth
++;
1265 _mesa_PopClientAttrib(void)
1267 struct gl_attrib_node
*attr
, *next
;
1269 GET_CURRENT_CONTEXT(ctx
);
1270 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1272 if (ctx
->ClientAttribStackDepth
== 0) {
1273 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1277 ctx
->ClientAttribStackDepth
--;
1278 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1281 switch (attr
->kind
) {
1282 case GL_CLIENT_PACK_BIT
:
1283 #if FEATURE_EXT_pixel_buffer_object
1284 ctx
->Pack
.BufferObj
->RefCount
--;
1285 if (ctx
->Pack
.BufferObj
->RefCount
<= 0) {
1286 _mesa_remove_buffer_object( ctx
, ctx
->Pack
.BufferObj
);
1287 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Pack
.BufferObj
);
1290 MEMCPY( &ctx
->Pack
, attr
->data
,
1291 sizeof(struct gl_pixelstore_attrib
) );
1292 ctx
->NewState
|= _NEW_PACKUNPACK
;
1294 case GL_CLIENT_UNPACK_BIT
:
1295 #if FEATURE_EXT_pixel_buffer_object
1296 ctx
->Unpack
.BufferObj
->RefCount
--;
1297 if (ctx
->Unpack
.BufferObj
->RefCount
<= 0) {
1298 _mesa_remove_buffer_object( ctx
, ctx
->Unpack
.BufferObj
);
1299 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Unpack
.BufferObj
);
1302 MEMCPY( &ctx
->Unpack
, attr
->data
,
1303 sizeof(struct gl_pixelstore_attrib
) );
1304 ctx
->NewState
|= _NEW_PACKUNPACK
;
1306 case GL_CLIENT_VERTEX_ARRAY_BIT
:
1307 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1308 MEMCPY( &ctx
->Array
, attr
->data
,
1309 sizeof(struct gl_array_attrib
) );
1310 /* decrement reference counts on buffer objects */
1311 ctx
->NewState
|= _NEW_ARRAY
;
1314 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1326 void _mesa_init_attrib( GLcontext
*ctx
)
1328 /* Renderer and client attribute stacks */
1329 ctx
->AttribStackDepth
= 0;
1330 ctx
->ClientAttribStackDepth
= 0;