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
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
100 GLboolean Map2TextureCoord1
;
101 GLboolean Map2TextureCoord2
;
102 GLboolean Map2TextureCoord3
;
103 GLboolean Map2TextureCoord4
;
104 GLboolean Map2Vertex3
;
105 GLboolean Map2Vertex4
;
108 GLboolean PixelTexture
;
109 GLboolean PointSmooth
;
110 GLboolean PolygonOffsetPoint
;
111 GLboolean PolygonOffsetLine
;
112 GLboolean PolygonOffsetFill
;
113 GLboolean PolygonSmooth
;
114 GLboolean PolygonStipple
;
115 GLboolean RescaleNormals
;
118 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
119 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
122 GLboolean SampleCoverage
; /* GL_ARB_multisample */
123 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
125 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
126 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
128 /* GL_ARB_vertex_program */
129 GLboolean VertexProgram
;
130 GLboolean VertexProgramPointSize
;
131 GLboolean VertexProgramTwoSide
;
133 /* GL_ARB_point_sprite / GL_NV_point_sprite */
134 GLboolean PointSprite
;
135 GLboolean FragmentShaderATI
;
137 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
138 GLboolean sRGBEnabled
;
143 * Node for the attribute stack.
145 struct gl_attrib_node
149 struct gl_attrib_node
*next
;
155 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
159 struct gl_texture_attrib Texture
; /**< The usual context state */
161 /** to save per texture object state (wrap modes, filters, etc): */
162 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
165 * To save references to texture objects (so they don't get accidentally
166 * deleted while saved in the attribute stack).
168 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
170 /* We need to keep a reference to the shared state. That's where the
171 * default texture objects are kept. We don't want that state to be
172 * freed while the attribute stack contains pointers to any default
175 struct gl_shared_state
*SharedRef
;
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
);
208 if (MESA_VERBOSE
& VERBOSE_API
)
209 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
211 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
212 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
216 /* Build linked list of attribute nodes which save all attribute */
217 /* groups specified by the mask. */
220 if (mask
& GL_ACCUM_BUFFER_BIT
) {
221 struct gl_accum_attrib
*attr
;
222 attr
= MALLOC_STRUCT( gl_accum_attrib
);
223 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
224 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
227 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 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
234 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
235 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
238 if (mask
& GL_CURRENT_BIT
) {
239 struct gl_current_attrib
*attr
;
240 FLUSH_CURRENT( ctx
, 0 );
241 attr
= MALLOC_STRUCT( gl_current_attrib
);
242 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
243 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
246 if (mask
& GL_DEPTH_BUFFER_BIT
) {
247 struct gl_depthbuffer_attrib
*attr
;
248 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
249 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
250 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
253 if (mask
& GL_ENABLE_BIT
) {
254 struct gl_enable_attrib
*attr
;
256 attr
= MALLOC_STRUCT( gl_enable_attrib
);
257 /* Copy enable flags from all other attributes into the enable struct. */
258 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
259 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
260 attr
->Blend
= ctx
->Color
.BlendEnabled
;
261 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
262 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
263 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
264 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
265 attr
->DepthTest
= ctx
->Depth
.Test
;
266 attr
->Dither
= ctx
->Color
.DitherFlag
;
267 attr
->Fog
= ctx
->Fog
.Enabled
;
268 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
269 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
271 attr
->Lighting
= ctx
->Light
.Enabled
;
272 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
273 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
274 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
275 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
276 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
277 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
278 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
279 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
280 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
281 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
282 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
283 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
284 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
285 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
286 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
287 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
288 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
289 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
290 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
291 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
292 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
293 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
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_ARB_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
);
321 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
322 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
325 if (mask
& GL_EVAL_BIT
) {
326 struct gl_eval_attrib
*attr
;
327 attr
= MALLOC_STRUCT( gl_eval_attrib
);
328 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
329 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
332 if (mask
& GL_FOG_BIT
) {
333 struct gl_fog_attrib
*attr
;
334 attr
= MALLOC_STRUCT( gl_fog_attrib
);
335 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
336 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
339 if (mask
& GL_HINT_BIT
) {
340 struct gl_hint_attrib
*attr
;
341 attr
= MALLOC_STRUCT( gl_hint_attrib
);
342 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
343 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
346 if (mask
& GL_LIGHTING_BIT
) {
347 struct gl_light_attrib
*attr
;
348 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
349 attr
= MALLOC_STRUCT( gl_light_attrib
);
350 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
351 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
354 if (mask
& GL_LINE_BIT
) {
355 struct gl_line_attrib
*attr
;
356 attr
= MALLOC_STRUCT( gl_line_attrib
);
357 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
358 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
361 if (mask
& GL_LIST_BIT
) {
362 struct gl_list_attrib
*attr
;
363 attr
= MALLOC_STRUCT( gl_list_attrib
);
364 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
365 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
368 if (mask
& GL_PIXEL_MODE_BIT
) {
369 struct gl_pixel_attrib
*attr
;
370 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
371 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
372 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
373 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
374 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
377 if (mask
& GL_POINT_BIT
) {
378 struct gl_point_attrib
*attr
;
379 attr
= MALLOC_STRUCT( gl_point_attrib
);
380 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
381 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
384 if (mask
& GL_POLYGON_BIT
) {
385 struct gl_polygon_attrib
*attr
;
386 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
387 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
388 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
391 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
393 stipple
= malloc( 32*sizeof(GLuint
) );
394 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
395 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
398 if (mask
& GL_SCISSOR_BIT
) {
399 struct gl_scissor_attrib
*attr
;
400 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
401 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
402 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
405 if (mask
& GL_STENCIL_BUFFER_BIT
) {
406 struct gl_stencil_attrib
*attr
;
407 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
408 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
409 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
412 if (mask
& GL_TEXTURE_BIT
) {
413 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
417 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
421 _mesa_lock_context_textures(ctx
);
423 /* copy/save the bulk of texture state here */
424 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
426 /* Save references to the currently bound texture objects so they don't
427 * accidentally get deleted while referenced in the attribute stack.
429 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
430 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
431 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
432 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
436 /* copy state/contents of the currently bound texture objects */
437 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
438 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
439 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
440 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
444 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
446 _mesa_unlock_context_textures(ctx
);
448 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
451 if (mask
& GL_TRANSFORM_BIT
) {
452 struct gl_transform_attrib
*attr
;
453 attr
= MALLOC_STRUCT( gl_transform_attrib
);
454 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
455 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
458 if (mask
& GL_VIEWPORT_BIT
) {
459 struct gl_viewport_attrib
*attr
;
460 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
461 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
462 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
465 /* GL_ARB_multisample */
466 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
467 struct gl_multisample_attrib
*attr
;
468 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
469 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
470 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
474 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
475 ctx
->AttribStackDepth
++;
481 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
483 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
486 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
487 if ((VALUE) != (NEWVALUE)) { \
488 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
491 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
492 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
493 if (ctx
->Extensions
.EXT_draw_buffers2
) {
495 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
496 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
500 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
504 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
505 const GLuint mask
= 1 << i
;
506 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
507 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
508 !!(enable
->ClipPlanes
& mask
));
511 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
513 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
514 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
516 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
517 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
518 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
519 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
520 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
521 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
523 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
525 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
528 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
532 GL_MAP1_TEXTURE_COORD_1
);
533 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
534 GL_MAP1_TEXTURE_COORD_2
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
536 GL_MAP1_TEXTURE_COORD_3
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
538 GL_MAP1_TEXTURE_COORD_4
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
541 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
544 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
548 GL_MAP2_TEXTURE_COORD_1
);
549 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
550 GL_MAP2_TEXTURE_COORD_2
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
552 GL_MAP2_TEXTURE_COORD_3
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
554 GL_MAP2_TEXTURE_COORD_4
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
557 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
560 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
561 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
562 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
563 GL_RESCALE_NORMAL_EXT
);
564 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
565 enable
->RasterPositionUnclipped
,
566 GL_RASTER_POSITION_UNCLIPPED_IBM
);
567 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
569 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
570 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
573 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
574 GL_POLYGON_OFFSET_POINT
);
575 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
576 GL_POLYGON_OFFSET_LINE
);
577 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
578 GL_POLYGON_OFFSET_FILL
);
579 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
581 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
583 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
584 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
585 if (ctx
->Extensions
.EXT_stencil_two_side
) {
586 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
588 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
590 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
591 enable
->SampleAlphaToCoverage
,
592 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
593 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
594 enable
->SampleAlphaToOne
,
595 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
596 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
597 enable
->SampleCoverage
,
598 GL_SAMPLE_COVERAGE_ARB
);
599 /* GL_ARB_vertex_program */
600 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
601 enable
->VertexProgram
,
602 GL_VERTEX_PROGRAM_ARB
);
603 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
604 enable
->VertexProgramPointSize
,
605 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
606 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
607 enable
->VertexProgramTwoSide
,
608 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
610 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
611 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
612 GL_FRAMEBUFFER_SRGB
);
614 /* texture unit enables */
615 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
616 const GLbitfield enabled
= enable
->Texture
[i
];
617 const GLbitfield genEnabled
= enable
->TexGen
[i
];
619 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
620 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
622 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
623 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
624 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
625 if (ctx
->Extensions
.NV_texture_rectangle
) {
626 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
627 !!(enabled
& TEXTURE_RECT_BIT
));
629 if (ctx
->Extensions
.ARB_texture_cube_map
) {
630 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
631 !!(enabled
& TEXTURE_CUBE_BIT
));
633 if (ctx
->Extensions
.MESA_texture_array
) {
634 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
635 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
636 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
637 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
641 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
642 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
643 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
644 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
645 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
646 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
650 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
655 * Pop/restore texture attribute/group state.
658 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
662 _mesa_lock_context_textures(ctx
);
664 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
665 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
668 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
669 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
670 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
671 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
672 if (ctx
->Extensions
.ARB_texture_cube_map
) {
673 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
674 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
676 if (ctx
->Extensions
.NV_texture_rectangle
) {
677 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
678 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
680 if (ctx
->Extensions
.MESA_texture_array
) {
681 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
682 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
683 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
684 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
686 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
687 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
688 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
689 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
690 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
691 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
692 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
693 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
694 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
695 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
696 /* Eye plane done differently to avoid re-transformation */
698 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
699 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
700 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
701 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
702 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
703 if (ctx
->Driver
.TexGen
) {
704 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
705 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
706 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
707 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
710 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
711 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
712 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
713 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
714 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
716 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
717 unit
->Combine
.ModeRGB
);
718 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
719 unit
->Combine
.ModeA
);
721 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
723 for (i
= 0; i
< n
; i
++) {
724 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
725 unit
->Combine
.SourceRGB
[i
]);
726 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
727 unit
->Combine
.SourceA
[i
]);
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
729 unit
->Combine
.OperandRGB
[i
]);
730 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
731 unit
->Combine
.OperandA
[i
]);
734 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
735 1 << unit
->Combine
.ScaleShiftRGB
);
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
737 1 << unit
->Combine
.ScaleShiftA
);
739 /* Restore texture object state for each target */
740 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
741 const struct gl_texture_object
*obj
= NULL
;
742 const struct gl_sampler_object
*samp
;
745 obj
= &texstate
->SavedObj
[u
][tgt
];
747 /* don't restore state for unsupported targets to prevent
750 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
751 !ctx
->Extensions
.ARB_texture_cube_map
) {
754 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
755 !ctx
->Extensions
.NV_texture_rectangle
) {
758 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
759 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
760 !ctx
->Extensions
.MESA_texture_array
) {
763 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
764 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
766 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
768 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
771 target
= obj
->Target
;
773 _mesa_BindTexture(target
, obj
->Name
);
775 samp
= &obj
->Sampler
;
777 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
778 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
779 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
780 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
781 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
782 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
783 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
784 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
785 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
786 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
787 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
788 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
789 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
790 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
791 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
792 samp
->MaxAnisotropy
);
794 if (ctx
->Extensions
.ARB_shadow
) {
795 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
797 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
800 if (ctx
->Extensions
.ARB_depth_texture
)
801 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
804 /* remove saved references to the texture objects */
805 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
806 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
810 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
812 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
814 _mesa_unlock_context_textures(ctx
);
819 * This function is kind of long just because we have to call a lot
820 * of device driver functions to update device driver state.
822 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
823 * in order to restore GL state. This isn't terribly efficient but it
824 * ensures that dirty flags and any derived state gets updated correctly.
825 * We could at least check if the value to restore equals the current value
826 * and then skip the Mesa call.
829 _mesa_PopAttrib(void)
831 struct gl_attrib_node
*attr
, *next
;
832 GET_CURRENT_CONTEXT(ctx
);
833 FLUSH_VERTICES(ctx
, 0);
835 if (ctx
->AttribStackDepth
== 0) {
836 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
840 ctx
->AttribStackDepth
--;
841 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
845 if (MESA_VERBOSE
& VERBOSE_API
) {
846 _mesa_debug(ctx
, "glPopAttrib %s\n",
847 _mesa_lookup_enum_by_nr(attr
->kind
));
850 switch (attr
->kind
) {
851 case GL_ACCUM_BUFFER_BIT
:
853 const struct gl_accum_attrib
*accum
;
854 accum
= (const struct gl_accum_attrib
*) attr
->data
;
855 _mesa_ClearAccum(accum
->ClearColor
[0],
856 accum
->ClearColor
[1],
857 accum
->ClearColor
[2],
858 accum
->ClearColor
[3]);
861 case GL_COLOR_BUFFER_BIT
:
863 const struct gl_colorbuffer_attrib
*color
;
865 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
866 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
867 _mesa_ClearColor(color
->ClearColor
.f
[0],
868 color
->ClearColor
.f
[1],
869 color
->ClearColor
.f
[2],
870 color
->ClearColor
.f
[3]);
871 _mesa_IndexMask(color
->IndexMask
);
872 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
873 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
874 (GLboolean
) (color
->ColorMask
[0][1] != 0),
875 (GLboolean
) (color
->ColorMask
[0][2] != 0),
876 (GLboolean
) (color
->ColorMask
[0][3] != 0));
880 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
882 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
883 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
884 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
885 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
889 /* Need to determine if more than one color output is
890 * specified. If so, call glDrawBuffersARB, else call
891 * glDrawBuffer(). This is a subtle, but essential point
892 * since GL_FRONT (for example) is illegal for the former
893 * function, but legal for the later.
895 GLboolean multipleBuffers
= GL_FALSE
;
898 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
899 if (color
->DrawBuffer
[i
] != GL_NONE
) {
900 multipleBuffers
= GL_TRUE
;
904 /* Call the API_level functions, not _mesa_drawbuffers()
905 * since we need to do error checking on the pop'd
907 * Ex: if GL_FRONT were pushed, but we're popping with a
908 * user FBO bound, GL_FRONT will be illegal and we'll need
909 * to record that error. Per OpenGL ARB decision.
912 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
,
915 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
917 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
918 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
919 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
920 if (ctx
->Extensions
.EXT_draw_buffers2
) {
922 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
923 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
924 (color
->BlendEnabled
>> i
) & 1);
928 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
931 if (ctx
->Color
._BlendFuncPerBuffer
||
932 ctx
->Color
._BlendEquationPerBuffer
) {
933 /* set blend per buffer */
935 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
936 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
937 color
->Blend
[buf
].DstRGB
,
938 color
->Blend
[buf
].SrcA
,
939 color
->Blend
[buf
].DstA
);
940 _mesa_BlendEquationSeparateiARB(buf
,
941 color
->Blend
[buf
].EquationRGB
,
942 color
->Blend
[buf
].EquationA
);
946 /* set same blend modes for all buffers */
947 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
948 color
->Blend
[0].DstRGB
,
949 color
->Blend
[0].SrcA
,
950 color
->Blend
[0].DstA
);
951 /* This special case is because glBlendEquationSeparateEXT
952 * cannot take GL_LOGIC_OP as a parameter.
954 if (color
->Blend
[0].EquationRGB
==
955 color
->Blend
[0].EquationA
) {
956 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
959 _mesa_BlendEquationSeparate(
960 color
->Blend
[0].EquationRGB
,
961 color
->Blend
[0].EquationA
);
964 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
965 color
->BlendColorUnclamped
[1],
966 color
->BlendColorUnclamped
[2],
967 color
->BlendColorUnclamped
[3]);
968 _mesa_LogicOp(color
->LogicOp
);
969 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
970 color
->ColorLogicOpEnabled
);
971 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
972 color
->IndexLogicOpEnabled
);
973 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
974 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
975 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
977 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
978 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
979 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
983 FLUSH_CURRENT( ctx
, 0 );
984 memcpy( &ctx
->Current
, attr
->data
,
985 sizeof(struct gl_current_attrib
) );
987 case GL_DEPTH_BUFFER_BIT
:
989 const struct gl_depthbuffer_attrib
*depth
;
990 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
991 _mesa_DepthFunc(depth
->Func
);
992 _mesa_ClearDepth(depth
->Clear
);
993 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
994 _mesa_DepthMask(depth
->Mask
);
999 const struct gl_enable_attrib
*enable
;
1000 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1001 pop_enable_group(ctx
, enable
);
1002 ctx
->NewState
|= _NEW_ALL
;
1006 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1007 ctx
->NewState
|= _NEW_EVAL
;
1011 const struct gl_fog_attrib
*fog
;
1012 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1013 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1014 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1015 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1016 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1017 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1018 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1019 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1024 const struct gl_hint_attrib
*hint
;
1025 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1026 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1027 hint
->PerspectiveCorrection
);
1028 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1029 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1030 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1031 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1032 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1033 hint
->ClipVolumeClipping
);
1034 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1035 hint
->TextureCompression
);
1038 case GL_LIGHTING_BIT
:
1041 const struct gl_light_attrib
*light
;
1042 light
= (const struct gl_light_attrib
*) attr
->data
;
1043 /* lighting enable */
1044 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1045 /* per-light state */
1046 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1047 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1049 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1050 const struct gl_light
*l
= &light
->Light
[i
];
1051 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1052 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1053 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1054 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1055 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1056 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1058 GLfloat p
[4] = { 0 };
1059 p
[0] = l
->SpotExponent
;
1060 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1063 GLfloat p
[4] = { 0 };
1064 p
[0] = l
->SpotCutoff
;
1065 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1068 GLfloat p
[4] = { 0 };
1069 p
[0] = l
->ConstantAttenuation
;
1070 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1073 GLfloat p
[4] = { 0 };
1074 p
[0] = l
->LinearAttenuation
;
1075 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1078 GLfloat p
[4] = { 0 };
1079 p
[0] = l
->QuadraticAttenuation
;
1080 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1084 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1085 light
->Model
.Ambient
);
1086 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1087 (GLfloat
) light
->Model
.LocalViewer
);
1088 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1089 (GLfloat
) light
->Model
.TwoSide
);
1090 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1091 (GLfloat
) light
->Model
.ColorControl
);
1093 _mesa_ShadeModel(light
->ShadeModel
);
1094 /* color material */
1095 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1096 light
->ColorMaterialMode
);
1097 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1098 light
->ColorMaterialEnabled
);
1100 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1101 sizeof(struct gl_material
));
1102 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1107 const struct gl_line_attrib
*line
;
1108 line
= (const struct gl_line_attrib
*) attr
->data
;
1109 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1110 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1111 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1112 _mesa_LineWidth(line
->Width
);
1116 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1118 case GL_PIXEL_MODE_BIT
:
1119 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1120 /* XXX what other pixel state needs to be set by function calls? */
1121 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1122 ctx
->NewState
|= _NEW_PIXEL
;
1126 const struct gl_point_attrib
*point
;
1127 point
= (const struct gl_point_attrib
*) attr
->data
;
1128 _mesa_PointSize(point
->Size
);
1129 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1130 if (ctx
->Extensions
.EXT_point_parameters
) {
1131 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1133 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1135 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1137 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1140 if (ctx
->Extensions
.NV_point_sprite
1141 || ctx
->Extensions
.ARB_point_sprite
) {
1143 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1144 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1145 (GLint
) point
->CoordReplace
[u
]);
1147 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1148 if (ctx
->Extensions
.NV_point_sprite
)
1149 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1150 ctx
->Point
.SpriteRMode
);
1152 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1153 || ctx
->API
== API_OPENGL_CORE
)
1154 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1155 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1159 case GL_POLYGON_BIT
:
1161 const struct gl_polygon_attrib
*polygon
;
1162 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1163 _mesa_CullFace(polygon
->CullFaceMode
);
1164 _mesa_FrontFace(polygon
->FrontFace
);
1165 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1166 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1167 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1168 polygon
->OffsetUnits
);
1169 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1170 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1171 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1172 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1173 polygon
->OffsetPoint
);
1174 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1175 polygon
->OffsetLine
);
1176 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1177 polygon
->OffsetFill
);
1180 case GL_POLYGON_STIPPLE_BIT
:
1181 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1182 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1183 if (ctx
->Driver
.PolygonStipple
)
1184 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1186 case GL_SCISSOR_BIT
:
1188 const struct gl_scissor_attrib
*scissor
;
1189 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1190 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1191 scissor
->Width
, scissor
->Height
);
1192 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1195 case GL_STENCIL_BUFFER_BIT
:
1197 const struct gl_stencil_attrib
*stencil
;
1198 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1199 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1200 _mesa_ClearStencil(stencil
->Clear
);
1201 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1202 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1203 stencil
->TestTwoSide
);
1204 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1205 ? GL_BACK
: GL_FRONT
);
1208 _mesa_StencilFuncSeparate(GL_FRONT
,
1209 stencil
->Function
[0],
1211 stencil
->ValueMask
[0]);
1212 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1213 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1214 stencil
->ZFailFunc
[0],
1215 stencil
->ZPassFunc
[0]);
1217 _mesa_StencilFuncSeparate(GL_BACK
,
1218 stencil
->Function
[1],
1220 stencil
->ValueMask
[1]);
1221 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1222 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1223 stencil
->ZFailFunc
[1],
1224 stencil
->ZPassFunc
[1]);
1227 case GL_TRANSFORM_BIT
:
1230 const struct gl_transform_attrib
*xform
;
1231 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1232 _mesa_MatrixMode(xform
->MatrixMode
);
1233 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1234 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1236 /* restore clip planes */
1237 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1238 const GLuint mask
= 1 << i
;
1239 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1240 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1241 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1242 !!(xform
->ClipPlanesEnabled
& mask
));
1243 if (ctx
->Driver
.ClipPlane
)
1244 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1247 /* normalize/rescale */
1248 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1249 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1250 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1251 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1252 ctx
->Transform
.RescaleNormals
);
1253 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1254 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1255 ctx
->Transform
.DepthClamp
);
1258 case GL_TEXTURE_BIT
:
1260 struct texture_state
*texstate
1261 = (struct texture_state
*) attr
->data
;
1262 pop_texture_group(ctx
, texstate
);
1263 ctx
->NewState
|= _NEW_TEXTURE
;
1266 case GL_VIEWPORT_BIT
:
1268 const struct gl_viewport_attrib
*vp
;
1269 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1270 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1271 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1274 case GL_MULTISAMPLE_BIT_ARB
:
1276 const struct gl_multisample_attrib
*ms
;
1277 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1279 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1283 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1285 GL_SAMPLE_COVERAGE
);
1287 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1288 ms
->SampleAlphaToCoverage
,
1289 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1291 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1292 ms
->SampleAlphaToOne
,
1293 GL_SAMPLE_ALPHA_TO_ONE
);
1295 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1296 ms
->SampleCoverageInvert
);
1301 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1314 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1318 copy_pixelstore(struct gl_context
*ctx
,
1319 struct gl_pixelstore_attrib
*dst
,
1320 const struct gl_pixelstore_attrib
*src
)
1322 dst
->Alignment
= src
->Alignment
;
1323 dst
->RowLength
= src
->RowLength
;
1324 dst
->SkipPixels
= src
->SkipPixels
;
1325 dst
->SkipRows
= src
->SkipRows
;
1326 dst
->ImageHeight
= src
->ImageHeight
;
1327 dst
->SkipImages
= src
->SkipImages
;
1328 dst
->SwapBytes
= src
->SwapBytes
;
1329 dst
->LsbFirst
= src
->LsbFirst
;
1330 dst
->Invert
= src
->Invert
;
1331 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1335 #define GL_CLIENT_PACK_BIT (1<<20)
1336 #define GL_CLIENT_UNPACK_BIT (1<<21)
1339 * Copy gl_array_object from src to dest.
1340 * 'dest' must be in an initialized state.
1343 copy_array_object(struct gl_context
*ctx
,
1344 struct gl_array_object
*dest
,
1345 struct gl_array_object
*src
)
1352 /* In theory must be the same anyway, but on recreate make sure it matches */
1353 dest
->ARBsemantics
= src
->ARBsemantics
;
1355 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1356 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1358 /* _Enabled must be the same than on push */
1359 dest
->_Enabled
= src
->_Enabled
;
1360 dest
->_MaxElement
= src
->_MaxElement
;
1364 * Copy gl_array_attrib from src to dest.
1365 * 'dest' must be in an initialized state.
1368 copy_array_attrib(struct gl_context
*ctx
,
1369 struct gl_array_attrib
*dest
,
1370 struct gl_array_attrib
*src
,
1374 /* skip DefaultArrayObj, Objects */
1375 dest
->ActiveTexture
= src
->ActiveTexture
;
1376 dest
->LockFirst
= src
->LockFirst
;
1377 dest
->LockCount
= src
->LockCount
;
1378 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1379 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1380 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1381 dest
->RestartIndex
= src
->RestartIndex
;
1382 dest
->_RestartIndex
= src
->_RestartIndex
;
1384 /* skip RebindArrays */
1387 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1389 /* skip ArrayBufferObj */
1390 /* skip ElementArrayBufferObj */
1394 * Save the content of src to dest.
1397 save_array_attrib(struct gl_context
*ctx
,
1398 struct gl_array_attrib
*dest
,
1399 struct gl_array_attrib
*src
)
1401 /* Set the Name, needed for restore, but do never overwrite.
1402 * Needs to match value in the object hash. */
1403 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1404 /* And copy all of the rest. */
1405 copy_array_attrib(ctx
, dest
, src
, false);
1407 /* Just reference them here */
1408 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1409 src
->ArrayBufferObj
);
1410 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1411 src
->ArrayObj
->ElementArrayBufferObj
);
1415 * Restore the content of src to dest.
1418 restore_array_attrib(struct gl_context
*ctx
,
1419 struct gl_array_attrib
*dest
,
1420 struct gl_array_attrib
*src
)
1422 /* The ARB_vertex_array_object spec says:
1424 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1425 * if array is not a name returned from a previous call to
1426 * GenVertexArrays, or if such a name has since been deleted with
1427 * DeleteVertexArrays."
1429 * Therefore popping a deleted VAO cannot magically recreate it.
1431 * The semantics of objects created using APPLE_vertex_array_objects behave
1432 * differently. These objects expect to be recreated by pop. Alas.
1434 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1435 && src
->ArrayObj
->ARBsemantics
);
1437 if (arb_vao
&& !_mesa_IsVertexArray(src
->ArrayObj
->Name
))
1440 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1442 /* Restore or recreate the buffer objects by the names ... */
1444 || src
->ArrayBufferObj
->Name
== 0
1445 || _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1446 /* ... and restore its content */
1447 copy_array_attrib(ctx
, dest
, src
, false);
1449 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1450 src
->ArrayBufferObj
->Name
);
1452 copy_array_attrib(ctx
, dest
, src
, true);
1456 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1457 || _mesa_IsBuffer(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1458 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1459 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1463 * init/alloc the fields of 'attrib'.
1464 * Needs to the init part matching free_array_attrib_data below.
1467 init_array_attrib_data(struct gl_context
*ctx
,
1468 struct gl_array_attrib
*attrib
)
1470 /* Get a non driver gl_array_object. */
1471 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1472 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1476 * Free/unreference the fields of 'attrib' but don't delete it (that's
1477 * done later in the calling code).
1478 * Needs to the cleanup part matching init_array_attrib_data above.
1481 free_array_attrib_data(struct gl_context
*ctx
,
1482 struct gl_array_attrib
*attrib
)
1484 /* We use a non driver array object, so don't just unref since we would
1485 * end up using the drivers DeleteArrayObject function for deletion. */
1486 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1487 attrib
->ArrayObj
= 0;
1488 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1493 _mesa_PushClientAttrib(GLbitfield mask
)
1495 struct gl_attrib_node
*head
;
1497 GET_CURRENT_CONTEXT(ctx
);
1499 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1500 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1504 /* Build linked list of attribute nodes which save all attribute
1505 * groups specified by the mask.
1509 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1510 struct gl_pixelstore_attrib
*attr
;
1511 /* packing attribs */
1512 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1513 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1514 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1515 /* unpacking attribs */
1516 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1517 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1518 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1521 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1522 struct gl_array_attrib
*attr
;
1523 attr
= CALLOC_STRUCT( gl_array_attrib
);
1524 init_array_attrib_data(ctx
, attr
);
1525 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1526 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1529 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1530 ctx
->ClientAttribStackDepth
++;
1537 _mesa_PopClientAttrib(void)
1539 struct gl_attrib_node
*node
, *next
;
1541 GET_CURRENT_CONTEXT(ctx
);
1542 FLUSH_VERTICES(ctx
, 0);
1544 if (ctx
->ClientAttribStackDepth
== 0) {
1545 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1549 ctx
->ClientAttribStackDepth
--;
1550 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1553 switch (node
->kind
) {
1554 case GL_CLIENT_PACK_BIT
:
1556 struct gl_pixelstore_attrib
*store
=
1557 (struct gl_pixelstore_attrib
*) node
->data
;
1558 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1559 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1561 ctx
->NewState
|= _NEW_PACKUNPACK
;
1563 case GL_CLIENT_UNPACK_BIT
:
1565 struct gl_pixelstore_attrib
*store
=
1566 (struct gl_pixelstore_attrib
*) node
->data
;
1567 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1568 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1570 ctx
->NewState
|= _NEW_PACKUNPACK
;
1572 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1573 struct gl_array_attrib
* attr
=
1574 (struct gl_array_attrib
*) node
->data
;
1575 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1576 free_array_attrib_data(ctx
, attr
);
1577 ctx
->NewState
|= _NEW_ARRAY
;
1581 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1594 * Free any attribute state data that might be attached to the context.
1597 _mesa_free_attrib_data(struct gl_context
*ctx
)
1599 while (ctx
->AttribStackDepth
> 0) {
1600 struct gl_attrib_node
*attr
, *next
;
1602 ctx
->AttribStackDepth
--;
1603 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1606 if (attr
->kind
== GL_TEXTURE_BIT
) {
1607 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1609 /* clear references to the saved texture objects */
1610 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1611 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1612 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1615 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1618 /* any other chunks of state that requires special handling? */
1630 void _mesa_init_attrib( struct gl_context
*ctx
)
1632 /* Renderer and client attribute stacks */
1633 ctx
->AttribStackDepth
= 0;
1634 ctx
->ClientAttribStackDepth
= 0;