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.
27 #include "util/imports.h"
33 #include "bufferobj.h"
45 #include "multisample.h"
46 #include "pixelstore.h"
66 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
68 struct gl_enable_attrib
73 GLbitfield ClipPlanes
;
74 GLboolean ColorMaterial
;
76 GLboolean DepthClampNear
;
77 GLboolean DepthClampFar
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
100 GLboolean Map2TextureCoord1
;
101 GLboolean Map2TextureCoord2
;
102 GLboolean Map2TextureCoord3
;
103 GLboolean Map2TextureCoord4
;
104 GLboolean Map2Vertex3
;
105 GLboolean Map2Vertex4
;
108 GLboolean PixelTexture
;
109 GLboolean PointSmooth
;
110 GLboolean PolygonOffsetPoint
;
111 GLboolean PolygonOffsetLine
;
112 GLboolean PolygonOffsetFill
;
113 GLboolean PolygonSmooth
;
114 GLboolean PolygonStipple
;
115 GLboolean RescaleNormals
;
118 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
119 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
122 GLboolean SampleCoverage
; /* GL_ARB_multisample */
123 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
125 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
126 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
128 /* GL_ARB_vertex_program */
129 GLboolean VertexProgram
;
130 GLboolean VertexProgramPointSize
;
131 GLboolean VertexProgramTwoSide
;
133 /* GL_ARB_fragment_program */
134 GLboolean FragmentProgram
;
136 /* GL_ARB_point_sprite / GL_NV_point_sprite */
137 GLboolean PointSprite
;
138 GLboolean FragmentShaderATI
;
140 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
141 GLboolean sRGBEnabled
;
143 /* GL_NV_conservative_raster */
144 GLboolean ConservativeRasterization
;
149 * Node for the attribute stack.
151 struct gl_attrib_node
155 struct gl_attrib_node
*next
;
161 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
165 struct gl_texture_attrib Texture
; /**< The usual context state */
167 /** to save per texture object state (wrap modes, filters, etc): */
168 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
171 * To save references to texture objects (so they don't get accidentally
172 * deleted while saved in the attribute stack).
174 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
176 /* We need to keep a reference to the shared state. That's where the
177 * default texture objects are kept. We don't want that state to be
178 * freed while the attribute stack contains pointers to any default
181 struct gl_shared_state
*SharedRef
;
185 struct viewport_state
187 struct gl_viewport_attrib ViewportArray
[MAX_VIEWPORTS
];
188 GLuint SubpixelPrecisionBias
[2];
192 /** An unused GL_*_BIT value */
193 #define DUMMY_BIT 0x10000000
197 * Allocate new attribute node of given type/kind. Attach payload data.
198 * Insert it into the linked list named by 'head'.
201 save_attrib_data(struct gl_attrib_node
**head
,
202 GLbitfield kind
, void *payload
)
204 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
221 * Helper function for_mesa_PushAttrib for simple attributes.
222 * Allocates memory for attribute data and copies the given attribute data.
223 * \param head head of linked list to insert attribute data into
224 * \param attr_bit one of the GL_<attrib>_BIT flags
225 * \param attr_size number of bytes to allocate for attribute data
226 * \param attr_data the attribute data to copy
227 * \return true for success, false for out of memory
230 push_attrib(struct gl_context
*ctx
, struct gl_attrib_node
**head
,
231 GLbitfield attr_bit
, GLuint attr_size
, const void *attr_data
)
235 attribute
= malloc(attr_size
);
236 if (attribute
== NULL
) {
237 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
241 if (save_attrib_data(head
, attr_bit
, attribute
)) {
242 memcpy(attribute
, attr_data
, attr_size
);
246 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
254 _mesa_PushAttrib(GLbitfield mask
)
256 struct gl_attrib_node
*head
;
258 GET_CURRENT_CONTEXT(ctx
);
260 if (MESA_VERBOSE
& VERBOSE_API
)
261 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
263 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
264 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushAttrib");
268 /* Build linked list of attribute nodes which save all attribute */
269 /* groups specified by the mask. */
273 /* if mask is zero we still need to push something so that we
274 * don't get a GL_STACK_UNDERFLOW error in glPopAttrib().
277 if (!push_attrib(ctx
, &head
, DUMMY_BIT
, sizeof(dummy
), &dummy
))
281 if (mask
& GL_ACCUM_BUFFER_BIT
) {
282 if (!push_attrib(ctx
, &head
, GL_ACCUM_BUFFER_BIT
,
283 sizeof(struct gl_accum_attrib
),
288 if (mask
& GL_COLOR_BUFFER_BIT
) {
290 struct gl_colorbuffer_attrib
*attr
;
291 attr
= MALLOC_STRUCT(gl_colorbuffer_attrib
);
293 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
297 if (save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
)) {
298 memcpy(attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
));
299 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
300 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
301 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
305 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
310 if (mask
& GL_CURRENT_BIT
) {
311 FLUSH_CURRENT(ctx
, 0);
312 if (!push_attrib(ctx
, &head
, GL_CURRENT_BIT
,
313 sizeof(struct gl_current_attrib
),
314 (void*)&ctx
->Current
))
318 if (mask
& GL_DEPTH_BUFFER_BIT
) {
319 if (!push_attrib(ctx
, &head
, GL_DEPTH_BUFFER_BIT
,
320 sizeof(struct gl_depthbuffer_attrib
),
325 if (mask
& GL_ENABLE_BIT
) {
326 struct gl_enable_attrib
*attr
;
328 attr
= MALLOC_STRUCT(gl_enable_attrib
);
330 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
334 /* Copy enable flags from all other attributes into the enable struct. */
335 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
336 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
337 attr
->Blend
= ctx
->Color
.BlendEnabled
;
338 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
339 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
340 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
341 attr
->DepthClampNear
= ctx
->Transform
.DepthClampNear
;
342 attr
->DepthClampFar
= ctx
->Transform
.DepthClampFar
;
343 attr
->DepthTest
= ctx
->Depth
.Test
;
344 attr
->Dither
= ctx
->Color
.DitherFlag
;
345 attr
->Fog
= ctx
->Fog
.Enabled
;
346 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
347 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
349 attr
->Lighting
= ctx
->Light
.Enabled
;
350 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
351 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
352 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
353 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
354 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
355 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
356 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
357 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
358 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
359 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
360 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
361 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
362 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
363 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
364 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
365 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
366 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
367 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
368 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
369 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
370 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
371 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
372 attr
->Normalize
= ctx
->Transform
.Normalize
;
373 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
374 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
375 attr
->PointSprite
= ctx
->Point
.PointSprite
;
376 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
377 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
378 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
379 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
380 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
381 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
382 attr
->Scissor
= ctx
->Scissor
.EnableFlags
;
383 attr
->Stencil
= ctx
->Stencil
.Enabled
;
384 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
385 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
386 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
387 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
388 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
389 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
390 attr
->Texture
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].Enabled
;
391 attr
->TexGen
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
;
393 /* GL_ARB_vertex_program */
394 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
395 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
396 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
398 /* GL_ARB_fragment_program */
399 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
401 if (!save_attrib_data(&head
, GL_ENABLE_BIT
, attr
)) {
403 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
407 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
408 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
410 /* GL_NV_conservative_raster */
411 attr
->ConservativeRasterization
= ctx
->ConservativeRasterization
;
414 if (mask
& GL_EVAL_BIT
) {
415 if (!push_attrib(ctx
, &head
, GL_EVAL_BIT
,
416 sizeof(struct gl_eval_attrib
),
421 if (mask
& GL_FOG_BIT
) {
422 if (!push_attrib(ctx
, &head
, GL_FOG_BIT
,
423 sizeof(struct gl_fog_attrib
),
428 if (mask
& GL_HINT_BIT
) {
429 if (!push_attrib(ctx
, &head
, GL_HINT_BIT
,
430 sizeof(struct gl_hint_attrib
),
435 if (mask
& GL_LIGHTING_BIT
) {
436 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
437 if (!push_attrib(ctx
, &head
, GL_LIGHTING_BIT
,
438 sizeof(struct gl_light_attrib
),
443 if (mask
& GL_LINE_BIT
) {
444 if (!push_attrib(ctx
, &head
, GL_LINE_BIT
,
445 sizeof(struct gl_line_attrib
),
450 if (mask
& GL_LIST_BIT
) {
451 if (!push_attrib(ctx
, &head
, GL_LIST_BIT
,
452 sizeof(struct gl_list_attrib
),
457 if (mask
& GL_PIXEL_MODE_BIT
) {
458 struct gl_pixel_attrib
*attr
;
459 attr
= MALLOC_STRUCT(gl_pixel_attrib
);
461 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
465 if (save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
)) {
466 memcpy(attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
));
467 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
468 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
472 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
477 if (mask
& GL_POINT_BIT
) {
478 if (!push_attrib(ctx
, &head
, GL_POINT_BIT
,
479 sizeof(struct gl_point_attrib
),
484 if (mask
& GL_POLYGON_BIT
) {
485 if (!push_attrib(ctx
, &head
, GL_POLYGON_BIT
,
486 sizeof(struct gl_polygon_attrib
),
487 (void*)&ctx
->Polygon
))
491 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
492 if (!push_attrib(ctx
, &head
, GL_POLYGON_STIPPLE_BIT
,
493 sizeof(ctx
->PolygonStipple
),
494 (void*)&ctx
->PolygonStipple
))
498 if (mask
& GL_SCISSOR_BIT
) {
499 if (!push_attrib(ctx
, &head
, GL_SCISSOR_BIT
,
500 sizeof(struct gl_scissor_attrib
),
501 (void*)&ctx
->Scissor
))
505 if (mask
& GL_STENCIL_BUFFER_BIT
) {
506 if (!push_attrib(ctx
, &head
, GL_STENCIL_BUFFER_BIT
,
507 sizeof(struct gl_stencil_attrib
),
508 (void*)&ctx
->Stencil
))
512 if (mask
& GL_TEXTURE_BIT
) {
513 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
517 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
521 if (!save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
)) {
523 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
527 _mesa_lock_context_textures(ctx
);
529 /* copy/save the bulk of texture state here */
530 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
532 /* Save references to the currently bound texture objects so they don't
533 * accidentally get deleted while referenced in the attribute stack.
535 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
536 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
537 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
538 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
542 /* copy state/contents of the currently bound texture objects */
543 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
544 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
545 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
546 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
550 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
552 _mesa_unlock_context_textures(ctx
);
555 if (mask
& GL_TRANSFORM_BIT
) {
556 if (!push_attrib(ctx
, &head
, GL_TRANSFORM_BIT
,
557 sizeof(struct gl_transform_attrib
),
558 (void*)&ctx
->Transform
))
562 if (mask
& GL_VIEWPORT_BIT
) {
563 struct viewport_state
*viewstate
= CALLOC_STRUCT(viewport_state
);
565 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
569 if (!save_attrib_data(&head
, GL_VIEWPORT_BIT
, viewstate
)) {
571 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
575 memcpy(&viewstate
->ViewportArray
, &ctx
->ViewportArray
,
576 sizeof(struct gl_viewport_attrib
)*ctx
->Const
.MaxViewports
);
578 viewstate
->SubpixelPrecisionBias
[0] = ctx
->SubpixelPrecisionBias
[0];
579 viewstate
->SubpixelPrecisionBias
[1] = ctx
->SubpixelPrecisionBias
[1];
582 /* GL_ARB_multisample */
583 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
584 if (!push_attrib(ctx
, &head
, GL_MULTISAMPLE_BIT_ARB
,
585 sizeof(struct gl_multisample_attrib
),
586 (void*)&ctx
->Multisample
))
592 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
593 ctx
->AttribStackDepth
++;
600 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
602 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
605 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
606 if ((VALUE) != (NEWVALUE)) { \
607 _mesa_set_enable(ctx, ENUM, (NEWVALUE)); \
610 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
611 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
612 if (ctx
->Extensions
.EXT_draw_buffers2
) {
614 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
615 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
619 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
623 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
624 const GLuint mask
= 1 << i
;
625 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
626 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
627 !!(enable
->ClipPlanes
& mask
));
630 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
632 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
634 if (!ctx
->Extensions
.AMD_depth_clamp_separate
) {
635 TEST_AND_UPDATE(ctx
->Transform
.DepthClampNear
&& ctx
->Transform
.DepthClampFar
,
636 enable
->DepthClampNear
&& enable
->DepthClampFar
,
639 TEST_AND_UPDATE(ctx
->Transform
.DepthClampNear
, enable
->DepthClampNear
,
640 GL_DEPTH_CLAMP_NEAR_AMD
);
641 TEST_AND_UPDATE(ctx
->Transform
.DepthClampFar
, enable
->DepthClampFar
,
642 GL_DEPTH_CLAMP_FAR_AMD
);
645 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
646 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
647 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
648 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
649 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
650 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
652 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
654 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
657 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
658 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
659 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
660 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
661 GL_MAP1_TEXTURE_COORD_1
);
662 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
663 GL_MAP1_TEXTURE_COORD_2
);
664 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
665 GL_MAP1_TEXTURE_COORD_3
);
666 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
667 GL_MAP1_TEXTURE_COORD_4
);
668 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
670 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
673 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
674 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
675 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
676 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
677 GL_MAP2_TEXTURE_COORD_1
);
678 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
679 GL_MAP2_TEXTURE_COORD_2
);
680 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
681 GL_MAP2_TEXTURE_COORD_3
);
682 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
683 GL_MAP2_TEXTURE_COORD_4
);
684 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
686 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
689 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
690 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
691 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
692 GL_RESCALE_NORMAL_EXT
);
693 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
694 enable
->RasterPositionUnclipped
,
695 GL_RASTER_POSITION_UNCLIPPED_IBM
);
696 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
698 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
699 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
702 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
703 GL_POLYGON_OFFSET_POINT
);
704 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
705 GL_POLYGON_OFFSET_LINE
);
706 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
707 GL_POLYGON_OFFSET_FILL
);
708 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
710 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
712 if (ctx
->Scissor
.EnableFlags
!= enable
->Scissor
) {
715 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
716 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
, (enable
->Scissor
>> i
) & 1);
719 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
720 if (ctx
->Extensions
.EXT_stencil_two_side
) {
721 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
723 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
725 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
726 enable
->SampleAlphaToCoverage
,
727 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
728 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
729 enable
->SampleAlphaToOne
,
730 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
731 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
732 enable
->SampleCoverage
,
733 GL_SAMPLE_COVERAGE_ARB
);
734 /* GL_ARB_vertex_program */
735 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
736 enable
->VertexProgram
,
737 GL_VERTEX_PROGRAM_ARB
);
738 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
739 enable
->VertexProgramPointSize
,
740 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
741 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
742 enable
->VertexProgramTwoSide
,
743 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
745 /* GL_ARB_fragment_program */
746 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
747 enable
->FragmentProgram
,
748 GL_FRAGMENT_PROGRAM_ARB
);
750 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
751 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
752 GL_FRAMEBUFFER_SRGB
);
754 /* GL_NV_conservative_raster */
755 if (ctx
->Extensions
.NV_conservative_raster
) {
756 TEST_AND_UPDATE(ctx
->ConservativeRasterization
,
757 enable
->ConservativeRasterization
,
758 GL_CONSERVATIVE_RASTERIZATION_NV
);
761 /* texture unit enables */
762 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
763 const GLbitfield enabled
= enable
->Texture
[i
];
764 const GLbitfield genEnabled
= enable
->TexGen
[i
];
766 if (ctx
->Texture
.FixedFuncUnit
[i
].Enabled
!= enabled
) {
767 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
769 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
770 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
771 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
772 if (ctx
->Extensions
.NV_texture_rectangle
) {
773 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
774 !!(enabled
& TEXTURE_RECT_BIT
));
776 if (ctx
->Extensions
.ARB_texture_cube_map
) {
777 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
778 !!(enabled
& TEXTURE_CUBE_BIT
));
782 if (ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
!= genEnabled
) {
783 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
784 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
785 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
786 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
787 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
791 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
796 * Pop/restore texture attribute/group state.
799 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
803 _mesa_lock_context_textures(ctx
);
805 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
806 const struct gl_fixedfunc_texture_unit
*unit
=
807 &texstate
->Texture
.FixedFuncUnit
[u
];
810 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
811 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
812 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
813 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
814 if (ctx
->Extensions
.ARB_texture_cube_map
) {
815 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
816 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
818 if (ctx
->Extensions
.NV_texture_rectangle
) {
819 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
820 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
822 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
823 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
824 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
825 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
826 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
827 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
828 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
829 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
830 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
831 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
832 /* Eye plane done differently to avoid re-transformation */
834 struct gl_fixedfunc_texture_unit
*destUnit
=
835 &ctx
->Texture
.FixedFuncUnit
[u
];
837 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
838 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
839 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
840 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
841 if (ctx
->Driver
.TexGen
) {
842 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
843 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
844 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
845 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
848 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
849 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
850 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
851 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
852 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
853 texstate
->Texture
.Unit
[u
].LodBias
);
854 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
855 unit
->Combine
.ModeRGB
);
856 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
857 unit
->Combine
.ModeA
);
859 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
861 for (i
= 0; i
< n
; i
++) {
862 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
863 unit
->Combine
.SourceRGB
[i
]);
864 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
865 unit
->Combine
.SourceA
[i
]);
866 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
867 unit
->Combine
.OperandRGB
[i
]);
868 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
869 unit
->Combine
.OperandA
[i
]);
872 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
873 1 << unit
->Combine
.ScaleShiftRGB
);
874 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
875 1 << unit
->Combine
.ScaleShiftA
);
877 /* Restore texture object state for each target */
878 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
879 const struct gl_texture_object
*obj
= NULL
;
880 const struct gl_sampler_object
*samp
;
883 obj
= &texstate
->SavedObj
[u
][tgt
];
885 /* don't restore state for unsupported targets to prevent
888 if (obj
->Target
== GL_TEXTURE_CUBE_MAP
&&
889 !ctx
->Extensions
.ARB_texture_cube_map
) {
892 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
893 !ctx
->Extensions
.NV_texture_rectangle
) {
896 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
897 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
898 !ctx
->Extensions
.EXT_texture_array
) {
901 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
902 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
904 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
906 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
908 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
909 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
912 target
= obj
->Target
;
914 _mesa_BindTexture(target
, obj
->Name
);
916 samp
= &obj
->Sampler
;
918 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
919 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
920 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
921 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
922 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
923 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
924 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
925 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
926 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
927 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
928 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
929 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
930 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
931 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
932 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
933 samp
->MaxAnisotropy
);
935 if (ctx
->Extensions
.ARB_shadow
) {
936 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
938 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
941 if (ctx
->Extensions
.ARB_depth_texture
)
942 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
945 /* remove saved references to the texture objects */
946 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
947 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
951 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
953 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
955 _mesa_unlock_context_textures(ctx
);
960 * This function is kind of long just because we have to call a lot
961 * of device driver functions to update device driver state.
963 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
964 * in order to restore GL state. This isn't terribly efficient but it
965 * ensures that dirty flags and any derived state gets updated correctly.
966 * We could at least check if the value to restore equals the current value
967 * and then skip the Mesa call.
970 _mesa_PopAttrib(void)
972 struct gl_attrib_node
*attr
, *next
;
973 GET_CURRENT_CONTEXT(ctx
);
974 FLUSH_VERTICES(ctx
, 0);
976 if (ctx
->AttribStackDepth
== 0) {
977 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib");
981 ctx
->AttribStackDepth
--;
982 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
986 if (MESA_VERBOSE
& VERBOSE_API
) {
987 _mesa_debug(ctx
, "glPopAttrib %s\n",
988 _mesa_enum_to_string(attr
->kind
));
991 switch (attr
->kind
) {
996 case GL_ACCUM_BUFFER_BIT
:
998 const struct gl_accum_attrib
*accum
;
999 accum
= (const struct gl_accum_attrib
*) attr
->data
;
1000 _mesa_ClearAccum(accum
->ClearColor
[0],
1001 accum
->ClearColor
[1],
1002 accum
->ClearColor
[2],
1003 accum
->ClearColor
[3]);
1006 case GL_COLOR_BUFFER_BIT
:
1008 const struct gl_colorbuffer_attrib
*color
;
1010 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
1011 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
1012 _mesa_ClearColor(color
->ClearColor
.f
[0],
1013 color
->ClearColor
.f
[1],
1014 color
->ClearColor
.f
[2],
1015 color
->ClearColor
.f
[3]);
1016 _mesa_IndexMask(color
->IndexMask
);
1017 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1018 _mesa_ColorMask(GET_COLORMASK_BIT(color
->ColorMask
, 0, 0),
1019 GET_COLORMASK_BIT(color
->ColorMask
, 0, 1),
1020 GET_COLORMASK_BIT(color
->ColorMask
, 0, 2),
1021 GET_COLORMASK_BIT(color
->ColorMask
, 0, 3));
1025 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1027 GET_COLORMASK_BIT(color
->ColorMask
, i
, 0),
1028 GET_COLORMASK_BIT(color
->ColorMask
, i
, 1),
1029 GET_COLORMASK_BIT(color
->ColorMask
, i
, 2),
1030 GET_COLORMASK_BIT(color
->ColorMask
, i
, 3));
1034 /* Need to determine if more than one color output is
1035 * specified. If so, call glDrawBuffersARB, else call
1036 * glDrawBuffer(). This is a subtle, but essential point
1037 * since GL_FRONT (for example) is illegal for the former
1038 * function, but legal for the later.
1040 GLboolean multipleBuffers
= GL_FALSE
;
1043 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1044 if (color
->DrawBuffer
[i
] != GL_NONE
) {
1045 multipleBuffers
= GL_TRUE
;
1049 /* Call the API_level functions, not _mesa_drawbuffers()
1050 * since we need to do error checking on the pop'd
1052 * Ex: if GL_FRONT were pushed, but we're popping with a
1053 * user FBO bound, GL_FRONT will be illegal and we'll need
1054 * to record that error. Per OpenGL ARB decision.
1056 if (multipleBuffers
) {
1057 GLenum buffers
[MAX_DRAW_BUFFERS
];
1059 for (unsigned i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
1060 buffers
[i
] = color
->DrawBuffer
[i
];
1062 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
, buffers
);
1064 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1067 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1068 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
1069 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
1070 if (ctx
->Extensions
.EXT_draw_buffers2
) {
1072 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1073 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
1074 (color
->BlendEnabled
>> i
) & 1);
1078 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
1081 if (ctx
->Color
._BlendFuncPerBuffer
||
1082 ctx
->Color
._BlendEquationPerBuffer
) {
1083 /* set blend per buffer */
1085 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
1086 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
1087 color
->Blend
[buf
].DstRGB
,
1088 color
->Blend
[buf
].SrcA
,
1089 color
->Blend
[buf
].DstA
);
1090 _mesa_BlendEquationSeparateiARB(buf
,
1091 color
->Blend
[buf
].EquationRGB
,
1092 color
->Blend
[buf
].EquationA
);
1096 /* set same blend modes for all buffers */
1097 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
1098 color
->Blend
[0].DstRGB
,
1099 color
->Blend
[0].SrcA
,
1100 color
->Blend
[0].DstA
);
1101 /* This special case is because glBlendEquationSeparateEXT
1102 * cannot take GL_LOGIC_OP as a parameter.
1104 if (color
->Blend
[0].EquationRGB
==
1105 color
->Blend
[0].EquationA
) {
1106 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
1109 _mesa_BlendEquationSeparate(
1110 color
->Blend
[0].EquationRGB
,
1111 color
->Blend
[0].EquationA
);
1114 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
1115 color
->BlendColorUnclamped
[1],
1116 color
->BlendColorUnclamped
[2],
1117 color
->BlendColorUnclamped
[3]);
1118 _mesa_LogicOp(color
->LogicOp
);
1119 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1120 color
->ColorLogicOpEnabled
);
1121 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1122 color
->IndexLogicOpEnabled
);
1123 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1124 if (ctx
->Extensions
.ARB_color_buffer_float
)
1125 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
1126 color
->ClampFragmentColor
);
1127 if (ctx
->Extensions
.ARB_color_buffer_float
|| ctx
->Version
>= 30)
1128 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
1130 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
1131 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
1132 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
1135 case GL_CURRENT_BIT
:
1136 FLUSH_CURRENT(ctx
, 0);
1137 memcpy(&ctx
->Current
, attr
->data
,
1138 sizeof(struct gl_current_attrib
));
1140 case GL_DEPTH_BUFFER_BIT
:
1142 const struct gl_depthbuffer_attrib
*depth
;
1143 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1144 _mesa_DepthFunc(depth
->Func
);
1145 _mesa_ClearDepth(depth
->Clear
);
1146 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1147 _mesa_DepthMask(depth
->Mask
);
1148 if (ctx
->Extensions
.EXT_depth_bounds_test
) {
1149 _mesa_set_enable(ctx
, GL_DEPTH_BOUNDS_TEST_EXT
,
1151 _mesa_DepthBoundsEXT(depth
->BoundsMin
, depth
->BoundsMax
);
1157 const struct gl_enable_attrib
*enable
;
1158 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1159 pop_enable_group(ctx
, enable
);
1160 ctx
->NewState
|= _NEW_ALL
;
1161 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
|
1162 ctx
->DriverFlags
.NewBlend
|
1163 ctx
->DriverFlags
.NewClipPlaneEnable
|
1164 ctx
->DriverFlags
.NewDepth
|
1165 ctx
->DriverFlags
.NewDepthClamp
|
1166 ctx
->DriverFlags
.NewFramebufferSRGB
|
1167 ctx
->DriverFlags
.NewLineState
|
1168 ctx
->DriverFlags
.NewLogicOp
|
1169 ctx
->DriverFlags
.NewMultisampleEnable
|
1170 ctx
->DriverFlags
.NewPolygonState
|
1171 ctx
->DriverFlags
.NewSampleAlphaToXEnable
|
1172 ctx
->DriverFlags
.NewSampleMask
|
1173 ctx
->DriverFlags
.NewScissorTest
|
1174 ctx
->DriverFlags
.NewStencil
|
1175 ctx
->DriverFlags
.NewNvConservativeRasterization
;
1179 memcpy(&ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
));
1180 ctx
->NewState
|= _NEW_EVAL
;
1184 const struct gl_fog_attrib
*fog
;
1185 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1186 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1187 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1188 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1189 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1190 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1191 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1192 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1197 const struct gl_hint_attrib
*hint
;
1198 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1199 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1200 hint
->PerspectiveCorrection
);
1201 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1202 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1203 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1204 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1205 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1206 hint
->TextureCompression
);
1209 case GL_LIGHTING_BIT
:
1212 const struct gl_light_attrib
*light
;
1213 light
= (const struct gl_light_attrib
*) attr
->data
;
1214 /* lighting enable */
1215 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1216 /* per-light state */
1217 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1218 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
1220 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1221 const struct gl_light
*l
= &light
->Light
[i
];
1222 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1223 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1224 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1225 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1226 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1227 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1229 GLfloat p
[4] = { 0 };
1230 p
[0] = l
->SpotExponent
;
1231 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1234 GLfloat p
[4] = { 0 };
1235 p
[0] = l
->SpotCutoff
;
1236 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1239 GLfloat p
[4] = { 0 };
1240 p
[0] = l
->ConstantAttenuation
;
1241 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1244 GLfloat p
[4] = { 0 };
1245 p
[0] = l
->LinearAttenuation
;
1246 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1249 GLfloat p
[4] = { 0 };
1250 p
[0] = l
->QuadraticAttenuation
;
1251 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1255 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1256 light
->Model
.Ambient
);
1257 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1258 (GLfloat
) light
->Model
.LocalViewer
);
1259 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1260 (GLfloat
) light
->Model
.TwoSide
);
1261 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1262 (GLfloat
) light
->Model
.ColorControl
);
1264 _mesa_ShadeModel(light
->ShadeModel
);
1265 /* color material */
1266 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1267 light
->ColorMaterialMode
);
1268 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1269 light
->ColorMaterialEnabled
);
1271 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1272 sizeof(struct gl_material
));
1273 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1274 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1275 light
->ClampVertexColor
);
1281 const struct gl_line_attrib
*line
;
1282 line
= (const struct gl_line_attrib
*) attr
->data
;
1283 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1284 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1285 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1286 _mesa_LineWidth(line
->Width
);
1290 memcpy(&ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
));
1292 case GL_PIXEL_MODE_BIT
:
1293 memcpy(&ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
));
1294 /* XXX what other pixel state needs to be set by function calls? */
1295 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1296 ctx
->NewState
|= _NEW_PIXEL
;
1300 const struct gl_point_attrib
*point
;
1301 point
= (const struct gl_point_attrib
*) attr
->data
;
1302 _mesa_PointSize(point
->Size
);
1303 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1304 if (ctx
->Extensions
.EXT_point_parameters
) {
1305 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1307 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1309 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1311 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1314 if (ctx
->Extensions
.NV_point_sprite
1315 || ctx
->Extensions
.ARB_point_sprite
) {
1317 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1318 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1319 !!(point
->CoordReplace
& (1u << u
)));
1321 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1322 if (ctx
->Extensions
.NV_point_sprite
)
1323 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1324 ctx
->Point
.SpriteRMode
);
1326 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1327 || ctx
->API
== API_OPENGL_CORE
)
1328 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1329 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1333 case GL_POLYGON_BIT
:
1335 const struct gl_polygon_attrib
*polygon
;
1336 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1337 _mesa_CullFace(polygon
->CullFaceMode
);
1338 _mesa_FrontFace(polygon
->FrontFace
);
1339 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1340 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1341 _mesa_polygon_offset_clamp(ctx
,
1342 polygon
->OffsetFactor
,
1343 polygon
->OffsetUnits
,
1344 polygon
->OffsetClamp
);
1345 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1346 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1347 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1348 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1349 polygon
->OffsetPoint
);
1350 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1351 polygon
->OffsetLine
);
1352 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1353 polygon
->OffsetFill
);
1356 case GL_POLYGON_STIPPLE_BIT
:
1357 memcpy(ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
));
1359 if (ctx
->DriverFlags
.NewPolygonStipple
)
1360 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
1362 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1364 if (ctx
->Driver
.PolygonStipple
)
1365 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) attr
->data
);
1367 case GL_SCISSOR_BIT
:
1370 const struct gl_scissor_attrib
*scissor
;
1371 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1373 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1374 _mesa_set_scissor(ctx
, i
,
1375 scissor
->ScissorArray
[i
].X
,
1376 scissor
->ScissorArray
[i
].Y
,
1377 scissor
->ScissorArray
[i
].Width
,
1378 scissor
->ScissorArray
[i
].Height
);
1379 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
1380 (scissor
->EnableFlags
>> i
) & 1);
1382 if (ctx
->Extensions
.EXT_window_rectangles
) {
1383 STATIC_ASSERT(sizeof(struct gl_scissor_rect
) ==
1385 _mesa_WindowRectanglesEXT(
1386 scissor
->WindowRectMode
, scissor
->NumWindowRects
,
1387 (const GLint
*)scissor
->WindowRects
);
1391 case GL_STENCIL_BUFFER_BIT
:
1393 const struct gl_stencil_attrib
*stencil
;
1394 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1395 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1396 _mesa_ClearStencil(stencil
->Clear
);
1397 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1398 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1399 stencil
->TestTwoSide
);
1400 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1401 ? GL_BACK
: GL_FRONT
);
1404 _mesa_StencilFuncSeparate(GL_FRONT
,
1405 stencil
->Function
[0],
1407 stencil
->ValueMask
[0]);
1408 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1409 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1410 stencil
->ZFailFunc
[0],
1411 stencil
->ZPassFunc
[0]);
1413 _mesa_StencilFuncSeparate(GL_BACK
,
1414 stencil
->Function
[1],
1416 stencil
->ValueMask
[1]);
1417 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1418 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1419 stencil
->ZFailFunc
[1],
1420 stencil
->ZPassFunc
[1]);
1423 case GL_TRANSFORM_BIT
:
1426 const struct gl_transform_attrib
*xform
;
1427 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1428 _mesa_MatrixMode(xform
->MatrixMode
);
1429 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1430 _math_matrix_analyse(ctx
->ProjectionMatrixStack
.Top
);
1432 /* restore clip planes */
1433 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1434 const GLuint mask
= 1 << i
;
1435 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1436 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1437 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1438 !!(xform
->ClipPlanesEnabled
& mask
));
1439 if (ctx
->Driver
.ClipPlane
)
1440 ctx
->Driver
.ClipPlane(ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1443 /* normalize/rescale */
1444 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1445 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1446 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1447 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1448 ctx
->Transform
.RescaleNormals
);
1450 if (!ctx
->Extensions
.AMD_depth_clamp_separate
) {
1451 if (xform
->DepthClampNear
!= ctx
->Transform
.DepthClampNear
&&
1452 xform
->DepthClampFar
!= ctx
->Transform
.DepthClampFar
) {
1453 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1454 ctx
->Transform
.DepthClampNear
&&
1455 ctx
->Transform
.DepthClampFar
);
1458 if (xform
->DepthClampNear
!= ctx
->Transform
.DepthClampNear
)
1459 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP_NEAR_AMD
,
1460 ctx
->Transform
.DepthClampNear
);
1461 if (xform
->DepthClampFar
!= ctx
->Transform
.DepthClampFar
)
1462 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP_FAR_AMD
,
1463 ctx
->Transform
.DepthClampFar
);
1466 if (ctx
->Extensions
.ARB_clip_control
)
1467 _mesa_ClipControl(xform
->ClipOrigin
, xform
->ClipDepthMode
);
1470 case GL_TEXTURE_BIT
:
1472 struct texture_state
*texstate
1473 = (struct texture_state
*) attr
->data
;
1474 pop_texture_group(ctx
, texstate
);
1475 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
| _NEW_TEXTURE_STATE
;
1478 case GL_VIEWPORT_BIT
:
1481 const struct viewport_state
*viewstate
;
1482 viewstate
= (const struct viewport_state
*) attr
->data
;
1484 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1485 const struct gl_viewport_attrib
*vp
= &viewstate
->ViewportArray
[i
];
1486 _mesa_set_viewport(ctx
, i
, vp
->X
, vp
->Y
, vp
->Width
,
1488 _mesa_set_depth_range(ctx
, i
, vp
->Near
, vp
->Far
);
1491 if (ctx
->Extensions
.NV_conservative_raster
) {
1492 GLuint biasx
= viewstate
->SubpixelPrecisionBias
[0];
1493 GLuint biasy
= viewstate
->SubpixelPrecisionBias
[1];
1494 _mesa_SubpixelPrecisionBiasNV(biasx
, biasy
);
1498 case GL_MULTISAMPLE_BIT_ARB
:
1500 const struct gl_multisample_attrib
*ms
;
1501 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1503 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1507 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1509 GL_SAMPLE_COVERAGE
);
1511 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1512 ms
->SampleAlphaToCoverage
,
1513 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1515 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1516 ms
->SampleAlphaToOne
,
1517 GL_SAMPLE_ALPHA_TO_ONE
);
1519 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1520 ms
->SampleCoverageInvert
);
1525 unreachable("Bad attrib flag in PopAttrib");
1537 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1541 copy_pixelstore(struct gl_context
*ctx
,
1542 struct gl_pixelstore_attrib
*dst
,
1543 const struct gl_pixelstore_attrib
*src
)
1545 dst
->Alignment
= src
->Alignment
;
1546 dst
->RowLength
= src
->RowLength
;
1547 dst
->SkipPixels
= src
->SkipPixels
;
1548 dst
->SkipRows
= src
->SkipRows
;
1549 dst
->ImageHeight
= src
->ImageHeight
;
1550 dst
->SkipImages
= src
->SkipImages
;
1551 dst
->SwapBytes
= src
->SwapBytes
;
1552 dst
->LsbFirst
= src
->LsbFirst
;
1553 dst
->Invert
= src
->Invert
;
1554 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1558 #define GL_CLIENT_PACK_BIT (1<<20)
1559 #define GL_CLIENT_UNPACK_BIT (1<<21)
1562 * Copy gl_vertex_array_object from src to dest.
1563 * 'dest' must be in an initialized state.
1566 copy_array_object(struct gl_context
*ctx
,
1567 struct gl_vertex_array_object
*dest
,
1568 struct gl_vertex_array_object
*src
)
1575 for (i
= 0; i
< ARRAY_SIZE(src
->VertexAttrib
); i
++) {
1576 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1577 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->BufferBinding
[i
], &src
->BufferBinding
[i
]);
1580 /* Enabled must be the same than on push */
1581 dest
->Enabled
= src
->Enabled
;
1582 dest
->_EffEnabledVBO
= src
->_EffEnabledVBO
;
1583 dest
->_EffEnabledNonZeroDivisor
= src
->_EffEnabledNonZeroDivisor
;
1584 /* The bitmask of bound VBOs needs to match the VertexBinding array */
1585 dest
->VertexAttribBufferMask
= src
->VertexAttribBufferMask
;
1586 dest
->NonZeroDivisorMask
= src
->NonZeroDivisorMask
;
1587 dest
->_AttributeMapMode
= src
->_AttributeMapMode
;
1588 dest
->NewArrays
= src
->NewArrays
;
1592 * Copy gl_array_attrib from src to dest.
1593 * 'dest' must be in an initialized state.
1596 copy_array_attrib(struct gl_context
*ctx
,
1597 struct gl_array_attrib
*dest
,
1598 struct gl_array_attrib
*src
,
1602 /* skip DefaultArrayObj, Objects */
1603 dest
->ActiveTexture
= src
->ActiveTexture
;
1604 dest
->LockFirst
= src
->LockFirst
;
1605 dest
->LockCount
= src
->LockCount
;
1606 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1607 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1608 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1609 dest
->RestartIndex
= src
->RestartIndex
;
1611 /* skip RebindArrays */
1614 copy_array_object(ctx
, dest
->VAO
, src
->VAO
);
1616 /* skip ArrayBufferObj */
1617 /* skip IndexBufferObj */
1619 /* Invalidate array state. It will be updated during the next draw. */
1620 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1624 * Save the content of src to dest.
1627 save_array_attrib(struct gl_context
*ctx
,
1628 struct gl_array_attrib
*dest
,
1629 struct gl_array_attrib
*src
)
1631 /* Set the Name, needed for restore, but do never overwrite.
1632 * Needs to match value in the object hash. */
1633 dest
->VAO
->Name
= src
->VAO
->Name
;
1634 /* And copy all of the rest. */
1635 copy_array_attrib(ctx
, dest
, src
, false);
1637 /* Just reference them here */
1638 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1639 src
->ArrayBufferObj
);
1640 _mesa_reference_buffer_object(ctx
, &dest
->VAO
->IndexBufferObj
,
1641 src
->VAO
->IndexBufferObj
);
1645 * Restore the content of src to dest.
1648 restore_array_attrib(struct gl_context
*ctx
,
1649 struct gl_array_attrib
*dest
,
1650 struct gl_array_attrib
*src
)
1652 bool is_vao_name_zero
= src
->VAO
->Name
== 0;
1654 /* The ARB_vertex_array_object spec says:
1656 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1657 * if array is not a name returned from a previous call to
1658 * GenVertexArrays, or if such a name has since been deleted with
1659 * DeleteVertexArrays."
1661 * Therefore popping a deleted VAO cannot magically recreate it.
1663 if (!is_vao_name_zero
&& !_mesa_IsVertexArray(src
->VAO
->Name
))
1666 _mesa_BindVertexArray(src
->VAO
->Name
);
1668 /* Restore or recreate the buffer objects by the names ... */
1669 if (is_vao_name_zero
|| src
->ArrayBufferObj
->Name
== 0 ||
1670 _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1671 /* ... and restore its content */
1672 copy_array_attrib(ctx
, dest
, src
, false);
1674 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1675 src
->ArrayBufferObj
->Name
);
1677 copy_array_attrib(ctx
, dest
, src
, true);
1680 if (is_vao_name_zero
|| src
->VAO
->IndexBufferObj
->Name
== 0 ||
1681 _mesa_IsBuffer(src
->VAO
->IndexBufferObj
->Name
))
1682 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1683 src
->VAO
->IndexBufferObj
->Name
);
1687 * init/alloc the fields of 'attrib'.
1688 * Needs to the init part matching free_array_attrib_data below.
1691 init_array_attrib_data(struct gl_context
*ctx
,
1692 struct gl_array_attrib
*attrib
)
1694 /* Get a non driver gl_vertex_array_object. */
1695 attrib
->VAO
= CALLOC_STRUCT(gl_vertex_array_object
);
1697 if (attrib
->VAO
== NULL
) {
1698 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1702 _mesa_initialize_vao(ctx
, attrib
->VAO
, 0);
1707 * Free/unreference the fields of 'attrib' but don't delete it (that's
1708 * done later in the calling code).
1709 * Needs to the cleanup part matching init_array_attrib_data above.
1712 free_array_attrib_data(struct gl_context
*ctx
,
1713 struct gl_array_attrib
*attrib
)
1715 /* We use a non driver array object, so don't just unref since we would
1716 * end up using the drivers DeleteArrayObject function for deletion. */
1717 _mesa_delete_vao(ctx
, attrib
->VAO
);
1719 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1724 _mesa_PushClientAttrib(GLbitfield mask
)
1726 struct gl_attrib_node
*head
;
1728 GET_CURRENT_CONTEXT(ctx
);
1730 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1731 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib");
1735 /* Build linked list of attribute nodes which save all attribute
1736 * groups specified by the mask.
1740 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1741 struct gl_pixelstore_attrib
*attr
;
1742 /* packing attribs */
1743 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1745 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1748 if (save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
)) {
1749 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1752 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1757 /* unpacking attribs */
1758 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1760 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1764 if (save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
)) {
1765 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1768 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1774 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1775 struct gl_array_attrib
*attr
;
1776 attr
= CALLOC_STRUCT(gl_array_attrib
);
1778 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1782 if (!init_array_attrib_data(ctx
, attr
)) {
1787 if (save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
)) {
1788 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1791 free_array_attrib_data(ctx
, attr
);
1792 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1794 /* goto to keep safe from possible later changes */
1800 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1801 ctx
->ClientAttribStackDepth
++;
1807 _mesa_PopClientAttrib(void)
1809 struct gl_attrib_node
*node
, *next
;
1811 GET_CURRENT_CONTEXT(ctx
);
1812 FLUSH_VERTICES(ctx
, 0);
1814 if (ctx
->ClientAttribStackDepth
== 0) {
1815 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib");
1819 ctx
->ClientAttribStackDepth
--;
1820 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1823 switch (node
->kind
) {
1824 case GL_CLIENT_PACK_BIT
:
1826 struct gl_pixelstore_attrib
*store
=
1827 (struct gl_pixelstore_attrib
*) node
->data
;
1828 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1829 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1832 case GL_CLIENT_UNPACK_BIT
:
1834 struct gl_pixelstore_attrib
*store
=
1835 (struct gl_pixelstore_attrib
*) node
->data
;
1836 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1837 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1840 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1841 struct gl_array_attrib
* attr
=
1842 (struct gl_array_attrib
*) node
->data
;
1843 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1844 free_array_attrib_data(ctx
, attr
);
1848 unreachable("Bad attrib flag in PopClientAttrib");
1859 _mesa_ClientAttribDefaultEXT( GLbitfield mask
)
1861 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1862 _mesa_PixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
1863 _mesa_PixelStorei(GL_UNPACK_LSB_FIRST
, GL_FALSE
);
1864 _mesa_PixelStorei(GL_UNPACK_IMAGE_HEIGHT
, 0);
1865 _mesa_PixelStorei(GL_UNPACK_SKIP_IMAGES
, 0);
1866 _mesa_PixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
1867 _mesa_PixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
1868 _mesa_PixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
1869 _mesa_PixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1870 _mesa_PixelStorei(GL_PACK_SWAP_BYTES
, GL_FALSE
);
1871 _mesa_PixelStorei(GL_PACK_LSB_FIRST
, GL_FALSE
);
1872 _mesa_PixelStorei(GL_PACK_IMAGE_HEIGHT
, 0);
1873 _mesa_PixelStorei(GL_PACK_SKIP_IMAGES
, 0);
1874 _mesa_PixelStorei(GL_PACK_ROW_LENGTH
, 0);
1875 _mesa_PixelStorei(GL_PACK_SKIP_ROWS
, 0);
1876 _mesa_PixelStorei(GL_PACK_SKIP_PIXELS
, 0);
1877 _mesa_PixelStorei(GL_PACK_ALIGNMENT
, 4);
1879 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER
, 0);
1880 _mesa_BindBuffer(GL_PIXEL_PACK_BUFFER
, 0);
1882 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1883 GET_CURRENT_CONTEXT(ctx
);
1886 _mesa_BindBuffer(GL_ARRAY_BUFFER
, 0);
1887 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
1889 _mesa_DisableClientState(GL_EDGE_FLAG_ARRAY
);
1890 _mesa_EdgeFlagPointer(0, 0);
1892 _mesa_DisableClientState(GL_INDEX_ARRAY
);
1893 _mesa_IndexPointer(GL_FLOAT
, 0, 0);
1895 _mesa_DisableClientState(GL_SECONDARY_COLOR_ARRAY
);
1896 _mesa_SecondaryColorPointer(4, GL_FLOAT
, 0, 0);
1898 _mesa_DisableClientState(GL_FOG_COORD_ARRAY
);
1899 _mesa_FogCoordPointer(GL_FLOAT
, 0, 0);
1901 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
1902 _mesa_ClientActiveTexture(GL_TEXTURE0
+ i
);
1903 _mesa_DisableClientState(GL_TEXTURE_COORD_ARRAY
);
1904 _mesa_TexCoordPointer(4, GL_FLOAT
, 0, 0);
1907 _mesa_DisableClientState(GL_COLOR_ARRAY
);
1908 _mesa_ColorPointer(4, GL_FLOAT
, 0, 0);
1910 _mesa_DisableClientState(GL_NORMAL_ARRAY
);
1911 _mesa_NormalPointer(GL_FLOAT
, 0, 0);
1913 _mesa_DisableClientState(GL_VERTEX_ARRAY
);
1914 _mesa_VertexPointer(4, GL_FLOAT
, 0, 0);
1916 for (i
= 0; i
< ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
; i
++) {
1917 _mesa_DisableVertexAttribArray(i
);
1918 _mesa_VertexAttribPointer(i
, 4, GL_FLOAT
, GL_FALSE
, 0, 0);
1921 _mesa_ClientActiveTexture(GL_TEXTURE0
);
1926 _mesa_PushClientAttribDefaultEXT( GLbitfield mask
)
1928 _mesa_PushClientAttrib(mask
);
1929 _mesa_ClientAttribDefaultEXT(mask
);
1934 * Free any attribute state data that might be attached to the context.
1937 _mesa_free_attrib_data(struct gl_context
*ctx
)
1939 while (ctx
->AttribStackDepth
> 0) {
1940 struct gl_attrib_node
*attr
, *next
;
1942 ctx
->AttribStackDepth
--;
1943 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1946 if (attr
->kind
== GL_TEXTURE_BIT
) {
1947 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1949 /* clear references to the saved texture objects */
1950 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1951 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1952 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1955 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1958 /* any other chunks of state that requires special handling? */
1971 _mesa_init_attrib(struct gl_context
*ctx
)
1973 /* Renderer and client attribute stacks */
1974 ctx
->AttribStackDepth
= 0;
1975 ctx
->ClientAttribStackDepth
= 0;