2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
31 struct gl_enable_attrib
36 GLbitfield ClipPlanes
;
37 GLboolean ColorMaterial
;
42 GLboolean Light
[MAX_LIGHTS
];
45 GLboolean LineStipple
;
46 GLboolean IndexLogicOp
;
47 GLboolean ColorLogicOp
;
52 GLboolean Map1TextureCoord1
;
53 GLboolean Map1TextureCoord2
;
54 GLboolean Map1TextureCoord3
;
55 GLboolean Map1TextureCoord4
;
56 GLboolean Map1Vertex3
;
57 GLboolean Map1Vertex4
;
61 GLboolean Map2TextureCoord1
;
62 GLboolean Map2TextureCoord2
;
63 GLboolean Map2TextureCoord3
;
64 GLboolean Map2TextureCoord4
;
65 GLboolean Map2Vertex3
;
66 GLboolean Map2Vertex4
;
69 GLboolean PixelTexture
;
70 GLboolean PointSmooth
;
71 GLboolean PolygonOffsetPoint
;
72 GLboolean PolygonOffsetLine
;
73 GLboolean PolygonOffsetFill
;
74 GLboolean PolygonSmooth
;
75 GLboolean PolygonStipple
;
76 GLboolean RescaleNormals
;
79 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
80 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
81 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
82 GLboolean SampleCoverage
; /* GL_ARB_multisample */
83 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
88 /* GL_ARB_point_sprite / GL_NV_point_sprite */
89 GLboolean PointSprite
;
94 * Node for the attribute stack.
100 struct gl_attrib_node
*next
;
106 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
110 struct gl_texture_attrib Texture
; /**< The usual context state */
112 /** to save per texture object state (wrap modes, filters, etc): */
113 struct gl_texture_object SavedObj
[NUM_TEXTURE_TARGETS
];
116 * To save references to texture objects (so they don't get accidentally
117 * deleted while saved in the attribute stack).
119 struct gl_texture_object
*SavedTexRef
[NUM_TEXTURE_TARGETS
];
121 /* We need to keep a reference to the shared state. That's where the
122 * default texture objects are kept. We don't want that state to be
123 * freed while the attribute stack contains pointers to any default
126 struct gl_shared_state
*SharedRef
;
130 #if FEATURE_attrib_stack
134 * Allocate new attribute node of given type/kind. Attach payload data.
135 * Insert it into the linked list named by 'head'.
138 save_attrib_data(struct gl_attrib_node
**head
,
139 GLbitfield kind
, void *payload
)
141 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
156 _mesa_PushAttrib(GLbitfield mask
)
158 struct gl_attrib_node
*head
;
160 GET_CURRENT_CONTEXT(ctx
);
161 ASSERT_OUTSIDE_BEGIN_END(ctx
);
163 if (MESA_VERBOSE
& VERBOSE_API
)
164 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
166 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
167 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
171 /* Build linked list of attribute nodes which save all attribute */
172 /* groups specified by the mask. */
175 if (mask
& GL_ACCUM_BUFFER_BIT
) {
176 struct gl_accum_attrib
*attr
;
177 attr
= MALLOC_STRUCT( gl_accum_attrib
);
178 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
179 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
182 if (mask
& GL_COLOR_BUFFER_BIT
) {
183 struct gl_colorbuffer_attrib
*attr
;
184 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
185 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
186 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
187 attr
->DrawBuffer
= ctx
->DrawBuffer
->ColorDrawBuffer
;
188 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
191 if (mask
& GL_CURRENT_BIT
) {
192 struct gl_current_attrib
*attr
;
193 FLUSH_CURRENT( ctx
, 0 );
194 attr
= MALLOC_STRUCT( gl_current_attrib
);
195 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
196 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
199 if (mask
& GL_DEPTH_BUFFER_BIT
) {
200 struct gl_depthbuffer_attrib
*attr
;
201 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
202 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
203 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
206 if (mask
& GL_ENABLE_BIT
) {
207 struct gl_enable_attrib
*attr
;
209 attr
= MALLOC_STRUCT( gl_enable_attrib
);
210 /* Copy enable flags from all other attributes into the enable struct. */
211 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
212 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
213 attr
->Blend
= ctx
->Color
.BlendEnabled
;
214 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
215 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
216 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
217 attr
->DepthTest
= ctx
->Depth
.Test
;
218 attr
->Dither
= ctx
->Color
.DitherFlag
;
219 attr
->Fog
= ctx
->Fog
.Enabled
;
220 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
221 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
223 attr
->Lighting
= ctx
->Light
.Enabled
;
224 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
225 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
226 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
227 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
228 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
229 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
230 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
231 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
232 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
233 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
234 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
235 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
236 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
237 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
238 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
239 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
240 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
241 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
242 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
243 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
244 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
245 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
246 attr
->Normalize
= ctx
->Transform
.Normalize
;
247 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
248 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
249 attr
->PointSprite
= ctx
->Point
.PointSprite
;
250 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
251 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
252 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
253 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
254 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
255 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
256 attr
->Scissor
= ctx
->Scissor
.Enabled
;
257 attr
->Stencil
= ctx
->Stencil
.Enabled
;
258 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
259 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
260 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
261 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
262 attr
->Texture
= ctx
->Texture
.Unit
.Enabled
;
263 attr
->TexGen
= ctx
->Texture
.Unit
.TexGenEnabled
;
264 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
267 if (mask
& GL_EVAL_BIT
) {
268 struct gl_eval_attrib
*attr
;
269 attr
= MALLOC_STRUCT( gl_eval_attrib
);
270 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
271 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
274 if (mask
& GL_FOG_BIT
) {
275 struct gl_fog_attrib
*attr
;
276 attr
= MALLOC_STRUCT( gl_fog_attrib
);
277 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
278 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
281 if (mask
& GL_HINT_BIT
) {
282 struct gl_hint_attrib
*attr
;
283 attr
= MALLOC_STRUCT( gl_hint_attrib
);
284 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
285 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
288 if (mask
& GL_LIGHTING_BIT
) {
289 struct gl_light_attrib
*attr
;
290 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
291 attr
= MALLOC_STRUCT( gl_light_attrib
);
292 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
293 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
296 if (mask
& GL_LINE_BIT
) {
297 struct gl_line_attrib
*attr
;
298 attr
= MALLOC_STRUCT( gl_line_attrib
);
299 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
300 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
303 if (mask
& GL_LIST_BIT
) {
304 struct gl_list_attrib
*attr
;
305 attr
= MALLOC_STRUCT( gl_list_attrib
);
306 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
307 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
310 if (mask
& GL_PIXEL_MODE_BIT
) {
311 struct gl_pixel_attrib
*attr
;
312 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
313 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
314 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
315 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
316 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
319 if (mask
& GL_POINT_BIT
) {
320 struct gl_point_attrib
*attr
;
321 attr
= MALLOC_STRUCT( gl_point_attrib
);
322 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
323 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
326 if (mask
& GL_POLYGON_BIT
) {
327 struct gl_polygon_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
329 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
330 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
333 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
335 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
336 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
337 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
340 if (mask
& GL_SCISSOR_BIT
) {
341 struct gl_scissor_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
343 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
344 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
347 if (mask
& GL_STENCIL_BUFFER_BIT
) {
348 struct gl_stencil_attrib
*attr
;
349 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
350 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
351 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
354 if (mask
& GL_TEXTURE_BIT
) {
355 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
359 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
363 _mesa_lock_context_textures(ctx
);
365 /* copy/save the bulk of texture state here */
366 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
368 /* Save references to the currently bound texture objects so they don't
369 * accidentally get deleted while referenced in the attribute stack.
371 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
372 _mesa_reference_texobj(&texstate
->SavedTexRef
[tex
],
373 ctx
->Texture
.Unit
.CurrentTex
[tex
]);
376 /* copy state/contents of the currently bound texture objects */
377 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
378 _mesa_copy_texture_object(&texstate
->SavedObj
[tex
],
379 ctx
->Texture
.Unit
.CurrentTex
[tex
]);
382 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
384 _mesa_unlock_context_textures(ctx
);
386 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
389 if (mask
& GL_TRANSFORM_BIT
) {
390 struct gl_transform_attrib
*attr
;
391 attr
= MALLOC_STRUCT( gl_transform_attrib
);
392 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
393 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
396 if (mask
& GL_VIEWPORT_BIT
) {
397 struct gl_viewport_attrib
*attr
;
398 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
399 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
400 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
403 /* GL_ARB_multisample */
404 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
405 struct gl_multisample_attrib
*attr
;
406 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
407 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
408 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
412 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
413 ctx
->AttribStackDepth
++;
419 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
423 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
424 if ((VALUE) != (NEWVALUE)) { \
425 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
428 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
429 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
430 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
433 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
434 const GLuint mask
= 1 << i
;
435 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
436 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
437 !!(enable
->ClipPlanes
& mask
));
440 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
442 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
443 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
444 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
445 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
446 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
447 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
448 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
450 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
452 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
455 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
456 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
457 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
458 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
459 GL_MAP1_TEXTURE_COORD_1
);
460 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
461 GL_MAP1_TEXTURE_COORD_2
);
462 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
463 GL_MAP1_TEXTURE_COORD_3
);
464 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
465 GL_MAP1_TEXTURE_COORD_4
);
466 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
468 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
471 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
472 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
473 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
474 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
475 GL_MAP2_TEXTURE_COORD_1
);
476 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
477 GL_MAP2_TEXTURE_COORD_2
);
478 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
479 GL_MAP2_TEXTURE_COORD_3
);
480 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
481 GL_MAP2_TEXTURE_COORD_4
);
482 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
484 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
487 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
488 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
489 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
490 GL_RESCALE_NORMAL_EXT
);
491 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
492 enable
->RasterPositionUnclipped
,
493 GL_RASTER_POSITION_UNCLIPPED_IBM
);
494 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
496 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
497 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
500 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
501 GL_POLYGON_OFFSET_POINT
);
502 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
503 GL_POLYGON_OFFSET_LINE
);
504 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
505 GL_POLYGON_OFFSET_FILL
);
506 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
508 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
510 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
511 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
512 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
514 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
515 enable
->SampleAlphaToCoverage
,
516 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
517 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
518 enable
->SampleAlphaToOne
,
519 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
520 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
521 enable
->SampleCoverage
,
522 GL_SAMPLE_COVERAGE_ARB
);
524 /* texture unit enables */
526 const GLbitfield enabled
= enable
->Texture
;
527 const GLbitfield genEnabled
= enable
->TexGen
;
529 if (ctx
->Texture
.Unit
.Enabled
!= enabled
) {
530 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
531 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
532 if (ctx
->Extensions
.ARB_texture_cube_map
) {
533 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
534 !!(enabled
& TEXTURE_CUBE_BIT
));
538 if (ctx
->Texture
.Unit
.TexGenEnabled
!= genEnabled
) {
539 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
540 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
541 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
542 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
549 * Pop/restore texture attribute/group state.
552 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
554 const struct gl_texture_unit
*unit
;
557 _mesa_lock_context_textures(ctx
);
559 unit
= &texstate
->Texture
.Unit
;
561 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
562 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
564 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
565 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
566 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
567 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
568 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
569 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
570 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
571 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
572 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
573 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
574 /* Eye plane done differently to avoid re-transformation */
576 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
;
577 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
578 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
579 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
580 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
581 if (ctx
->Driver
.TexGen
) {
582 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
583 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
584 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
585 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
588 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
589 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
590 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
591 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
592 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
594 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
595 unit
->Combine
.ModeRGB
);
596 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
597 unit
->Combine
.ModeA
);
599 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
601 for (i
= 0; i
< n
; i
++) {
602 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
603 unit
->Combine
.SourceRGB
[i
]);
604 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
605 unit
->Combine
.SourceA
[i
]);
606 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
607 unit
->Combine
.OperandRGB
[i
]);
608 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
609 unit
->Combine
.OperandA
[i
]);
612 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
, 1 << unit
->Combine
.ScaleShiftRGB
);
613 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
, 1 << unit
->Combine
.ScaleShiftA
);
615 /* Restore texture object state for each target */
616 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
617 const struct gl_texture_object
*obj
= NULL
;
618 const struct gl_sampler_object
*samp
;
621 obj
= &texstate
->SavedObj
[tgt
];
623 /* don't restore state for unsupported targets to prevent
626 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
627 !ctx
->Extensions
.ARB_texture_cube_map
) {
631 target
= obj
->Target
;
633 _mesa_BindTexture(target
, obj
->Name
);
635 samp
= &obj
->Sampler
;
637 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
638 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
639 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
640 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
641 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
642 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
643 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
644 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
645 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
646 samp
->MaxAnisotropy
);
650 /* remove saved references to the texture objects */
651 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
652 _mesa_reference_texobj(&texstate
->SavedTexRef
[tgt
], NULL
);
655 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
657 _mesa_unlock_context_textures(ctx
);
662 * This function is kind of long just because we have to call a lot
663 * of device driver functions to update device driver state.
665 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
666 * in order to restore GL state. This isn't terribly efficient but it
667 * ensures that dirty flags and any derived state gets updated correctly.
668 * We could at least check if the value to restore equals the current value
669 * and then skip the Mesa call.
672 _mesa_PopAttrib(void)
674 struct gl_attrib_node
*attr
, *next
;
675 GET_CURRENT_CONTEXT(ctx
);
676 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
678 if (ctx
->AttribStackDepth
== 0) {
679 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
683 ctx
->AttribStackDepth
--;
684 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
688 if (MESA_VERBOSE
& VERBOSE_API
) {
689 _mesa_debug(ctx
, "glPopAttrib %s\n",
690 _mesa_lookup_enum_by_nr(attr
->kind
));
693 switch (attr
->kind
) {
694 case GL_ACCUM_BUFFER_BIT
:
696 const struct gl_accum_attrib
*accum
;
697 accum
= (const struct gl_accum_attrib
*) attr
->data
;
698 _mesa_ClearAccum(accum
->ClearColor
[0],
699 accum
->ClearColor
[1],
700 accum
->ClearColor
[2],
701 accum
->ClearColor
[3]);
704 case GL_COLOR_BUFFER_BIT
:
706 const struct gl_colorbuffer_attrib
*color
;
708 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
709 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
710 _mesa_ClearColor(color
->ClearColor
.f
[0],
711 color
->ClearColor
.f
[1],
712 color
->ClearColor
.f
[2],
713 color
->ClearColor
.f
[3]);
714 _mesa_IndexMask(color
->IndexMask
);
715 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
716 (GLboolean
) (color
->ColorMask
[1] != 0),
717 (GLboolean
) (color
->ColorMask
[2] != 0),
718 (GLboolean
) (color
->ColorMask
[3] != 0));
719 _mesa_DrawBuffer(color
->DrawBuffer
);
720 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
721 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
722 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
723 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
725 /* set same blend modes for all buffers */
726 _mesa_BlendFuncSeparateEXT(color
->SrcRGB
,
730 /* This special case is because glBlendEquationSeparateEXT
731 * cannot take GL_LOGIC_OP as a parameter.
733 if (color
->EquationRGB
== color
->EquationA
) {
734 _mesa_BlendEquation(color
->EquationRGB
);
737 _mesa_BlendEquationSeparateEXT(
741 _mesa_BlendColor(color
->BlendColor
[0],
742 color
->BlendColor
[1],
743 color
->BlendColor
[2],
744 color
->BlendColor
[3]);
745 _mesa_LogicOp(color
->LogicOp
);
746 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
747 color
->ColorLogicOpEnabled
);
748 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
749 color
->IndexLogicOpEnabled
);
750 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
754 FLUSH_CURRENT( ctx
, 0 );
755 memcpy( &ctx
->Current
, attr
->data
,
756 sizeof(struct gl_current_attrib
) );
758 case GL_DEPTH_BUFFER_BIT
:
760 const struct gl_depthbuffer_attrib
*depth
;
761 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
762 _mesa_DepthFunc(depth
->Func
);
763 _mesa_ClearDepth(depth
->Clear
);
764 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
765 _mesa_DepthMask(depth
->Mask
);
770 const struct gl_enable_attrib
*enable
;
771 enable
= (const struct gl_enable_attrib
*) attr
->data
;
772 pop_enable_group(ctx
, enable
);
773 ctx
->NewState
|= _NEW_ALL
;
777 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
778 ctx
->NewState
|= _NEW_EVAL
;
782 const struct gl_fog_attrib
*fog
;
783 fog
= (const struct gl_fog_attrib
*) attr
->data
;
784 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
785 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
786 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
787 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
788 _mesa_Fogf(GL_FOG_END
, fog
->End
);
789 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
790 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
795 const struct gl_hint_attrib
*hint
;
796 hint
= (const struct gl_hint_attrib
*) attr
->data
;
797 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
798 hint
->PerspectiveCorrection
);
799 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
800 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
801 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
802 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
803 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
804 hint
->ClipVolumeClipping
);
807 case GL_LIGHTING_BIT
:
810 const struct gl_light_attrib
*light
;
811 light
= (const struct gl_light_attrib
*) attr
->data
;
812 /* lighting enable */
813 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
814 /* per-light state */
815 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
816 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
818 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
819 const struct gl_light
*l
= &light
->Light
[i
];
820 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
821 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
822 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
823 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
824 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
825 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
827 GLfloat p
[4] = { 0 };
828 p
[0] = l
->SpotExponent
;
829 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
832 GLfloat p
[4] = { 0 };
833 p
[0] = l
->SpotCutoff
;
834 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
837 GLfloat p
[4] = { 0 };
838 p
[0] = l
->ConstantAttenuation
;
839 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
842 GLfloat p
[4] = { 0 };
843 p
[0] = l
->LinearAttenuation
;
844 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
847 GLfloat p
[4] = { 0 };
848 p
[0] = l
->QuadraticAttenuation
;
849 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
853 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
854 light
->Model
.Ambient
);
855 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
856 (GLfloat
) light
->Model
.LocalViewer
);
857 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
858 (GLfloat
) light
->Model
.TwoSide
);
859 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
860 (GLfloat
) light
->Model
.ColorControl
);
862 _mesa_ShadeModel(light
->ShadeModel
);
864 _mesa_ColorMaterial(light
->ColorMaterialFace
,
865 light
->ColorMaterialMode
);
866 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
867 light
->ColorMaterialEnabled
);
869 memcpy(&ctx
->Light
.Material
, &light
->Material
,
870 sizeof(struct gl_material
));
875 const struct gl_line_attrib
*line
;
876 line
= (const struct gl_line_attrib
*) attr
->data
;
877 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
878 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
879 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
880 _mesa_LineWidth(line
->Width
);
884 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
886 case GL_PIXEL_MODE_BIT
:
887 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
888 /* XXX what other pixel state needs to be set by function calls? */
889 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
890 ctx
->NewState
|= _NEW_PIXEL
;
894 const struct gl_point_attrib
*point
;
895 point
= (const struct gl_point_attrib
*) attr
->data
;
896 _mesa_PointSize(point
->Size
);
897 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
902 const struct gl_polygon_attrib
*polygon
;
903 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
904 _mesa_CullFace(polygon
->CullFaceMode
);
905 _mesa_FrontFace(polygon
->FrontFace
);
906 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
907 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
908 _mesa_PolygonOffset(polygon
->OffsetFactor
,
909 polygon
->OffsetUnits
);
910 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
911 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
912 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
913 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
914 polygon
->OffsetPoint
);
915 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
916 polygon
->OffsetLine
);
917 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
918 polygon
->OffsetFill
);
921 case GL_POLYGON_STIPPLE_BIT
:
922 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
923 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
924 if (ctx
->Driver
.PolygonStipple
)
925 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
929 const struct gl_scissor_attrib
*scissor
;
930 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
931 _mesa_Scissor(scissor
->X
, scissor
->Y
,
932 scissor
->Width
, scissor
->Height
);
933 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
936 case GL_STENCIL_BUFFER_BIT
:
938 const struct gl_stencil_attrib
*stencil
;
939 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
940 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
941 _mesa_ClearStencil(stencil
->Clear
);
942 _mesa_StencilFunc(stencil
->Function
,
945 _mesa_StencilMask(stencil
->WriteMask
);
946 _mesa_StencilOp(stencil
->FailFunc
,
951 case GL_TRANSFORM_BIT
:
954 const struct gl_transform_attrib
*xform
;
955 xform
= (const struct gl_transform_attrib
*) attr
->data
;
956 _mesa_MatrixMode(xform
->MatrixMode
);
957 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
958 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
960 /* restore clip planes */
961 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
962 const GLuint mask
= 1 << i
;
963 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
964 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
965 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
966 !!(xform
->ClipPlanesEnabled
& mask
));
967 if (ctx
->Driver
.ClipPlane
)
968 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
971 /* normalize/rescale */
972 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
973 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
974 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
975 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
976 ctx
->Transform
.RescaleNormals
);
980 /* Take care of texture object reference counters */
982 struct texture_state
*texstate
983 = (struct texture_state
*) attr
->data
;
984 pop_texture_group(ctx
, texstate
);
985 ctx
->NewState
|= _NEW_TEXTURE
;
988 case GL_VIEWPORT_BIT
:
990 const struct gl_viewport_attrib
*vp
;
991 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
992 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
993 _mesa_DepthRange(vp
->Near
, vp
->Far
);
996 case GL_MULTISAMPLE_BIT_ARB
:
998 const struct gl_multisample_attrib
*ms
;
999 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1001 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1005 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1007 GL_SAMPLE_COVERAGE
);
1009 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1010 ms
->SampleAlphaToCoverage
,
1011 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1013 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1014 ms
->SampleAlphaToOne
,
1015 GL_SAMPLE_ALPHA_TO_ONE
);
1017 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1018 ms
->SampleCoverageInvert
);
1023 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1036 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1040 copy_pixelstore(struct gl_context
*ctx
,
1041 struct gl_pixelstore_attrib
*dst
,
1042 const struct gl_pixelstore_attrib
*src
)
1044 dst
->Alignment
= src
->Alignment
;
1045 dst
->RowLength
= src
->RowLength
;
1046 dst
->SkipPixels
= src
->SkipPixels
;
1047 dst
->SkipRows
= src
->SkipRows
;
1048 dst
->ImageHeight
= src
->ImageHeight
;
1049 dst
->SkipImages
= src
->SkipImages
;
1050 dst
->SwapBytes
= src
->SwapBytes
;
1051 dst
->LsbFirst
= src
->LsbFirst
;
1052 dst
->Invert
= src
->Invert
;
1056 #define GL_CLIENT_PACK_BIT (1<<20)
1057 #define GL_CLIENT_UNPACK_BIT (1<<21)
1060 * Copy gl_array_attrib from src to dest.
1061 * 'dest' must be in an initialized state.
1064 copy_array_attrib(struct gl_context
*ctx
,
1065 struct gl_array_attrib
*dest
,
1066 struct gl_array_attrib
*src
,
1067 GLboolean vbo_deleted
)
1070 /* skip DefaultArrayObj, Objects */
1071 dest
->LockFirst
= src
->LockFirst
;
1072 dest
->LockCount
= src
->LockCount
;
1074 /* skip RebindArrays */
1083 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1084 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1086 /* _Enabled must be the same than on push */
1087 dest
->_Enabled
= src
->_Enabled
;
1088 dest
->_MaxElement
= src
->_MaxElement
;
1091 /* skip ArrayBufferObj */
1092 /* skip ElementArrayBufferObj */
1096 * Save the content of src to dest.
1099 save_array_attrib(struct gl_context
*ctx
,
1100 struct gl_array_attrib
*dest
,
1101 struct gl_array_attrib
*src
)
1103 /* And copy all of the rest. */
1104 copy_array_attrib(ctx
, dest
, src
, GL_FALSE
);
1106 /* Just reference them here */
1107 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1108 src
->ArrayBufferObj
);
1109 _mesa_reference_buffer_object(ctx
, &dest
->ElementArrayBufferObj
,
1110 src
->ElementArrayBufferObj
);
1114 * Restore the content of src to dest.
1117 restore_array_attrib(struct gl_context
*ctx
,
1118 struct gl_array_attrib
*dest
,
1119 struct gl_array_attrib
*src
)
1121 /* Restore or recreate the buffer objects by the names ... */
1122 if (!src
->ArrayBufferObj
->Name
== 0
1123 || _mesa_IsBufferARB(src
->ArrayBufferObj
->Name
)) {
1124 /* ... and restore its content */
1125 copy_array_attrib(ctx
, dest
, src
, GL_FALSE
);
1127 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1128 src
->ArrayBufferObj
->Name
);
1130 copy_array_attrib(ctx
, dest
, src
, GL_TRUE
);
1133 if (src
->ElementArrayBufferObj
->Name
== 0
1134 || _mesa_IsBufferARB(src
->ElementArrayBufferObj
->Name
))
1135 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1136 src
->ElementArrayBufferObj
->Name
);
1138 /* Better safe than sorry?! */
1139 dest
->RebindArrays
= GL_TRUE
;
1141 /* FIXME: Should some bits in ctx->Array->NewState also be set
1142 * FIXME: here? It seems like it should be set to inclusive-or
1143 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1146 dest
->NewState
|= src
->_Enabled
| dest
->_Enabled
;
1150 * Free/unreference the fields of 'attrib' but don't delete it (that's
1151 * done later in the calling code).
1152 * Needs to the cleanup part matching init_array_attrib_data above.
1155 free_array_attrib_data(struct gl_context
*ctx
,
1156 struct gl_array_attrib
*attrib
)
1158 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1159 _mesa_free_varray_data(ctx
, attrib
);
1164 _mesa_PushClientAttrib(GLbitfield mask
)
1166 struct gl_attrib_node
*head
;
1168 GET_CURRENT_CONTEXT(ctx
);
1169 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1171 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1172 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1176 /* Build linked list of attribute nodes which save all attribute
1177 * groups specified by the mask.
1181 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1182 struct gl_pixelstore_attrib
*attr
;
1183 /* packing attribs */
1184 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1185 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1186 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1187 /* unpacking attribs */
1188 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1189 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1190 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1193 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1194 struct gl_array_attrib
*attr
;
1195 attr
= CALLOC_STRUCT( gl_array_attrib
);
1196 _mesa_init_varray(ctx
, attr
);
1197 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1198 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1201 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1202 ctx
->ClientAttribStackDepth
++;
1209 _mesa_PopClientAttrib(void)
1211 struct gl_attrib_node
*node
, *next
;
1213 GET_CURRENT_CONTEXT(ctx
);
1214 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1216 if (ctx
->ClientAttribStackDepth
== 0) {
1217 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1221 ctx
->ClientAttribStackDepth
--;
1222 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1225 switch (node
->kind
) {
1226 case GL_CLIENT_PACK_BIT
:
1228 struct gl_pixelstore_attrib
*store
=
1229 (struct gl_pixelstore_attrib
*) node
->data
;
1230 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1232 ctx
->NewState
|= _NEW_PACKUNPACK
;
1234 case GL_CLIENT_UNPACK_BIT
:
1236 struct gl_pixelstore_attrib
*store
=
1237 (struct gl_pixelstore_attrib
*) node
->data
;
1238 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1240 ctx
->NewState
|= _NEW_PACKUNPACK
;
1242 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1243 struct gl_array_attrib
* attr
=
1244 (struct gl_array_attrib
*) node
->data
;
1245 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1246 free_array_attrib_data(ctx
, attr
);
1247 ctx
->NewState
|= _NEW_ARRAY
;
1251 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1264 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1266 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1267 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1268 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1269 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1273 #endif /* FEATURE_attrib_stack */
1277 * Free any attribute state data that might be attached to the context.
1280 _mesa_free_attrib_data(struct gl_context
*ctx
)
1282 while (ctx
->AttribStackDepth
> 0) {
1283 struct gl_attrib_node
*attr
, *next
;
1285 ctx
->AttribStackDepth
--;
1286 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1289 if (attr
->kind
== GL_TEXTURE_BIT
) {
1290 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1292 /* clear references to the saved texture objects */
1293 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1294 _mesa_reference_texobj(&texstate
->SavedTexRef
[tgt
], NULL
);
1296 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1299 /* any other chunks of state that requires special handling? */
1311 void _mesa_init_attrib( struct gl_context
*ctx
)
1313 /* Renderer and client attribute stacks */
1314 ctx
->AttribStackDepth
= 0;
1315 ctx
->ClientAttribStackDepth
= 0;