2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
45 #include "multisample.h"
59 #include "main/dispatch.h"
66 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
68 struct gl_enable_attrib
73 GLbitfield ClipPlanes
;
74 GLboolean ColorMaterial
;
80 GLboolean Light
[MAX_LIGHTS
];
83 GLboolean LineStipple
;
84 GLboolean IndexLogicOp
;
85 GLboolean ColorLogicOp
;
90 GLboolean Map1TextureCoord1
;
91 GLboolean Map1TextureCoord2
;
92 GLboolean Map1TextureCoord3
;
93 GLboolean Map1TextureCoord4
;
94 GLboolean Map1Vertex3
;
95 GLboolean Map1Vertex4
;
99 GLboolean Map2TextureCoord1
;
100 GLboolean Map2TextureCoord2
;
101 GLboolean Map2TextureCoord3
;
102 GLboolean Map2TextureCoord4
;
103 GLboolean Map2Vertex3
;
104 GLboolean Map2Vertex4
;
107 GLboolean PixelTexture
;
108 GLboolean PointSmooth
;
109 GLboolean PolygonOffsetPoint
;
110 GLboolean PolygonOffsetLine
;
111 GLboolean PolygonOffsetFill
;
112 GLboolean PolygonSmooth
;
113 GLboolean PolygonStipple
;
114 GLboolean RescaleNormals
;
117 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
118 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
121 GLboolean SampleCoverage
; /* GL_ARB_multisample */
122 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
124 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
125 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
127 /* GL_ARB_vertex_program */
128 GLboolean VertexProgram
;
129 GLboolean VertexProgramPointSize
;
130 GLboolean VertexProgramTwoSide
;
132 /* GL_ARB_fragment_program */
133 GLboolean FragmentProgram
;
135 /* GL_ARB_point_sprite / GL_NV_point_sprite */
136 GLboolean PointSprite
;
137 GLboolean FragmentShaderATI
;
139 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
140 GLboolean sRGBEnabled
;
145 * Node for the attribute stack.
147 struct gl_attrib_node
151 struct gl_attrib_node
*next
;
157 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
161 struct gl_texture_attrib Texture
; /**< The usual context state */
163 /** to save per texture object state (wrap modes, filters, etc): */
164 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
167 * To save references to texture objects (so they don't get accidentally
168 * deleted while saved in the attribute stack).
170 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
172 /* We need to keep a reference to the shared state. That's where the
173 * default texture objects are kept. We don't want that state to be
174 * freed while the attribute stack contains pointers to any default
177 struct gl_shared_state
*SharedRef
;
181 /** An unused GL_*_BIT value */
182 #define DUMMY_BIT 0x10000000
186 * Allocate new attribute node of given type/kind. Attach payload data.
187 * Insert it into the linked list named by 'head'.
190 save_attrib_data(struct gl_attrib_node
**head
,
191 GLbitfield kind
, void *payload
)
193 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
210 * Helper function for_mesa_PushAttrib for simple attributes.
211 * Allocates memory for attribute data and copies the given attribute data.
212 * \param head head of linked list to insert attribute data into
213 * \param attr_bit one of the GL_<attrib>_BIT flags
214 * \param attr_size number of bytes to allocate for attribute data
215 * \param attr_data the attribute data to copy
216 * \return true for success, false for out of memory
219 push_attrib(struct gl_context
*ctx
, struct gl_attrib_node
**head
,
220 GLbitfield attr_bit
, GLuint attr_size
, const void *attr_data
)
224 attribute
= malloc(attr_size
);
225 if (attribute
== NULL
) {
226 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
230 if (save_attrib_data(head
, attr_bit
, attribute
)) {
231 memcpy(attribute
, attr_data
, attr_size
);
235 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
243 _mesa_PushAttrib(GLbitfield mask
)
245 struct gl_attrib_node
*head
;
247 GET_CURRENT_CONTEXT(ctx
);
249 if (MESA_VERBOSE
& VERBOSE_API
)
250 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
252 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
253 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushAttrib");
257 /* Build linked list of attribute nodes which save all attribute */
258 /* groups specified by the mask. */
262 /* if mask is zero we still need to push something so that we
263 * don't get a GL_STACK_UNDERFLOW error in glPopAttrib().
266 if (!push_attrib(ctx
, &head
, DUMMY_BIT
, sizeof(dummy
), &dummy
))
270 if (mask
& GL_ACCUM_BUFFER_BIT
) {
271 if (!push_attrib(ctx
, &head
, GL_ACCUM_BUFFER_BIT
,
272 sizeof(struct gl_accum_attrib
),
277 if (mask
& GL_COLOR_BUFFER_BIT
) {
279 struct gl_colorbuffer_attrib
*attr
;
280 attr
= MALLOC_STRUCT(gl_colorbuffer_attrib
);
282 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
286 if (save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
)) {
287 memcpy(attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
));
288 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
289 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
290 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
294 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
299 if (mask
& GL_CURRENT_BIT
) {
300 FLUSH_CURRENT(ctx
, 0);
301 if (!push_attrib(ctx
, &head
, GL_CURRENT_BIT
,
302 sizeof(struct gl_current_attrib
),
303 (void*)&ctx
->Current
))
307 if (mask
& GL_DEPTH_BUFFER_BIT
) {
308 if (!push_attrib(ctx
, &head
, GL_DEPTH_BUFFER_BIT
,
309 sizeof(struct gl_depthbuffer_attrib
),
314 if (mask
& GL_ENABLE_BIT
) {
315 struct gl_enable_attrib
*attr
;
317 attr
= MALLOC_STRUCT(gl_enable_attrib
);
319 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
323 /* Copy enable flags from all other attributes into the enable struct. */
324 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
325 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
326 attr
->Blend
= ctx
->Color
.BlendEnabled
;
327 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
328 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
329 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
330 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
331 attr
->DepthTest
= ctx
->Depth
.Test
;
332 attr
->Dither
= ctx
->Color
.DitherFlag
;
333 attr
->Fog
= ctx
->Fog
.Enabled
;
334 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
335 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
337 attr
->Lighting
= ctx
->Light
.Enabled
;
338 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
339 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
340 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
341 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
342 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
343 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
344 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
345 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
346 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
347 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
348 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
349 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
350 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
351 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
352 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
353 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
354 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
355 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
356 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
357 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
358 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
359 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
360 attr
->Normalize
= ctx
->Transform
.Normalize
;
361 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
362 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
363 attr
->PointSprite
= ctx
->Point
.PointSprite
;
364 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
365 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
366 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
367 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
368 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
369 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
370 attr
->Scissor
= ctx
->Scissor
.EnableFlags
;
371 attr
->Stencil
= ctx
->Stencil
.Enabled
;
372 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
373 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
374 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
375 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
376 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
377 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
378 attr
->Texture
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].Enabled
;
379 attr
->TexGen
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
;
381 /* GL_ARB_vertex_program */
382 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
383 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
384 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
386 /* GL_ARB_fragment_program */
387 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
389 if (!save_attrib_data(&head
, GL_ENABLE_BIT
, attr
)) {
391 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
395 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
396 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
399 if (mask
& GL_EVAL_BIT
) {
400 if (!push_attrib(ctx
, &head
, GL_EVAL_BIT
,
401 sizeof(struct gl_eval_attrib
),
406 if (mask
& GL_FOG_BIT
) {
407 if (!push_attrib(ctx
, &head
, GL_FOG_BIT
,
408 sizeof(struct gl_fog_attrib
),
413 if (mask
& GL_HINT_BIT
) {
414 if (!push_attrib(ctx
, &head
, GL_HINT_BIT
,
415 sizeof(struct gl_hint_attrib
),
420 if (mask
& GL_LIGHTING_BIT
) {
421 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
422 if (!push_attrib(ctx
, &head
, GL_LIGHTING_BIT
,
423 sizeof(struct gl_light_attrib
),
428 if (mask
& GL_LINE_BIT
) {
429 if (!push_attrib(ctx
, &head
, GL_LINE_BIT
,
430 sizeof(struct gl_line_attrib
),
435 if (mask
& GL_LIST_BIT
) {
436 if (!push_attrib(ctx
, &head
, GL_LIST_BIT
,
437 sizeof(struct gl_list_attrib
),
442 if (mask
& GL_PIXEL_MODE_BIT
) {
443 struct gl_pixel_attrib
*attr
;
444 attr
= MALLOC_STRUCT(gl_pixel_attrib
);
446 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
450 if (save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
)) {
451 memcpy(attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
));
452 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
453 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
457 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
462 if (mask
& GL_POINT_BIT
) {
463 if (!push_attrib(ctx
, &head
, GL_POINT_BIT
,
464 sizeof(struct gl_point_attrib
),
469 if (mask
& GL_POLYGON_BIT
) {
470 if (!push_attrib(ctx
, &head
, GL_POLYGON_BIT
,
471 sizeof(struct gl_polygon_attrib
),
472 (void*)&ctx
->Polygon
))
476 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
477 if (!push_attrib(ctx
, &head
, GL_POLYGON_STIPPLE_BIT
,
478 sizeof(ctx
->PolygonStipple
),
479 (void*)&ctx
->PolygonStipple
))
483 if (mask
& GL_SCISSOR_BIT
) {
484 if (!push_attrib(ctx
, &head
, GL_SCISSOR_BIT
,
485 sizeof(struct gl_scissor_attrib
),
486 (void*)&ctx
->Scissor
))
490 if (mask
& GL_STENCIL_BUFFER_BIT
) {
491 if (!push_attrib(ctx
, &head
, GL_STENCIL_BUFFER_BIT
,
492 sizeof(struct gl_stencil_attrib
),
493 (void*)&ctx
->Stencil
))
497 if (mask
& GL_TEXTURE_BIT
) {
498 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
502 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
506 if (!save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
)) {
508 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
512 _mesa_lock_context_textures(ctx
);
514 /* copy/save the bulk of texture state here */
515 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
517 /* Save references to the currently bound texture objects so they don't
518 * accidentally get deleted while referenced in the attribute stack.
520 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
521 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
522 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
523 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
527 /* copy state/contents of the currently bound texture objects */
528 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
529 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
530 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
531 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
535 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
537 _mesa_unlock_context_textures(ctx
);
540 if (mask
& GL_TRANSFORM_BIT
) {
541 if (!push_attrib(ctx
, &head
, GL_TRANSFORM_BIT
,
542 sizeof(struct gl_transform_attrib
),
543 (void*)&ctx
->Transform
))
547 if (mask
& GL_VIEWPORT_BIT
) {
548 if (!push_attrib(ctx
, &head
, GL_VIEWPORT_BIT
,
549 sizeof(struct gl_viewport_attrib
)
550 * ctx
->Const
.MaxViewports
,
551 (void*)&ctx
->ViewportArray
))
555 /* GL_ARB_multisample */
556 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
557 if (!push_attrib(ctx
, &head
, GL_MULTISAMPLE_BIT_ARB
,
558 sizeof(struct gl_multisample_attrib
),
559 (void*)&ctx
->Multisample
))
565 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
566 ctx
->AttribStackDepth
++;
573 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
575 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
578 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
579 if ((VALUE) != (NEWVALUE)) { \
580 _mesa_set_enable(ctx, ENUM, (NEWVALUE)); \
583 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
584 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
585 if (ctx
->Extensions
.EXT_draw_buffers2
) {
587 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
588 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
592 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
596 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
597 const GLuint mask
= 1 << i
;
598 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
599 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
600 !!(enable
->ClipPlanes
& mask
));
603 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
605 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
606 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
608 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
609 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
610 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
611 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
612 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
613 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
615 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
617 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
620 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
621 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
622 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
623 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
624 GL_MAP1_TEXTURE_COORD_1
);
625 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
626 GL_MAP1_TEXTURE_COORD_2
);
627 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
628 GL_MAP1_TEXTURE_COORD_3
);
629 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
630 GL_MAP1_TEXTURE_COORD_4
);
631 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
633 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
636 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
637 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
638 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
639 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
640 GL_MAP2_TEXTURE_COORD_1
);
641 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
642 GL_MAP2_TEXTURE_COORD_2
);
643 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
644 GL_MAP2_TEXTURE_COORD_3
);
645 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
646 GL_MAP2_TEXTURE_COORD_4
);
647 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
649 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
652 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
653 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
654 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
655 GL_RESCALE_NORMAL_EXT
);
656 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
657 enable
->RasterPositionUnclipped
,
658 GL_RASTER_POSITION_UNCLIPPED_IBM
);
659 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
661 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
662 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
665 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
666 GL_POLYGON_OFFSET_POINT
);
667 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
668 GL_POLYGON_OFFSET_LINE
);
669 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
670 GL_POLYGON_OFFSET_FILL
);
671 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
673 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
675 if (ctx
->Scissor
.EnableFlags
!= enable
->Scissor
) {
678 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
679 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
, (enable
->Scissor
>> i
) & 1);
682 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
683 if (ctx
->Extensions
.EXT_stencil_two_side
) {
684 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
686 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
688 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
689 enable
->SampleAlphaToCoverage
,
690 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
691 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
692 enable
->SampleAlphaToOne
,
693 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
694 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
695 enable
->SampleCoverage
,
696 GL_SAMPLE_COVERAGE_ARB
);
697 /* GL_ARB_vertex_program */
698 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
699 enable
->VertexProgram
,
700 GL_VERTEX_PROGRAM_ARB
);
701 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
702 enable
->VertexProgramPointSize
,
703 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
704 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
705 enable
->VertexProgramTwoSide
,
706 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
708 /* GL_ARB_fragment_program */
709 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
710 enable
->FragmentProgram
,
711 GL_FRAGMENT_PROGRAM_ARB
);
713 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
714 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
715 GL_FRAMEBUFFER_SRGB
);
717 /* texture unit enables */
718 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
719 const GLbitfield enabled
= enable
->Texture
[i
];
720 const GLbitfield genEnabled
= enable
->TexGen
[i
];
722 if (ctx
->Texture
.FixedFuncUnit
[i
].Enabled
!= enabled
) {
723 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
725 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
726 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
727 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
728 if (ctx
->Extensions
.NV_texture_rectangle
) {
729 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
730 !!(enabled
& TEXTURE_RECT_BIT
));
732 if (ctx
->Extensions
.ARB_texture_cube_map
) {
733 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
734 !!(enabled
& TEXTURE_CUBE_BIT
));
738 if (ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
!= genEnabled
) {
739 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
740 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
741 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
742 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
743 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
747 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
752 * Pop/restore texture attribute/group state.
755 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
759 _mesa_lock_context_textures(ctx
);
761 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
762 const struct gl_fixedfunc_texture_unit
*unit
=
763 &texstate
->Texture
.FixedFuncUnit
[u
];
766 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
767 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
768 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
769 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
770 if (ctx
->Extensions
.ARB_texture_cube_map
) {
771 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
772 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
774 if (ctx
->Extensions
.NV_texture_rectangle
) {
775 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
776 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
779 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
780 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
781 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
782 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
783 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
784 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
785 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
786 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
787 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
788 /* Eye plane done differently to avoid re-transformation */
790 struct gl_fixedfunc_texture_unit
*destUnit
=
791 &ctx
->Texture
.FixedFuncUnit
[u
];
793 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
794 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
795 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
796 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
797 if (ctx
->Driver
.TexGen
) {
798 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
799 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
800 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
801 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
804 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
805 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
806 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
807 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
808 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
809 texstate
->Texture
.Unit
[u
].LodBias
);
810 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
811 unit
->Combine
.ModeRGB
);
812 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
813 unit
->Combine
.ModeA
);
815 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
817 for (i
= 0; i
< n
; i
++) {
818 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
819 unit
->Combine
.SourceRGB
[i
]);
820 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
821 unit
->Combine
.SourceA
[i
]);
822 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
823 unit
->Combine
.OperandRGB
[i
]);
824 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
825 unit
->Combine
.OperandA
[i
]);
828 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
829 1 << unit
->Combine
.ScaleShiftRGB
);
830 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
831 1 << unit
->Combine
.ScaleShiftA
);
833 /* Restore texture object state for each target */
834 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
835 const struct gl_texture_object
*obj
= NULL
;
836 const struct gl_sampler_object
*samp
;
839 obj
= &texstate
->SavedObj
[u
][tgt
];
841 /* don't restore state for unsupported targets to prevent
844 if (obj
->Target
== GL_TEXTURE_CUBE_MAP
&&
845 !ctx
->Extensions
.ARB_texture_cube_map
) {
848 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
849 !ctx
->Extensions
.NV_texture_rectangle
) {
852 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
853 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
854 !ctx
->Extensions
.EXT_texture_array
) {
857 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
858 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
860 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
862 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
864 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
865 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
868 target
= obj
->Target
;
870 _mesa_BindTexture(target
, obj
->Name
);
872 samp
= &obj
->Sampler
;
874 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
875 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
876 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
877 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
878 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
879 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
880 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
881 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
882 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
883 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
884 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
885 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
886 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
887 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
888 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
889 samp
->MaxAnisotropy
);
891 if (ctx
->Extensions
.ARB_shadow
) {
892 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
894 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
897 if (ctx
->Extensions
.ARB_depth_texture
)
898 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
901 /* remove saved references to the texture objects */
902 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
903 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
907 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
909 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
911 _mesa_unlock_context_textures(ctx
);
916 * This function is kind of long just because we have to call a lot
917 * of device driver functions to update device driver state.
919 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
920 * in order to restore GL state. This isn't terribly efficient but it
921 * ensures that dirty flags and any derived state gets updated correctly.
922 * We could at least check if the value to restore equals the current value
923 * and then skip the Mesa call.
926 _mesa_PopAttrib(void)
928 struct gl_attrib_node
*attr
, *next
;
929 GET_CURRENT_CONTEXT(ctx
);
930 FLUSH_VERTICES(ctx
, 0);
932 if (ctx
->AttribStackDepth
== 0) {
933 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib");
937 ctx
->AttribStackDepth
--;
938 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
942 if (MESA_VERBOSE
& VERBOSE_API
) {
943 _mesa_debug(ctx
, "glPopAttrib %s\n",
944 _mesa_enum_to_string(attr
->kind
));
947 switch (attr
->kind
) {
952 case GL_ACCUM_BUFFER_BIT
:
954 const struct gl_accum_attrib
*accum
;
955 accum
= (const struct gl_accum_attrib
*) attr
->data
;
956 _mesa_ClearAccum(accum
->ClearColor
[0],
957 accum
->ClearColor
[1],
958 accum
->ClearColor
[2],
959 accum
->ClearColor
[3]);
962 case GL_COLOR_BUFFER_BIT
:
964 const struct gl_colorbuffer_attrib
*color
;
966 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
967 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
968 _mesa_ClearColor(color
->ClearColor
.f
[0],
969 color
->ClearColor
.f
[1],
970 color
->ClearColor
.f
[2],
971 color
->ClearColor
.f
[3]);
972 _mesa_IndexMask(color
->IndexMask
);
973 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
974 _mesa_ColorMask(GET_COLORMASK_BIT(color
->ColorMask
, 0, 0),
975 GET_COLORMASK_BIT(color
->ColorMask
, 0, 1),
976 GET_COLORMASK_BIT(color
->ColorMask
, 0, 2),
977 GET_COLORMASK_BIT(color
->ColorMask
, 0, 3));
981 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
983 GET_COLORMASK_BIT(color
->ColorMask
, i
, 0),
984 GET_COLORMASK_BIT(color
->ColorMask
, i
, 1),
985 GET_COLORMASK_BIT(color
->ColorMask
, i
, 2),
986 GET_COLORMASK_BIT(color
->ColorMask
, i
, 3));
990 /* Need to determine if more than one color output is
991 * specified. If so, call glDrawBuffersARB, else call
992 * glDrawBuffer(). This is a subtle, but essential point
993 * since GL_FRONT (for example) is illegal for the former
994 * function, but legal for the later.
996 GLboolean multipleBuffers
= GL_FALSE
;
999 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1000 if (color
->DrawBuffer
[i
] != GL_NONE
) {
1001 multipleBuffers
= GL_TRUE
;
1005 /* Call the API_level functions, not _mesa_drawbuffers()
1006 * since we need to do error checking on the pop'd
1008 * Ex: if GL_FRONT were pushed, but we're popping with a
1009 * user FBO bound, GL_FRONT will be illegal and we'll need
1010 * to record that error. Per OpenGL ARB decision.
1012 if (multipleBuffers
) {
1013 GLenum buffers
[MAX_DRAW_BUFFERS
];
1015 for (unsigned i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
1016 buffers
[i
] = color
->DrawBuffer
[i
];
1018 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
, buffers
);
1020 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1023 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1024 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
1025 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
1026 if (ctx
->Extensions
.EXT_draw_buffers2
) {
1028 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1029 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
1030 (color
->BlendEnabled
>> i
) & 1);
1034 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
1037 if (ctx
->Color
._BlendFuncPerBuffer
||
1038 ctx
->Color
._BlendEquationPerBuffer
) {
1039 /* set blend per buffer */
1041 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
1042 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
1043 color
->Blend
[buf
].DstRGB
,
1044 color
->Blend
[buf
].SrcA
,
1045 color
->Blend
[buf
].DstA
);
1046 _mesa_BlendEquationSeparateiARB(buf
,
1047 color
->Blend
[buf
].EquationRGB
,
1048 color
->Blend
[buf
].EquationA
);
1052 /* set same blend modes for all buffers */
1053 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
1054 color
->Blend
[0].DstRGB
,
1055 color
->Blend
[0].SrcA
,
1056 color
->Blend
[0].DstA
);
1057 /* This special case is because glBlendEquationSeparateEXT
1058 * cannot take GL_LOGIC_OP as a parameter.
1060 if (color
->Blend
[0].EquationRGB
==
1061 color
->Blend
[0].EquationA
) {
1062 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
1065 _mesa_BlendEquationSeparate(
1066 color
->Blend
[0].EquationRGB
,
1067 color
->Blend
[0].EquationA
);
1070 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
1071 color
->BlendColorUnclamped
[1],
1072 color
->BlendColorUnclamped
[2],
1073 color
->BlendColorUnclamped
[3]);
1074 _mesa_LogicOp(color
->LogicOp
);
1075 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1076 color
->ColorLogicOpEnabled
);
1077 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1078 color
->IndexLogicOpEnabled
);
1079 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1080 if (ctx
->Extensions
.ARB_color_buffer_float
)
1081 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
1082 color
->ClampFragmentColor
);
1083 if (ctx
->Extensions
.ARB_color_buffer_float
|| ctx
->Version
>= 30)
1084 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
1086 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
1087 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
1088 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
1091 case GL_CURRENT_BIT
:
1092 FLUSH_CURRENT(ctx
, 0);
1093 memcpy(&ctx
->Current
, attr
->data
,
1094 sizeof(struct gl_current_attrib
));
1096 case GL_DEPTH_BUFFER_BIT
:
1098 const struct gl_depthbuffer_attrib
*depth
;
1099 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1100 _mesa_DepthFunc(depth
->Func
);
1101 _mesa_ClearDepth(depth
->Clear
);
1102 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1103 _mesa_DepthMask(depth
->Mask
);
1104 if (ctx
->Extensions
.EXT_depth_bounds_test
) {
1105 _mesa_set_enable(ctx
, GL_DEPTH_BOUNDS_TEST_EXT
,
1107 _mesa_DepthBoundsEXT(depth
->BoundsMin
, depth
->BoundsMax
);
1113 const struct gl_enable_attrib
*enable
;
1114 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1115 pop_enable_group(ctx
, enable
);
1116 ctx
->NewState
|= _NEW_ALL
;
1117 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
|
1118 ctx
->DriverFlags
.NewBlend
|
1119 ctx
->DriverFlags
.NewClipPlaneEnable
|
1120 ctx
->DriverFlags
.NewDepth
|
1121 ctx
->DriverFlags
.NewDepthClamp
|
1122 ctx
->DriverFlags
.NewFramebufferSRGB
|
1123 ctx
->DriverFlags
.NewLineState
|
1124 ctx
->DriverFlags
.NewLogicOp
|
1125 ctx
->DriverFlags
.NewMultisampleEnable
|
1126 ctx
->DriverFlags
.NewPolygonState
|
1127 ctx
->DriverFlags
.NewSampleAlphaToXEnable
|
1128 ctx
->DriverFlags
.NewSampleMask
|
1129 ctx
->DriverFlags
.NewScissorTest
|
1130 ctx
->DriverFlags
.NewStencil
;
1134 memcpy(&ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
));
1135 ctx
->NewState
|= _NEW_EVAL
;
1139 const struct gl_fog_attrib
*fog
;
1140 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1141 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1142 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1143 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1144 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1145 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1146 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1147 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1152 const struct gl_hint_attrib
*hint
;
1153 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1154 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1155 hint
->PerspectiveCorrection
);
1156 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1157 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1158 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1159 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1160 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1161 hint
->TextureCompression
);
1164 case GL_LIGHTING_BIT
:
1167 const struct gl_light_attrib
*light
;
1168 light
= (const struct gl_light_attrib
*) attr
->data
;
1169 /* lighting enable */
1170 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1171 /* per-light state */
1172 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1173 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
1175 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1176 const struct gl_light
*l
= &light
->Light
[i
];
1177 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1178 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1179 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1180 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1181 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1182 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1184 GLfloat p
[4] = { 0 };
1185 p
[0] = l
->SpotExponent
;
1186 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1189 GLfloat p
[4] = { 0 };
1190 p
[0] = l
->SpotCutoff
;
1191 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1194 GLfloat p
[4] = { 0 };
1195 p
[0] = l
->ConstantAttenuation
;
1196 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1199 GLfloat p
[4] = { 0 };
1200 p
[0] = l
->LinearAttenuation
;
1201 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1204 GLfloat p
[4] = { 0 };
1205 p
[0] = l
->QuadraticAttenuation
;
1206 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1210 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1211 light
->Model
.Ambient
);
1212 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1213 (GLfloat
) light
->Model
.LocalViewer
);
1214 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1215 (GLfloat
) light
->Model
.TwoSide
);
1216 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1217 (GLfloat
) light
->Model
.ColorControl
);
1219 _mesa_ShadeModel(light
->ShadeModel
);
1220 /* color material */
1221 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1222 light
->ColorMaterialMode
);
1223 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1224 light
->ColorMaterialEnabled
);
1226 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1227 sizeof(struct gl_material
));
1228 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1229 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1230 light
->ClampVertexColor
);
1236 const struct gl_line_attrib
*line
;
1237 line
= (const struct gl_line_attrib
*) attr
->data
;
1238 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1239 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1240 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1241 _mesa_LineWidth(line
->Width
);
1245 memcpy(&ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
));
1247 case GL_PIXEL_MODE_BIT
:
1248 memcpy(&ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
));
1249 /* XXX what other pixel state needs to be set by function calls? */
1250 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1251 ctx
->NewState
|= _NEW_PIXEL
;
1255 const struct gl_point_attrib
*point
;
1256 point
= (const struct gl_point_attrib
*) attr
->data
;
1257 _mesa_PointSize(point
->Size
);
1258 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1259 if (ctx
->Extensions
.EXT_point_parameters
) {
1260 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1262 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1264 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1266 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1269 if (ctx
->Extensions
.NV_point_sprite
1270 || ctx
->Extensions
.ARB_point_sprite
) {
1272 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1273 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1274 !!(point
->CoordReplace
& (1u << u
)));
1276 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1277 if (ctx
->Extensions
.NV_point_sprite
)
1278 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1279 ctx
->Point
.SpriteRMode
);
1281 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1282 || ctx
->API
== API_OPENGL_CORE
)
1283 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1284 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1288 case GL_POLYGON_BIT
:
1290 const struct gl_polygon_attrib
*polygon
;
1291 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1292 _mesa_CullFace(polygon
->CullFaceMode
);
1293 _mesa_FrontFace(polygon
->FrontFace
);
1294 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1295 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1296 _mesa_polygon_offset_clamp(ctx
,
1297 polygon
->OffsetFactor
,
1298 polygon
->OffsetUnits
,
1299 polygon
->OffsetClamp
);
1300 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1301 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1302 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1303 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1304 polygon
->OffsetPoint
);
1305 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1306 polygon
->OffsetLine
);
1307 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1308 polygon
->OffsetFill
);
1311 case GL_POLYGON_STIPPLE_BIT
:
1312 memcpy(ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
));
1314 if (ctx
->DriverFlags
.NewPolygonStipple
)
1315 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
1317 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1319 if (ctx
->Driver
.PolygonStipple
)
1320 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) attr
->data
);
1322 case GL_SCISSOR_BIT
:
1325 const struct gl_scissor_attrib
*scissor
;
1326 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1328 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1329 _mesa_set_scissor(ctx
, i
,
1330 scissor
->ScissorArray
[i
].X
,
1331 scissor
->ScissorArray
[i
].Y
,
1332 scissor
->ScissorArray
[i
].Width
,
1333 scissor
->ScissorArray
[i
].Height
);
1334 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
1335 (scissor
->EnableFlags
>> i
) & 1);
1337 if (ctx
->Extensions
.EXT_window_rectangles
) {
1338 STATIC_ASSERT(sizeof(struct gl_scissor_rect
) ==
1340 _mesa_WindowRectanglesEXT(
1341 scissor
->WindowRectMode
, scissor
->NumWindowRects
,
1342 (const GLint
*)scissor
->WindowRects
);
1346 case GL_STENCIL_BUFFER_BIT
:
1348 const struct gl_stencil_attrib
*stencil
;
1349 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1350 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1351 _mesa_ClearStencil(stencil
->Clear
);
1352 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1353 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1354 stencil
->TestTwoSide
);
1355 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1356 ? GL_BACK
: GL_FRONT
);
1359 _mesa_StencilFuncSeparate(GL_FRONT
,
1360 stencil
->Function
[0],
1362 stencil
->ValueMask
[0]);
1363 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1364 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1365 stencil
->ZFailFunc
[0],
1366 stencil
->ZPassFunc
[0]);
1368 _mesa_StencilFuncSeparate(GL_BACK
,
1369 stencil
->Function
[1],
1371 stencil
->ValueMask
[1]);
1372 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1373 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1374 stencil
->ZFailFunc
[1],
1375 stencil
->ZPassFunc
[1]);
1378 case GL_TRANSFORM_BIT
:
1381 const struct gl_transform_attrib
*xform
;
1382 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1383 _mesa_MatrixMode(xform
->MatrixMode
);
1384 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1385 _math_matrix_analyse(ctx
->ProjectionMatrixStack
.Top
);
1387 /* restore clip planes */
1388 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1389 const GLuint mask
= 1 << i
;
1390 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1391 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1392 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1393 !!(xform
->ClipPlanesEnabled
& mask
));
1394 if (ctx
->Driver
.ClipPlane
)
1395 ctx
->Driver
.ClipPlane(ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1398 /* normalize/rescale */
1399 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1400 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1401 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1402 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1403 ctx
->Transform
.RescaleNormals
);
1404 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1405 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1406 ctx
->Transform
.DepthClamp
);
1407 if (ctx
->Extensions
.ARB_clip_control
)
1408 _mesa_ClipControl(xform
->ClipOrigin
, xform
->ClipDepthMode
);
1411 case GL_TEXTURE_BIT
:
1413 struct texture_state
*texstate
1414 = (struct texture_state
*) attr
->data
;
1415 pop_texture_group(ctx
, texstate
);
1416 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
| _NEW_TEXTURE_STATE
;
1419 case GL_VIEWPORT_BIT
:
1422 const struct gl_viewport_attrib
*vp
;
1423 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1425 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1426 _mesa_set_viewport(ctx
, i
, vp
[i
].X
, vp
[i
].Y
, vp
[i
].Width
,
1428 _mesa_set_depth_range(ctx
, i
, vp
[i
].Near
, vp
[i
].Far
);
1432 case GL_MULTISAMPLE_BIT_ARB
:
1434 const struct gl_multisample_attrib
*ms
;
1435 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1437 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1441 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1443 GL_SAMPLE_COVERAGE
);
1445 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1446 ms
->SampleAlphaToCoverage
,
1447 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1449 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1450 ms
->SampleAlphaToOne
,
1451 GL_SAMPLE_ALPHA_TO_ONE
);
1453 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1454 ms
->SampleCoverageInvert
);
1459 unreachable("Bad attrib flag in PopAttrib");
1471 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1475 copy_pixelstore(struct gl_context
*ctx
,
1476 struct gl_pixelstore_attrib
*dst
,
1477 const struct gl_pixelstore_attrib
*src
)
1479 dst
->Alignment
= src
->Alignment
;
1480 dst
->RowLength
= src
->RowLength
;
1481 dst
->SkipPixels
= src
->SkipPixels
;
1482 dst
->SkipRows
= src
->SkipRows
;
1483 dst
->ImageHeight
= src
->ImageHeight
;
1484 dst
->SkipImages
= src
->SkipImages
;
1485 dst
->SwapBytes
= src
->SwapBytes
;
1486 dst
->LsbFirst
= src
->LsbFirst
;
1487 dst
->Invert
= src
->Invert
;
1488 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1492 #define GL_CLIENT_PACK_BIT (1<<20)
1493 #define GL_CLIENT_UNPACK_BIT (1<<21)
1496 * Copy gl_vertex_array_object from src to dest.
1497 * 'dest' must be in an initialized state.
1500 copy_array_object(struct gl_context
*ctx
,
1501 struct gl_vertex_array_object
*dest
,
1502 struct gl_vertex_array_object
*src
)
1509 for (i
= 0; i
< ARRAY_SIZE(src
->VertexAttrib
); i
++) {
1510 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1511 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->BufferBinding
[i
], &src
->BufferBinding
[i
]);
1514 /* _Enabled must be the same than on push */
1515 dest
->_Enabled
= src
->_Enabled
;
1516 /* The bitmask of bound VBOs needs to match the VertexBinding array */
1517 dest
->VertexAttribBufferMask
= src
->VertexAttribBufferMask
;
1518 dest
->_AttributeMapMode
= src
->_AttributeMapMode
;
1519 dest
->NewArrays
= src
->NewArrays
;
1523 * Copy gl_array_attrib from src to dest.
1524 * 'dest' must be in an initialized state.
1527 copy_array_attrib(struct gl_context
*ctx
,
1528 struct gl_array_attrib
*dest
,
1529 struct gl_array_attrib
*src
,
1533 /* skip DefaultArrayObj, Objects */
1534 dest
->ActiveTexture
= src
->ActiveTexture
;
1535 dest
->LockFirst
= src
->LockFirst
;
1536 dest
->LockCount
= src
->LockCount
;
1537 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1538 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1539 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1540 dest
->RestartIndex
= src
->RestartIndex
;
1542 /* skip RebindArrays */
1545 copy_array_object(ctx
, dest
->VAO
, src
->VAO
);
1547 /* skip ArrayBufferObj */
1548 /* skip IndexBufferObj */
1550 /* Invalidate array state. It will be updated during the next draw. */
1551 _mesa_set_drawing_arrays(ctx
, NULL
);
1552 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1556 * Save the content of src to dest.
1559 save_array_attrib(struct gl_context
*ctx
,
1560 struct gl_array_attrib
*dest
,
1561 struct gl_array_attrib
*src
)
1563 /* Set the Name, needed for restore, but do never overwrite.
1564 * Needs to match value in the object hash. */
1565 dest
->VAO
->Name
= src
->VAO
->Name
;
1566 /* And copy all of the rest. */
1567 copy_array_attrib(ctx
, dest
, src
, false);
1569 /* Just reference them here */
1570 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1571 src
->ArrayBufferObj
);
1572 _mesa_reference_buffer_object(ctx
, &dest
->VAO
->IndexBufferObj
,
1573 src
->VAO
->IndexBufferObj
);
1577 * Restore the content of src to dest.
1580 restore_array_attrib(struct gl_context
*ctx
,
1581 struct gl_array_attrib
*dest
,
1582 struct gl_array_attrib
*src
)
1584 bool is_vao_name_zero
= src
->VAO
->Name
== 0;
1586 /* The ARB_vertex_array_object spec says:
1588 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1589 * if array is not a name returned from a previous call to
1590 * GenVertexArrays, or if such a name has since been deleted with
1591 * DeleteVertexArrays."
1593 * Therefore popping a deleted VAO cannot magically recreate it.
1595 if (!is_vao_name_zero
&& !_mesa_IsVertexArray(src
->VAO
->Name
))
1598 _mesa_BindVertexArray(src
->VAO
->Name
);
1600 /* Restore or recreate the buffer objects by the names ... */
1601 if (is_vao_name_zero
|| src
->ArrayBufferObj
->Name
== 0 ||
1602 _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1603 /* ... and restore its content */
1604 copy_array_attrib(ctx
, dest
, src
, false);
1606 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1607 src
->ArrayBufferObj
->Name
);
1609 copy_array_attrib(ctx
, dest
, src
, true);
1612 if (is_vao_name_zero
|| src
->VAO
->IndexBufferObj
->Name
== 0 ||
1613 _mesa_IsBuffer(src
->VAO
->IndexBufferObj
->Name
))
1614 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1615 src
->VAO
->IndexBufferObj
->Name
);
1619 * init/alloc the fields of 'attrib'.
1620 * Needs to the init part matching free_array_attrib_data below.
1623 init_array_attrib_data(struct gl_context
*ctx
,
1624 struct gl_array_attrib
*attrib
)
1626 /* Get a non driver gl_vertex_array_object. */
1627 attrib
->VAO
= CALLOC_STRUCT(gl_vertex_array_object
);
1629 if (attrib
->VAO
== NULL
) {
1630 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1634 _mesa_initialize_vao(ctx
, attrib
->VAO
, 0);
1639 * Free/unreference the fields of 'attrib' but don't delete it (that's
1640 * done later in the calling code).
1641 * Needs to the cleanup part matching init_array_attrib_data above.
1644 free_array_attrib_data(struct gl_context
*ctx
,
1645 struct gl_array_attrib
*attrib
)
1647 /* We use a non driver array object, so don't just unref since we would
1648 * end up using the drivers DeleteArrayObject function for deletion. */
1649 _mesa_delete_vao(ctx
, attrib
->VAO
);
1651 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1656 _mesa_PushClientAttrib(GLbitfield mask
)
1658 struct gl_attrib_node
*head
;
1660 GET_CURRENT_CONTEXT(ctx
);
1662 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1663 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib");
1667 /* Build linked list of attribute nodes which save all attribute
1668 * groups specified by the mask.
1672 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1673 struct gl_pixelstore_attrib
*attr
;
1674 /* packing attribs */
1675 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1677 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1680 if (save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
)) {
1681 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1684 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1689 /* unpacking attribs */
1690 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1692 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1696 if (save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
)) {
1697 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1700 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1706 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1707 struct gl_array_attrib
*attr
;
1708 attr
= CALLOC_STRUCT(gl_array_attrib
);
1710 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1714 if (!init_array_attrib_data(ctx
, attr
)) {
1719 if (save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
)) {
1720 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1723 free_array_attrib_data(ctx
, attr
);
1724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1726 /* goto to keep safe from possible later changes */
1732 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1733 ctx
->ClientAttribStackDepth
++;
1739 _mesa_PopClientAttrib(void)
1741 struct gl_attrib_node
*node
, *next
;
1743 GET_CURRENT_CONTEXT(ctx
);
1744 FLUSH_VERTICES(ctx
, 0);
1746 if (ctx
->ClientAttribStackDepth
== 0) {
1747 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib");
1751 ctx
->ClientAttribStackDepth
--;
1752 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1755 switch (node
->kind
) {
1756 case GL_CLIENT_PACK_BIT
:
1758 struct gl_pixelstore_attrib
*store
=
1759 (struct gl_pixelstore_attrib
*) node
->data
;
1760 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1761 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1764 case GL_CLIENT_UNPACK_BIT
:
1766 struct gl_pixelstore_attrib
*store
=
1767 (struct gl_pixelstore_attrib
*) node
->data
;
1768 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1769 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1772 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1773 struct gl_array_attrib
* attr
=
1774 (struct gl_array_attrib
*) node
->data
;
1775 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1776 free_array_attrib_data(ctx
, attr
);
1777 ctx
->NewState
|= _NEW_ARRAY
;
1781 unreachable("Bad attrib flag in PopClientAttrib");
1793 * Free any attribute state data that might be attached to the context.
1796 _mesa_free_attrib_data(struct gl_context
*ctx
)
1798 while (ctx
->AttribStackDepth
> 0) {
1799 struct gl_attrib_node
*attr
, *next
;
1801 ctx
->AttribStackDepth
--;
1802 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1805 if (attr
->kind
== GL_TEXTURE_BIT
) {
1806 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1808 /* clear references to the saved texture objects */
1809 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1810 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1811 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1814 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1817 /* any other chunks of state that requires special handling? */
1830 _mesa_init_attrib(struct gl_context
*ctx
)
1832 /* Renderer and client attribute stacks */
1833 ctx
->AttribStackDepth
= 0;
1834 ctx
->ClientAttribStackDepth
= 0;