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"
46 #include "pixelstore.h"
63 #include "util/u_memory.h"
67 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
69 struct gl_enable_attrib
74 GLbitfield ClipPlanes
;
75 GLboolean ColorMaterial
;
77 GLboolean DepthClampNear
;
78 GLboolean DepthClampFar
;
82 GLboolean Light
[MAX_LIGHTS
];
85 GLboolean LineStipple
;
86 GLboolean IndexLogicOp
;
87 GLboolean ColorLogicOp
;
92 GLboolean Map1TextureCoord1
;
93 GLboolean Map1TextureCoord2
;
94 GLboolean Map1TextureCoord3
;
95 GLboolean Map1TextureCoord4
;
96 GLboolean Map1Vertex3
;
97 GLboolean Map1Vertex4
;
100 GLboolean Map2Normal
;
101 GLboolean Map2TextureCoord1
;
102 GLboolean Map2TextureCoord2
;
103 GLboolean Map2TextureCoord3
;
104 GLboolean Map2TextureCoord4
;
105 GLboolean Map2Vertex3
;
106 GLboolean Map2Vertex4
;
109 GLboolean PixelTexture
;
110 GLboolean PointSmooth
;
111 GLboolean PolygonOffsetPoint
;
112 GLboolean PolygonOffsetLine
;
113 GLboolean PolygonOffsetFill
;
114 GLboolean PolygonSmooth
;
115 GLboolean PolygonStipple
;
116 GLboolean RescaleNormals
;
119 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
120 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
122 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
123 GLboolean SampleCoverage
; /* GL_ARB_multisample */
124 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
126 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
127 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
129 /* GL_ARB_vertex_program */
130 GLboolean VertexProgram
;
131 GLboolean VertexProgramPointSize
;
132 GLboolean VertexProgramTwoSide
;
134 /* GL_ARB_fragment_program */
135 GLboolean FragmentProgram
;
137 /* GL_ARB_point_sprite / GL_NV_point_sprite */
138 GLboolean PointSprite
;
139 GLboolean FragmentShaderATI
;
141 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
142 GLboolean sRGBEnabled
;
144 /* GL_NV_conservative_raster */
145 GLboolean ConservativeRasterization
;
150 * Node for the attribute stack.
152 struct gl_attrib_node
156 struct gl_attrib_node
*next
;
162 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
166 struct gl_texture_attrib Texture
; /**< The usual context state */
168 /** to save per texture object state (wrap modes, filters, etc): */
169 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
172 * To save references to texture objects (so they don't get accidentally
173 * deleted while saved in the attribute stack).
175 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
177 /* We need to keep a reference to the shared state. That's where the
178 * default texture objects are kept. We don't want that state to be
179 * freed while the attribute stack contains pointers to any default
182 struct gl_shared_state
*SharedRef
;
186 struct viewport_state
188 struct gl_viewport_attrib ViewportArray
[MAX_VIEWPORTS
];
189 GLuint SubpixelPrecisionBias
[2];
193 /** An unused GL_*_BIT value */
194 #define DUMMY_BIT 0x10000000
198 * Allocate new attribute node of given type/kind. Attach payload data.
199 * Insert it into the linked list named by 'head'.
202 save_attrib_data(struct gl_attrib_node
**head
,
203 GLbitfield kind
, void *payload
)
205 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
222 * Helper function for_mesa_PushAttrib for simple attributes.
223 * Allocates memory for attribute data and copies the given attribute data.
224 * \param head head of linked list to insert attribute data into
225 * \param attr_bit one of the GL_<attrib>_BIT flags
226 * \param attr_size number of bytes to allocate for attribute data
227 * \param attr_data the attribute data to copy
228 * \return true for success, false for out of memory
231 push_attrib(struct gl_context
*ctx
, struct gl_attrib_node
**head
,
232 GLbitfield attr_bit
, GLuint attr_size
, const void *attr_data
)
236 attribute
= malloc(attr_size
);
237 if (attribute
== NULL
) {
238 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
242 if (save_attrib_data(head
, attr_bit
, attribute
)) {
243 memcpy(attribute
, attr_data
, attr_size
);
247 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
255 _mesa_PushAttrib(GLbitfield mask
)
257 struct gl_attrib_node
*head
;
259 GET_CURRENT_CONTEXT(ctx
);
261 if (MESA_VERBOSE
& VERBOSE_API
)
262 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
264 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
265 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushAttrib");
269 /* Build linked list of attribute nodes which save all attribute */
270 /* groups specified by the mask. */
274 /* if mask is zero we still need to push something so that we
275 * don't get a GL_STACK_UNDERFLOW error in glPopAttrib().
278 if (!push_attrib(ctx
, &head
, DUMMY_BIT
, sizeof(dummy
), &dummy
))
282 if (mask
& GL_ACCUM_BUFFER_BIT
) {
283 if (!push_attrib(ctx
, &head
, GL_ACCUM_BUFFER_BIT
,
284 sizeof(struct gl_accum_attrib
),
289 if (mask
& GL_COLOR_BUFFER_BIT
) {
291 struct gl_colorbuffer_attrib
*attr
;
292 attr
= MALLOC_STRUCT(gl_colorbuffer_attrib
);
294 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
298 if (save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
)) {
299 memcpy(attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
));
300 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
301 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
302 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
306 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
311 if (mask
& GL_CURRENT_BIT
) {
312 FLUSH_CURRENT(ctx
, 0);
313 if (!push_attrib(ctx
, &head
, GL_CURRENT_BIT
,
314 sizeof(struct gl_current_attrib
),
315 (void*)&ctx
->Current
))
319 if (mask
& GL_DEPTH_BUFFER_BIT
) {
320 if (!push_attrib(ctx
, &head
, GL_DEPTH_BUFFER_BIT
,
321 sizeof(struct gl_depthbuffer_attrib
),
326 if (mask
& GL_ENABLE_BIT
) {
327 struct gl_enable_attrib
*attr
;
329 attr
= MALLOC_STRUCT(gl_enable_attrib
);
331 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
335 /* Copy enable flags from all other attributes into the enable struct. */
336 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
337 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
338 attr
->Blend
= ctx
->Color
.BlendEnabled
;
339 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
340 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
341 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
342 attr
->DepthClampNear
= ctx
->Transform
.DepthClampNear
;
343 attr
->DepthClampFar
= ctx
->Transform
.DepthClampFar
;
344 attr
->DepthTest
= ctx
->Depth
.Test
;
345 attr
->Dither
= ctx
->Color
.DitherFlag
;
346 attr
->Fog
= ctx
->Fog
.Enabled
;
347 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
348 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
350 attr
->Lighting
= ctx
->Light
.Enabled
;
351 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
352 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
353 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
354 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
355 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
356 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
357 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
358 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
359 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
360 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
361 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
362 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
363 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
364 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
365 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
366 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
367 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
368 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
369 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
370 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
371 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
372 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
373 attr
->Normalize
= ctx
->Transform
.Normalize
;
374 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
375 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
376 attr
->PointSprite
= ctx
->Point
.PointSprite
;
377 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
378 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
379 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
380 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
381 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
382 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
383 attr
->Scissor
= ctx
->Scissor
.EnableFlags
;
384 attr
->Stencil
= ctx
->Stencil
.Enabled
;
385 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
386 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
387 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
388 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
389 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
390 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
391 attr
->Texture
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].Enabled
;
392 attr
->TexGen
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
;
394 /* GL_ARB_vertex_program */
395 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
396 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
397 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
399 /* GL_ARB_fragment_program */
400 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
402 if (!save_attrib_data(&head
, GL_ENABLE_BIT
, attr
)) {
404 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
408 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
409 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
411 /* GL_NV_conservative_raster */
412 attr
->ConservativeRasterization
= ctx
->ConservativeRasterization
;
415 if (mask
& GL_EVAL_BIT
) {
416 if (!push_attrib(ctx
, &head
, GL_EVAL_BIT
,
417 sizeof(struct gl_eval_attrib
),
422 if (mask
& GL_FOG_BIT
) {
423 if (!push_attrib(ctx
, &head
, GL_FOG_BIT
,
424 sizeof(struct gl_fog_attrib
),
429 if (mask
& GL_HINT_BIT
) {
430 if (!push_attrib(ctx
, &head
, GL_HINT_BIT
,
431 sizeof(struct gl_hint_attrib
),
436 if (mask
& GL_LIGHTING_BIT
) {
437 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
438 if (!push_attrib(ctx
, &head
, GL_LIGHTING_BIT
,
439 sizeof(struct gl_light_attrib
),
444 if (mask
& GL_LINE_BIT
) {
445 if (!push_attrib(ctx
, &head
, GL_LINE_BIT
,
446 sizeof(struct gl_line_attrib
),
451 if (mask
& GL_LIST_BIT
) {
452 if (!push_attrib(ctx
, &head
, GL_LIST_BIT
,
453 sizeof(struct gl_list_attrib
),
458 if (mask
& GL_PIXEL_MODE_BIT
) {
459 struct gl_pixel_attrib
*attr
;
460 attr
= MALLOC_STRUCT(gl_pixel_attrib
);
462 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
466 if (save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
)) {
467 memcpy(attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
));
468 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
469 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
473 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
478 if (mask
& GL_POINT_BIT
) {
479 if (!push_attrib(ctx
, &head
, GL_POINT_BIT
,
480 sizeof(struct gl_point_attrib
),
485 if (mask
& GL_POLYGON_BIT
) {
486 if (!push_attrib(ctx
, &head
, GL_POLYGON_BIT
,
487 sizeof(struct gl_polygon_attrib
),
488 (void*)&ctx
->Polygon
))
492 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
493 if (!push_attrib(ctx
, &head
, GL_POLYGON_STIPPLE_BIT
,
494 sizeof(ctx
->PolygonStipple
),
495 (void*)&ctx
->PolygonStipple
))
499 if (mask
& GL_SCISSOR_BIT
) {
500 if (!push_attrib(ctx
, &head
, GL_SCISSOR_BIT
,
501 sizeof(struct gl_scissor_attrib
),
502 (void*)&ctx
->Scissor
))
506 if (mask
& GL_STENCIL_BUFFER_BIT
) {
507 if (!push_attrib(ctx
, &head
, GL_STENCIL_BUFFER_BIT
,
508 sizeof(struct gl_stencil_attrib
),
509 (void*)&ctx
->Stencil
))
513 if (mask
& GL_TEXTURE_BIT
) {
514 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
518 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
522 if (!save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
)) {
524 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
528 _mesa_lock_context_textures(ctx
);
530 /* copy/save the bulk of texture state here */
531 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
533 /* Save references to the currently bound texture objects so they don't
534 * accidentally get deleted while referenced in the attribute stack.
536 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
537 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
538 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
539 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
543 /* copy state/contents of the currently bound texture objects */
544 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
545 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
546 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
547 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
551 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
553 _mesa_unlock_context_textures(ctx
);
556 if (mask
& GL_TRANSFORM_BIT
) {
557 if (!push_attrib(ctx
, &head
, GL_TRANSFORM_BIT
,
558 sizeof(struct gl_transform_attrib
),
559 (void*)&ctx
->Transform
))
563 if (mask
& GL_VIEWPORT_BIT
) {
564 struct viewport_state
*viewstate
= CALLOC_STRUCT(viewport_state
);
566 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
570 if (!save_attrib_data(&head
, GL_VIEWPORT_BIT
, viewstate
)) {
572 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
576 memcpy(&viewstate
->ViewportArray
, &ctx
->ViewportArray
,
577 sizeof(struct gl_viewport_attrib
)*ctx
->Const
.MaxViewports
);
579 viewstate
->SubpixelPrecisionBias
[0] = ctx
->SubpixelPrecisionBias
[0];
580 viewstate
->SubpixelPrecisionBias
[1] = ctx
->SubpixelPrecisionBias
[1];
583 /* GL_ARB_multisample */
584 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
585 if (!push_attrib(ctx
, &head
, GL_MULTISAMPLE_BIT_ARB
,
586 sizeof(struct gl_multisample_attrib
),
587 (void*)&ctx
->Multisample
))
593 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
594 ctx
->AttribStackDepth
++;
601 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
603 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
606 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
607 if ((VALUE) != (NEWVALUE)) { \
608 _mesa_set_enable(ctx, ENUM, (NEWVALUE)); \
611 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
612 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
613 if (ctx
->Extensions
.EXT_draw_buffers2
) {
615 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
616 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
620 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
624 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
625 const GLuint mask
= 1 << i
;
626 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
627 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
628 !!(enable
->ClipPlanes
& mask
));
631 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
633 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
635 if (!ctx
->Extensions
.AMD_depth_clamp_separate
) {
636 TEST_AND_UPDATE(ctx
->Transform
.DepthClampNear
&& ctx
->Transform
.DepthClampFar
,
637 enable
->DepthClampNear
&& enable
->DepthClampFar
,
640 TEST_AND_UPDATE(ctx
->Transform
.DepthClampNear
, enable
->DepthClampNear
,
641 GL_DEPTH_CLAMP_NEAR_AMD
);
642 TEST_AND_UPDATE(ctx
->Transform
.DepthClampFar
, enable
->DepthClampFar
,
643 GL_DEPTH_CLAMP_FAR_AMD
);
646 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
647 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
648 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
649 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
650 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
651 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
653 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
655 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
658 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
659 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
660 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
661 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
662 GL_MAP1_TEXTURE_COORD_1
);
663 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
664 GL_MAP1_TEXTURE_COORD_2
);
665 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
666 GL_MAP1_TEXTURE_COORD_3
);
667 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
668 GL_MAP1_TEXTURE_COORD_4
);
669 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
671 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
674 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
675 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
676 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
677 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
678 GL_MAP2_TEXTURE_COORD_1
);
679 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
680 GL_MAP2_TEXTURE_COORD_2
);
681 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
682 GL_MAP2_TEXTURE_COORD_3
);
683 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
684 GL_MAP2_TEXTURE_COORD_4
);
685 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
687 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
690 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
691 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
692 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
693 GL_RESCALE_NORMAL_EXT
);
694 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
695 enable
->RasterPositionUnclipped
,
696 GL_RASTER_POSITION_UNCLIPPED_IBM
);
697 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
699 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
700 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
703 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
704 GL_POLYGON_OFFSET_POINT
);
705 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
706 GL_POLYGON_OFFSET_LINE
);
707 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
708 GL_POLYGON_OFFSET_FILL
);
709 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
711 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
713 if (ctx
->Scissor
.EnableFlags
!= enable
->Scissor
) {
716 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
717 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
, (enable
->Scissor
>> i
) & 1);
720 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
721 if (ctx
->Extensions
.EXT_stencil_two_side
) {
722 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
724 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
726 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
727 enable
->SampleAlphaToCoverage
,
728 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
729 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
730 enable
->SampleAlphaToOne
,
731 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
732 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
733 enable
->SampleCoverage
,
734 GL_SAMPLE_COVERAGE_ARB
);
735 /* GL_ARB_vertex_program */
736 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
737 enable
->VertexProgram
,
738 GL_VERTEX_PROGRAM_ARB
);
739 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
740 enable
->VertexProgramPointSize
,
741 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
742 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
743 enable
->VertexProgramTwoSide
,
744 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
746 /* GL_ARB_fragment_program */
747 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
748 enable
->FragmentProgram
,
749 GL_FRAGMENT_PROGRAM_ARB
);
751 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
752 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
753 GL_FRAMEBUFFER_SRGB
);
755 /* GL_NV_conservative_raster */
756 if (ctx
->Extensions
.NV_conservative_raster
) {
757 TEST_AND_UPDATE(ctx
->ConservativeRasterization
,
758 enable
->ConservativeRasterization
,
759 GL_CONSERVATIVE_RASTERIZATION_NV
);
762 /* texture unit enables */
763 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
764 const GLbitfield enabled
= enable
->Texture
[i
];
765 const GLbitfield genEnabled
= enable
->TexGen
[i
];
767 if (ctx
->Texture
.FixedFuncUnit
[i
].Enabled
!= enabled
) {
768 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
770 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
771 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
772 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
773 if (ctx
->Extensions
.NV_texture_rectangle
) {
774 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
775 !!(enabled
& TEXTURE_RECT_BIT
));
777 if (ctx
->Extensions
.ARB_texture_cube_map
) {
778 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
779 !!(enabled
& TEXTURE_CUBE_BIT
));
783 if (ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
!= genEnabled
) {
784 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
785 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
786 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
787 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
788 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
792 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
797 * Pop/restore texture attribute/group state.
800 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
804 _mesa_lock_context_textures(ctx
);
806 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
807 const struct gl_fixedfunc_texture_unit
*unit
=
808 &texstate
->Texture
.FixedFuncUnit
[u
];
811 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
812 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
813 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
814 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
815 if (ctx
->Extensions
.ARB_texture_cube_map
) {
816 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
817 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
819 if (ctx
->Extensions
.NV_texture_rectangle
) {
820 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
821 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
823 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
824 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
825 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
826 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
827 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
828 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
829 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
830 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
831 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
832 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
833 /* Eye plane done differently to avoid re-transformation */
835 struct gl_fixedfunc_texture_unit
*destUnit
=
836 &ctx
->Texture
.FixedFuncUnit
[u
];
838 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
839 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
840 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
841 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
842 if (ctx
->Driver
.TexGen
) {
843 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
844 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
845 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
846 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
849 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
850 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
851 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
852 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
853 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
854 texstate
->Texture
.Unit
[u
].LodBias
);
855 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
856 unit
->Combine
.ModeRGB
);
857 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
858 unit
->Combine
.ModeA
);
860 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
862 for (i
= 0; i
< n
; i
++) {
863 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
864 unit
->Combine
.SourceRGB
[i
]);
865 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
866 unit
->Combine
.SourceA
[i
]);
867 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
868 unit
->Combine
.OperandRGB
[i
]);
869 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
870 unit
->Combine
.OperandA
[i
]);
873 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
874 1 << unit
->Combine
.ScaleShiftRGB
);
875 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
876 1 << unit
->Combine
.ScaleShiftA
);
878 /* Restore texture object state for each target */
879 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
880 const struct gl_texture_object
*obj
= NULL
;
881 const struct gl_sampler_object
*samp
;
884 obj
= &texstate
->SavedObj
[u
][tgt
];
886 /* don't restore state for unsupported targets to prevent
889 if (obj
->Target
== GL_TEXTURE_CUBE_MAP
&&
890 !ctx
->Extensions
.ARB_texture_cube_map
) {
893 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
894 !ctx
->Extensions
.NV_texture_rectangle
) {
897 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
898 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
899 !ctx
->Extensions
.EXT_texture_array
) {
902 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
903 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
905 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
907 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
909 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
910 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
913 target
= obj
->Target
;
915 _mesa_BindTexture(target
, obj
->Name
);
917 samp
= &obj
->Sampler
;
919 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
920 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
921 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
922 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
923 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
924 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
925 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
926 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
927 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
928 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
929 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
930 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
931 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
932 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
933 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
934 samp
->MaxAnisotropy
);
936 if (ctx
->Extensions
.ARB_shadow
) {
937 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
939 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
942 if (ctx
->Extensions
.ARB_depth_texture
)
943 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
946 /* remove saved references to the texture objects */
947 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
948 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
952 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
954 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
956 _mesa_unlock_context_textures(ctx
);
961 * This function is kind of long just because we have to call a lot
962 * of device driver functions to update device driver state.
964 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
965 * in order to restore GL state. This isn't terribly efficient but it
966 * ensures that dirty flags and any derived state gets updated correctly.
967 * We could at least check if the value to restore equals the current value
968 * and then skip the Mesa call.
971 _mesa_PopAttrib(void)
973 struct gl_attrib_node
*attr
, *next
;
974 GET_CURRENT_CONTEXT(ctx
);
975 FLUSH_VERTICES(ctx
, 0);
977 if (ctx
->AttribStackDepth
== 0) {
978 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib");
982 ctx
->AttribStackDepth
--;
983 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
987 if (MESA_VERBOSE
& VERBOSE_API
) {
988 _mesa_debug(ctx
, "glPopAttrib %s\n",
989 _mesa_enum_to_string(attr
->kind
));
992 switch (attr
->kind
) {
997 case GL_ACCUM_BUFFER_BIT
:
999 const struct gl_accum_attrib
*accum
;
1000 accum
= (const struct gl_accum_attrib
*) attr
->data
;
1001 _mesa_ClearAccum(accum
->ClearColor
[0],
1002 accum
->ClearColor
[1],
1003 accum
->ClearColor
[2],
1004 accum
->ClearColor
[3]);
1007 case GL_COLOR_BUFFER_BIT
:
1009 const struct gl_colorbuffer_attrib
*color
;
1011 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
1012 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
1013 _mesa_ClearColor(color
->ClearColor
.f
[0],
1014 color
->ClearColor
.f
[1],
1015 color
->ClearColor
.f
[2],
1016 color
->ClearColor
.f
[3]);
1017 _mesa_IndexMask(color
->IndexMask
);
1018 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1019 _mesa_ColorMask(GET_COLORMASK_BIT(color
->ColorMask
, 0, 0),
1020 GET_COLORMASK_BIT(color
->ColorMask
, 0, 1),
1021 GET_COLORMASK_BIT(color
->ColorMask
, 0, 2),
1022 GET_COLORMASK_BIT(color
->ColorMask
, 0, 3));
1026 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1028 GET_COLORMASK_BIT(color
->ColorMask
, i
, 0),
1029 GET_COLORMASK_BIT(color
->ColorMask
, i
, 1),
1030 GET_COLORMASK_BIT(color
->ColorMask
, i
, 2),
1031 GET_COLORMASK_BIT(color
->ColorMask
, i
, 3));
1035 /* Need to determine if more than one color output is
1036 * specified. If so, call glDrawBuffersARB, else call
1037 * glDrawBuffer(). This is a subtle, but essential point
1038 * since GL_FRONT (for example) is illegal for the former
1039 * function, but legal for the later.
1041 GLboolean multipleBuffers
= GL_FALSE
;
1044 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1045 if (color
->DrawBuffer
[i
] != GL_NONE
) {
1046 multipleBuffers
= GL_TRUE
;
1050 /* Call the API_level functions, not _mesa_drawbuffers()
1051 * since we need to do error checking on the pop'd
1053 * Ex: if GL_FRONT were pushed, but we're popping with a
1054 * user FBO bound, GL_FRONT will be illegal and we'll need
1055 * to record that error. Per OpenGL ARB decision.
1057 if (multipleBuffers
) {
1058 GLenum buffers
[MAX_DRAW_BUFFERS
];
1060 for (unsigned i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
1061 buffers
[i
] = color
->DrawBuffer
[i
];
1063 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
, buffers
);
1065 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1068 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1069 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
1070 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
1071 if (ctx
->Extensions
.EXT_draw_buffers2
) {
1073 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1074 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
1075 (color
->BlendEnabled
>> i
) & 1);
1079 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
1082 if (ctx
->Color
._BlendFuncPerBuffer
||
1083 ctx
->Color
._BlendEquationPerBuffer
) {
1084 /* set blend per buffer */
1086 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
1087 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
1088 color
->Blend
[buf
].DstRGB
,
1089 color
->Blend
[buf
].SrcA
,
1090 color
->Blend
[buf
].DstA
);
1091 _mesa_BlendEquationSeparateiARB(buf
,
1092 color
->Blend
[buf
].EquationRGB
,
1093 color
->Blend
[buf
].EquationA
);
1097 /* set same blend modes for all buffers */
1098 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
1099 color
->Blend
[0].DstRGB
,
1100 color
->Blend
[0].SrcA
,
1101 color
->Blend
[0].DstA
);
1102 /* This special case is because glBlendEquationSeparateEXT
1103 * cannot take GL_LOGIC_OP as a parameter.
1105 if (color
->Blend
[0].EquationRGB
==
1106 color
->Blend
[0].EquationA
) {
1107 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
1110 _mesa_BlendEquationSeparate(
1111 color
->Blend
[0].EquationRGB
,
1112 color
->Blend
[0].EquationA
);
1115 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
1116 color
->BlendColorUnclamped
[1],
1117 color
->BlendColorUnclamped
[2],
1118 color
->BlendColorUnclamped
[3]);
1119 _mesa_LogicOp(color
->LogicOp
);
1120 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1121 color
->ColorLogicOpEnabled
);
1122 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1123 color
->IndexLogicOpEnabled
);
1124 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1125 if (ctx
->Extensions
.ARB_color_buffer_float
)
1126 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
1127 color
->ClampFragmentColor
);
1128 if (ctx
->Extensions
.ARB_color_buffer_float
|| ctx
->Version
>= 30)
1129 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
1131 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
1132 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
1133 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
1136 case GL_CURRENT_BIT
:
1137 FLUSH_CURRENT(ctx
, 0);
1138 memcpy(&ctx
->Current
, attr
->data
,
1139 sizeof(struct gl_current_attrib
));
1141 case GL_DEPTH_BUFFER_BIT
:
1143 const struct gl_depthbuffer_attrib
*depth
;
1144 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1145 _mesa_DepthFunc(depth
->Func
);
1146 _mesa_ClearDepth(depth
->Clear
);
1147 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1148 _mesa_DepthMask(depth
->Mask
);
1149 if (ctx
->Extensions
.EXT_depth_bounds_test
) {
1150 _mesa_set_enable(ctx
, GL_DEPTH_BOUNDS_TEST_EXT
,
1152 _mesa_DepthBoundsEXT(depth
->BoundsMin
, depth
->BoundsMax
);
1158 const struct gl_enable_attrib
*enable
;
1159 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1160 pop_enable_group(ctx
, enable
);
1161 ctx
->NewState
|= _NEW_ALL
;
1162 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
|
1163 ctx
->DriverFlags
.NewBlend
|
1164 ctx
->DriverFlags
.NewClipPlaneEnable
|
1165 ctx
->DriverFlags
.NewDepth
|
1166 ctx
->DriverFlags
.NewDepthClamp
|
1167 ctx
->DriverFlags
.NewFramebufferSRGB
|
1168 ctx
->DriverFlags
.NewLineState
|
1169 ctx
->DriverFlags
.NewLogicOp
|
1170 ctx
->DriverFlags
.NewMultisampleEnable
|
1171 ctx
->DriverFlags
.NewPolygonState
|
1172 ctx
->DriverFlags
.NewSampleAlphaToXEnable
|
1173 ctx
->DriverFlags
.NewSampleMask
|
1174 ctx
->DriverFlags
.NewScissorTest
|
1175 ctx
->DriverFlags
.NewStencil
|
1176 ctx
->DriverFlags
.NewNvConservativeRasterization
;
1180 memcpy(&ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
));
1181 vbo_exec_update_eval_maps(ctx
);
1185 const struct gl_fog_attrib
*fog
;
1186 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1187 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1188 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1189 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1190 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1191 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1192 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1193 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1198 const struct gl_hint_attrib
*hint
;
1199 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1200 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1201 hint
->PerspectiveCorrection
);
1202 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1203 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1204 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1205 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1206 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1207 hint
->TextureCompression
);
1210 case GL_LIGHTING_BIT
:
1213 const struct gl_light_attrib
*light
;
1214 light
= (const struct gl_light_attrib
*) attr
->data
;
1215 /* lighting enable */
1216 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1217 /* per-light state */
1218 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1219 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
1221 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1222 const struct gl_light
*l
= &light
->Light
[i
];
1223 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1224 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1225 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1226 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1227 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1228 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1230 GLfloat p
[4] = { 0 };
1231 p
[0] = l
->SpotExponent
;
1232 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1235 GLfloat p
[4] = { 0 };
1236 p
[0] = l
->SpotCutoff
;
1237 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1240 GLfloat p
[4] = { 0 };
1241 p
[0] = l
->ConstantAttenuation
;
1242 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1245 GLfloat p
[4] = { 0 };
1246 p
[0] = l
->LinearAttenuation
;
1247 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1250 GLfloat p
[4] = { 0 };
1251 p
[0] = l
->QuadraticAttenuation
;
1252 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1256 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1257 light
->Model
.Ambient
);
1258 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1259 (GLfloat
) light
->Model
.LocalViewer
);
1260 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1261 (GLfloat
) light
->Model
.TwoSide
);
1262 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1263 (GLfloat
) light
->Model
.ColorControl
);
1265 _mesa_ShadeModel(light
->ShadeModel
);
1266 /* color material */
1267 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1268 light
->ColorMaterialMode
);
1269 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1270 light
->ColorMaterialEnabled
);
1272 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1273 sizeof(struct gl_material
));
1274 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1275 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1276 light
->ClampVertexColor
);
1282 const struct gl_line_attrib
*line
;
1283 line
= (const struct gl_line_attrib
*) attr
->data
;
1284 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1285 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1286 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1287 _mesa_LineWidth(line
->Width
);
1291 memcpy(&ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
));
1293 case GL_PIXEL_MODE_BIT
:
1294 memcpy(&ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
));
1295 /* XXX what other pixel state needs to be set by function calls? */
1296 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1297 ctx
->NewState
|= _NEW_PIXEL
;
1301 const struct gl_point_attrib
*point
;
1302 point
= (const struct gl_point_attrib
*) attr
->data
;
1303 _mesa_PointSize(point
->Size
);
1304 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1305 if (ctx
->Extensions
.EXT_point_parameters
) {
1306 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1308 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1310 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1312 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1315 if (ctx
->Extensions
.NV_point_sprite
1316 || ctx
->Extensions
.ARB_point_sprite
) {
1318 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1319 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1320 !!(point
->CoordReplace
& (1u << u
)));
1322 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1323 if (ctx
->Extensions
.NV_point_sprite
)
1324 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1325 ctx
->Point
.SpriteRMode
);
1327 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1328 || ctx
->API
== API_OPENGL_CORE
)
1329 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1330 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1334 case GL_POLYGON_BIT
:
1336 const struct gl_polygon_attrib
*polygon
;
1337 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1338 _mesa_CullFace(polygon
->CullFaceMode
);
1339 _mesa_FrontFace(polygon
->FrontFace
);
1340 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1341 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1342 _mesa_polygon_offset_clamp(ctx
,
1343 polygon
->OffsetFactor
,
1344 polygon
->OffsetUnits
,
1345 polygon
->OffsetClamp
);
1346 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1347 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1348 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1349 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1350 polygon
->OffsetPoint
);
1351 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1352 polygon
->OffsetLine
);
1353 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1354 polygon
->OffsetFill
);
1357 case GL_POLYGON_STIPPLE_BIT
:
1358 memcpy(ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
));
1360 if (ctx
->DriverFlags
.NewPolygonStipple
)
1361 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
1363 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1365 if (ctx
->Driver
.PolygonStipple
)
1366 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) attr
->data
);
1368 case GL_SCISSOR_BIT
:
1371 const struct gl_scissor_attrib
*scissor
;
1372 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1374 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1375 _mesa_set_scissor(ctx
, i
,
1376 scissor
->ScissorArray
[i
].X
,
1377 scissor
->ScissorArray
[i
].Y
,
1378 scissor
->ScissorArray
[i
].Width
,
1379 scissor
->ScissorArray
[i
].Height
);
1380 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
1381 (scissor
->EnableFlags
>> i
) & 1);
1383 if (ctx
->Extensions
.EXT_window_rectangles
) {
1384 STATIC_ASSERT(sizeof(struct gl_scissor_rect
) ==
1386 _mesa_WindowRectanglesEXT(
1387 scissor
->WindowRectMode
, scissor
->NumWindowRects
,
1388 (const GLint
*)scissor
->WindowRects
);
1392 case GL_STENCIL_BUFFER_BIT
:
1394 const struct gl_stencil_attrib
*stencil
;
1395 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1396 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1397 _mesa_ClearStencil(stencil
->Clear
);
1398 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1399 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1400 stencil
->TestTwoSide
);
1401 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1402 ? GL_BACK
: GL_FRONT
);
1405 _mesa_StencilFuncSeparate(GL_FRONT
,
1406 stencil
->Function
[0],
1408 stencil
->ValueMask
[0]);
1409 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1410 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1411 stencil
->ZFailFunc
[0],
1412 stencil
->ZPassFunc
[0]);
1414 _mesa_StencilFuncSeparate(GL_BACK
,
1415 stencil
->Function
[1],
1417 stencil
->ValueMask
[1]);
1418 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1419 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1420 stencil
->ZFailFunc
[1],
1421 stencil
->ZPassFunc
[1]);
1424 case GL_TRANSFORM_BIT
:
1427 const struct gl_transform_attrib
*xform
;
1428 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1429 _mesa_MatrixMode(xform
->MatrixMode
);
1430 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1431 _math_matrix_analyse(ctx
->ProjectionMatrixStack
.Top
);
1433 /* restore clip planes */
1434 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1435 const GLuint mask
= 1 << i
;
1436 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1437 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1438 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1439 !!(xform
->ClipPlanesEnabled
& mask
));
1440 if (ctx
->Driver
.ClipPlane
)
1441 ctx
->Driver
.ClipPlane(ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1444 /* normalize/rescale */
1445 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1446 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1447 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1448 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1449 ctx
->Transform
.RescaleNormals
);
1451 if (!ctx
->Extensions
.AMD_depth_clamp_separate
) {
1452 if (xform
->DepthClampNear
!= ctx
->Transform
.DepthClampNear
&&
1453 xform
->DepthClampFar
!= ctx
->Transform
.DepthClampFar
) {
1454 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1455 ctx
->Transform
.DepthClampNear
&&
1456 ctx
->Transform
.DepthClampFar
);
1459 if (xform
->DepthClampNear
!= ctx
->Transform
.DepthClampNear
)
1460 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP_NEAR_AMD
,
1461 ctx
->Transform
.DepthClampNear
);
1462 if (xform
->DepthClampFar
!= ctx
->Transform
.DepthClampFar
)
1463 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP_FAR_AMD
,
1464 ctx
->Transform
.DepthClampFar
);
1467 if (ctx
->Extensions
.ARB_clip_control
)
1468 _mesa_ClipControl(xform
->ClipOrigin
, xform
->ClipDepthMode
);
1471 case GL_TEXTURE_BIT
:
1473 struct texture_state
*texstate
1474 = (struct texture_state
*) attr
->data
;
1475 pop_texture_group(ctx
, texstate
);
1476 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
| _NEW_TEXTURE_STATE
;
1479 case GL_VIEWPORT_BIT
:
1482 const struct viewport_state
*viewstate
;
1483 viewstate
= (const struct viewport_state
*) attr
->data
;
1485 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1486 const struct gl_viewport_attrib
*vp
= &viewstate
->ViewportArray
[i
];
1487 _mesa_set_viewport(ctx
, i
, vp
->X
, vp
->Y
, vp
->Width
,
1489 _mesa_set_depth_range(ctx
, i
, vp
->Near
, vp
->Far
);
1492 if (ctx
->Extensions
.NV_conservative_raster
) {
1493 GLuint biasx
= viewstate
->SubpixelPrecisionBias
[0];
1494 GLuint biasy
= viewstate
->SubpixelPrecisionBias
[1];
1495 _mesa_SubpixelPrecisionBiasNV(biasx
, biasy
);
1499 case GL_MULTISAMPLE_BIT_ARB
:
1501 const struct gl_multisample_attrib
*ms
;
1502 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1504 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1508 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1510 GL_SAMPLE_COVERAGE
);
1512 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1513 ms
->SampleAlphaToCoverage
,
1514 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1516 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1517 ms
->SampleAlphaToOne
,
1518 GL_SAMPLE_ALPHA_TO_ONE
);
1520 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1521 ms
->SampleCoverageInvert
);
1523 _mesa_AlphaToCoverageDitherControlNV(ms
->SampleAlphaToCoverageDitherControl
);
1528 unreachable("Bad attrib flag in PopAttrib");
1540 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1544 copy_pixelstore(struct gl_context
*ctx
,
1545 struct gl_pixelstore_attrib
*dst
,
1546 const struct gl_pixelstore_attrib
*src
)
1548 dst
->Alignment
= src
->Alignment
;
1549 dst
->RowLength
= src
->RowLength
;
1550 dst
->SkipPixels
= src
->SkipPixels
;
1551 dst
->SkipRows
= src
->SkipRows
;
1552 dst
->ImageHeight
= src
->ImageHeight
;
1553 dst
->SkipImages
= src
->SkipImages
;
1554 dst
->SwapBytes
= src
->SwapBytes
;
1555 dst
->LsbFirst
= src
->LsbFirst
;
1556 dst
->Invert
= src
->Invert
;
1557 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1561 #define GL_CLIENT_PACK_BIT (1<<20)
1562 #define GL_CLIENT_UNPACK_BIT (1<<21)
1565 * Copy gl_vertex_array_object from src to dest.
1566 * 'dest' must be in an initialized state.
1569 copy_array_object(struct gl_context
*ctx
,
1570 struct gl_vertex_array_object
*dest
,
1571 struct gl_vertex_array_object
*src
)
1578 for (i
= 0; i
< ARRAY_SIZE(src
->VertexAttrib
); i
++) {
1579 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1580 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->BufferBinding
[i
], &src
->BufferBinding
[i
]);
1583 /* Enabled must be the same than on push */
1584 dest
->Enabled
= src
->Enabled
;
1585 dest
->_EffEnabledVBO
= src
->_EffEnabledVBO
;
1586 dest
->_EffEnabledNonZeroDivisor
= src
->_EffEnabledNonZeroDivisor
;
1587 /* The bitmask of bound VBOs needs to match the VertexBinding array */
1588 dest
->VertexAttribBufferMask
= src
->VertexAttribBufferMask
;
1589 dest
->NonZeroDivisorMask
= src
->NonZeroDivisorMask
;
1590 dest
->_AttributeMapMode
= src
->_AttributeMapMode
;
1591 dest
->NewArrays
= src
->NewArrays
;
1592 dest
->NumUpdates
= src
->NumUpdates
;
1593 dest
->IsDynamic
= src
->IsDynamic
;
1597 * Copy gl_array_attrib from src to dest.
1598 * 'dest' must be in an initialized state.
1601 copy_array_attrib(struct gl_context
*ctx
,
1602 struct gl_array_attrib
*dest
,
1603 struct gl_array_attrib
*src
,
1607 /* skip DefaultArrayObj, Objects */
1608 dest
->ActiveTexture
= src
->ActiveTexture
;
1609 dest
->LockFirst
= src
->LockFirst
;
1610 dest
->LockCount
= src
->LockCount
;
1611 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1612 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1613 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1614 dest
->RestartIndex
= src
->RestartIndex
;
1615 memcpy(dest
->_RestartIndex
, src
->_RestartIndex
, sizeof(src
->_RestartIndex
));
1617 /* skip RebindArrays */
1620 copy_array_object(ctx
, dest
->VAO
, src
->VAO
);
1622 /* skip ArrayBufferObj */
1623 /* skip IndexBufferObj */
1625 /* Invalidate array state. It will be updated during the next draw. */
1626 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1630 * Save the content of src to dest.
1633 save_array_attrib(struct gl_context
*ctx
,
1634 struct gl_array_attrib
*dest
,
1635 struct gl_array_attrib
*src
)
1637 /* Set the Name, needed for restore, but do never overwrite.
1638 * Needs to match value in the object hash. */
1639 dest
->VAO
->Name
= src
->VAO
->Name
;
1640 /* And copy all of the rest. */
1641 copy_array_attrib(ctx
, dest
, src
, false);
1643 /* Just reference them here */
1644 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1645 src
->ArrayBufferObj
);
1646 _mesa_reference_buffer_object(ctx
, &dest
->VAO
->IndexBufferObj
,
1647 src
->VAO
->IndexBufferObj
);
1651 * Restore the content of src to dest.
1654 restore_array_attrib(struct gl_context
*ctx
,
1655 struct gl_array_attrib
*dest
,
1656 struct gl_array_attrib
*src
)
1658 bool is_vao_name_zero
= src
->VAO
->Name
== 0;
1660 /* The ARB_vertex_array_object spec says:
1662 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1663 * if array is not a name returned from a previous call to
1664 * GenVertexArrays, or if such a name has since been deleted with
1665 * DeleteVertexArrays."
1667 * Therefore popping a deleted VAO cannot magically recreate it.
1669 if (!is_vao_name_zero
&& !_mesa_IsVertexArray(src
->VAO
->Name
))
1672 _mesa_BindVertexArray(src
->VAO
->Name
);
1674 /* Restore or recreate the buffer objects by the names ... */
1675 if (is_vao_name_zero
|| !src
->ArrayBufferObj
||
1676 _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1677 /* ... and restore its content */
1678 copy_array_attrib(ctx
, dest
, src
, false);
1680 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1681 src
->ArrayBufferObj
?
1682 src
->ArrayBufferObj
->Name
: 0);
1684 copy_array_attrib(ctx
, dest
, src
, true);
1687 if (is_vao_name_zero
|| !src
->VAO
->IndexBufferObj
||
1688 _mesa_IsBuffer(src
->VAO
->IndexBufferObj
->Name
)) {
1689 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1690 src
->VAO
->IndexBufferObj
?
1691 src
->VAO
->IndexBufferObj
->Name
: 0);
1697 _mesa_PushClientAttrib(GLbitfield mask
)
1699 struct gl_client_attrib_node
*head
;
1701 GET_CURRENT_CONTEXT(ctx
);
1703 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1704 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib");
1708 head
= &ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1711 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1712 copy_pixelstore(ctx
, &head
->Pack
, &ctx
->Pack
);
1713 copy_pixelstore(ctx
, &head
->Unpack
, &ctx
->Unpack
);
1716 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1717 _mesa_initialize_vao(ctx
, &head
->VAO
, 0);
1718 /* Use the VAO declared within the node instead of allocating it. */
1719 head
->Array
.VAO
= &head
->VAO
;
1720 save_array_attrib(ctx
, &head
->Array
, &ctx
->Array
);
1723 ctx
->ClientAttribStackDepth
++;
1728 _mesa_PopClientAttrib(void)
1730 struct gl_client_attrib_node
*head
;
1732 GET_CURRENT_CONTEXT(ctx
);
1733 FLUSH_VERTICES(ctx
, 0);
1735 if (ctx
->ClientAttribStackDepth
== 0) {
1736 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib");
1740 ctx
->ClientAttribStackDepth
--;
1741 head
= &ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1743 if (head
->Mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1744 copy_pixelstore(ctx
, &ctx
->Pack
, &head
->Pack
);
1745 _mesa_reference_buffer_object(ctx
, &head
->Pack
.BufferObj
, NULL
);
1747 copy_pixelstore(ctx
, &ctx
->Unpack
, &head
->Unpack
);
1748 _mesa_reference_buffer_object(ctx
, &head
->Unpack
.BufferObj
, NULL
);
1751 if (head
->Mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1752 restore_array_attrib(ctx
, &ctx
->Array
, &head
->Array
);
1753 _mesa_unbind_array_object_vbos(ctx
, &head
->VAO
);
1754 _mesa_reference_buffer_object(ctx
, &head
->VAO
.IndexBufferObj
, NULL
);
1755 _mesa_reference_buffer_object(ctx
, &head
->Array
.ArrayBufferObj
, NULL
);
1760 _mesa_ClientAttribDefaultEXT( GLbitfield mask
)
1762 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1763 _mesa_PixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
1764 _mesa_PixelStorei(GL_UNPACK_LSB_FIRST
, GL_FALSE
);
1765 _mesa_PixelStorei(GL_UNPACK_IMAGE_HEIGHT
, 0);
1766 _mesa_PixelStorei(GL_UNPACK_SKIP_IMAGES
, 0);
1767 _mesa_PixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
1768 _mesa_PixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
1769 _mesa_PixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
1770 _mesa_PixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1771 _mesa_PixelStorei(GL_PACK_SWAP_BYTES
, GL_FALSE
);
1772 _mesa_PixelStorei(GL_PACK_LSB_FIRST
, GL_FALSE
);
1773 _mesa_PixelStorei(GL_PACK_IMAGE_HEIGHT
, 0);
1774 _mesa_PixelStorei(GL_PACK_SKIP_IMAGES
, 0);
1775 _mesa_PixelStorei(GL_PACK_ROW_LENGTH
, 0);
1776 _mesa_PixelStorei(GL_PACK_SKIP_ROWS
, 0);
1777 _mesa_PixelStorei(GL_PACK_SKIP_PIXELS
, 0);
1778 _mesa_PixelStorei(GL_PACK_ALIGNMENT
, 4);
1780 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER
, 0);
1781 _mesa_BindBuffer(GL_PIXEL_PACK_BUFFER
, 0);
1783 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1784 GET_CURRENT_CONTEXT(ctx
);
1787 _mesa_BindBuffer(GL_ARRAY_BUFFER
, 0);
1788 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
1790 _mesa_DisableClientState(GL_EDGE_FLAG_ARRAY
);
1791 _mesa_EdgeFlagPointer(0, 0);
1793 _mesa_DisableClientState(GL_INDEX_ARRAY
);
1794 _mesa_IndexPointer(GL_FLOAT
, 0, 0);
1796 _mesa_DisableClientState(GL_SECONDARY_COLOR_ARRAY
);
1797 _mesa_SecondaryColorPointer(4, GL_FLOAT
, 0, 0);
1799 _mesa_DisableClientState(GL_FOG_COORD_ARRAY
);
1800 _mesa_FogCoordPointer(GL_FLOAT
, 0, 0);
1802 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
1803 _mesa_ClientActiveTexture(GL_TEXTURE0
+ i
);
1804 _mesa_DisableClientState(GL_TEXTURE_COORD_ARRAY
);
1805 _mesa_TexCoordPointer(4, GL_FLOAT
, 0, 0);
1808 _mesa_DisableClientState(GL_COLOR_ARRAY
);
1809 _mesa_ColorPointer(4, GL_FLOAT
, 0, 0);
1811 _mesa_DisableClientState(GL_NORMAL_ARRAY
);
1812 _mesa_NormalPointer(GL_FLOAT
, 0, 0);
1814 _mesa_DisableClientState(GL_VERTEX_ARRAY
);
1815 _mesa_VertexPointer(4, GL_FLOAT
, 0, 0);
1817 for (i
= 0; i
< ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
; i
++) {
1818 _mesa_DisableVertexAttribArray(i
);
1819 _mesa_VertexAttribPointer(i
, 4, GL_FLOAT
, GL_FALSE
, 0, 0);
1822 _mesa_ClientActiveTexture(GL_TEXTURE0
);
1824 _mesa_PrimitiveRestartIndex_no_error(0);
1825 if (ctx
->Version
>= 31)
1826 _mesa_Disable(GL_PRIMITIVE_RESTART
);
1827 else if (_mesa_has_NV_primitive_restart(ctx
))
1828 _mesa_DisableClientState(GL_PRIMITIVE_RESTART_NV
);
1830 if (_mesa_has_ARB_ES3_compatibility(ctx
))
1831 _mesa_Disable(GL_PRIMITIVE_RESTART_FIXED_INDEX
);
1836 _mesa_PushClientAttribDefaultEXT( GLbitfield mask
)
1838 _mesa_PushClientAttrib(mask
);
1839 _mesa_ClientAttribDefaultEXT(mask
);
1844 * Free any attribute state data that might be attached to the context.
1847 _mesa_free_attrib_data(struct gl_context
*ctx
)
1849 while (ctx
->AttribStackDepth
> 0) {
1850 struct gl_attrib_node
*attr
, *next
;
1852 ctx
->AttribStackDepth
--;
1853 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1856 if (attr
->kind
== GL_TEXTURE_BIT
) {
1857 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1859 /* clear references to the saved texture objects */
1860 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1861 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1862 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1865 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1868 /* any other chunks of state that requires special handling? */
1881 _mesa_init_attrib(struct gl_context
*ctx
)
1883 /* Renderer and client attribute stacks */
1884 ctx
->AttribStackDepth
= 0;
1885 ctx
->ClientAttribStackDepth
= 0;