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 / GL_NV_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
);
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
) {
230 struct gl_colorbuffer_attrib
*attr
;
231 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
232 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
233 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
234 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
235 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
236 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
239 if (mask
& GL_CURRENT_BIT
) {
240 struct gl_current_attrib
*attr
;
241 FLUSH_CURRENT( ctx
, 0 );
242 attr
= MALLOC_STRUCT( gl_current_attrib
);
243 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
244 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
247 if (mask
& GL_DEPTH_BUFFER_BIT
) {
248 struct gl_depthbuffer_attrib
*attr
;
249 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
250 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
251 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
254 if (mask
& GL_ENABLE_BIT
) {
255 struct gl_enable_attrib
*attr
;
257 attr
= MALLOC_STRUCT( gl_enable_attrib
);
258 /* Copy enable flags from all other attributes into the enable struct. */
259 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
260 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
261 attr
->Blend
= ctx
->Color
.BlendEnabled
;
262 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
263 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
264 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
265 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
266 attr
->DepthTest
= ctx
->Depth
.Test
;
267 attr
->Dither
= ctx
->Color
.DitherFlag
;
268 attr
->Fog
= ctx
->Fog
.Enabled
;
269 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
270 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
272 attr
->Lighting
= ctx
->Light
.Enabled
;
273 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
274 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
275 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
276 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
277 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
278 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
279 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
280 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
281 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
282 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
283 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
284 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
285 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
286 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
287 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
288 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
289 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
290 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
291 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
292 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
293 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
294 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
295 attr
->Normalize
= ctx
->Transform
.Normalize
;
296 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
297 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
298 attr
->PointSprite
= ctx
->Point
.PointSprite
;
299 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
300 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
301 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
302 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
303 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
304 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
305 attr
->Scissor
= ctx
->Scissor
.Enabled
;
306 attr
->Stencil
= ctx
->Stencil
.Enabled
;
307 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
308 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
309 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
310 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
311 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
312 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
313 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
314 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
316 /* GL_NV_vertex_program */
317 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
318 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
319 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
320 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
322 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
323 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
326 if (mask
& GL_EVAL_BIT
) {
327 struct gl_eval_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_eval_attrib
);
329 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
330 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
333 if (mask
& GL_FOG_BIT
) {
334 struct gl_fog_attrib
*attr
;
335 attr
= MALLOC_STRUCT( gl_fog_attrib
);
336 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
337 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
340 if (mask
& GL_HINT_BIT
) {
341 struct gl_hint_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_hint_attrib
);
343 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
344 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
347 if (mask
& GL_LIGHTING_BIT
) {
348 struct gl_light_attrib
*attr
;
349 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
350 attr
= MALLOC_STRUCT( gl_light_attrib
);
351 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
352 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
355 if (mask
& GL_LINE_BIT
) {
356 struct gl_line_attrib
*attr
;
357 attr
= MALLOC_STRUCT( gl_line_attrib
);
358 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
359 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
362 if (mask
& GL_LIST_BIT
) {
363 struct gl_list_attrib
*attr
;
364 attr
= MALLOC_STRUCT( gl_list_attrib
);
365 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
366 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
369 if (mask
& GL_PIXEL_MODE_BIT
) {
370 struct gl_pixel_attrib
*attr
;
371 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
372 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
373 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
374 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
375 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
378 if (mask
& GL_POINT_BIT
) {
379 struct gl_point_attrib
*attr
;
380 attr
= MALLOC_STRUCT( gl_point_attrib
);
381 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
382 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
385 if (mask
& GL_POLYGON_BIT
) {
386 struct gl_polygon_attrib
*attr
;
387 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
388 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
389 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
392 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
394 stipple
= malloc( 32*sizeof(GLuint
) );
395 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
396 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
399 if (mask
& GL_SCISSOR_BIT
) {
400 struct gl_scissor_attrib
*attr
;
401 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
402 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
403 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
406 if (mask
& GL_STENCIL_BUFFER_BIT
) {
407 struct gl_stencil_attrib
*attr
;
408 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
409 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
410 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
413 if (mask
& GL_TEXTURE_BIT
) {
414 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
418 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
422 _mesa_lock_context_textures(ctx
);
424 /* copy/save the bulk of texture state here */
425 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
427 /* Save references to the currently bound texture objects so they don't
428 * accidentally get deleted while referenced in the attribute stack.
430 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
431 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
432 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
433 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
437 /* copy state/contents of the currently bound texture objects */
438 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
439 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
440 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
441 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
445 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
447 _mesa_unlock_context_textures(ctx
);
449 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
452 if (mask
& GL_TRANSFORM_BIT
) {
453 struct gl_transform_attrib
*attr
;
454 attr
= MALLOC_STRUCT( gl_transform_attrib
);
455 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
456 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
459 if (mask
& GL_VIEWPORT_BIT
) {
460 struct gl_viewport_attrib
*attr
;
461 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
462 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
463 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
466 /* GL_ARB_multisample */
467 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
468 struct gl_multisample_attrib
*attr
;
469 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
470 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
471 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
475 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
476 ctx
->AttribStackDepth
++;
482 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
484 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
487 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
488 if ((VALUE) != (NEWVALUE)) { \
489 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
492 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
493 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
494 if (ctx
->Extensions
.EXT_draw_buffers2
) {
496 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
497 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
501 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
505 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
506 const GLuint mask
= 1 << i
;
507 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
508 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
509 !!(enable
->ClipPlanes
& mask
));
512 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
514 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
515 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
517 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
518 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
519 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
520 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
521 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
522 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
524 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
526 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
529 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
532 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
533 GL_MAP1_TEXTURE_COORD_1
);
534 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
535 GL_MAP1_TEXTURE_COORD_2
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
537 GL_MAP1_TEXTURE_COORD_3
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
539 GL_MAP1_TEXTURE_COORD_4
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
542 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
545 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
548 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
549 GL_MAP2_TEXTURE_COORD_1
);
550 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
551 GL_MAP2_TEXTURE_COORD_2
);
552 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
553 GL_MAP2_TEXTURE_COORD_3
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
555 GL_MAP2_TEXTURE_COORD_4
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
558 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
561 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
562 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
563 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
564 GL_RESCALE_NORMAL_EXT
);
565 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
566 enable
->RasterPositionUnclipped
,
567 GL_RASTER_POSITION_UNCLIPPED_IBM
);
568 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
570 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
571 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
574 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
575 GL_POLYGON_OFFSET_POINT
);
576 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
577 GL_POLYGON_OFFSET_LINE
);
578 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
579 GL_POLYGON_OFFSET_FILL
);
580 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
582 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
584 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
585 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
586 if (ctx
->Extensions
.EXT_stencil_two_side
) {
587 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
589 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
591 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
592 enable
->SampleAlphaToCoverage
,
593 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
594 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
595 enable
->SampleAlphaToOne
,
596 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
597 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
598 enable
->SampleCoverage
,
599 GL_SAMPLE_COVERAGE_ARB
);
600 /* GL_ARB_vertex_program, GL_NV_vertex_program */
601 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
602 enable
->VertexProgram
,
603 GL_VERTEX_PROGRAM_ARB
);
604 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
605 enable
->VertexProgramPointSize
,
606 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
607 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
608 enable
->VertexProgramTwoSide
,
609 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
611 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
612 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
613 GL_FRAMEBUFFER_SRGB
);
615 /* texture unit enables */
616 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
617 const GLbitfield enabled
= enable
->Texture
[i
];
618 const GLbitfield genEnabled
= enable
->TexGen
[i
];
620 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
621 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
623 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
624 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
625 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
626 if (ctx
->Extensions
.NV_texture_rectangle
) {
627 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
628 !!(enabled
& TEXTURE_RECT_BIT
));
630 if (ctx
->Extensions
.ARB_texture_cube_map
) {
631 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
632 !!(enabled
& TEXTURE_CUBE_BIT
));
634 if (ctx
->Extensions
.MESA_texture_array
) {
635 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
636 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
637 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
638 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
642 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
643 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
644 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
645 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
646 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
647 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
651 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
656 * Pop/restore texture attribute/group state.
659 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
663 _mesa_lock_context_textures(ctx
);
665 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
666 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
669 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
670 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
671 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
672 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
673 if (ctx
->Extensions
.ARB_texture_cube_map
) {
674 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
675 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
677 if (ctx
->Extensions
.NV_texture_rectangle
) {
678 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
679 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
681 if (ctx
->Extensions
.MESA_texture_array
) {
682 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
683 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
684 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
685 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
688 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
689 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
690 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
691 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
692 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
693 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
694 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
695 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
696 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
697 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
698 /* Eye plane done differently to avoid re-transformation */
700 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
701 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
702 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
703 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
704 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
705 if (ctx
->Driver
.TexGen
) {
706 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
707 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
708 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
709 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
713 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
714 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
715 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
716 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
718 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
719 unit
->Combine
.ModeRGB
);
720 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
721 unit
->Combine
.ModeA
);
723 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
725 for (i
= 0; i
< n
; i
++) {
726 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
727 unit
->Combine
.SourceRGB
[i
]);
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
729 unit
->Combine
.SourceA
[i
]);
730 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
731 unit
->Combine
.OperandRGB
[i
]);
732 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
733 unit
->Combine
.OperandA
[i
]);
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
737 1 << unit
->Combine
.ScaleShiftRGB
);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
739 1 << unit
->Combine
.ScaleShiftA
);
741 /* Restore texture object state for each target */
742 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
743 const struct gl_texture_object
*obj
= NULL
;
744 const struct gl_sampler_object
*samp
;
747 obj
= &texstate
->SavedObj
[u
][tgt
];
749 /* don't restore state for unsupported targets to prevent
752 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
753 !ctx
->Extensions
.ARB_texture_cube_map
) {
756 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
757 !ctx
->Extensions
.NV_texture_rectangle
) {
760 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
761 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
762 !ctx
->Extensions
.MESA_texture_array
) {
765 else if (obj
->Target
== GL_TEXTURE_BUFFER
)
767 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
770 target
= obj
->Target
;
772 _mesa_BindTexture(target
, obj
->Name
);
774 samp
= &obj
->Sampler
;
776 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
777 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
778 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
779 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
780 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
781 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
782 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
783 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
784 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
785 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
786 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
787 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
788 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
789 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
790 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
791 samp
->MaxAnisotropy
);
793 if (ctx
->Extensions
.ARB_shadow
) {
794 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
796 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
799 if (ctx
->Extensions
.ARB_depth_texture
)
800 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
803 /* remove saved references to the texture objects */
804 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
805 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
809 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
811 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
813 _mesa_unlock_context_textures(ctx
);
818 * This function is kind of long just because we have to call a lot
819 * of device driver functions to update device driver state.
821 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
822 * in order to restore GL state. This isn't terribly efficient but it
823 * ensures that dirty flags and any derived state gets updated correctly.
824 * We could at least check if the value to restore equals the current value
825 * and then skip the Mesa call.
828 _mesa_PopAttrib(void)
830 struct gl_attrib_node
*attr
, *next
;
831 GET_CURRENT_CONTEXT(ctx
);
832 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
834 if (ctx
->AttribStackDepth
== 0) {
835 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
839 ctx
->AttribStackDepth
--;
840 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
844 if (MESA_VERBOSE
& VERBOSE_API
) {
845 _mesa_debug(ctx
, "glPopAttrib %s\n",
846 _mesa_lookup_enum_by_nr(attr
->kind
));
849 switch (attr
->kind
) {
850 case GL_ACCUM_BUFFER_BIT
:
852 const struct gl_accum_attrib
*accum
;
853 accum
= (const struct gl_accum_attrib
*) attr
->data
;
854 _mesa_ClearAccum(accum
->ClearColor
[0],
855 accum
->ClearColor
[1],
856 accum
->ClearColor
[2],
857 accum
->ClearColor
[3]);
860 case GL_COLOR_BUFFER_BIT
:
862 const struct gl_colorbuffer_attrib
*color
;
864 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
865 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
866 _mesa_ClearColor(color
->ClearColor
.f
[0],
867 color
->ClearColor
.f
[1],
868 color
->ClearColor
.f
[2],
869 color
->ClearColor
.f
[3]);
870 _mesa_IndexMask(color
->IndexMask
);
871 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
872 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
873 (GLboolean
) (color
->ColorMask
[0][1] != 0),
874 (GLboolean
) (color
->ColorMask
[0][2] != 0),
875 (GLboolean
) (color
->ColorMask
[0][3] != 0));
879 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
880 _mesa_ColorMaskIndexed(i
,
881 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
882 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
883 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
884 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
888 /* Need to determine if more than one color output is
889 * specified. If so, call glDrawBuffersARB, else call
890 * glDrawBuffer(). This is a subtle, but essential point
891 * since GL_FRONT (for example) is illegal for the former
892 * function, but legal for the later.
894 GLboolean multipleBuffers
= GL_FALSE
;
897 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
898 if (color
->DrawBuffer
[i
] != GL_NONE
) {
899 multipleBuffers
= GL_TRUE
;
903 /* Call the API_level functions, not _mesa_drawbuffers()
904 * since we need to do error checking on the pop'd
906 * Ex: if GL_FRONT were pushed, but we're popping with a
907 * user FBO bound, GL_FRONT will be illegal and we'll need
908 * to record that error. Per OpenGL ARB decision.
911 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
914 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
916 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
917 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
918 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
919 if (ctx
->Extensions
.EXT_draw_buffers2
) {
921 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
922 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
923 (color
->BlendEnabled
>> i
) & 1);
927 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
930 if (ctx
->Color
._BlendFuncPerBuffer
||
931 ctx
->Color
._BlendEquationPerBuffer
) {
932 /* set blend per buffer */
934 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
935 _mesa_BlendFuncSeparatei(buf
, color
->Blend
[buf
].SrcRGB
,
936 color
->Blend
[buf
].DstRGB
,
937 color
->Blend
[buf
].SrcA
,
938 color
->Blend
[buf
].DstA
);
939 _mesa_BlendEquationSeparatei(buf
,
940 color
->Blend
[buf
].EquationRGB
,
941 color
->Blend
[buf
].EquationA
);
945 /* set same blend modes for all buffers */
946 _mesa_BlendFuncSeparateEXT(color
->Blend
[0].SrcRGB
,
947 color
->Blend
[0].DstRGB
,
948 color
->Blend
[0].SrcA
,
949 color
->Blend
[0].DstA
);
950 /* This special case is because glBlendEquationSeparateEXT
951 * cannot take GL_LOGIC_OP as a parameter.
953 if (color
->Blend
[0].EquationRGB
==
954 color
->Blend
[0].EquationA
) {
955 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
958 _mesa_BlendEquationSeparateEXT(
959 color
->Blend
[0].EquationRGB
,
960 color
->Blend
[0].EquationA
);
963 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
964 color
->BlendColorUnclamped
[1],
965 color
->BlendColorUnclamped
[2],
966 color
->BlendColorUnclamped
[3]);
967 _mesa_LogicOp(color
->LogicOp
);
968 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
969 color
->ColorLogicOpEnabled
);
970 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
971 color
->IndexLogicOpEnabled
);
972 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
973 _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
974 _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
976 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
977 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
978 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
982 FLUSH_CURRENT( ctx
, 0 );
983 memcpy( &ctx
->Current
, attr
->data
,
984 sizeof(struct gl_current_attrib
) );
986 case GL_DEPTH_BUFFER_BIT
:
988 const struct gl_depthbuffer_attrib
*depth
;
989 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
990 _mesa_DepthFunc(depth
->Func
);
991 _mesa_ClearDepth(depth
->Clear
);
992 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
993 _mesa_DepthMask(depth
->Mask
);
998 const struct gl_enable_attrib
*enable
;
999 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1000 pop_enable_group(ctx
, enable
);
1001 ctx
->NewState
|= _NEW_ALL
;
1005 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1006 ctx
->NewState
|= _NEW_EVAL
;
1010 const struct gl_fog_attrib
*fog
;
1011 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1012 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1013 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1014 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1015 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1016 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1017 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1018 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1023 const struct gl_hint_attrib
*hint
;
1024 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1025 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1026 hint
->PerspectiveCorrection
);
1027 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1028 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1029 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1030 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1031 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1032 hint
->ClipVolumeClipping
);
1033 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1034 hint
->TextureCompression
);
1037 case GL_LIGHTING_BIT
:
1040 const struct gl_light_attrib
*light
;
1041 light
= (const struct gl_light_attrib
*) attr
->data
;
1042 /* lighting enable */
1043 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1044 /* per-light state */
1045 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1046 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1048 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1049 const struct gl_light
*l
= &light
->Light
[i
];
1050 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1051 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1052 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1053 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1054 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1055 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1057 GLfloat p
[4] = { 0 };
1058 p
[0] = l
->SpotExponent
;
1059 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1062 GLfloat p
[4] = { 0 };
1063 p
[0] = l
->SpotCutoff
;
1064 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1067 GLfloat p
[4] = { 0 };
1068 p
[0] = l
->ConstantAttenuation
;
1069 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1072 GLfloat p
[4] = { 0 };
1073 p
[0] = l
->LinearAttenuation
;
1074 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1077 GLfloat p
[4] = { 0 };
1078 p
[0] = l
->QuadraticAttenuation
;
1079 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1083 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1084 light
->Model
.Ambient
);
1085 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1086 (GLfloat
) light
->Model
.LocalViewer
);
1087 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1088 (GLfloat
) light
->Model
.TwoSide
);
1089 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1090 (GLfloat
) light
->Model
.ColorControl
);
1092 _mesa_ShadeModel(light
->ShadeModel
);
1093 /* color material */
1094 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1095 light
->ColorMaterialMode
);
1096 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1097 light
->ColorMaterialEnabled
);
1099 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1100 sizeof(struct gl_material
));
1101 _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1106 const struct gl_line_attrib
*line
;
1107 line
= (const struct gl_line_attrib
*) attr
->data
;
1108 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1109 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1110 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1111 _mesa_LineWidth(line
->Width
);
1115 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1117 case GL_PIXEL_MODE_BIT
:
1118 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1119 /* XXX what other pixel state needs to be set by function calls? */
1120 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1121 ctx
->NewState
|= _NEW_PIXEL
;
1125 const struct gl_point_attrib
*point
;
1126 point
= (const struct gl_point_attrib
*) attr
->data
;
1127 _mesa_PointSize(point
->Size
);
1128 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1129 if (ctx
->Extensions
.EXT_point_parameters
) {
1130 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1132 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1134 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1136 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1139 if (ctx
->Extensions
.NV_point_sprite
1140 || ctx
->Extensions
.ARB_point_sprite
) {
1142 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1143 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1144 (GLint
) point
->CoordReplace
[u
]);
1146 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1147 if (ctx
->Extensions
.NV_point_sprite
)
1148 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1149 ctx
->Point
.SpriteRMode
);
1150 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1151 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1155 case GL_POLYGON_BIT
:
1157 const struct gl_polygon_attrib
*polygon
;
1158 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1159 _mesa_CullFace(polygon
->CullFaceMode
);
1160 _mesa_FrontFace(polygon
->FrontFace
);
1161 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1162 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1163 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1164 polygon
->OffsetUnits
);
1165 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1166 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1167 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1168 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1169 polygon
->OffsetPoint
);
1170 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1171 polygon
->OffsetLine
);
1172 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1173 polygon
->OffsetFill
);
1176 case GL_POLYGON_STIPPLE_BIT
:
1177 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1178 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1179 if (ctx
->Driver
.PolygonStipple
)
1180 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1182 case GL_SCISSOR_BIT
:
1184 const struct gl_scissor_attrib
*scissor
;
1185 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1186 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1187 scissor
->Width
, scissor
->Height
);
1188 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1191 case GL_STENCIL_BUFFER_BIT
:
1193 const struct gl_stencil_attrib
*stencil
;
1194 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1195 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1196 _mesa_ClearStencil(stencil
->Clear
);
1197 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1198 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1199 stencil
->TestTwoSide
);
1200 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1201 ? GL_BACK
: GL_FRONT
);
1204 _mesa_StencilFuncSeparate(GL_FRONT
,
1205 stencil
->Function
[0],
1207 stencil
->ValueMask
[0]);
1208 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1209 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1210 stencil
->ZFailFunc
[0],
1211 stencil
->ZPassFunc
[0]);
1213 _mesa_StencilFuncSeparate(GL_BACK
,
1214 stencil
->Function
[1],
1216 stencil
->ValueMask
[1]);
1217 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1218 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1219 stencil
->ZFailFunc
[1],
1220 stencil
->ZPassFunc
[1]);
1223 case GL_TRANSFORM_BIT
:
1226 const struct gl_transform_attrib
*xform
;
1227 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1228 _mesa_MatrixMode(xform
->MatrixMode
);
1229 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1230 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1232 /* restore clip planes */
1233 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1234 const GLuint mask
= 1 << i
;
1235 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1236 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1237 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1238 !!(xform
->ClipPlanesEnabled
& mask
));
1239 if (ctx
->Driver
.ClipPlane
)
1240 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1243 /* normalize/rescale */
1244 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1245 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1246 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1247 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1248 ctx
->Transform
.RescaleNormals
);
1249 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1250 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1251 ctx
->Transform
.DepthClamp
);
1254 case GL_TEXTURE_BIT
:
1256 struct texture_state
*texstate
1257 = (struct texture_state
*) attr
->data
;
1258 pop_texture_group(ctx
, texstate
);
1259 ctx
->NewState
|= _NEW_TEXTURE
;
1262 case GL_VIEWPORT_BIT
:
1264 const struct gl_viewport_attrib
*vp
;
1265 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1266 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1267 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1270 case GL_MULTISAMPLE_BIT_ARB
:
1272 const struct gl_multisample_attrib
*ms
;
1273 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1275 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1279 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1281 GL_SAMPLE_COVERAGE
);
1283 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1284 ms
->SampleAlphaToCoverage
,
1285 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1287 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1288 ms
->SampleAlphaToOne
,
1289 GL_SAMPLE_ALPHA_TO_ONE
);
1291 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1292 ms
->SampleCoverageInvert
);
1297 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1310 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1314 copy_pixelstore(struct gl_context
*ctx
,
1315 struct gl_pixelstore_attrib
*dst
,
1316 const struct gl_pixelstore_attrib
*src
)
1318 dst
->Alignment
= src
->Alignment
;
1319 dst
->RowLength
= src
->RowLength
;
1320 dst
->SkipPixels
= src
->SkipPixels
;
1321 dst
->SkipRows
= src
->SkipRows
;
1322 dst
->ImageHeight
= src
->ImageHeight
;
1323 dst
->SkipImages
= src
->SkipImages
;
1324 dst
->SwapBytes
= src
->SwapBytes
;
1325 dst
->LsbFirst
= src
->LsbFirst
;
1326 dst
->Invert
= src
->Invert
;
1327 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1331 #define GL_CLIENT_PACK_BIT (1<<20)
1332 #define GL_CLIENT_UNPACK_BIT (1<<21)
1335 * Copy gl_array_object from src to dest.
1336 * 'dest' must be in an initialized state.
1339 copy_array_object(struct gl_context
*ctx
,
1340 struct gl_array_object
*dest
,
1341 struct gl_array_object
*src
)
1348 /* In theory must be the same anyway, but on recreate make sure it matches */
1349 dest
->ARBsemantics
= src
->ARBsemantics
;
1351 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1352 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1354 /* _Enabled must be the same than on push */
1355 dest
->_Enabled
= src
->_Enabled
;
1356 dest
->_MaxElement
= src
->_MaxElement
;
1360 * Copy gl_array_attrib from src to dest.
1361 * 'dest' must be in an initialized state.
1364 copy_array_attrib(struct gl_context
*ctx
,
1365 struct gl_array_attrib
*dest
,
1366 struct gl_array_attrib
*src
,
1370 /* skip DefaultArrayObj, Objects */
1371 dest
->ActiveTexture
= src
->ActiveTexture
;
1372 dest
->LockFirst
= src
->LockFirst
;
1373 dest
->LockCount
= src
->LockCount
;
1374 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1375 dest
->RestartIndex
= src
->RestartIndex
;
1377 /* skip RebindArrays */
1380 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1382 /* skip ArrayBufferObj */
1383 /* skip ElementArrayBufferObj */
1387 * Save the content of src to dest.
1390 save_array_attrib(struct gl_context
*ctx
,
1391 struct gl_array_attrib
*dest
,
1392 struct gl_array_attrib
*src
)
1394 /* Set the Name, needed for restore, but do never overwrite.
1395 * Needs to match value in the object hash. */
1396 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1397 /* And copy all of the rest. */
1398 copy_array_attrib(ctx
, dest
, src
, false);
1400 /* Just reference them here */
1401 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1402 src
->ArrayBufferObj
);
1403 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1404 src
->ArrayObj
->ElementArrayBufferObj
);
1408 * Restore the content of src to dest.
1411 restore_array_attrib(struct gl_context
*ctx
,
1412 struct gl_array_attrib
*dest
,
1413 struct gl_array_attrib
*src
)
1415 /* The ARB_vertex_array_object spec says:
1417 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1418 * if array is not a name returned from a previous call to
1419 * GenVertexArrays, or if such a name has since been deleted with
1420 * DeleteVertexArrays."
1422 * Therefore popping a deleted VAO cannot magically recreate it.
1424 * The semantics of objects created using APPLE_vertex_array_objects behave
1425 * differently. These objects expect to be recreated by pop. Alas.
1427 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1428 && src
->ArrayObj
->ARBsemantics
);
1430 if (arb_vao
&& !_mesa_IsVertexArrayAPPLE(src
->ArrayObj
->Name
))
1433 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1435 /* Restore or recreate the buffer objects by the names ... */
1437 || src
->ArrayBufferObj
->Name
== 0
1438 || _mesa_IsBufferARB(src
->ArrayBufferObj
->Name
)) {
1439 /* ... and restore its content */
1440 copy_array_attrib(ctx
, dest
, src
, false);
1442 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1443 src
->ArrayBufferObj
->Name
);
1445 copy_array_attrib(ctx
, dest
, src
, true);
1449 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1450 || _mesa_IsBufferARB(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1451 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1452 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1456 * init/alloc the fields of 'attrib'.
1457 * Needs to the init part matching free_array_attrib_data below.
1460 init_array_attrib_data(struct gl_context
*ctx
,
1461 struct gl_array_attrib
*attrib
)
1463 /* Get a non driver gl_array_object. */
1464 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1465 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1469 * Free/unreference the fields of 'attrib' but don't delete it (that's
1470 * done later in the calling code).
1471 * Needs to the cleanup part matching init_array_attrib_data above.
1474 free_array_attrib_data(struct gl_context
*ctx
,
1475 struct gl_array_attrib
*attrib
)
1477 /* We use a non driver array object, so don't just unref since we would
1478 * end up using the drivers DeleteArrayObject function for deletion. */
1479 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1480 attrib
->ArrayObj
= 0;
1481 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1486 _mesa_PushClientAttrib(GLbitfield mask
)
1488 struct gl_attrib_node
*head
;
1490 GET_CURRENT_CONTEXT(ctx
);
1491 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1493 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1494 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1498 /* Build linked list of attribute nodes which save all attribute
1499 * groups specified by the mask.
1503 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1504 struct gl_pixelstore_attrib
*attr
;
1505 /* packing attribs */
1506 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1507 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1508 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1509 /* unpacking attribs */
1510 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1511 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1512 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1515 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1516 struct gl_array_attrib
*attr
;
1517 attr
= CALLOC_STRUCT( gl_array_attrib
);
1518 init_array_attrib_data(ctx
, attr
);
1519 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1520 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1523 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1524 ctx
->ClientAttribStackDepth
++;
1531 _mesa_PopClientAttrib(void)
1533 struct gl_attrib_node
*node
, *next
;
1535 GET_CURRENT_CONTEXT(ctx
);
1536 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1538 if (ctx
->ClientAttribStackDepth
== 0) {
1539 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1543 ctx
->ClientAttribStackDepth
--;
1544 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1547 switch (node
->kind
) {
1548 case GL_CLIENT_PACK_BIT
:
1550 struct gl_pixelstore_attrib
*store
=
1551 (struct gl_pixelstore_attrib
*) node
->data
;
1552 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1553 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1555 ctx
->NewState
|= _NEW_PACKUNPACK
;
1557 case GL_CLIENT_UNPACK_BIT
:
1559 struct gl_pixelstore_attrib
*store
=
1560 (struct gl_pixelstore_attrib
*) node
->data
;
1561 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1562 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1564 ctx
->NewState
|= _NEW_PACKUNPACK
;
1566 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1567 struct gl_array_attrib
* attr
=
1568 (struct gl_array_attrib
*) node
->data
;
1569 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1570 free_array_attrib_data(ctx
, attr
);
1571 ctx
->NewState
|= _NEW_ARRAY
;
1575 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1588 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1590 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1591 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1592 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1593 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1598 * Free any attribute state data that might be attached to the context.
1601 _mesa_free_attrib_data(struct gl_context
*ctx
)
1603 while (ctx
->AttribStackDepth
> 0) {
1604 struct gl_attrib_node
*attr
, *next
;
1606 ctx
->AttribStackDepth
--;
1607 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1610 if (attr
->kind
== GL_TEXTURE_BIT
) {
1611 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1613 /* clear references to the saved texture objects */
1614 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1615 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1616 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1619 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1622 /* any other chunks of state that requires special handling? */
1634 void _mesa_init_attrib( struct gl_context
*ctx
)
1636 /* Renderer and client attribute stacks */
1637 ctx
->AttribStackDepth
= 0;
1638 ctx
->ClientAttribStackDepth
= 0;