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"
65 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
67 struct gl_enable_attrib
72 GLbitfield ClipPlanes
;
73 GLboolean ColorMaterial
;
79 GLboolean Light
[MAX_LIGHTS
];
82 GLboolean LineStipple
;
83 GLboolean IndexLogicOp
;
84 GLboolean ColorLogicOp
;
89 GLboolean Map1TextureCoord1
;
90 GLboolean Map1TextureCoord2
;
91 GLboolean Map1TextureCoord3
;
92 GLboolean Map1TextureCoord4
;
93 GLboolean Map1Vertex3
;
94 GLboolean Map1Vertex4
;
98 GLboolean Map2TextureCoord1
;
99 GLboolean Map2TextureCoord2
;
100 GLboolean Map2TextureCoord3
;
101 GLboolean Map2TextureCoord4
;
102 GLboolean Map2Vertex3
;
103 GLboolean Map2Vertex4
;
106 GLboolean PixelTexture
;
107 GLboolean PointSmooth
;
108 GLboolean PolygonOffsetPoint
;
109 GLboolean PolygonOffsetLine
;
110 GLboolean PolygonOffsetFill
;
111 GLboolean PolygonSmooth
;
112 GLboolean PolygonStipple
;
113 GLboolean RescaleNormals
;
116 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
117 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
118 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
120 GLboolean SampleCoverage
; /* GL_ARB_multisample */
121 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
123 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
124 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
126 /* GL_ARB_vertex_program */
127 GLboolean VertexProgram
;
128 GLboolean VertexProgramPointSize
;
129 GLboolean VertexProgramTwoSide
;
131 /* GL_ARB_fragment_program */
132 GLboolean FragmentProgram
;
134 /* GL_ARB_point_sprite / GL_NV_point_sprite */
135 GLboolean PointSprite
;
136 GLboolean FragmentShaderATI
;
138 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
139 GLboolean sRGBEnabled
;
144 * Node for the attribute stack.
146 struct gl_attrib_node
150 struct gl_attrib_node
*next
;
156 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
160 struct gl_texture_attrib Texture
; /**< The usual context state */
162 /** to save per texture object state (wrap modes, filters, etc): */
163 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
166 * To save references to texture objects (so they don't get accidentally
167 * deleted while saved in the attribute stack).
169 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
171 /* We need to keep a reference to the shared state. That's where the
172 * default texture objects are kept. We don't want that state to be
173 * freed while the attribute stack contains pointers to any default
176 struct gl_shared_state
*SharedRef
;
180 /** An unused GL_*_BIT value */
181 #define DUMMY_BIT 0x10000000
185 * Allocate new attribute node of given type/kind. Attach payload data.
186 * Insert it into the linked list named by 'head'.
189 save_attrib_data(struct gl_attrib_node
**head
,
190 GLbitfield kind
, void *payload
)
192 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
209 * Helper function for_mesa_PushAttrib for simple attributes.
210 * Allocates memory for attribute data and copies the given attribute data.
211 * \param head head of linked list to insert attribute data into
212 * \param attr_bit one of the GL_<attrib>_BIT flags
213 * \param attr_size number of bytes to allocate for attribute data
214 * \param attr_data the attribute data to copy
215 * \return true for success, false for out of memory
218 push_attrib(struct gl_context
*ctx
, struct gl_attrib_node
**head
,
219 GLbitfield attr_bit
, GLuint attr_size
, const void *attr_data
)
223 attribute
= malloc(attr_size
);
224 if (attribute
== NULL
) {
225 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
229 if (save_attrib_data(head
, attr_bit
, attribute
)) {
230 memcpy(attribute
, attr_data
, attr_size
);
234 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
242 _mesa_PushAttrib(GLbitfield mask
)
244 struct gl_attrib_node
*head
;
246 GET_CURRENT_CONTEXT(ctx
);
248 if (MESA_VERBOSE
& VERBOSE_API
)
249 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
251 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
252 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushAttrib");
256 /* Build linked list of attribute nodes which save all attribute */
257 /* groups specified by the mask. */
261 /* if mask is zero we still need to push something so that we
262 * don't get a GL_STACK_UNDERFLOW error in glPopAttrib().
265 if (!push_attrib(ctx
, &head
, DUMMY_BIT
, sizeof(dummy
), &dummy
))
269 if (mask
& GL_ACCUM_BUFFER_BIT
) {
270 if (!push_attrib(ctx
, &head
, GL_ACCUM_BUFFER_BIT
,
271 sizeof(struct gl_accum_attrib
),
276 if (mask
& GL_COLOR_BUFFER_BIT
) {
278 struct gl_colorbuffer_attrib
*attr
;
279 attr
= MALLOC_STRUCT(gl_colorbuffer_attrib
);
281 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
285 if (save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
)) {
286 memcpy(attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
));
287 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
288 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
289 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
293 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
298 if (mask
& GL_CURRENT_BIT
) {
299 FLUSH_CURRENT(ctx
, 0);
300 if (!push_attrib(ctx
, &head
, GL_CURRENT_BIT
,
301 sizeof(struct gl_current_attrib
),
302 (void*)&ctx
->Current
))
306 if (mask
& GL_DEPTH_BUFFER_BIT
) {
307 if (!push_attrib(ctx
, &head
, GL_DEPTH_BUFFER_BIT
,
308 sizeof(struct gl_depthbuffer_attrib
),
313 if (mask
& GL_ENABLE_BIT
) {
314 struct gl_enable_attrib
*attr
;
316 attr
= MALLOC_STRUCT(gl_enable_attrib
);
318 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
322 /* Copy enable flags from all other attributes into the enable struct. */
323 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
324 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
325 attr
->Blend
= ctx
->Color
.BlendEnabled
;
326 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
327 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
328 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
329 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
330 attr
->DepthTest
= ctx
->Depth
.Test
;
331 attr
->Dither
= ctx
->Color
.DitherFlag
;
332 attr
->Fog
= ctx
->Fog
.Enabled
;
333 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
334 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
336 attr
->Lighting
= ctx
->Light
.Enabled
;
337 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
338 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
339 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
340 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
341 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
342 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
343 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
344 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
345 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
346 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
347 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
348 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
349 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
350 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
351 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
352 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
353 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
354 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
355 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
356 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
357 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
358 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
359 attr
->Normalize
= ctx
->Transform
.Normalize
;
360 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
361 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
362 attr
->PointSprite
= ctx
->Point
.PointSprite
;
363 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
364 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
365 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
366 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
367 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
368 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
369 attr
->Scissor
= ctx
->Scissor
.EnableFlags
;
370 attr
->Stencil
= ctx
->Stencil
.Enabled
;
371 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
372 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
373 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
374 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
375 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
376 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
377 attr
->Texture
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].Enabled
;
378 attr
->TexGen
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
;
380 /* GL_ARB_vertex_program */
381 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
382 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
383 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
385 /* GL_ARB_fragment_program */
386 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
388 if (!save_attrib_data(&head
, GL_ENABLE_BIT
, attr
)) {
390 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
394 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
395 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
398 if (mask
& GL_EVAL_BIT
) {
399 if (!push_attrib(ctx
, &head
, GL_EVAL_BIT
,
400 sizeof(struct gl_eval_attrib
),
405 if (mask
& GL_FOG_BIT
) {
406 if (!push_attrib(ctx
, &head
, GL_FOG_BIT
,
407 sizeof(struct gl_fog_attrib
),
412 if (mask
& GL_HINT_BIT
) {
413 if (!push_attrib(ctx
, &head
, GL_HINT_BIT
,
414 sizeof(struct gl_hint_attrib
),
419 if (mask
& GL_LIGHTING_BIT
) {
420 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
421 if (!push_attrib(ctx
, &head
, GL_LIGHTING_BIT
,
422 sizeof(struct gl_light_attrib
),
427 if (mask
& GL_LINE_BIT
) {
428 if (!push_attrib(ctx
, &head
, GL_LINE_BIT
,
429 sizeof(struct gl_line_attrib
),
434 if (mask
& GL_LIST_BIT
) {
435 if (!push_attrib(ctx
, &head
, GL_LIST_BIT
,
436 sizeof(struct gl_list_attrib
),
441 if (mask
& GL_PIXEL_MODE_BIT
) {
442 struct gl_pixel_attrib
*attr
;
443 attr
= MALLOC_STRUCT(gl_pixel_attrib
);
445 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
449 if (save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
)) {
450 memcpy(attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
));
451 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
452 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
456 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
461 if (mask
& GL_POINT_BIT
) {
462 if (!push_attrib(ctx
, &head
, GL_POINT_BIT
,
463 sizeof(struct gl_point_attrib
),
468 if (mask
& GL_POLYGON_BIT
) {
469 if (!push_attrib(ctx
, &head
, GL_POLYGON_BIT
,
470 sizeof(struct gl_polygon_attrib
),
471 (void*)&ctx
->Polygon
))
475 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
476 if (!push_attrib(ctx
, &head
, GL_POLYGON_STIPPLE_BIT
,
477 sizeof(ctx
->PolygonStipple
),
478 (void*)&ctx
->PolygonStipple
))
482 if (mask
& GL_SCISSOR_BIT
) {
483 if (!push_attrib(ctx
, &head
, GL_SCISSOR_BIT
,
484 sizeof(struct gl_scissor_attrib
),
485 (void*)&ctx
->Scissor
))
489 if (mask
& GL_STENCIL_BUFFER_BIT
) {
490 if (!push_attrib(ctx
, &head
, GL_STENCIL_BUFFER_BIT
,
491 sizeof(struct gl_stencil_attrib
),
492 (void*)&ctx
->Stencil
))
496 if (mask
& GL_TEXTURE_BIT
) {
497 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
501 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
505 if (!save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
)) {
507 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
511 _mesa_lock_context_textures(ctx
);
513 /* copy/save the bulk of texture state here */
514 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
516 /* Save references to the currently bound texture objects so they don't
517 * accidentally get deleted while referenced in the attribute stack.
519 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
520 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
521 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
522 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
526 /* copy state/contents of the currently bound texture objects */
527 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
528 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
529 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
530 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
534 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
536 _mesa_unlock_context_textures(ctx
);
539 if (mask
& GL_TRANSFORM_BIT
) {
540 if (!push_attrib(ctx
, &head
, GL_TRANSFORM_BIT
,
541 sizeof(struct gl_transform_attrib
),
542 (void*)&ctx
->Transform
))
546 if (mask
& GL_VIEWPORT_BIT
) {
547 if (!push_attrib(ctx
, &head
, GL_VIEWPORT_BIT
,
548 sizeof(struct gl_viewport_attrib
)
549 * ctx
->Const
.MaxViewports
,
550 (void*)&ctx
->ViewportArray
))
554 /* GL_ARB_multisample */
555 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
556 if (!push_attrib(ctx
, &head
, GL_MULTISAMPLE_BIT_ARB
,
557 sizeof(struct gl_multisample_attrib
),
558 (void*)&ctx
->Multisample
))
564 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
565 ctx
->AttribStackDepth
++;
572 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
574 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
577 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
578 if ((VALUE) != (NEWVALUE)) { \
579 _mesa_set_enable(ctx, ENUM, (NEWVALUE)); \
582 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
583 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
584 if (ctx
->Extensions
.EXT_draw_buffers2
) {
586 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
587 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
591 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
595 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
596 const GLuint mask
= 1 << i
;
597 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
598 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
599 !!(enable
->ClipPlanes
& mask
));
602 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
604 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
605 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
607 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
608 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
609 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
610 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
611 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
612 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
614 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
616 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
619 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
620 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
621 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
622 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
623 GL_MAP1_TEXTURE_COORD_1
);
624 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
625 GL_MAP1_TEXTURE_COORD_2
);
626 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
627 GL_MAP1_TEXTURE_COORD_3
);
628 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
629 GL_MAP1_TEXTURE_COORD_4
);
630 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
632 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
635 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
636 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
637 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
638 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
639 GL_MAP2_TEXTURE_COORD_1
);
640 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
641 GL_MAP2_TEXTURE_COORD_2
);
642 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
643 GL_MAP2_TEXTURE_COORD_3
);
644 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
645 GL_MAP2_TEXTURE_COORD_4
);
646 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
648 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
651 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
652 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
653 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
654 GL_RESCALE_NORMAL_EXT
);
655 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
656 enable
->RasterPositionUnclipped
,
657 GL_RASTER_POSITION_UNCLIPPED_IBM
);
658 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
660 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
661 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
664 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
665 GL_POLYGON_OFFSET_POINT
);
666 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
667 GL_POLYGON_OFFSET_LINE
);
668 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
669 GL_POLYGON_OFFSET_FILL
);
670 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
672 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
674 if (ctx
->Scissor
.EnableFlags
!= enable
->Scissor
) {
677 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
678 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
, (enable
->Scissor
>> i
) & 1);
681 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
682 if (ctx
->Extensions
.EXT_stencil_two_side
) {
683 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
685 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
687 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
688 enable
->SampleAlphaToCoverage
,
689 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
690 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
691 enable
->SampleAlphaToOne
,
692 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
693 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
694 enable
->SampleCoverage
,
695 GL_SAMPLE_COVERAGE_ARB
);
696 /* GL_ARB_vertex_program */
697 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
698 enable
->VertexProgram
,
699 GL_VERTEX_PROGRAM_ARB
);
700 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
701 enable
->VertexProgramPointSize
,
702 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
703 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
704 enable
->VertexProgramTwoSide
,
705 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
707 /* GL_ARB_fragment_program */
708 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
709 enable
->FragmentProgram
,
710 GL_FRAGMENT_PROGRAM_ARB
);
712 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
713 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
714 GL_FRAMEBUFFER_SRGB
);
716 /* texture unit enables */
717 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
718 const GLbitfield enabled
= enable
->Texture
[i
];
719 const GLbitfield genEnabled
= enable
->TexGen
[i
];
721 if (ctx
->Texture
.FixedFuncUnit
[i
].Enabled
!= enabled
) {
722 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
724 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
725 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
726 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
727 if (ctx
->Extensions
.NV_texture_rectangle
) {
728 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
729 !!(enabled
& TEXTURE_RECT_BIT
));
731 if (ctx
->Extensions
.ARB_texture_cube_map
) {
732 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
733 !!(enabled
& TEXTURE_CUBE_BIT
));
737 if (ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
!= genEnabled
) {
738 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
739 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
740 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
741 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
742 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
746 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
751 * Pop/restore texture attribute/group state.
754 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
758 _mesa_lock_context_textures(ctx
);
760 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
761 const struct gl_fixedfunc_texture_unit
*unit
=
762 &texstate
->Texture
.FixedFuncUnit
[u
];
765 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
766 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
767 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
768 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
769 if (ctx
->Extensions
.ARB_texture_cube_map
) {
770 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
771 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
773 if (ctx
->Extensions
.NV_texture_rectangle
) {
774 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
775 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
777 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
778 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
779 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
780 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
781 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
782 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
783 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
784 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
785 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
786 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
787 /* Eye plane done differently to avoid re-transformation */
789 struct gl_fixedfunc_texture_unit
*destUnit
=
790 &ctx
->Texture
.FixedFuncUnit
[u
];
792 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
793 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
794 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
795 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
796 if (ctx
->Driver
.TexGen
) {
797 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
798 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
799 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
800 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
803 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
804 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
805 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
806 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
807 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
808 texstate
->Texture
.Unit
[u
].LodBias
);
809 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
810 unit
->Combine
.ModeRGB
);
811 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
812 unit
->Combine
.ModeA
);
814 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
816 for (i
= 0; i
< n
; i
++) {
817 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
818 unit
->Combine
.SourceRGB
[i
]);
819 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
820 unit
->Combine
.SourceA
[i
]);
821 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
822 unit
->Combine
.OperandRGB
[i
]);
823 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
824 unit
->Combine
.OperandA
[i
]);
827 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
828 1 << unit
->Combine
.ScaleShiftRGB
);
829 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
830 1 << unit
->Combine
.ScaleShiftA
);
832 /* Restore texture object state for each target */
833 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
834 const struct gl_texture_object
*obj
= NULL
;
835 const struct gl_sampler_object
*samp
;
838 obj
= &texstate
->SavedObj
[u
][tgt
];
840 /* don't restore state for unsupported targets to prevent
843 if (obj
->Target
== GL_TEXTURE_CUBE_MAP
&&
844 !ctx
->Extensions
.ARB_texture_cube_map
) {
847 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
848 !ctx
->Extensions
.NV_texture_rectangle
) {
851 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
852 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
853 !ctx
->Extensions
.EXT_texture_array
) {
856 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
857 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
859 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
861 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
863 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
864 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
867 target
= obj
->Target
;
869 _mesa_BindTexture(target
, obj
->Name
);
871 samp
= &obj
->Sampler
;
873 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
874 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
875 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
876 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
877 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
878 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
879 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
880 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
881 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
882 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
883 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
884 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
885 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
886 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
887 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
888 samp
->MaxAnisotropy
);
890 if (ctx
->Extensions
.ARB_shadow
) {
891 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
893 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
896 if (ctx
->Extensions
.ARB_depth_texture
)
897 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
900 /* remove saved references to the texture objects */
901 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
902 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
906 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
908 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
910 _mesa_unlock_context_textures(ctx
);
915 * This function is kind of long just because we have to call a lot
916 * of device driver functions to update device driver state.
918 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
919 * in order to restore GL state. This isn't terribly efficient but it
920 * ensures that dirty flags and any derived state gets updated correctly.
921 * We could at least check if the value to restore equals the current value
922 * and then skip the Mesa call.
925 _mesa_PopAttrib(void)
927 struct gl_attrib_node
*attr
, *next
;
928 GET_CURRENT_CONTEXT(ctx
);
929 FLUSH_VERTICES(ctx
, 0);
931 if (ctx
->AttribStackDepth
== 0) {
932 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib");
936 ctx
->AttribStackDepth
--;
937 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
941 if (MESA_VERBOSE
& VERBOSE_API
) {
942 _mesa_debug(ctx
, "glPopAttrib %s\n",
943 _mesa_enum_to_string(attr
->kind
));
946 switch (attr
->kind
) {
951 case GL_ACCUM_BUFFER_BIT
:
953 const struct gl_accum_attrib
*accum
;
954 accum
= (const struct gl_accum_attrib
*) attr
->data
;
955 _mesa_ClearAccum(accum
->ClearColor
[0],
956 accum
->ClearColor
[1],
957 accum
->ClearColor
[2],
958 accum
->ClearColor
[3]);
961 case GL_COLOR_BUFFER_BIT
:
963 const struct gl_colorbuffer_attrib
*color
;
965 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
966 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
967 _mesa_ClearColor(color
->ClearColor
.f
[0],
968 color
->ClearColor
.f
[1],
969 color
->ClearColor
.f
[2],
970 color
->ClearColor
.f
[3]);
971 _mesa_IndexMask(color
->IndexMask
);
972 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
973 _mesa_ColorMask(GET_COLORMASK_BIT(color
->ColorMask
, 0, 0),
974 GET_COLORMASK_BIT(color
->ColorMask
, 0, 1),
975 GET_COLORMASK_BIT(color
->ColorMask
, 0, 2),
976 GET_COLORMASK_BIT(color
->ColorMask
, 0, 3));
980 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
982 GET_COLORMASK_BIT(color
->ColorMask
, i
, 0),
983 GET_COLORMASK_BIT(color
->ColorMask
, i
, 1),
984 GET_COLORMASK_BIT(color
->ColorMask
, i
, 2),
985 GET_COLORMASK_BIT(color
->ColorMask
, i
, 3));
989 /* Need to determine if more than one color output is
990 * specified. If so, call glDrawBuffersARB, else call
991 * glDrawBuffer(). This is a subtle, but essential point
992 * since GL_FRONT (for example) is illegal for the former
993 * function, but legal for the later.
995 GLboolean multipleBuffers
= GL_FALSE
;
998 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
999 if (color
->DrawBuffer
[i
] != GL_NONE
) {
1000 multipleBuffers
= GL_TRUE
;
1004 /* Call the API_level functions, not _mesa_drawbuffers()
1005 * since we need to do error checking on the pop'd
1007 * Ex: if GL_FRONT were pushed, but we're popping with a
1008 * user FBO bound, GL_FRONT will be illegal and we'll need
1009 * to record that error. Per OpenGL ARB decision.
1011 if (multipleBuffers
) {
1012 GLenum buffers
[MAX_DRAW_BUFFERS
];
1014 for (unsigned i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
1015 buffers
[i
] = color
->DrawBuffer
[i
];
1017 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
, buffers
);
1019 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1022 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1023 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
1024 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
1025 if (ctx
->Extensions
.EXT_draw_buffers2
) {
1027 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1028 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
1029 (color
->BlendEnabled
>> i
) & 1);
1033 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
1036 if (ctx
->Color
._BlendFuncPerBuffer
||
1037 ctx
->Color
._BlendEquationPerBuffer
) {
1038 /* set blend per buffer */
1040 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
1041 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
1042 color
->Blend
[buf
].DstRGB
,
1043 color
->Blend
[buf
].SrcA
,
1044 color
->Blend
[buf
].DstA
);
1045 _mesa_BlendEquationSeparateiARB(buf
,
1046 color
->Blend
[buf
].EquationRGB
,
1047 color
->Blend
[buf
].EquationA
);
1051 /* set same blend modes for all buffers */
1052 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
1053 color
->Blend
[0].DstRGB
,
1054 color
->Blend
[0].SrcA
,
1055 color
->Blend
[0].DstA
);
1056 /* This special case is because glBlendEquationSeparateEXT
1057 * cannot take GL_LOGIC_OP as a parameter.
1059 if (color
->Blend
[0].EquationRGB
==
1060 color
->Blend
[0].EquationA
) {
1061 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
1064 _mesa_BlendEquationSeparate(
1065 color
->Blend
[0].EquationRGB
,
1066 color
->Blend
[0].EquationA
);
1069 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
1070 color
->BlendColorUnclamped
[1],
1071 color
->BlendColorUnclamped
[2],
1072 color
->BlendColorUnclamped
[3]);
1073 _mesa_LogicOp(color
->LogicOp
);
1074 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1075 color
->ColorLogicOpEnabled
);
1076 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1077 color
->IndexLogicOpEnabled
);
1078 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1079 if (ctx
->Extensions
.ARB_color_buffer_float
)
1080 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
1081 color
->ClampFragmentColor
);
1082 if (ctx
->Extensions
.ARB_color_buffer_float
|| ctx
->Version
>= 30)
1083 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
1085 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
1086 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
1087 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
1090 case GL_CURRENT_BIT
:
1091 FLUSH_CURRENT(ctx
, 0);
1092 memcpy(&ctx
->Current
, attr
->data
,
1093 sizeof(struct gl_current_attrib
));
1095 case GL_DEPTH_BUFFER_BIT
:
1097 const struct gl_depthbuffer_attrib
*depth
;
1098 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1099 _mesa_DepthFunc(depth
->Func
);
1100 _mesa_ClearDepth(depth
->Clear
);
1101 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1102 _mesa_DepthMask(depth
->Mask
);
1103 if (ctx
->Extensions
.EXT_depth_bounds_test
) {
1104 _mesa_set_enable(ctx
, GL_DEPTH_BOUNDS_TEST_EXT
,
1106 _mesa_DepthBoundsEXT(depth
->BoundsMin
, depth
->BoundsMax
);
1112 const struct gl_enable_attrib
*enable
;
1113 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1114 pop_enable_group(ctx
, enable
);
1115 ctx
->NewState
|= _NEW_ALL
;
1116 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
|
1117 ctx
->DriverFlags
.NewBlend
|
1118 ctx
->DriverFlags
.NewClipPlaneEnable
|
1119 ctx
->DriverFlags
.NewDepth
|
1120 ctx
->DriverFlags
.NewDepthClamp
|
1121 ctx
->DriverFlags
.NewFramebufferSRGB
|
1122 ctx
->DriverFlags
.NewLineState
|
1123 ctx
->DriverFlags
.NewLogicOp
|
1124 ctx
->DriverFlags
.NewMultisampleEnable
|
1125 ctx
->DriverFlags
.NewPolygonState
|
1126 ctx
->DriverFlags
.NewSampleAlphaToXEnable
|
1127 ctx
->DriverFlags
.NewSampleMask
|
1128 ctx
->DriverFlags
.NewScissorTest
|
1129 ctx
->DriverFlags
.NewStencil
;
1133 memcpy(&ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
));
1134 ctx
->NewState
|= _NEW_EVAL
;
1138 const struct gl_fog_attrib
*fog
;
1139 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1140 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1141 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1142 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1143 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1144 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1145 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1146 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1151 const struct gl_hint_attrib
*hint
;
1152 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1153 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1154 hint
->PerspectiveCorrection
);
1155 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1156 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1157 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1158 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1159 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1160 hint
->TextureCompression
);
1163 case GL_LIGHTING_BIT
:
1166 const struct gl_light_attrib
*light
;
1167 light
= (const struct gl_light_attrib
*) attr
->data
;
1168 /* lighting enable */
1169 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1170 /* per-light state */
1171 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1172 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
1174 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1175 const struct gl_light
*l
= &light
->Light
[i
];
1176 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1177 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1178 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1179 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1180 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1181 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1183 GLfloat p
[4] = { 0 };
1184 p
[0] = l
->SpotExponent
;
1185 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1188 GLfloat p
[4] = { 0 };
1189 p
[0] = l
->SpotCutoff
;
1190 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1193 GLfloat p
[4] = { 0 };
1194 p
[0] = l
->ConstantAttenuation
;
1195 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1198 GLfloat p
[4] = { 0 };
1199 p
[0] = l
->LinearAttenuation
;
1200 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1203 GLfloat p
[4] = { 0 };
1204 p
[0] = l
->QuadraticAttenuation
;
1205 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1209 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1210 light
->Model
.Ambient
);
1211 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1212 (GLfloat
) light
->Model
.LocalViewer
);
1213 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1214 (GLfloat
) light
->Model
.TwoSide
);
1215 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1216 (GLfloat
) light
->Model
.ColorControl
);
1218 _mesa_ShadeModel(light
->ShadeModel
);
1219 /* color material */
1220 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1221 light
->ColorMaterialMode
);
1222 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1223 light
->ColorMaterialEnabled
);
1225 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1226 sizeof(struct gl_material
));
1227 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1228 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1229 light
->ClampVertexColor
);
1235 const struct gl_line_attrib
*line
;
1236 line
= (const struct gl_line_attrib
*) attr
->data
;
1237 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1238 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1239 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1240 _mesa_LineWidth(line
->Width
);
1244 memcpy(&ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
));
1246 case GL_PIXEL_MODE_BIT
:
1247 memcpy(&ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
));
1248 /* XXX what other pixel state needs to be set by function calls? */
1249 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1250 ctx
->NewState
|= _NEW_PIXEL
;
1254 const struct gl_point_attrib
*point
;
1255 point
= (const struct gl_point_attrib
*) attr
->data
;
1256 _mesa_PointSize(point
->Size
);
1257 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1258 if (ctx
->Extensions
.EXT_point_parameters
) {
1259 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1261 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1263 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1265 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1268 if (ctx
->Extensions
.NV_point_sprite
1269 || ctx
->Extensions
.ARB_point_sprite
) {
1271 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1272 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1273 !!(point
->CoordReplace
& (1u << u
)));
1275 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1276 if (ctx
->Extensions
.NV_point_sprite
)
1277 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1278 ctx
->Point
.SpriteRMode
);
1280 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1281 || ctx
->API
== API_OPENGL_CORE
)
1282 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1283 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1287 case GL_POLYGON_BIT
:
1289 const struct gl_polygon_attrib
*polygon
;
1290 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1291 _mesa_CullFace(polygon
->CullFaceMode
);
1292 _mesa_FrontFace(polygon
->FrontFace
);
1293 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1294 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1295 _mesa_polygon_offset_clamp(ctx
,
1296 polygon
->OffsetFactor
,
1297 polygon
->OffsetUnits
,
1298 polygon
->OffsetClamp
);
1299 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1300 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1301 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1302 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1303 polygon
->OffsetPoint
);
1304 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1305 polygon
->OffsetLine
);
1306 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1307 polygon
->OffsetFill
);
1310 case GL_POLYGON_STIPPLE_BIT
:
1311 memcpy(ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
));
1313 if (ctx
->DriverFlags
.NewPolygonStipple
)
1314 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
1316 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1318 if (ctx
->Driver
.PolygonStipple
)
1319 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) attr
->data
);
1321 case GL_SCISSOR_BIT
:
1324 const struct gl_scissor_attrib
*scissor
;
1325 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1327 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1328 _mesa_set_scissor(ctx
, i
,
1329 scissor
->ScissorArray
[i
].X
,
1330 scissor
->ScissorArray
[i
].Y
,
1331 scissor
->ScissorArray
[i
].Width
,
1332 scissor
->ScissorArray
[i
].Height
);
1333 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
1334 (scissor
->EnableFlags
>> i
) & 1);
1336 if (ctx
->Extensions
.EXT_window_rectangles
) {
1337 STATIC_ASSERT(sizeof(struct gl_scissor_rect
) ==
1339 _mesa_WindowRectanglesEXT(
1340 scissor
->WindowRectMode
, scissor
->NumWindowRects
,
1341 (const GLint
*)scissor
->WindowRects
);
1345 case GL_STENCIL_BUFFER_BIT
:
1347 const struct gl_stencil_attrib
*stencil
;
1348 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1349 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1350 _mesa_ClearStencil(stencil
->Clear
);
1351 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1352 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1353 stencil
->TestTwoSide
);
1354 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1355 ? GL_BACK
: GL_FRONT
);
1358 _mesa_StencilFuncSeparate(GL_FRONT
,
1359 stencil
->Function
[0],
1361 stencil
->ValueMask
[0]);
1362 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1363 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1364 stencil
->ZFailFunc
[0],
1365 stencil
->ZPassFunc
[0]);
1367 _mesa_StencilFuncSeparate(GL_BACK
,
1368 stencil
->Function
[1],
1370 stencil
->ValueMask
[1]);
1371 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1372 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1373 stencil
->ZFailFunc
[1],
1374 stencil
->ZPassFunc
[1]);
1377 case GL_TRANSFORM_BIT
:
1380 const struct gl_transform_attrib
*xform
;
1381 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1382 _mesa_MatrixMode(xform
->MatrixMode
);
1383 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1384 _math_matrix_analyse(ctx
->ProjectionMatrixStack
.Top
);
1386 /* restore clip planes */
1387 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1388 const GLuint mask
= 1 << i
;
1389 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1390 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1391 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1392 !!(xform
->ClipPlanesEnabled
& mask
));
1393 if (ctx
->Driver
.ClipPlane
)
1394 ctx
->Driver
.ClipPlane(ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1397 /* normalize/rescale */
1398 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1399 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1400 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1401 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1402 ctx
->Transform
.RescaleNormals
);
1403 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1404 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1405 ctx
->Transform
.DepthClamp
);
1406 if (ctx
->Extensions
.ARB_clip_control
)
1407 _mesa_ClipControl(xform
->ClipOrigin
, xform
->ClipDepthMode
);
1410 case GL_TEXTURE_BIT
:
1412 struct texture_state
*texstate
1413 = (struct texture_state
*) attr
->data
;
1414 pop_texture_group(ctx
, texstate
);
1415 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
| _NEW_TEXTURE_STATE
;
1418 case GL_VIEWPORT_BIT
:
1421 const struct gl_viewport_attrib
*vp
;
1422 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1424 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1425 _mesa_set_viewport(ctx
, i
, vp
[i
].X
, vp
[i
].Y
, vp
[i
].Width
,
1427 _mesa_set_depth_range(ctx
, i
, vp
[i
].Near
, vp
[i
].Far
);
1431 case GL_MULTISAMPLE_BIT_ARB
:
1433 const struct gl_multisample_attrib
*ms
;
1434 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1436 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1440 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1442 GL_SAMPLE_COVERAGE
);
1444 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1445 ms
->SampleAlphaToCoverage
,
1446 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1448 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1449 ms
->SampleAlphaToOne
,
1450 GL_SAMPLE_ALPHA_TO_ONE
);
1452 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1453 ms
->SampleCoverageInvert
);
1458 unreachable("Bad attrib flag in PopAttrib");
1470 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1474 copy_pixelstore(struct gl_context
*ctx
,
1475 struct gl_pixelstore_attrib
*dst
,
1476 const struct gl_pixelstore_attrib
*src
)
1478 dst
->Alignment
= src
->Alignment
;
1479 dst
->RowLength
= src
->RowLength
;
1480 dst
->SkipPixels
= src
->SkipPixels
;
1481 dst
->SkipRows
= src
->SkipRows
;
1482 dst
->ImageHeight
= src
->ImageHeight
;
1483 dst
->SkipImages
= src
->SkipImages
;
1484 dst
->SwapBytes
= src
->SwapBytes
;
1485 dst
->LsbFirst
= src
->LsbFirst
;
1486 dst
->Invert
= src
->Invert
;
1487 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1491 #define GL_CLIENT_PACK_BIT (1<<20)
1492 #define GL_CLIENT_UNPACK_BIT (1<<21)
1495 * Copy gl_vertex_array_object from src to dest.
1496 * 'dest' must be in an initialized state.
1499 copy_array_object(struct gl_context
*ctx
,
1500 struct gl_vertex_array_object
*dest
,
1501 struct gl_vertex_array_object
*src
)
1508 for (i
= 0; i
< ARRAY_SIZE(src
->VertexAttrib
); i
++) {
1509 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1510 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->BufferBinding
[i
], &src
->BufferBinding
[i
]);
1513 /* _Enabled must be the same than on push */
1514 dest
->_Enabled
= src
->_Enabled
;
1515 /* The bitmask of bound VBOs needs to match the VertexBinding array */
1516 dest
->VertexAttribBufferMask
= src
->VertexAttribBufferMask
;
1517 dest
->_AttributeMapMode
= src
->_AttributeMapMode
;
1518 dest
->NewArrays
= src
->NewArrays
;
1522 * Copy gl_array_attrib from src to dest.
1523 * 'dest' must be in an initialized state.
1526 copy_array_attrib(struct gl_context
*ctx
,
1527 struct gl_array_attrib
*dest
,
1528 struct gl_array_attrib
*src
,
1532 /* skip DefaultArrayObj, Objects */
1533 dest
->ActiveTexture
= src
->ActiveTexture
;
1534 dest
->LockFirst
= src
->LockFirst
;
1535 dest
->LockCount
= src
->LockCount
;
1536 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1537 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1538 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1539 dest
->RestartIndex
= src
->RestartIndex
;
1541 /* skip RebindArrays */
1544 copy_array_object(ctx
, dest
->VAO
, src
->VAO
);
1546 /* skip ArrayBufferObj */
1547 /* skip IndexBufferObj */
1549 /* Invalidate array state. It will be updated during the next draw. */
1550 _mesa_set_drawing_arrays(ctx
, NULL
);
1551 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1555 * Save the content of src to dest.
1558 save_array_attrib(struct gl_context
*ctx
,
1559 struct gl_array_attrib
*dest
,
1560 struct gl_array_attrib
*src
)
1562 /* Set the Name, needed for restore, but do never overwrite.
1563 * Needs to match value in the object hash. */
1564 dest
->VAO
->Name
= src
->VAO
->Name
;
1565 /* And copy all of the rest. */
1566 copy_array_attrib(ctx
, dest
, src
, false);
1568 /* Just reference them here */
1569 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1570 src
->ArrayBufferObj
);
1571 _mesa_reference_buffer_object(ctx
, &dest
->VAO
->IndexBufferObj
,
1572 src
->VAO
->IndexBufferObj
);
1576 * Restore the content of src to dest.
1579 restore_array_attrib(struct gl_context
*ctx
,
1580 struct gl_array_attrib
*dest
,
1581 struct gl_array_attrib
*src
)
1583 bool is_vao_name_zero
= src
->VAO
->Name
== 0;
1585 /* The ARB_vertex_array_object spec says:
1587 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1588 * if array is not a name returned from a previous call to
1589 * GenVertexArrays, or if such a name has since been deleted with
1590 * DeleteVertexArrays."
1592 * Therefore popping a deleted VAO cannot magically recreate it.
1594 if (!is_vao_name_zero
&& !_mesa_IsVertexArray(src
->VAO
->Name
))
1597 _mesa_BindVertexArray(src
->VAO
->Name
);
1599 /* Restore or recreate the buffer objects by the names ... */
1600 if (is_vao_name_zero
|| src
->ArrayBufferObj
->Name
== 0 ||
1601 _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1602 /* ... and restore its content */
1603 copy_array_attrib(ctx
, dest
, src
, false);
1605 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1606 src
->ArrayBufferObj
->Name
);
1608 copy_array_attrib(ctx
, dest
, src
, true);
1611 if (is_vao_name_zero
|| src
->VAO
->IndexBufferObj
->Name
== 0 ||
1612 _mesa_IsBuffer(src
->VAO
->IndexBufferObj
->Name
))
1613 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1614 src
->VAO
->IndexBufferObj
->Name
);
1618 * init/alloc the fields of 'attrib'.
1619 * Needs to the init part matching free_array_attrib_data below.
1622 init_array_attrib_data(struct gl_context
*ctx
,
1623 struct gl_array_attrib
*attrib
)
1625 /* Get a non driver gl_vertex_array_object. */
1626 attrib
->VAO
= CALLOC_STRUCT(gl_vertex_array_object
);
1628 if (attrib
->VAO
== NULL
) {
1629 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1633 _mesa_initialize_vao(ctx
, attrib
->VAO
, 0);
1638 * Free/unreference the fields of 'attrib' but don't delete it (that's
1639 * done later in the calling code).
1640 * Needs to the cleanup part matching init_array_attrib_data above.
1643 free_array_attrib_data(struct gl_context
*ctx
,
1644 struct gl_array_attrib
*attrib
)
1646 /* We use a non driver array object, so don't just unref since we would
1647 * end up using the drivers DeleteArrayObject function for deletion. */
1648 _mesa_delete_vao(ctx
, attrib
->VAO
);
1650 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1655 _mesa_PushClientAttrib(GLbitfield mask
)
1657 struct gl_attrib_node
*head
;
1659 GET_CURRENT_CONTEXT(ctx
);
1661 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1662 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib");
1666 /* Build linked list of attribute nodes which save all attribute
1667 * groups specified by the mask.
1671 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1672 struct gl_pixelstore_attrib
*attr
;
1673 /* packing attribs */
1674 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1676 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1679 if (save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
)) {
1680 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1683 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1688 /* unpacking attribs */
1689 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1691 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1695 if (save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
)) {
1696 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1699 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1705 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1706 struct gl_array_attrib
*attr
;
1707 attr
= CALLOC_STRUCT(gl_array_attrib
);
1709 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1713 if (!init_array_attrib_data(ctx
, attr
)) {
1718 if (save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
)) {
1719 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1722 free_array_attrib_data(ctx
, attr
);
1723 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1725 /* goto to keep safe from possible later changes */
1731 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1732 ctx
->ClientAttribStackDepth
++;
1738 _mesa_PopClientAttrib(void)
1740 struct gl_attrib_node
*node
, *next
;
1742 GET_CURRENT_CONTEXT(ctx
);
1743 FLUSH_VERTICES(ctx
, 0);
1745 if (ctx
->ClientAttribStackDepth
== 0) {
1746 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib");
1750 ctx
->ClientAttribStackDepth
--;
1751 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1754 switch (node
->kind
) {
1755 case GL_CLIENT_PACK_BIT
:
1757 struct gl_pixelstore_attrib
*store
=
1758 (struct gl_pixelstore_attrib
*) node
->data
;
1759 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1760 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1763 case GL_CLIENT_UNPACK_BIT
:
1765 struct gl_pixelstore_attrib
*store
=
1766 (struct gl_pixelstore_attrib
*) node
->data
;
1767 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1768 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1771 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1772 struct gl_array_attrib
* attr
=
1773 (struct gl_array_attrib
*) node
->data
;
1774 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1775 free_array_attrib_data(ctx
, attr
);
1776 ctx
->NewState
|= _NEW_ARRAY
;
1780 unreachable("Bad attrib flag in PopClientAttrib");
1792 * Free any attribute state data that might be attached to the context.
1795 _mesa_free_attrib_data(struct gl_context
*ctx
)
1797 while (ctx
->AttribStackDepth
> 0) {
1798 struct gl_attrib_node
*attr
, *next
;
1800 ctx
->AttribStackDepth
--;
1801 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1804 if (attr
->kind
== GL_TEXTURE_BIT
) {
1805 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1807 /* clear references to the saved texture objects */
1808 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1809 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1810 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1813 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1816 /* any other chunks of state that requires special handling? */
1829 _mesa_init_attrib(struct gl_context
*ctx
)
1831 /* Renderer and client attribute stacks */
1832 ctx
->AttribStackDepth
= 0;
1833 ctx
->ClientAttribStackDepth
= 0;