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.
33 #include "bufferobj.h"
46 #include "mfeatures.h"
47 #include "multisample.h"
61 #include "main/dispatch.h"
67 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
69 struct gl_enable_attrib
74 GLbitfield ClipPlanes
;
75 GLboolean ColorMaterial
;
80 GLboolean Light
[MAX_LIGHTS
];
83 GLboolean LineStipple
;
84 GLboolean IndexLogicOp
;
85 GLboolean ColorLogicOp
;
90 GLboolean Map1TextureCoord1
;
91 GLboolean Map1TextureCoord2
;
92 GLboolean Map1TextureCoord3
;
93 GLboolean Map1TextureCoord4
;
94 GLboolean Map1Vertex3
;
95 GLboolean Map1Vertex4
;
96 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2TextureCoord1
;
101 GLboolean Map2TextureCoord2
;
102 GLboolean Map2TextureCoord3
;
103 GLboolean Map2TextureCoord4
;
104 GLboolean Map2Vertex3
;
105 GLboolean Map2Vertex4
;
106 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
109 GLboolean PixelTexture
;
110 GLboolean PointSmooth
;
111 GLboolean PolygonOffsetPoint
;
112 GLboolean PolygonOffsetLine
;
113 GLboolean PolygonOffsetFill
;
114 GLboolean PolygonSmooth
;
115 GLboolean PolygonStipple
;
116 GLboolean RescaleNormals
;
119 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
120 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
122 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
123 GLboolean SampleCoverage
; /* GL_ARB_multisample */
124 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
126 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
127 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
129 /* GL_ARB_vertex_program / GL_NV_vertex_program */
130 GLboolean VertexProgram
;
131 GLboolean VertexProgramPointSize
;
132 GLboolean VertexProgramTwoSide
;
134 /* GL_ARB_point_sprite / GL_NV_point_sprite */
135 GLboolean PointSprite
;
140 * Node for the attribute stack.
142 struct gl_attrib_node
146 struct gl_attrib_node
*next
;
152 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
156 struct gl_texture_attrib Texture
; /**< The usual context state */
158 /** to save per texture object state (wrap modes, filters, etc): */
159 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
162 * To save references to texture objects (so they don't get accidentally
163 * deleted while saved in the attribute stack).
165 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
167 /* We need to keep a reference to the shared state. That's where the
168 * default texture objects are kept. We don't want that state to be
169 * freed while the attribute stack contains pointers to any default
172 struct gl_shared_state
*SharedRef
;
176 #if FEATURE_attrib_stack
180 * Allocate new attribute node of given type/kind. Attach payload data.
181 * Insert it into the linked list named by 'head'.
184 save_attrib_data(struct gl_attrib_node
**head
,
185 GLbitfield kind
, void *payload
)
187 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
202 _mesa_PushAttrib(GLbitfield mask
)
204 struct gl_attrib_node
*head
;
206 GET_CURRENT_CONTEXT(ctx
);
207 ASSERT_OUTSIDE_BEGIN_END(ctx
);
209 if (MESA_VERBOSE
& VERBOSE_API
)
210 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
212 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
213 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
217 /* Build linked list of attribute nodes which save all attribute */
218 /* groups specified by the mask. */
221 if (mask
& GL_ACCUM_BUFFER_BIT
) {
222 struct gl_accum_attrib
*attr
;
223 attr
= MALLOC_STRUCT( gl_accum_attrib
);
224 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
225 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
228 if (mask
& GL_COLOR_BUFFER_BIT
) {
229 struct gl_colorbuffer_attrib
*attr
;
230 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
231 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
232 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
233 attr
->DrawBuffer
= ctx
->DrawBuffer
->ColorDrawBuffer
;
234 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
237 if (mask
& GL_CURRENT_BIT
) {
238 struct gl_current_attrib
*attr
;
239 FLUSH_CURRENT( ctx
, 0 );
240 attr
= MALLOC_STRUCT( gl_current_attrib
);
241 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
242 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
245 if (mask
& GL_DEPTH_BUFFER_BIT
) {
246 struct gl_depthbuffer_attrib
*attr
;
247 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
248 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
249 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
252 if (mask
& GL_ENABLE_BIT
) {
253 struct gl_enable_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_enable_attrib
);
256 /* Copy enable flags from all other attributes into the enable struct. */
257 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
258 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
259 attr
->Blend
= ctx
->Color
.BlendEnabled
;
260 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
261 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
262 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
263 attr
->DepthTest
= ctx
->Depth
.Test
;
264 attr
->Dither
= ctx
->Color
.DitherFlag
;
265 attr
->Fog
= ctx
->Fog
.Enabled
;
266 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
267 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
269 attr
->Lighting
= ctx
->Light
.Enabled
;
270 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
271 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
272 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
273 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
274 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
275 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
276 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
277 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
278 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
279 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
280 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
281 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
282 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
283 memcpy(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
284 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
285 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
286 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
287 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
288 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
289 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
290 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
291 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
292 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
293 memcpy(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
294 attr
->Normalize
= ctx
->Transform
.Normalize
;
295 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
296 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
297 attr
->PointSprite
= ctx
->Point
.PointSprite
;
298 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
299 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
300 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
301 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
302 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
303 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
304 attr
->Scissor
= ctx
->Scissor
.Enabled
;
305 attr
->Stencil
= ctx
->Stencil
.Enabled
;
306 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
307 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
308 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
309 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
310 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
311 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
312 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
313 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
315 /* GL_NV_vertex_program */
316 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
317 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
318 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
319 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
322 if (mask
& GL_EVAL_BIT
) {
323 struct gl_eval_attrib
*attr
;
324 attr
= MALLOC_STRUCT( gl_eval_attrib
);
325 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
326 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
329 if (mask
& GL_FOG_BIT
) {
330 struct gl_fog_attrib
*attr
;
331 attr
= MALLOC_STRUCT( gl_fog_attrib
);
332 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
333 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
336 if (mask
& GL_HINT_BIT
) {
337 struct gl_hint_attrib
*attr
;
338 attr
= MALLOC_STRUCT( gl_hint_attrib
);
339 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
340 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
343 if (mask
& GL_LIGHTING_BIT
) {
344 struct gl_light_attrib
*attr
;
345 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
346 attr
= MALLOC_STRUCT( gl_light_attrib
);
347 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
348 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
351 if (mask
& GL_LINE_BIT
) {
352 struct gl_line_attrib
*attr
;
353 attr
= MALLOC_STRUCT( gl_line_attrib
);
354 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
355 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
358 if (mask
& GL_LIST_BIT
) {
359 struct gl_list_attrib
*attr
;
360 attr
= MALLOC_STRUCT( gl_list_attrib
);
361 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
362 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
365 if (mask
& GL_PIXEL_MODE_BIT
) {
366 struct gl_pixel_attrib
*attr
;
367 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
368 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
369 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
370 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
371 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
374 if (mask
& GL_POINT_BIT
) {
375 struct gl_point_attrib
*attr
;
376 attr
= MALLOC_STRUCT( gl_point_attrib
);
377 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
378 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
381 if (mask
& GL_POLYGON_BIT
) {
382 struct gl_polygon_attrib
*attr
;
383 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
384 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
385 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
388 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
390 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
391 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
392 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
395 if (mask
& GL_SCISSOR_BIT
) {
396 struct gl_scissor_attrib
*attr
;
397 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
398 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
399 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
402 if (mask
& GL_STENCIL_BUFFER_BIT
) {
403 struct gl_stencil_attrib
*attr
;
404 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
405 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
406 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
409 if (mask
& GL_TEXTURE_BIT
) {
410 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
414 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
418 _mesa_lock_context_textures(ctx
);
420 /* copy/save the bulk of texture state here */
421 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
423 /* Save references to the currently bound texture objects so they don't
424 * accidentally get deleted while referenced in the attribute stack.
426 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
427 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
428 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
429 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
433 /* copy state/contents of the currently bound texture objects */
434 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
435 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
436 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
437 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
441 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
443 _mesa_unlock_context_textures(ctx
);
445 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
448 if (mask
& GL_TRANSFORM_BIT
) {
449 struct gl_transform_attrib
*attr
;
450 attr
= MALLOC_STRUCT( gl_transform_attrib
);
451 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
452 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
455 if (mask
& GL_VIEWPORT_BIT
) {
456 struct gl_viewport_attrib
*attr
;
457 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
458 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
459 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
462 /* GL_ARB_multisample */
463 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
464 struct gl_multisample_attrib
*attr
;
465 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
466 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
467 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
471 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
472 ctx
->AttribStackDepth
++;
478 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
480 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
483 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
484 if ((VALUE) != (NEWVALUE)) { \
485 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
488 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
489 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
490 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
493 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
494 const GLuint mask
= 1 << i
;
495 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
496 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
497 !!(enable
->ClipPlanes
& mask
));
500 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
502 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
503 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
504 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
505 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
506 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
507 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
508 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
510 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
512 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
515 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
518 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
519 GL_MAP1_TEXTURE_COORD_1
);
520 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
521 GL_MAP1_TEXTURE_COORD_2
);
522 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
523 GL_MAP1_TEXTURE_COORD_3
);
524 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
525 GL_MAP1_TEXTURE_COORD_4
);
526 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
528 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
530 for (i
= 0; i
< 16; i
++) {
531 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
532 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
539 GL_MAP2_TEXTURE_COORD_1
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
541 GL_MAP2_TEXTURE_COORD_2
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
543 GL_MAP2_TEXTURE_COORD_3
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
545 GL_MAP2_TEXTURE_COORD_4
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
548 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
550 for (i
= 0; i
< 16; i
++) {
551 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
552 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
555 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
556 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
557 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
558 GL_RESCALE_NORMAL_EXT
);
559 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
560 enable
->RasterPositionUnclipped
,
561 GL_RASTER_POSITION_UNCLIPPED_IBM
);
562 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
564 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
565 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
568 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
569 GL_POLYGON_OFFSET_POINT
);
570 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
571 GL_POLYGON_OFFSET_LINE
);
572 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
573 GL_POLYGON_OFFSET_FILL
);
574 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
576 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
578 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
579 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
580 if (ctx
->Extensions
.EXT_stencil_two_side
) {
581 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
583 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
585 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
586 enable
->SampleAlphaToCoverage
,
587 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
588 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
589 enable
->SampleAlphaToOne
,
590 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
591 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
592 enable
->SampleCoverage
,
593 GL_SAMPLE_COVERAGE_ARB
);
594 /* GL_ARB_vertex_program, GL_NV_vertex_program */
595 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
596 enable
->VertexProgram
,
597 GL_VERTEX_PROGRAM_ARB
);
598 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
599 enable
->VertexProgramPointSize
,
600 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
601 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
602 enable
->VertexProgramTwoSide
,
603 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
605 /* texture unit enables */
606 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
607 const GLbitfield enabled
= enable
->Texture
[i
];
608 const GLbitfield genEnabled
= enable
->TexGen
[i
];
610 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
611 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
613 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
614 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
615 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
616 if (ctx
->Extensions
.ARB_texture_cube_map
) {
617 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
618 !!(enabled
& TEXTURE_CUBE_BIT
));
622 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
623 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
624 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
625 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
626 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
627 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
631 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
636 * Pop/restore texture attribute/group state.
639 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
643 _mesa_lock_context_textures(ctx
);
645 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
646 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
649 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
650 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
651 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
652 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
653 if (ctx
->Extensions
.ARB_texture_cube_map
) {
654 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
655 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
658 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
659 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
660 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
661 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
662 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
663 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
664 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
665 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
666 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
667 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
668 /* Eye plane done differently to avoid re-transformation */
670 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
671 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
672 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
673 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
674 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
675 if (ctx
->Driver
.TexGen
) {
676 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
677 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
678 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
679 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
682 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
683 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
684 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
685 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
686 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
688 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
689 unit
->Combine
.ModeRGB
);
690 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
691 unit
->Combine
.ModeA
);
693 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
695 for (i
= 0; i
< n
; i
++) {
696 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
697 unit
->Combine
.SourceRGB
[i
]);
698 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
699 unit
->Combine
.SourceA
[i
]);
700 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
701 unit
->Combine
.OperandRGB
[i
]);
702 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
703 unit
->Combine
.OperandA
[i
]);
706 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
707 1 << unit
->Combine
.ScaleShiftRGB
);
708 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
709 1 << unit
->Combine
.ScaleShiftA
);
711 /* Restore texture object state for each target */
712 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
713 const struct gl_texture_object
*obj
= NULL
;
714 const struct gl_sampler_object
*samp
;
717 obj
= &texstate
->SavedObj
[u
][tgt
];
719 /* don't restore state for unsupported targets to prevent
722 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
723 !ctx
->Extensions
.ARB_texture_cube_map
) {
727 target
= obj
->Target
;
729 _mesa_BindTexture(target
, obj
->Name
);
731 samp
= &obj
->Sampler
;
733 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
734 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
735 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
736 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
737 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
738 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
739 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
740 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
741 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
742 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
743 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
744 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
745 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
746 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
747 samp
->MaxAnisotropy
);
751 /* remove saved references to the texture objects */
752 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
753 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
757 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
759 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
761 _mesa_unlock_context_textures(ctx
);
766 * This function is kind of long just because we have to call a lot
767 * of device driver functions to update device driver state.
769 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
770 * in order to restore GL state. This isn't terribly efficient but it
771 * ensures that dirty flags and any derived state gets updated correctly.
772 * We could at least check if the value to restore equals the current value
773 * and then skip the Mesa call.
776 _mesa_PopAttrib(void)
778 struct gl_attrib_node
*attr
, *next
;
779 GET_CURRENT_CONTEXT(ctx
);
780 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
782 if (ctx
->AttribStackDepth
== 0) {
783 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
787 ctx
->AttribStackDepth
--;
788 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
792 if (MESA_VERBOSE
& VERBOSE_API
) {
793 _mesa_debug(ctx
, "glPopAttrib %s\n",
794 _mesa_lookup_enum_by_nr(attr
->kind
));
797 switch (attr
->kind
) {
798 case GL_ACCUM_BUFFER_BIT
:
800 const struct gl_accum_attrib
*accum
;
801 accum
= (const struct gl_accum_attrib
*) attr
->data
;
802 _mesa_ClearAccum(accum
->ClearColor
[0],
803 accum
->ClearColor
[1],
804 accum
->ClearColor
[2],
805 accum
->ClearColor
[3]);
808 case GL_COLOR_BUFFER_BIT
:
810 const struct gl_colorbuffer_attrib
*color
;
812 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
813 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
814 _mesa_ClearColor(color
->ClearColor
.f
[0],
815 color
->ClearColor
.f
[1],
816 color
->ClearColor
.f
[2],
817 color
->ClearColor
.f
[3]);
818 _mesa_IndexMask(color
->IndexMask
);
819 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
820 (GLboolean
) (color
->ColorMask
[1] != 0),
821 (GLboolean
) (color
->ColorMask
[2] != 0),
822 (GLboolean
) (color
->ColorMask
[3] != 0));
823 _mesa_DrawBuffer(color
->DrawBuffer
);
824 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
825 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
826 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
827 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
829 /* set same blend modes for all buffers */
830 _mesa_BlendFuncSeparateEXT(color
->SrcRGB
,
834 /* This special case is because glBlendEquationSeparateEXT
835 * cannot take GL_LOGIC_OP as a parameter.
837 if (color
->EquationRGB
== color
->EquationA
) {
838 _mesa_BlendEquation(color
->EquationRGB
);
841 _mesa_BlendEquationSeparateEXT(
845 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
846 color
->BlendColorUnclamped
[1],
847 color
->BlendColorUnclamped
[2],
848 color
->BlendColorUnclamped
[3]);
849 _mesa_LogicOp(color
->LogicOp
);
850 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
851 color
->ColorLogicOpEnabled
);
852 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
853 color
->IndexLogicOpEnabled
);
854 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
855 _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
856 _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
860 FLUSH_CURRENT( ctx
, 0 );
861 memcpy( &ctx
->Current
, attr
->data
,
862 sizeof(struct gl_current_attrib
) );
864 case GL_DEPTH_BUFFER_BIT
:
866 const struct gl_depthbuffer_attrib
*depth
;
867 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
868 _mesa_DepthFunc(depth
->Func
);
869 _mesa_ClearDepth(depth
->Clear
);
870 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
871 _mesa_DepthMask(depth
->Mask
);
876 const struct gl_enable_attrib
*enable
;
877 enable
= (const struct gl_enable_attrib
*) attr
->data
;
878 pop_enable_group(ctx
, enable
);
879 ctx
->NewState
|= _NEW_ALL
;
883 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
884 ctx
->NewState
|= _NEW_EVAL
;
888 const struct gl_fog_attrib
*fog
;
889 fog
= (const struct gl_fog_attrib
*) attr
->data
;
890 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
891 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
892 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
893 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
894 _mesa_Fogf(GL_FOG_END
, fog
->End
);
895 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
896 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
901 const struct gl_hint_attrib
*hint
;
902 hint
= (const struct gl_hint_attrib
*) attr
->data
;
903 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
904 hint
->PerspectiveCorrection
);
905 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
906 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
907 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
908 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
909 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
910 hint
->ClipVolumeClipping
);
911 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
912 hint
->TextureCompression
);
915 case GL_LIGHTING_BIT
:
918 const struct gl_light_attrib
*light
;
919 light
= (const struct gl_light_attrib
*) attr
->data
;
920 /* lighting enable */
921 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
922 /* per-light state */
923 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
924 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
926 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
927 const struct gl_light
*l
= &light
->Light
[i
];
928 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
929 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
930 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
931 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
932 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
933 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
935 GLfloat p
[4] = { 0 };
936 p
[0] = l
->SpotExponent
;
937 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
940 GLfloat p
[4] = { 0 };
941 p
[0] = l
->SpotCutoff
;
942 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
945 GLfloat p
[4] = { 0 };
946 p
[0] = l
->ConstantAttenuation
;
947 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
950 GLfloat p
[4] = { 0 };
951 p
[0] = l
->LinearAttenuation
;
952 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
955 GLfloat p
[4] = { 0 };
956 p
[0] = l
->QuadraticAttenuation
;
957 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
961 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
962 light
->Model
.Ambient
);
963 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
964 (GLfloat
) light
->Model
.LocalViewer
);
965 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
966 (GLfloat
) light
->Model
.TwoSide
);
967 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
968 (GLfloat
) light
->Model
.ColorControl
);
970 _mesa_ShadeModel(light
->ShadeModel
);
972 _mesa_ColorMaterial(light
->ColorMaterialFace
,
973 light
->ColorMaterialMode
);
974 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
975 light
->ColorMaterialEnabled
);
977 memcpy(&ctx
->Light
.Material
, &light
->Material
,
978 sizeof(struct gl_material
));
979 _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
984 const struct gl_line_attrib
*line
;
985 line
= (const struct gl_line_attrib
*) attr
->data
;
986 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
987 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
988 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
989 _mesa_LineWidth(line
->Width
);
993 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
995 case GL_PIXEL_MODE_BIT
:
996 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
997 /* XXX what other pixel state needs to be set by function calls? */
998 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
999 ctx
->NewState
|= _NEW_PIXEL
;
1003 const struct gl_point_attrib
*point
;
1004 point
= (const struct gl_point_attrib
*) attr
->data
;
1005 _mesa_PointSize(point
->Size
);
1006 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1007 if (ctx
->Extensions
.EXT_point_parameters
) {
1008 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1010 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1012 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1014 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1017 if (ctx
->Extensions
.NV_point_sprite
1018 || ctx
->Extensions
.ARB_point_sprite
) {
1020 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1021 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1022 (GLint
) point
->CoordReplace
[u
]);
1024 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1025 if (ctx
->Extensions
.NV_point_sprite
)
1026 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1027 ctx
->Point
.SpriteRMode
);
1028 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1029 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1033 case GL_POLYGON_BIT
:
1035 const struct gl_polygon_attrib
*polygon
;
1036 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1037 _mesa_CullFace(polygon
->CullFaceMode
);
1038 _mesa_FrontFace(polygon
->FrontFace
);
1039 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1040 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1041 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1042 polygon
->OffsetUnits
);
1043 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1044 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1045 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1046 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1047 polygon
->OffsetPoint
);
1048 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1049 polygon
->OffsetLine
);
1050 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1051 polygon
->OffsetFill
);
1054 case GL_POLYGON_STIPPLE_BIT
:
1055 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1056 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1057 if (ctx
->Driver
.PolygonStipple
)
1058 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1060 case GL_SCISSOR_BIT
:
1062 const struct gl_scissor_attrib
*scissor
;
1063 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1064 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1065 scissor
->Width
, scissor
->Height
);
1066 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1069 case GL_STENCIL_BUFFER_BIT
:
1071 const struct gl_stencil_attrib
*stencil
;
1072 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1073 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1074 _mesa_ClearStencil(stencil
->Clear
);
1075 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1076 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1077 stencil
->TestTwoSide
);
1078 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1079 ? GL_BACK
: GL_FRONT
);
1082 _mesa_StencilFuncSeparate(GL_FRONT
,
1083 stencil
->Function
[0],
1085 stencil
->ValueMask
[0]);
1086 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1087 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1088 stencil
->ZFailFunc
[0],
1089 stencil
->ZPassFunc
[0]);
1091 _mesa_StencilFuncSeparate(GL_BACK
,
1092 stencil
->Function
[1],
1094 stencil
->ValueMask
[1]);
1095 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1096 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1097 stencil
->ZFailFunc
[1],
1098 stencil
->ZPassFunc
[1]);
1101 case GL_TRANSFORM_BIT
:
1104 const struct gl_transform_attrib
*xform
;
1105 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1106 _mesa_MatrixMode(xform
->MatrixMode
);
1107 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1108 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1110 /* restore clip planes */
1111 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1112 const GLuint mask
= 1 << i
;
1113 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1114 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1115 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1116 !!(xform
->ClipPlanesEnabled
& mask
));
1117 if (ctx
->Driver
.ClipPlane
)
1118 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1121 /* normalize/rescale */
1122 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1123 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1124 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1125 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1126 ctx
->Transform
.RescaleNormals
);
1129 case GL_TEXTURE_BIT
:
1130 /* Take care of texture object reference counters */
1132 struct texture_state
*texstate
1133 = (struct texture_state
*) attr
->data
;
1134 pop_texture_group(ctx
, texstate
);
1135 ctx
->NewState
|= _NEW_TEXTURE
;
1138 case GL_VIEWPORT_BIT
:
1140 const struct gl_viewport_attrib
*vp
;
1141 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1142 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1143 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1146 case GL_MULTISAMPLE_BIT_ARB
:
1148 const struct gl_multisample_attrib
*ms
;
1149 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1151 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1155 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1157 GL_SAMPLE_COVERAGE
);
1159 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1160 ms
->SampleAlphaToCoverage
,
1161 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1163 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1164 ms
->SampleAlphaToOne
,
1165 GL_SAMPLE_ALPHA_TO_ONE
);
1167 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1168 ms
->SampleCoverageInvert
);
1173 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1186 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1190 copy_pixelstore(struct gl_context
*ctx
,
1191 struct gl_pixelstore_attrib
*dst
,
1192 const struct gl_pixelstore_attrib
*src
)
1194 dst
->Alignment
= src
->Alignment
;
1195 dst
->RowLength
= src
->RowLength
;
1196 dst
->SkipPixels
= src
->SkipPixels
;
1197 dst
->SkipRows
= src
->SkipRows
;
1198 dst
->ImageHeight
= src
->ImageHeight
;
1199 dst
->SkipImages
= src
->SkipImages
;
1200 dst
->SwapBytes
= src
->SwapBytes
;
1201 dst
->LsbFirst
= src
->LsbFirst
;
1202 dst
->Invert
= src
->Invert
;
1203 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1207 #define GL_CLIENT_PACK_BIT (1<<20)
1208 #define GL_CLIENT_UNPACK_BIT (1<<21)
1211 * Copy gl_array_object from src to dest.
1212 * 'dest' must be in an initialized state.
1215 copy_array_object(struct gl_context
*ctx
,
1216 struct gl_array_object
*dest
,
1217 struct gl_array_object
*src
)
1224 /* In theory must be the same anyway, but on recreate make sure it matches */
1225 dest
->ARBsemantics
= src
->ARBsemantics
;
1227 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1228 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1230 /* _Enabled must be the same than on push */
1231 dest
->_Enabled
= src
->_Enabled
;
1232 dest
->_MaxElement
= src
->_MaxElement
;
1236 * Copy gl_array_attrib from src to dest.
1237 * 'dest' must be in an initialized state.
1240 copy_array_attrib(struct gl_context
*ctx
,
1241 struct gl_array_attrib
*dest
,
1242 struct gl_array_attrib
*src
,
1246 /* skip DefaultArrayObj, Objects */
1247 dest
->ActiveTexture
= src
->ActiveTexture
;
1248 dest
->LockFirst
= src
->LockFirst
;
1249 dest
->LockCount
= src
->LockCount
;
1251 /* skip RebindArrays */
1254 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1256 /* skip ArrayBufferObj */
1257 /* skip ElementArrayBufferObj */
1261 * Save the content of src to dest.
1264 save_array_attrib(struct gl_context
*ctx
,
1265 struct gl_array_attrib
*dest
,
1266 struct gl_array_attrib
*src
)
1268 /* Set the Name, needed for restore, but do never overwrite.
1269 * Needs to match value in the object hash. */
1270 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1271 /* And copy all of the rest. */
1272 copy_array_attrib(ctx
, dest
, src
, false);
1274 /* Just reference them here */
1275 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1276 src
->ArrayBufferObj
);
1277 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1278 src
->ArrayObj
->ElementArrayBufferObj
);
1282 * Restore the content of src to dest.
1285 restore_array_attrib(struct gl_context
*ctx
,
1286 struct gl_array_attrib
*dest
,
1287 struct gl_array_attrib
*src
)
1289 /* The ARB_vertex_array_object spec says:
1291 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1292 * if array is not a name returned from a previous call to
1293 * GenVertexArrays, or if such a name has since been deleted with
1294 * DeleteVertexArrays."
1296 * Therefore popping a deleted VAO cannot magically recreate it.
1298 * The semantics of objects created using APPLE_vertex_array_objects behave
1299 * differently. These objects expect to be recreated by pop. Alas.
1301 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1302 && src
->ArrayObj
->ARBsemantics
);
1304 if (arb_vao
&& !_mesa_IsVertexArrayAPPLE(src
->ArrayObj
->Name
))
1307 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1309 /* Restore or recreate the buffer objects by the names ... */
1311 || src
->ArrayBufferObj
->Name
== 0
1312 || _mesa_IsBufferARB(src
->ArrayBufferObj
->Name
)) {
1313 /* ... and restore its content */
1314 copy_array_attrib(ctx
, dest
, src
, false);
1316 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1317 src
->ArrayBufferObj
->Name
);
1319 copy_array_attrib(ctx
, dest
, src
, true);
1323 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1324 || _mesa_IsBufferARB(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1325 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1326 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1328 /* Better safe than sorry?! */
1329 dest
->RebindArrays
= GL_TRUE
;
1331 /* FIXME: Should some bits in ctx->Array->NewState also be set
1332 * FIXME: here? It seems like it should be set to inclusive-or
1333 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1336 dest
->NewState
|= src
->ArrayObj
->_Enabled
| dest
->ArrayObj
->_Enabled
;
1340 * init/alloc the fields of 'attrib'.
1341 * Needs to the init part matching free_array_attrib_data below.
1344 init_array_attrib_data(struct gl_context
*ctx
,
1345 struct gl_array_attrib
*attrib
)
1347 /* Get a non driver gl_array_object. */
1348 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1349 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1353 * Free/unreference the fields of 'attrib' but don't delete it (that's
1354 * done later in the calling code).
1355 * Needs to the cleanup part matching init_array_attrib_data above.
1358 free_array_attrib_data(struct gl_context
*ctx
,
1359 struct gl_array_attrib
*attrib
)
1361 /* We use a non driver array object, so don't just unref since we would
1362 * end up using the drivers DeleteArrayObject function for deletion. */
1363 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1364 attrib
->ArrayObj
= 0;
1365 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1370 _mesa_PushClientAttrib(GLbitfield mask
)
1372 struct gl_attrib_node
*head
;
1374 GET_CURRENT_CONTEXT(ctx
);
1375 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1377 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1378 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1382 /* Build linked list of attribute nodes which save all attribute
1383 * groups specified by the mask.
1387 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1388 struct gl_pixelstore_attrib
*attr
;
1389 /* packing attribs */
1390 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1391 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1392 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1393 /* unpacking attribs */
1394 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1395 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1396 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1399 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1400 struct gl_array_attrib
*attr
;
1401 attr
= CALLOC_STRUCT( gl_array_attrib
);
1402 init_array_attrib_data(ctx
, attr
);
1403 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1404 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1407 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1408 ctx
->ClientAttribStackDepth
++;
1415 _mesa_PopClientAttrib(void)
1417 struct gl_attrib_node
*node
, *next
;
1419 GET_CURRENT_CONTEXT(ctx
);
1420 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1422 if (ctx
->ClientAttribStackDepth
== 0) {
1423 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1427 ctx
->ClientAttribStackDepth
--;
1428 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1431 switch (node
->kind
) {
1432 case GL_CLIENT_PACK_BIT
:
1434 struct gl_pixelstore_attrib
*store
=
1435 (struct gl_pixelstore_attrib
*) node
->data
;
1436 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1437 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1439 ctx
->NewState
|= _NEW_PACKUNPACK
;
1441 case GL_CLIENT_UNPACK_BIT
:
1443 struct gl_pixelstore_attrib
*store
=
1444 (struct gl_pixelstore_attrib
*) node
->data
;
1445 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1446 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1448 ctx
->NewState
|= _NEW_PACKUNPACK
;
1450 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1451 struct gl_array_attrib
* attr
=
1452 (struct gl_array_attrib
*) node
->data
;
1453 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1454 free_array_attrib_data(ctx
, attr
);
1455 ctx
->NewState
|= _NEW_ARRAY
;
1459 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1472 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1474 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1475 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1476 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1477 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1481 #endif /* FEATURE_attrib_stack */
1485 * Free any attribute state data that might be attached to the context.
1488 _mesa_free_attrib_data(struct gl_context
*ctx
)
1490 while (ctx
->AttribStackDepth
> 0) {
1491 struct gl_attrib_node
*attr
, *next
;
1493 ctx
->AttribStackDepth
--;
1494 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1497 if (attr
->kind
== GL_TEXTURE_BIT
) {
1498 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1500 /* clear references to the saved texture objects */
1501 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1502 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1503 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1506 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1509 /* any other chunks of state that requires special handling? */
1521 void _mesa_init_attrib( struct gl_context
*ctx
)
1523 /* Renderer and client attribute stacks */
1524 ctx
->AttribStackDepth
= 0;
1525 ctx
->ClientAttribStackDepth
= 0;