2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
45 #include "multisample.h"
65 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
67 struct gl_enable_attrib
72 GLbitfield ClipPlanes
;
73 GLboolean ColorMaterial
;
79 GLboolean Light
[MAX_LIGHTS
];
82 GLboolean LineStipple
;
83 GLboolean IndexLogicOp
;
84 GLboolean ColorLogicOp
;
89 GLboolean Map1TextureCoord1
;
90 GLboolean Map1TextureCoord2
;
91 GLboolean Map1TextureCoord3
;
92 GLboolean Map1TextureCoord4
;
93 GLboolean Map1Vertex3
;
94 GLboolean Map1Vertex4
;
98 GLboolean Map2TextureCoord1
;
99 GLboolean Map2TextureCoord2
;
100 GLboolean Map2TextureCoord3
;
101 GLboolean Map2TextureCoord4
;
102 GLboolean Map2Vertex3
;
103 GLboolean Map2Vertex4
;
106 GLboolean PixelTexture
;
107 GLboolean PointSmooth
;
108 GLboolean PolygonOffsetPoint
;
109 GLboolean PolygonOffsetLine
;
110 GLboolean PolygonOffsetFill
;
111 GLboolean PolygonSmooth
;
112 GLboolean PolygonStipple
;
113 GLboolean RescaleNormals
;
116 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
117 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
118 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
120 GLboolean SampleCoverage
; /* GL_ARB_multisample */
121 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
123 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
124 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
126 /* GL_ARB_vertex_program */
127 GLboolean VertexProgram
;
128 GLboolean VertexProgramPointSize
;
129 GLboolean VertexProgramTwoSide
;
131 /* GL_ARB_fragment_program */
132 GLboolean FragmentProgram
;
134 /* GL_ARB_point_sprite / GL_NV_point_sprite */
135 GLboolean PointSprite
;
136 GLboolean FragmentShaderATI
;
138 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
139 GLboolean sRGBEnabled
;
141 /* GL_NV_conservative_raster */
142 GLboolean ConservativeRasterization
;
147 * Node for the attribute stack.
149 struct gl_attrib_node
153 struct gl_attrib_node
*next
;
159 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
163 struct gl_texture_attrib Texture
; /**< The usual context state */
165 /** to save per texture object state (wrap modes, filters, etc): */
166 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
169 * To save references to texture objects (so they don't get accidentally
170 * deleted while saved in the attribute stack).
172 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
174 /* We need to keep a reference to the shared state. That's where the
175 * default texture objects are kept. We don't want that state to be
176 * freed while the attribute stack contains pointers to any default
179 struct gl_shared_state
*SharedRef
;
183 struct viewport_state
185 struct gl_viewport_attrib ViewportArray
[MAX_VIEWPORTS
];
186 GLuint SubpixelPrecisionBias
[2];
190 /** An unused GL_*_BIT value */
191 #define DUMMY_BIT 0x10000000
195 * Allocate new attribute node of given type/kind. Attach payload data.
196 * Insert it into the linked list named by 'head'.
199 save_attrib_data(struct gl_attrib_node
**head
,
200 GLbitfield kind
, void *payload
)
202 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
219 * Helper function for_mesa_PushAttrib for simple attributes.
220 * Allocates memory for attribute data and copies the given attribute data.
221 * \param head head of linked list to insert attribute data into
222 * \param attr_bit one of the GL_<attrib>_BIT flags
223 * \param attr_size number of bytes to allocate for attribute data
224 * \param attr_data the attribute data to copy
225 * \return true for success, false for out of memory
228 push_attrib(struct gl_context
*ctx
, struct gl_attrib_node
**head
,
229 GLbitfield attr_bit
, GLuint attr_size
, const void *attr_data
)
233 attribute
= malloc(attr_size
);
234 if (attribute
== NULL
) {
235 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
239 if (save_attrib_data(head
, attr_bit
, attribute
)) {
240 memcpy(attribute
, attr_data
, attr_size
);
244 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
252 _mesa_PushAttrib(GLbitfield mask
)
254 struct gl_attrib_node
*head
;
256 GET_CURRENT_CONTEXT(ctx
);
258 if (MESA_VERBOSE
& VERBOSE_API
)
259 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
261 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
262 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushAttrib");
266 /* Build linked list of attribute nodes which save all attribute */
267 /* groups specified by the mask. */
271 /* if mask is zero we still need to push something so that we
272 * don't get a GL_STACK_UNDERFLOW error in glPopAttrib().
275 if (!push_attrib(ctx
, &head
, DUMMY_BIT
, sizeof(dummy
), &dummy
))
279 if (mask
& GL_ACCUM_BUFFER_BIT
) {
280 if (!push_attrib(ctx
, &head
, GL_ACCUM_BUFFER_BIT
,
281 sizeof(struct gl_accum_attrib
),
286 if (mask
& GL_COLOR_BUFFER_BIT
) {
288 struct gl_colorbuffer_attrib
*attr
;
289 attr
= MALLOC_STRUCT(gl_colorbuffer_attrib
);
291 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
295 if (save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
)) {
296 memcpy(attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
));
297 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
298 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
299 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
303 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
308 if (mask
& GL_CURRENT_BIT
) {
309 FLUSH_CURRENT(ctx
, 0);
310 if (!push_attrib(ctx
, &head
, GL_CURRENT_BIT
,
311 sizeof(struct gl_current_attrib
),
312 (void*)&ctx
->Current
))
316 if (mask
& GL_DEPTH_BUFFER_BIT
) {
317 if (!push_attrib(ctx
, &head
, GL_DEPTH_BUFFER_BIT
,
318 sizeof(struct gl_depthbuffer_attrib
),
323 if (mask
& GL_ENABLE_BIT
) {
324 struct gl_enable_attrib
*attr
;
326 attr
= MALLOC_STRUCT(gl_enable_attrib
);
328 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
332 /* Copy enable flags from all other attributes into the enable struct. */
333 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
334 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
335 attr
->Blend
= ctx
->Color
.BlendEnabled
;
336 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
337 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
338 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
339 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
340 attr
->DepthTest
= ctx
->Depth
.Test
;
341 attr
->Dither
= ctx
->Color
.DitherFlag
;
342 attr
->Fog
= ctx
->Fog
.Enabled
;
343 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
344 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
346 attr
->Lighting
= ctx
->Light
.Enabled
;
347 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
348 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
349 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
350 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
351 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
352 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
353 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
354 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
355 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
356 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
357 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
358 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
359 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
360 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
361 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
362 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
363 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
364 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
365 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
366 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
367 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
368 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
369 attr
->Normalize
= ctx
->Transform
.Normalize
;
370 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
371 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
372 attr
->PointSprite
= ctx
->Point
.PointSprite
;
373 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
374 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
375 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
376 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
377 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
378 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
379 attr
->Scissor
= ctx
->Scissor
.EnableFlags
;
380 attr
->Stencil
= ctx
->Stencil
.Enabled
;
381 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
382 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
383 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
384 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
385 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
386 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
387 attr
->Texture
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].Enabled
;
388 attr
->TexGen
[i
] = ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
;
390 /* GL_ARB_vertex_program */
391 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
392 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
393 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
395 /* GL_ARB_fragment_program */
396 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
398 if (!save_attrib_data(&head
, GL_ENABLE_BIT
, attr
)) {
400 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
404 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
405 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
407 /* GL_NV_conservative_raster */
408 attr
->ConservativeRasterization
= ctx
->ConservativeRasterization
;
411 if (mask
& GL_EVAL_BIT
) {
412 if (!push_attrib(ctx
, &head
, GL_EVAL_BIT
,
413 sizeof(struct gl_eval_attrib
),
418 if (mask
& GL_FOG_BIT
) {
419 if (!push_attrib(ctx
, &head
, GL_FOG_BIT
,
420 sizeof(struct gl_fog_attrib
),
425 if (mask
& GL_HINT_BIT
) {
426 if (!push_attrib(ctx
, &head
, GL_HINT_BIT
,
427 sizeof(struct gl_hint_attrib
),
432 if (mask
& GL_LIGHTING_BIT
) {
433 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
434 if (!push_attrib(ctx
, &head
, GL_LIGHTING_BIT
,
435 sizeof(struct gl_light_attrib
),
440 if (mask
& GL_LINE_BIT
) {
441 if (!push_attrib(ctx
, &head
, GL_LINE_BIT
,
442 sizeof(struct gl_line_attrib
),
447 if (mask
& GL_LIST_BIT
) {
448 if (!push_attrib(ctx
, &head
, GL_LIST_BIT
,
449 sizeof(struct gl_list_attrib
),
454 if (mask
& GL_PIXEL_MODE_BIT
) {
455 struct gl_pixel_attrib
*attr
;
456 attr
= MALLOC_STRUCT(gl_pixel_attrib
);
458 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
462 if (save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
)) {
463 memcpy(attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
));
464 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
465 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
469 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib");
474 if (mask
& GL_POINT_BIT
) {
475 if (!push_attrib(ctx
, &head
, GL_POINT_BIT
,
476 sizeof(struct gl_point_attrib
),
481 if (mask
& GL_POLYGON_BIT
) {
482 if (!push_attrib(ctx
, &head
, GL_POLYGON_BIT
,
483 sizeof(struct gl_polygon_attrib
),
484 (void*)&ctx
->Polygon
))
488 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
489 if (!push_attrib(ctx
, &head
, GL_POLYGON_STIPPLE_BIT
,
490 sizeof(ctx
->PolygonStipple
),
491 (void*)&ctx
->PolygonStipple
))
495 if (mask
& GL_SCISSOR_BIT
) {
496 if (!push_attrib(ctx
, &head
, GL_SCISSOR_BIT
,
497 sizeof(struct gl_scissor_attrib
),
498 (void*)&ctx
->Scissor
))
502 if (mask
& GL_STENCIL_BUFFER_BIT
) {
503 if (!push_attrib(ctx
, &head
, GL_STENCIL_BUFFER_BIT
,
504 sizeof(struct gl_stencil_attrib
),
505 (void*)&ctx
->Stencil
))
509 if (mask
& GL_TEXTURE_BIT
) {
510 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
514 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
518 if (!save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
)) {
520 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
524 _mesa_lock_context_textures(ctx
);
526 /* copy/save the bulk of texture state here */
527 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
529 /* Save references to the currently bound texture objects so they don't
530 * accidentally get deleted while referenced in the attribute stack.
532 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
533 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
534 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
535 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
539 /* copy state/contents of the currently bound texture objects */
540 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
541 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
542 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
543 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
547 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
549 _mesa_unlock_context_textures(ctx
);
552 if (mask
& GL_TRANSFORM_BIT
) {
553 if (!push_attrib(ctx
, &head
, GL_TRANSFORM_BIT
,
554 sizeof(struct gl_transform_attrib
),
555 (void*)&ctx
->Transform
))
559 if (mask
& GL_VIEWPORT_BIT
) {
560 struct viewport_state
*viewstate
= CALLOC_STRUCT(viewport_state
);
562 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
566 if (!save_attrib_data(&head
, GL_VIEWPORT_BIT
, viewstate
)) {
568 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_VIEWPORT_BIT)");
572 memcpy(&viewstate
->ViewportArray
, &ctx
->ViewportArray
,
573 sizeof(struct gl_viewport_attrib
)*ctx
->Const
.MaxViewports
);
575 viewstate
->SubpixelPrecisionBias
[0] = ctx
->SubpixelPrecisionBias
[0];
576 viewstate
->SubpixelPrecisionBias
[1] = ctx
->SubpixelPrecisionBias
[1];
579 /* GL_ARB_multisample */
580 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
581 if (!push_attrib(ctx
, &head
, GL_MULTISAMPLE_BIT_ARB
,
582 sizeof(struct gl_multisample_attrib
),
583 (void*)&ctx
->Multisample
))
589 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
590 ctx
->AttribStackDepth
++;
597 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
599 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
602 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
603 if ((VALUE) != (NEWVALUE)) { \
604 _mesa_set_enable(ctx, ENUM, (NEWVALUE)); \
607 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
608 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
609 if (ctx
->Extensions
.EXT_draw_buffers2
) {
611 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
612 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
616 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
620 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
621 const GLuint mask
= 1 << i
;
622 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
623 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
624 !!(enable
->ClipPlanes
& mask
));
627 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
629 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
630 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
632 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
633 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
634 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
635 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
636 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
637 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
639 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
641 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
644 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
645 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
646 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
647 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
648 GL_MAP1_TEXTURE_COORD_1
);
649 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
650 GL_MAP1_TEXTURE_COORD_2
);
651 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
652 GL_MAP1_TEXTURE_COORD_3
);
653 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
654 GL_MAP1_TEXTURE_COORD_4
);
655 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
657 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
660 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
661 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
662 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
663 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
664 GL_MAP2_TEXTURE_COORD_1
);
665 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
666 GL_MAP2_TEXTURE_COORD_2
);
667 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
668 GL_MAP2_TEXTURE_COORD_3
);
669 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
670 GL_MAP2_TEXTURE_COORD_4
);
671 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
673 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
676 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
677 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
678 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
679 GL_RESCALE_NORMAL_EXT
);
680 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
681 enable
->RasterPositionUnclipped
,
682 GL_RASTER_POSITION_UNCLIPPED_IBM
);
683 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
685 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
686 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
689 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
690 GL_POLYGON_OFFSET_POINT
);
691 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
692 GL_POLYGON_OFFSET_LINE
);
693 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
694 GL_POLYGON_OFFSET_FILL
);
695 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
697 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
699 if (ctx
->Scissor
.EnableFlags
!= enable
->Scissor
) {
702 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
703 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
, (enable
->Scissor
>> i
) & 1);
706 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
707 if (ctx
->Extensions
.EXT_stencil_two_side
) {
708 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
710 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
712 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
713 enable
->SampleAlphaToCoverage
,
714 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
715 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
716 enable
->SampleAlphaToOne
,
717 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
718 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
719 enable
->SampleCoverage
,
720 GL_SAMPLE_COVERAGE_ARB
);
721 /* GL_ARB_vertex_program */
722 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
723 enable
->VertexProgram
,
724 GL_VERTEX_PROGRAM_ARB
);
725 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
726 enable
->VertexProgramPointSize
,
727 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
728 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
729 enable
->VertexProgramTwoSide
,
730 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
732 /* GL_ARB_fragment_program */
733 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
734 enable
->FragmentProgram
,
735 GL_FRAGMENT_PROGRAM_ARB
);
737 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
738 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
739 GL_FRAMEBUFFER_SRGB
);
741 /* GL_NV_conservative_raster */
742 if (ctx
->Extensions
.NV_conservative_raster
) {
743 TEST_AND_UPDATE(ctx
->ConservativeRasterization
,
744 enable
->ConservativeRasterization
,
745 GL_CONSERVATIVE_RASTERIZATION_NV
);
748 /* texture unit enables */
749 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
750 const GLbitfield enabled
= enable
->Texture
[i
];
751 const GLbitfield genEnabled
= enable
->TexGen
[i
];
753 if (ctx
->Texture
.FixedFuncUnit
[i
].Enabled
!= enabled
) {
754 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
756 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
757 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
758 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
759 if (ctx
->Extensions
.NV_texture_rectangle
) {
760 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
761 !!(enabled
& TEXTURE_RECT_BIT
));
763 if (ctx
->Extensions
.ARB_texture_cube_map
) {
764 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
765 !!(enabled
& TEXTURE_CUBE_BIT
));
769 if (ctx
->Texture
.FixedFuncUnit
[i
].TexGenEnabled
!= genEnabled
) {
770 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
771 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
772 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
773 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
774 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
778 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
783 * Pop/restore texture attribute/group state.
786 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
790 _mesa_lock_context_textures(ctx
);
792 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
793 const struct gl_fixedfunc_texture_unit
*unit
=
794 &texstate
->Texture
.FixedFuncUnit
[u
];
797 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
798 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
799 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
800 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
801 if (ctx
->Extensions
.ARB_texture_cube_map
) {
802 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
803 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
805 if (ctx
->Extensions
.NV_texture_rectangle
) {
806 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
807 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
809 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
810 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
811 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
812 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
813 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
814 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
815 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
816 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
817 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
818 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
819 /* Eye plane done differently to avoid re-transformation */
821 struct gl_fixedfunc_texture_unit
*destUnit
=
822 &ctx
->Texture
.FixedFuncUnit
[u
];
824 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
825 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
826 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
827 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
828 if (ctx
->Driver
.TexGen
) {
829 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
830 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
831 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
832 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
835 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
836 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
837 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
838 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
839 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
840 texstate
->Texture
.Unit
[u
].LodBias
);
841 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
842 unit
->Combine
.ModeRGB
);
843 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
844 unit
->Combine
.ModeA
);
846 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
848 for (i
= 0; i
< n
; i
++) {
849 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
850 unit
->Combine
.SourceRGB
[i
]);
851 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
852 unit
->Combine
.SourceA
[i
]);
853 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
854 unit
->Combine
.OperandRGB
[i
]);
855 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
856 unit
->Combine
.OperandA
[i
]);
859 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
860 1 << unit
->Combine
.ScaleShiftRGB
);
861 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
862 1 << unit
->Combine
.ScaleShiftA
);
864 /* Restore texture object state for each target */
865 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
866 const struct gl_texture_object
*obj
= NULL
;
867 const struct gl_sampler_object
*samp
;
870 obj
= &texstate
->SavedObj
[u
][tgt
];
872 /* don't restore state for unsupported targets to prevent
875 if (obj
->Target
== GL_TEXTURE_CUBE_MAP
&&
876 !ctx
->Extensions
.ARB_texture_cube_map
) {
879 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
880 !ctx
->Extensions
.NV_texture_rectangle
) {
883 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
884 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
885 !ctx
->Extensions
.EXT_texture_array
) {
888 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
889 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
891 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
893 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
895 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
896 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
899 target
= obj
->Target
;
901 _mesa_BindTexture(target
, obj
->Name
);
903 samp
= &obj
->Sampler
;
905 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
906 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
907 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
908 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
909 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
910 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
911 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
912 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
913 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
914 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
915 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
916 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
917 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
918 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
919 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
920 samp
->MaxAnisotropy
);
922 if (ctx
->Extensions
.ARB_shadow
) {
923 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
925 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
928 if (ctx
->Extensions
.ARB_depth_texture
)
929 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
932 /* remove saved references to the texture objects */
933 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
934 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
938 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
940 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
942 _mesa_unlock_context_textures(ctx
);
947 * This function is kind of long just because we have to call a lot
948 * of device driver functions to update device driver state.
950 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
951 * in order to restore GL state. This isn't terribly efficient but it
952 * ensures that dirty flags and any derived state gets updated correctly.
953 * We could at least check if the value to restore equals the current value
954 * and then skip the Mesa call.
957 _mesa_PopAttrib(void)
959 struct gl_attrib_node
*attr
, *next
;
960 GET_CURRENT_CONTEXT(ctx
);
961 FLUSH_VERTICES(ctx
, 0);
963 if (ctx
->AttribStackDepth
== 0) {
964 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib");
968 ctx
->AttribStackDepth
--;
969 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
973 if (MESA_VERBOSE
& VERBOSE_API
) {
974 _mesa_debug(ctx
, "glPopAttrib %s\n",
975 _mesa_enum_to_string(attr
->kind
));
978 switch (attr
->kind
) {
983 case GL_ACCUM_BUFFER_BIT
:
985 const struct gl_accum_attrib
*accum
;
986 accum
= (const struct gl_accum_attrib
*) attr
->data
;
987 _mesa_ClearAccum(accum
->ClearColor
[0],
988 accum
->ClearColor
[1],
989 accum
->ClearColor
[2],
990 accum
->ClearColor
[3]);
993 case GL_COLOR_BUFFER_BIT
:
995 const struct gl_colorbuffer_attrib
*color
;
997 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
998 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
999 _mesa_ClearColor(color
->ClearColor
.f
[0],
1000 color
->ClearColor
.f
[1],
1001 color
->ClearColor
.f
[2],
1002 color
->ClearColor
.f
[3]);
1003 _mesa_IndexMask(color
->IndexMask
);
1004 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1005 _mesa_ColorMask(GET_COLORMASK_BIT(color
->ColorMask
, 0, 0),
1006 GET_COLORMASK_BIT(color
->ColorMask
, 0, 1),
1007 GET_COLORMASK_BIT(color
->ColorMask
, 0, 2),
1008 GET_COLORMASK_BIT(color
->ColorMask
, 0, 3));
1012 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1014 GET_COLORMASK_BIT(color
->ColorMask
, i
, 0),
1015 GET_COLORMASK_BIT(color
->ColorMask
, i
, 1),
1016 GET_COLORMASK_BIT(color
->ColorMask
, i
, 2),
1017 GET_COLORMASK_BIT(color
->ColorMask
, i
, 3));
1021 /* Need to determine if more than one color output is
1022 * specified. If so, call glDrawBuffersARB, else call
1023 * glDrawBuffer(). This is a subtle, but essential point
1024 * since GL_FRONT (for example) is illegal for the former
1025 * function, but legal for the later.
1027 GLboolean multipleBuffers
= GL_FALSE
;
1030 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1031 if (color
->DrawBuffer
[i
] != GL_NONE
) {
1032 multipleBuffers
= GL_TRUE
;
1036 /* Call the API_level functions, not _mesa_drawbuffers()
1037 * since we need to do error checking on the pop'd
1039 * Ex: if GL_FRONT were pushed, but we're popping with a
1040 * user FBO bound, GL_FRONT will be illegal and we'll need
1041 * to record that error. Per OpenGL ARB decision.
1043 if (multipleBuffers
) {
1044 GLenum buffers
[MAX_DRAW_BUFFERS
];
1046 for (unsigned i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
1047 buffers
[i
] = color
->DrawBuffer
[i
];
1049 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
, buffers
);
1051 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1054 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1055 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
1056 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
1057 if (ctx
->Extensions
.EXT_draw_buffers2
) {
1059 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
1060 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
1061 (color
->BlendEnabled
>> i
) & 1);
1065 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
1068 if (ctx
->Color
._BlendFuncPerBuffer
||
1069 ctx
->Color
._BlendEquationPerBuffer
) {
1070 /* set blend per buffer */
1072 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
1073 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
1074 color
->Blend
[buf
].DstRGB
,
1075 color
->Blend
[buf
].SrcA
,
1076 color
->Blend
[buf
].DstA
);
1077 _mesa_BlendEquationSeparateiARB(buf
,
1078 color
->Blend
[buf
].EquationRGB
,
1079 color
->Blend
[buf
].EquationA
);
1083 /* set same blend modes for all buffers */
1084 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
1085 color
->Blend
[0].DstRGB
,
1086 color
->Blend
[0].SrcA
,
1087 color
->Blend
[0].DstA
);
1088 /* This special case is because glBlendEquationSeparateEXT
1089 * cannot take GL_LOGIC_OP as a parameter.
1091 if (color
->Blend
[0].EquationRGB
==
1092 color
->Blend
[0].EquationA
) {
1093 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
1096 _mesa_BlendEquationSeparate(
1097 color
->Blend
[0].EquationRGB
,
1098 color
->Blend
[0].EquationA
);
1101 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
1102 color
->BlendColorUnclamped
[1],
1103 color
->BlendColorUnclamped
[2],
1104 color
->BlendColorUnclamped
[3]);
1105 _mesa_LogicOp(color
->LogicOp
);
1106 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1107 color
->ColorLogicOpEnabled
);
1108 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1109 color
->IndexLogicOpEnabled
);
1110 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1111 if (ctx
->Extensions
.ARB_color_buffer_float
)
1112 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
1113 color
->ClampFragmentColor
);
1114 if (ctx
->Extensions
.ARB_color_buffer_float
|| ctx
->Version
>= 30)
1115 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
1117 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
1118 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
1119 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
1122 case GL_CURRENT_BIT
:
1123 FLUSH_CURRENT(ctx
, 0);
1124 memcpy(&ctx
->Current
, attr
->data
,
1125 sizeof(struct gl_current_attrib
));
1127 case GL_DEPTH_BUFFER_BIT
:
1129 const struct gl_depthbuffer_attrib
*depth
;
1130 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1131 _mesa_DepthFunc(depth
->Func
);
1132 _mesa_ClearDepth(depth
->Clear
);
1133 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1134 _mesa_DepthMask(depth
->Mask
);
1135 if (ctx
->Extensions
.EXT_depth_bounds_test
) {
1136 _mesa_set_enable(ctx
, GL_DEPTH_BOUNDS_TEST_EXT
,
1138 _mesa_DepthBoundsEXT(depth
->BoundsMin
, depth
->BoundsMax
);
1144 const struct gl_enable_attrib
*enable
;
1145 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1146 pop_enable_group(ctx
, enable
);
1147 ctx
->NewState
|= _NEW_ALL
;
1148 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
|
1149 ctx
->DriverFlags
.NewBlend
|
1150 ctx
->DriverFlags
.NewClipPlaneEnable
|
1151 ctx
->DriverFlags
.NewDepth
|
1152 ctx
->DriverFlags
.NewDepthClamp
|
1153 ctx
->DriverFlags
.NewFramebufferSRGB
|
1154 ctx
->DriverFlags
.NewLineState
|
1155 ctx
->DriverFlags
.NewLogicOp
|
1156 ctx
->DriverFlags
.NewMultisampleEnable
|
1157 ctx
->DriverFlags
.NewPolygonState
|
1158 ctx
->DriverFlags
.NewSampleAlphaToXEnable
|
1159 ctx
->DriverFlags
.NewSampleMask
|
1160 ctx
->DriverFlags
.NewScissorTest
|
1161 ctx
->DriverFlags
.NewStencil
|
1162 ctx
->DriverFlags
.NewNvConservativeRasterization
;
1166 memcpy(&ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
));
1167 ctx
->NewState
|= _NEW_EVAL
;
1171 const struct gl_fog_attrib
*fog
;
1172 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1173 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1174 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1175 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1176 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1177 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1178 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1179 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1184 const struct gl_hint_attrib
*hint
;
1185 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1186 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1187 hint
->PerspectiveCorrection
);
1188 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1189 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1190 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1191 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1192 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1193 hint
->TextureCompression
);
1196 case GL_LIGHTING_BIT
:
1199 const struct gl_light_attrib
*light
;
1200 light
= (const struct gl_light_attrib
*) attr
->data
;
1201 /* lighting enable */
1202 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1203 /* per-light state */
1204 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1205 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
1207 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1208 const struct gl_light
*l
= &light
->Light
[i
];
1209 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1210 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1211 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1212 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1213 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1214 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1216 GLfloat p
[4] = { 0 };
1217 p
[0] = l
->SpotExponent
;
1218 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1221 GLfloat p
[4] = { 0 };
1222 p
[0] = l
->SpotCutoff
;
1223 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1226 GLfloat p
[4] = { 0 };
1227 p
[0] = l
->ConstantAttenuation
;
1228 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1231 GLfloat p
[4] = { 0 };
1232 p
[0] = l
->LinearAttenuation
;
1233 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1236 GLfloat p
[4] = { 0 };
1237 p
[0] = l
->QuadraticAttenuation
;
1238 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1242 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1243 light
->Model
.Ambient
);
1244 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1245 (GLfloat
) light
->Model
.LocalViewer
);
1246 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1247 (GLfloat
) light
->Model
.TwoSide
);
1248 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1249 (GLfloat
) light
->Model
.ColorControl
);
1251 _mesa_ShadeModel(light
->ShadeModel
);
1252 /* color material */
1253 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1254 light
->ColorMaterialMode
);
1255 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1256 light
->ColorMaterialEnabled
);
1258 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1259 sizeof(struct gl_material
));
1260 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1261 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1262 light
->ClampVertexColor
);
1268 const struct gl_line_attrib
*line
;
1269 line
= (const struct gl_line_attrib
*) attr
->data
;
1270 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1271 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1272 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1273 _mesa_LineWidth(line
->Width
);
1277 memcpy(&ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
));
1279 case GL_PIXEL_MODE_BIT
:
1280 memcpy(&ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
));
1281 /* XXX what other pixel state needs to be set by function calls? */
1282 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1283 ctx
->NewState
|= _NEW_PIXEL
;
1287 const struct gl_point_attrib
*point
;
1288 point
= (const struct gl_point_attrib
*) attr
->data
;
1289 _mesa_PointSize(point
->Size
);
1290 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1291 if (ctx
->Extensions
.EXT_point_parameters
) {
1292 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1294 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1296 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1298 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1301 if (ctx
->Extensions
.NV_point_sprite
1302 || ctx
->Extensions
.ARB_point_sprite
) {
1304 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1305 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1306 !!(point
->CoordReplace
& (1u << u
)));
1308 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1309 if (ctx
->Extensions
.NV_point_sprite
)
1310 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1311 ctx
->Point
.SpriteRMode
);
1313 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1314 || ctx
->API
== API_OPENGL_CORE
)
1315 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1316 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1320 case GL_POLYGON_BIT
:
1322 const struct gl_polygon_attrib
*polygon
;
1323 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1324 _mesa_CullFace(polygon
->CullFaceMode
);
1325 _mesa_FrontFace(polygon
->FrontFace
);
1326 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1327 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1328 _mesa_polygon_offset_clamp(ctx
,
1329 polygon
->OffsetFactor
,
1330 polygon
->OffsetUnits
,
1331 polygon
->OffsetClamp
);
1332 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1333 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1334 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1335 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1336 polygon
->OffsetPoint
);
1337 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1338 polygon
->OffsetLine
);
1339 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1340 polygon
->OffsetFill
);
1343 case GL_POLYGON_STIPPLE_BIT
:
1344 memcpy(ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
));
1346 if (ctx
->DriverFlags
.NewPolygonStipple
)
1347 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
1349 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1351 if (ctx
->Driver
.PolygonStipple
)
1352 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) attr
->data
);
1354 case GL_SCISSOR_BIT
:
1357 const struct gl_scissor_attrib
*scissor
;
1358 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1360 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1361 _mesa_set_scissor(ctx
, i
,
1362 scissor
->ScissorArray
[i
].X
,
1363 scissor
->ScissorArray
[i
].Y
,
1364 scissor
->ScissorArray
[i
].Width
,
1365 scissor
->ScissorArray
[i
].Height
);
1366 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
1367 (scissor
->EnableFlags
>> i
) & 1);
1369 if (ctx
->Extensions
.EXT_window_rectangles
) {
1370 STATIC_ASSERT(sizeof(struct gl_scissor_rect
) ==
1372 _mesa_WindowRectanglesEXT(
1373 scissor
->WindowRectMode
, scissor
->NumWindowRects
,
1374 (const GLint
*)scissor
->WindowRects
);
1378 case GL_STENCIL_BUFFER_BIT
:
1380 const struct gl_stencil_attrib
*stencil
;
1381 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1382 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1383 _mesa_ClearStencil(stencil
->Clear
);
1384 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1385 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1386 stencil
->TestTwoSide
);
1387 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1388 ? GL_BACK
: GL_FRONT
);
1391 _mesa_StencilFuncSeparate(GL_FRONT
,
1392 stencil
->Function
[0],
1394 stencil
->ValueMask
[0]);
1395 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1396 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1397 stencil
->ZFailFunc
[0],
1398 stencil
->ZPassFunc
[0]);
1400 _mesa_StencilFuncSeparate(GL_BACK
,
1401 stencil
->Function
[1],
1403 stencil
->ValueMask
[1]);
1404 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1405 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1406 stencil
->ZFailFunc
[1],
1407 stencil
->ZPassFunc
[1]);
1410 case GL_TRANSFORM_BIT
:
1413 const struct gl_transform_attrib
*xform
;
1414 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1415 _mesa_MatrixMode(xform
->MatrixMode
);
1416 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1417 _math_matrix_analyse(ctx
->ProjectionMatrixStack
.Top
);
1419 /* restore clip planes */
1420 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1421 const GLuint mask
= 1 << i
;
1422 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1423 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1424 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1425 !!(xform
->ClipPlanesEnabled
& mask
));
1426 if (ctx
->Driver
.ClipPlane
)
1427 ctx
->Driver
.ClipPlane(ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1430 /* normalize/rescale */
1431 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1432 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1433 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1434 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1435 ctx
->Transform
.RescaleNormals
);
1436 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1437 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1438 ctx
->Transform
.DepthClamp
);
1439 if (ctx
->Extensions
.ARB_clip_control
)
1440 _mesa_ClipControl(xform
->ClipOrigin
, xform
->ClipDepthMode
);
1443 case GL_TEXTURE_BIT
:
1445 struct texture_state
*texstate
1446 = (struct texture_state
*) attr
->data
;
1447 pop_texture_group(ctx
, texstate
);
1448 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
| _NEW_TEXTURE_STATE
;
1451 case GL_VIEWPORT_BIT
:
1454 const struct viewport_state
*viewstate
;
1455 viewstate
= (const struct viewport_state
*) attr
->data
;
1457 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
1458 const struct gl_viewport_attrib
*vp
= &viewstate
->ViewportArray
[i
];
1459 _mesa_set_viewport(ctx
, i
, vp
->X
, vp
->Y
, vp
->Width
,
1461 _mesa_set_depth_range(ctx
, i
, vp
->Near
, vp
->Far
);
1464 if (ctx
->Extensions
.NV_conservative_raster
) {
1465 GLuint biasx
= viewstate
->SubpixelPrecisionBias
[0];
1466 GLuint biasy
= viewstate
->SubpixelPrecisionBias
[1];
1467 _mesa_SubpixelPrecisionBiasNV(biasx
, biasy
);
1471 case GL_MULTISAMPLE_BIT_ARB
:
1473 const struct gl_multisample_attrib
*ms
;
1474 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1476 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1480 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1482 GL_SAMPLE_COVERAGE
);
1484 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1485 ms
->SampleAlphaToCoverage
,
1486 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1488 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1489 ms
->SampleAlphaToOne
,
1490 GL_SAMPLE_ALPHA_TO_ONE
);
1492 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1493 ms
->SampleCoverageInvert
);
1498 unreachable("Bad attrib flag in PopAttrib");
1510 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1514 copy_pixelstore(struct gl_context
*ctx
,
1515 struct gl_pixelstore_attrib
*dst
,
1516 const struct gl_pixelstore_attrib
*src
)
1518 dst
->Alignment
= src
->Alignment
;
1519 dst
->RowLength
= src
->RowLength
;
1520 dst
->SkipPixels
= src
->SkipPixels
;
1521 dst
->SkipRows
= src
->SkipRows
;
1522 dst
->ImageHeight
= src
->ImageHeight
;
1523 dst
->SkipImages
= src
->SkipImages
;
1524 dst
->SwapBytes
= src
->SwapBytes
;
1525 dst
->LsbFirst
= src
->LsbFirst
;
1526 dst
->Invert
= src
->Invert
;
1527 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1531 #define GL_CLIENT_PACK_BIT (1<<20)
1532 #define GL_CLIENT_UNPACK_BIT (1<<21)
1535 * Copy gl_vertex_array_object from src to dest.
1536 * 'dest' must be in an initialized state.
1539 copy_array_object(struct gl_context
*ctx
,
1540 struct gl_vertex_array_object
*dest
,
1541 struct gl_vertex_array_object
*src
)
1548 for (i
= 0; i
< ARRAY_SIZE(src
->VertexAttrib
); i
++) {
1549 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1550 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->BufferBinding
[i
], &src
->BufferBinding
[i
]);
1553 /* _Enabled must be the same than on push */
1554 dest
->_Enabled
= src
->_Enabled
;
1555 dest
->_EffEnabledVBO
= src
->_EffEnabledVBO
;
1556 /* The bitmask of bound VBOs needs to match the VertexBinding array */
1557 dest
->VertexAttribBufferMask
= src
->VertexAttribBufferMask
;
1558 dest
->_AttributeMapMode
= src
->_AttributeMapMode
;
1559 dest
->NewArrays
= src
->NewArrays
;
1563 * Copy gl_array_attrib from src to dest.
1564 * 'dest' must be in an initialized state.
1567 copy_array_attrib(struct gl_context
*ctx
,
1568 struct gl_array_attrib
*dest
,
1569 struct gl_array_attrib
*src
,
1573 /* skip DefaultArrayObj, Objects */
1574 dest
->ActiveTexture
= src
->ActiveTexture
;
1575 dest
->LockFirst
= src
->LockFirst
;
1576 dest
->LockCount
= src
->LockCount
;
1577 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1578 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1579 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1580 dest
->RestartIndex
= src
->RestartIndex
;
1582 /* skip RebindArrays */
1585 copy_array_object(ctx
, dest
->VAO
, src
->VAO
);
1587 /* skip ArrayBufferObj */
1588 /* skip IndexBufferObj */
1590 /* Invalidate array state. It will be updated during the next draw. */
1591 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1595 * Save the content of src to dest.
1598 save_array_attrib(struct gl_context
*ctx
,
1599 struct gl_array_attrib
*dest
,
1600 struct gl_array_attrib
*src
)
1602 /* Set the Name, needed for restore, but do never overwrite.
1603 * Needs to match value in the object hash. */
1604 dest
->VAO
->Name
= src
->VAO
->Name
;
1605 /* And copy all of the rest. */
1606 copy_array_attrib(ctx
, dest
, src
, false);
1608 /* Just reference them here */
1609 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1610 src
->ArrayBufferObj
);
1611 _mesa_reference_buffer_object(ctx
, &dest
->VAO
->IndexBufferObj
,
1612 src
->VAO
->IndexBufferObj
);
1616 * Restore the content of src to dest.
1619 restore_array_attrib(struct gl_context
*ctx
,
1620 struct gl_array_attrib
*dest
,
1621 struct gl_array_attrib
*src
)
1623 bool is_vao_name_zero
= src
->VAO
->Name
== 0;
1625 /* The ARB_vertex_array_object spec says:
1627 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1628 * if array is not a name returned from a previous call to
1629 * GenVertexArrays, or if such a name has since been deleted with
1630 * DeleteVertexArrays."
1632 * Therefore popping a deleted VAO cannot magically recreate it.
1634 if (!is_vao_name_zero
&& !_mesa_IsVertexArray(src
->VAO
->Name
))
1637 _mesa_BindVertexArray(src
->VAO
->Name
);
1639 /* Restore or recreate the buffer objects by the names ... */
1640 if (is_vao_name_zero
|| src
->ArrayBufferObj
->Name
== 0 ||
1641 _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1642 /* ... and restore its content */
1643 copy_array_attrib(ctx
, dest
, src
, false);
1645 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1646 src
->ArrayBufferObj
->Name
);
1648 copy_array_attrib(ctx
, dest
, src
, true);
1651 if (is_vao_name_zero
|| src
->VAO
->IndexBufferObj
->Name
== 0 ||
1652 _mesa_IsBuffer(src
->VAO
->IndexBufferObj
->Name
))
1653 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1654 src
->VAO
->IndexBufferObj
->Name
);
1658 * init/alloc the fields of 'attrib'.
1659 * Needs to the init part matching free_array_attrib_data below.
1662 init_array_attrib_data(struct gl_context
*ctx
,
1663 struct gl_array_attrib
*attrib
)
1665 /* Get a non driver gl_vertex_array_object. */
1666 attrib
->VAO
= CALLOC_STRUCT(gl_vertex_array_object
);
1668 if (attrib
->VAO
== NULL
) {
1669 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1673 _mesa_initialize_vao(ctx
, attrib
->VAO
, 0);
1678 * Free/unreference the fields of 'attrib' but don't delete it (that's
1679 * done later in the calling code).
1680 * Needs to the cleanup part matching init_array_attrib_data above.
1683 free_array_attrib_data(struct gl_context
*ctx
,
1684 struct gl_array_attrib
*attrib
)
1686 /* We use a non driver array object, so don't just unref since we would
1687 * end up using the drivers DeleteArrayObject function for deletion. */
1688 _mesa_delete_vao(ctx
, attrib
->VAO
);
1690 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1695 _mesa_PushClientAttrib(GLbitfield mask
)
1697 struct gl_attrib_node
*head
;
1699 GET_CURRENT_CONTEXT(ctx
);
1701 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1702 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib");
1706 /* Build linked list of attribute nodes which save all attribute
1707 * groups specified by the mask.
1711 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1712 struct gl_pixelstore_attrib
*attr
;
1713 /* packing attribs */
1714 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1716 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1719 if (save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
)) {
1720 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1723 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1728 /* unpacking attribs */
1729 attr
= CALLOC_STRUCT(gl_pixelstore_attrib
);
1731 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1735 if (save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
)) {
1736 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1739 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1745 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1746 struct gl_array_attrib
*attr
;
1747 attr
= CALLOC_STRUCT(gl_array_attrib
);
1749 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1753 if (!init_array_attrib_data(ctx
, attr
)) {
1758 if (save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
)) {
1759 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1762 free_array_attrib_data(ctx
, attr
);
1763 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushClientAttrib");
1765 /* goto to keep safe from possible later changes */
1771 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1772 ctx
->ClientAttribStackDepth
++;
1778 _mesa_PopClientAttrib(void)
1780 struct gl_attrib_node
*node
, *next
;
1782 GET_CURRENT_CONTEXT(ctx
);
1783 FLUSH_VERTICES(ctx
, 0);
1785 if (ctx
->ClientAttribStackDepth
== 0) {
1786 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib");
1790 ctx
->ClientAttribStackDepth
--;
1791 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1794 switch (node
->kind
) {
1795 case GL_CLIENT_PACK_BIT
:
1797 struct gl_pixelstore_attrib
*store
=
1798 (struct gl_pixelstore_attrib
*) node
->data
;
1799 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1800 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1803 case GL_CLIENT_UNPACK_BIT
:
1805 struct gl_pixelstore_attrib
*store
=
1806 (struct gl_pixelstore_attrib
*) node
->data
;
1807 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1808 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1811 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1812 struct gl_array_attrib
* attr
=
1813 (struct gl_array_attrib
*) node
->data
;
1814 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1815 free_array_attrib_data(ctx
, attr
);
1816 ctx
->NewState
|= _NEW_ARRAY
;
1820 unreachable("Bad attrib flag in PopClientAttrib");
1832 * Free any attribute state data that might be attached to the context.
1835 _mesa_free_attrib_data(struct gl_context
*ctx
)
1837 while (ctx
->AttribStackDepth
> 0) {
1838 struct gl_attrib_node
*attr
, *next
;
1840 ctx
->AttribStackDepth
--;
1841 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1844 if (attr
->kind
== GL_TEXTURE_BIT
) {
1845 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1847 /* clear references to the saved texture objects */
1848 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1849 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1850 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1853 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1856 /* any other chunks of state that requires special handling? */
1869 _mesa_init_attrib(struct gl_context
*ctx
)
1871 /* Renderer and client attribute stacks */
1872 ctx
->AttribStackDepth
= 0;
1873 ctx
->ClientAttribStackDepth
= 0;