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"
46 #include "multisample.h"
60 #include "main/dispatch.h"
66 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
68 struct gl_enable_attrib
73 GLbitfield ClipPlanes
;
74 GLboolean ColorMaterial
;
80 GLboolean Light
[MAX_LIGHTS
];
83 GLboolean LineStipple
;
84 GLboolean IndexLogicOp
;
85 GLboolean ColorLogicOp
;
90 GLboolean Map1TextureCoord1
;
91 GLboolean Map1TextureCoord2
;
92 GLboolean Map1TextureCoord3
;
93 GLboolean Map1TextureCoord4
;
94 GLboolean Map1Vertex3
;
95 GLboolean Map1Vertex4
;
99 GLboolean Map2TextureCoord1
;
100 GLboolean Map2TextureCoord2
;
101 GLboolean Map2TextureCoord3
;
102 GLboolean Map2TextureCoord4
;
103 GLboolean Map2Vertex3
;
104 GLboolean Map2Vertex4
;
107 GLboolean PixelTexture
;
108 GLboolean PointSmooth
;
109 GLboolean PolygonOffsetPoint
;
110 GLboolean PolygonOffsetLine
;
111 GLboolean PolygonOffsetFill
;
112 GLboolean PolygonSmooth
;
113 GLboolean PolygonStipple
;
114 GLboolean RescaleNormals
;
117 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
118 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
121 GLboolean SampleCoverage
; /* GL_ARB_multisample */
122 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
124 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
125 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
127 /* GL_ARB_vertex_program */
128 GLboolean VertexProgram
;
129 GLboolean VertexProgramPointSize
;
130 GLboolean VertexProgramTwoSide
;
132 /* GL_ARB_fragment_program */
133 GLboolean FragmentProgram
;
135 /* GL_ARB_point_sprite / GL_NV_point_sprite */
136 GLboolean PointSprite
;
137 GLboolean FragmentShaderATI
;
139 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
140 GLboolean sRGBEnabled
;
145 * Node for the attribute stack.
147 struct gl_attrib_node
151 struct gl_attrib_node
*next
;
157 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
161 struct gl_texture_attrib Texture
; /**< The usual context state */
163 /** to save per texture object state (wrap modes, filters, etc): */
164 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
167 * To save references to texture objects (so they don't get accidentally
168 * deleted while saved in the attribute stack).
170 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
172 /* We need to keep a reference to the shared state. That's where the
173 * default texture objects are kept. We don't want that state to be
174 * freed while the attribute stack contains pointers to any default
177 struct gl_shared_state
*SharedRef
;
182 * Allocate new attribute node of given type/kind. Attach payload data.
183 * Insert it into the linked list named by 'head'.
186 save_attrib_data(struct gl_attrib_node
**head
,
187 GLbitfield kind
, void *payload
)
189 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
204 _mesa_PushAttrib(GLbitfield mask
)
206 struct gl_attrib_node
*head
;
208 GET_CURRENT_CONTEXT(ctx
);
210 if (MESA_VERBOSE
& VERBOSE_API
)
211 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
213 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
214 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
218 /* Build linked list of attribute nodes which save all attribute */
219 /* groups specified by the mask. */
222 if (mask
& GL_ACCUM_BUFFER_BIT
) {
223 struct gl_accum_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_accum_attrib
);
225 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
226 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
229 if (mask
& GL_COLOR_BUFFER_BIT
) {
231 struct gl_colorbuffer_attrib
*attr
;
232 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
233 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
234 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
235 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
236 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
237 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
240 if (mask
& GL_CURRENT_BIT
) {
241 struct gl_current_attrib
*attr
;
242 FLUSH_CURRENT( ctx
, 0 );
243 attr
= MALLOC_STRUCT( gl_current_attrib
);
244 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
245 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
248 if (mask
& GL_DEPTH_BUFFER_BIT
) {
249 struct gl_depthbuffer_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
251 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
252 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
255 if (mask
& GL_ENABLE_BIT
) {
256 struct gl_enable_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_enable_attrib
);
259 /* Copy enable flags from all other attributes into the enable struct. */
260 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
261 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
262 attr
->Blend
= ctx
->Color
.BlendEnabled
;
263 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
264 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
265 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
266 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
267 attr
->DepthTest
= ctx
->Depth
.Test
;
268 attr
->Dither
= ctx
->Color
.DitherFlag
;
269 attr
->Fog
= ctx
->Fog
.Enabled
;
270 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
271 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
273 attr
->Lighting
= ctx
->Light
.Enabled
;
274 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
275 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
276 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
277 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
278 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
279 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
280 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
281 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
282 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
283 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
284 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
285 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
286 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
287 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
288 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
289 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
290 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
291 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
292 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
293 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
294 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
295 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
296 attr
->Normalize
= ctx
->Transform
.Normalize
;
297 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
298 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
299 attr
->PointSprite
= ctx
->Point
.PointSprite
;
300 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
301 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
302 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
303 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
304 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
305 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
306 attr
->Scissor
= ctx
->Scissor
.Enabled
;
307 attr
->Stencil
= ctx
->Stencil
.Enabled
;
308 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
309 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
310 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
311 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
312 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
313 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
314 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
315 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
317 /* GL_ARB_vertex_program */
318 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
319 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
320 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
322 /* GL_ARB_fragment_program */
323 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
325 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
327 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
328 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
331 if (mask
& GL_EVAL_BIT
) {
332 struct gl_eval_attrib
*attr
;
333 attr
= MALLOC_STRUCT( gl_eval_attrib
);
334 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
335 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
338 if (mask
& GL_FOG_BIT
) {
339 struct gl_fog_attrib
*attr
;
340 attr
= MALLOC_STRUCT( gl_fog_attrib
);
341 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
342 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
345 if (mask
& GL_HINT_BIT
) {
346 struct gl_hint_attrib
*attr
;
347 attr
= MALLOC_STRUCT( gl_hint_attrib
);
348 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
349 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
352 if (mask
& GL_LIGHTING_BIT
) {
353 struct gl_light_attrib
*attr
;
354 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
355 attr
= MALLOC_STRUCT( gl_light_attrib
);
356 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
357 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
360 if (mask
& GL_LINE_BIT
) {
361 struct gl_line_attrib
*attr
;
362 attr
= MALLOC_STRUCT( gl_line_attrib
);
363 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
364 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
367 if (mask
& GL_LIST_BIT
) {
368 struct gl_list_attrib
*attr
;
369 attr
= MALLOC_STRUCT( gl_list_attrib
);
370 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
371 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
374 if (mask
& GL_PIXEL_MODE_BIT
) {
375 struct gl_pixel_attrib
*attr
;
376 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
377 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
378 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
379 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
380 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
383 if (mask
& GL_POINT_BIT
) {
384 struct gl_point_attrib
*attr
;
385 attr
= MALLOC_STRUCT( gl_point_attrib
);
386 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
387 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
390 if (mask
& GL_POLYGON_BIT
) {
391 struct gl_polygon_attrib
*attr
;
392 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
393 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
394 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
397 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
399 stipple
= malloc( 32*sizeof(GLuint
) );
400 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
401 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
404 if (mask
& GL_SCISSOR_BIT
) {
405 struct gl_scissor_attrib
*attr
;
406 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
407 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
408 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
411 if (mask
& GL_STENCIL_BUFFER_BIT
) {
412 struct gl_stencil_attrib
*attr
;
413 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
414 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
415 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
418 if (mask
& GL_TEXTURE_BIT
) {
419 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
427 _mesa_lock_context_textures(ctx
);
429 /* copy/save the bulk of texture state here */
430 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
432 /* Save references to the currently bound texture objects so they don't
433 * accidentally get deleted while referenced in the attribute stack.
435 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
436 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
437 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
438 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
442 /* copy state/contents of the currently bound texture objects */
443 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
444 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
445 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
446 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
450 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
452 _mesa_unlock_context_textures(ctx
);
454 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
457 if (mask
& GL_TRANSFORM_BIT
) {
458 struct gl_transform_attrib
*attr
;
459 attr
= MALLOC_STRUCT( gl_transform_attrib
);
460 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
461 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
464 if (mask
& GL_VIEWPORT_BIT
) {
465 struct gl_viewport_attrib
*attr
;
466 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
467 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
468 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
471 /* GL_ARB_multisample */
472 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
473 struct gl_multisample_attrib
*attr
;
474 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
475 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
476 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
480 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
481 ctx
->AttribStackDepth
++;
487 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
489 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
492 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
493 if ((VALUE) != (NEWVALUE)) { \
494 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
497 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
498 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
499 if (ctx
->Extensions
.EXT_draw_buffers2
) {
501 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
502 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
506 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
510 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
511 const GLuint mask
= 1 << i
;
512 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
513 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
514 !!(enable
->ClipPlanes
& mask
));
517 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
519 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
520 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
522 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
523 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
524 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
525 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
526 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
527 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
529 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
531 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
534 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
538 GL_MAP1_TEXTURE_COORD_1
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
540 GL_MAP1_TEXTURE_COORD_2
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
542 GL_MAP1_TEXTURE_COORD_3
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
544 GL_MAP1_TEXTURE_COORD_4
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
547 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
550 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
552 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
554 GL_MAP2_TEXTURE_COORD_1
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
556 GL_MAP2_TEXTURE_COORD_2
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
558 GL_MAP2_TEXTURE_COORD_3
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
560 GL_MAP2_TEXTURE_COORD_4
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
563 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
566 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
567 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
568 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
569 GL_RESCALE_NORMAL_EXT
);
570 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
571 enable
->RasterPositionUnclipped
,
572 GL_RASTER_POSITION_UNCLIPPED_IBM
);
573 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
575 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
576 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
579 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
580 GL_POLYGON_OFFSET_POINT
);
581 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
582 GL_POLYGON_OFFSET_LINE
);
583 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
584 GL_POLYGON_OFFSET_FILL
);
585 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
587 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
589 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
590 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
591 if (ctx
->Extensions
.EXT_stencil_two_side
) {
592 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
594 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
596 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
597 enable
->SampleAlphaToCoverage
,
598 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
599 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
600 enable
->SampleAlphaToOne
,
601 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
602 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
603 enable
->SampleCoverage
,
604 GL_SAMPLE_COVERAGE_ARB
);
605 /* GL_ARB_vertex_program */
606 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
607 enable
->VertexProgram
,
608 GL_VERTEX_PROGRAM_ARB
);
609 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
610 enable
->VertexProgramPointSize
,
611 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
612 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
613 enable
->VertexProgramTwoSide
,
614 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
616 /* GL_ARB_fragment_program */
617 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
618 enable
->FragmentProgram
,
619 GL_FRAGMENT_PROGRAM_ARB
);
621 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
622 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
623 GL_FRAMEBUFFER_SRGB
);
625 /* texture unit enables */
626 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
627 const GLbitfield enabled
= enable
->Texture
[i
];
628 const GLbitfield genEnabled
= enable
->TexGen
[i
];
630 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
631 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
633 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
634 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
635 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
636 if (ctx
->Extensions
.NV_texture_rectangle
) {
637 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
638 !!(enabled
& TEXTURE_RECT_BIT
));
640 if (ctx
->Extensions
.ARB_texture_cube_map
) {
641 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
642 !!(enabled
& TEXTURE_CUBE_BIT
));
644 if (ctx
->Extensions
.MESA_texture_array
) {
645 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
646 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
647 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
648 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
652 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
653 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
654 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
655 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
656 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
657 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
661 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
666 * Pop/restore texture attribute/group state.
669 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
673 _mesa_lock_context_textures(ctx
);
675 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
676 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
679 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
680 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
681 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
682 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
683 if (ctx
->Extensions
.ARB_texture_cube_map
) {
684 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
685 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
687 if (ctx
->Extensions
.NV_texture_rectangle
) {
688 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
689 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
691 if (ctx
->Extensions
.MESA_texture_array
) {
692 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
693 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
694 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
695 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
697 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
698 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
699 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
700 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
701 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
702 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
703 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
704 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
705 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
706 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
707 /* Eye plane done differently to avoid re-transformation */
709 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
710 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
711 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
712 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
713 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
714 if (ctx
->Driver
.TexGen
) {
715 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
716 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
717 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
718 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
721 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
722 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
723 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
724 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
725 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
727 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
728 unit
->Combine
.ModeRGB
);
729 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
730 unit
->Combine
.ModeA
);
732 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
734 for (i
= 0; i
< n
; i
++) {
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
736 unit
->Combine
.SourceRGB
[i
]);
737 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
738 unit
->Combine
.SourceA
[i
]);
739 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
740 unit
->Combine
.OperandRGB
[i
]);
741 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
742 unit
->Combine
.OperandA
[i
]);
745 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
746 1 << unit
->Combine
.ScaleShiftRGB
);
747 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
748 1 << unit
->Combine
.ScaleShiftA
);
750 /* Restore texture object state for each target */
751 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
752 const struct gl_texture_object
*obj
= NULL
;
753 const struct gl_sampler_object
*samp
;
756 obj
= &texstate
->SavedObj
[u
][tgt
];
758 /* don't restore state for unsupported targets to prevent
761 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
762 !ctx
->Extensions
.ARB_texture_cube_map
) {
765 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
766 !ctx
->Extensions
.NV_texture_rectangle
) {
769 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
770 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
771 !ctx
->Extensions
.MESA_texture_array
) {
774 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
775 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
777 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
779 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
781 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
782 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
785 target
= obj
->Target
;
787 _mesa_BindTexture(target
, obj
->Name
);
789 samp
= &obj
->Sampler
;
791 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
792 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
793 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
794 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
795 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
796 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
797 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
798 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
799 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
800 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
801 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
802 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
803 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
804 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
805 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
806 samp
->MaxAnisotropy
);
808 if (ctx
->Extensions
.ARB_shadow
) {
809 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
811 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
814 if (ctx
->Extensions
.ARB_depth_texture
)
815 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
818 /* remove saved references to the texture objects */
819 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
820 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
824 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
826 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
828 _mesa_unlock_context_textures(ctx
);
833 * This function is kind of long just because we have to call a lot
834 * of device driver functions to update device driver state.
836 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
837 * in order to restore GL state. This isn't terribly efficient but it
838 * ensures that dirty flags and any derived state gets updated correctly.
839 * We could at least check if the value to restore equals the current value
840 * and then skip the Mesa call.
843 _mesa_PopAttrib(void)
845 struct gl_attrib_node
*attr
, *next
;
846 GET_CURRENT_CONTEXT(ctx
);
847 FLUSH_VERTICES(ctx
, 0);
849 if (ctx
->AttribStackDepth
== 0) {
850 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
854 ctx
->AttribStackDepth
--;
855 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
859 if (MESA_VERBOSE
& VERBOSE_API
) {
860 _mesa_debug(ctx
, "glPopAttrib %s\n",
861 _mesa_lookup_enum_by_nr(attr
->kind
));
864 switch (attr
->kind
) {
865 case GL_ACCUM_BUFFER_BIT
:
867 const struct gl_accum_attrib
*accum
;
868 accum
= (const struct gl_accum_attrib
*) attr
->data
;
869 _mesa_ClearAccum(accum
->ClearColor
[0],
870 accum
->ClearColor
[1],
871 accum
->ClearColor
[2],
872 accum
->ClearColor
[3]);
875 case GL_COLOR_BUFFER_BIT
:
877 const struct gl_colorbuffer_attrib
*color
;
879 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
880 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
881 _mesa_ClearColor(color
->ClearColor
.f
[0],
882 color
->ClearColor
.f
[1],
883 color
->ClearColor
.f
[2],
884 color
->ClearColor
.f
[3]);
885 _mesa_IndexMask(color
->IndexMask
);
886 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
887 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
888 (GLboolean
) (color
->ColorMask
[0][1] != 0),
889 (GLboolean
) (color
->ColorMask
[0][2] != 0),
890 (GLboolean
) (color
->ColorMask
[0][3] != 0));
894 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
896 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
897 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
898 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
899 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
903 /* Need to determine if more than one color output is
904 * specified. If so, call glDrawBuffersARB, else call
905 * glDrawBuffer(). This is a subtle, but essential point
906 * since GL_FRONT (for example) is illegal for the former
907 * function, but legal for the later.
909 GLboolean multipleBuffers
= GL_FALSE
;
912 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
913 if (color
->DrawBuffer
[i
] != GL_NONE
) {
914 multipleBuffers
= GL_TRUE
;
918 /* Call the API_level functions, not _mesa_drawbuffers()
919 * since we need to do error checking on the pop'd
921 * Ex: if GL_FRONT were pushed, but we're popping with a
922 * user FBO bound, GL_FRONT will be illegal and we'll need
923 * to record that error. Per OpenGL ARB decision.
926 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
,
929 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
931 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
932 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
933 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
934 if (ctx
->Extensions
.EXT_draw_buffers2
) {
936 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
937 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
938 (color
->BlendEnabled
>> i
) & 1);
942 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
945 if (ctx
->Color
._BlendFuncPerBuffer
||
946 ctx
->Color
._BlendEquationPerBuffer
) {
947 /* set blend per buffer */
949 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
950 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
951 color
->Blend
[buf
].DstRGB
,
952 color
->Blend
[buf
].SrcA
,
953 color
->Blend
[buf
].DstA
);
954 _mesa_BlendEquationSeparateiARB(buf
,
955 color
->Blend
[buf
].EquationRGB
,
956 color
->Blend
[buf
].EquationA
);
960 /* set same blend modes for all buffers */
961 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
962 color
->Blend
[0].DstRGB
,
963 color
->Blend
[0].SrcA
,
964 color
->Blend
[0].DstA
);
965 /* This special case is because glBlendEquationSeparateEXT
966 * cannot take GL_LOGIC_OP as a parameter.
968 if (color
->Blend
[0].EquationRGB
==
969 color
->Blend
[0].EquationA
) {
970 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
973 _mesa_BlendEquationSeparate(
974 color
->Blend
[0].EquationRGB
,
975 color
->Blend
[0].EquationA
);
978 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
979 color
->BlendColorUnclamped
[1],
980 color
->BlendColorUnclamped
[2],
981 color
->BlendColorUnclamped
[3]);
982 _mesa_LogicOp(color
->LogicOp
);
983 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
984 color
->ColorLogicOpEnabled
);
985 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
986 color
->IndexLogicOpEnabled
);
987 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
988 if (ctx
->Extensions
.ARB_color_buffer_float
)
989 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
990 color
->ClampFragmentColor
);
991 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
993 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
994 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
995 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
999 FLUSH_CURRENT( ctx
, 0 );
1000 memcpy( &ctx
->Current
, attr
->data
,
1001 sizeof(struct gl_current_attrib
) );
1003 case GL_DEPTH_BUFFER_BIT
:
1005 const struct gl_depthbuffer_attrib
*depth
;
1006 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1007 _mesa_DepthFunc(depth
->Func
);
1008 _mesa_ClearDepth(depth
->Clear
);
1009 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1010 _mesa_DepthMask(depth
->Mask
);
1015 const struct gl_enable_attrib
*enable
;
1016 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1017 pop_enable_group(ctx
, enable
);
1018 ctx
->NewState
|= _NEW_ALL
;
1022 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1023 ctx
->NewState
|= _NEW_EVAL
;
1027 const struct gl_fog_attrib
*fog
;
1028 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1029 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1030 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1031 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1032 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1033 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1034 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1035 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1040 const struct gl_hint_attrib
*hint
;
1041 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1042 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1043 hint
->PerspectiveCorrection
);
1044 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1045 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1046 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1047 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1048 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1049 hint
->ClipVolumeClipping
);
1050 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1051 hint
->TextureCompression
);
1054 case GL_LIGHTING_BIT
:
1057 const struct gl_light_attrib
*light
;
1058 light
= (const struct gl_light_attrib
*) attr
->data
;
1059 /* lighting enable */
1060 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1061 /* per-light state */
1062 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1063 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1065 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1066 const struct gl_light
*l
= &light
->Light
[i
];
1067 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1068 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1069 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1070 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1071 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1072 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1074 GLfloat p
[4] = { 0 };
1075 p
[0] = l
->SpotExponent
;
1076 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1079 GLfloat p
[4] = { 0 };
1080 p
[0] = l
->SpotCutoff
;
1081 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1084 GLfloat p
[4] = { 0 };
1085 p
[0] = l
->ConstantAttenuation
;
1086 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1089 GLfloat p
[4] = { 0 };
1090 p
[0] = l
->LinearAttenuation
;
1091 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1094 GLfloat p
[4] = { 0 };
1095 p
[0] = l
->QuadraticAttenuation
;
1096 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1100 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1101 light
->Model
.Ambient
);
1102 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1103 (GLfloat
) light
->Model
.LocalViewer
);
1104 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1105 (GLfloat
) light
->Model
.TwoSide
);
1106 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1107 (GLfloat
) light
->Model
.ColorControl
);
1109 _mesa_ShadeModel(light
->ShadeModel
);
1110 /* color material */
1111 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1112 light
->ColorMaterialMode
);
1113 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1114 light
->ColorMaterialEnabled
);
1116 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1117 sizeof(struct gl_material
));
1118 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1119 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1120 light
->ClampVertexColor
);
1126 const struct gl_line_attrib
*line
;
1127 line
= (const struct gl_line_attrib
*) attr
->data
;
1128 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1129 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1130 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1131 _mesa_LineWidth(line
->Width
);
1135 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1137 case GL_PIXEL_MODE_BIT
:
1138 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1139 /* XXX what other pixel state needs to be set by function calls? */
1140 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1141 ctx
->NewState
|= _NEW_PIXEL
;
1145 const struct gl_point_attrib
*point
;
1146 point
= (const struct gl_point_attrib
*) attr
->data
;
1147 _mesa_PointSize(point
->Size
);
1148 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1149 if (ctx
->Extensions
.EXT_point_parameters
) {
1150 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1152 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1154 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1156 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1159 if (ctx
->Extensions
.NV_point_sprite
1160 || ctx
->Extensions
.ARB_point_sprite
) {
1162 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1163 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1164 (GLint
) point
->CoordReplace
[u
]);
1166 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1167 if (ctx
->Extensions
.NV_point_sprite
)
1168 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1169 ctx
->Point
.SpriteRMode
);
1171 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1172 || ctx
->API
== API_OPENGL_CORE
)
1173 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1174 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1178 case GL_POLYGON_BIT
:
1180 const struct gl_polygon_attrib
*polygon
;
1181 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1182 _mesa_CullFace(polygon
->CullFaceMode
);
1183 _mesa_FrontFace(polygon
->FrontFace
);
1184 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1185 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1186 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1187 polygon
->OffsetUnits
);
1188 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1189 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1190 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1191 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1192 polygon
->OffsetPoint
);
1193 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1194 polygon
->OffsetLine
);
1195 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1196 polygon
->OffsetFill
);
1199 case GL_POLYGON_STIPPLE_BIT
:
1200 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1201 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1202 if (ctx
->Driver
.PolygonStipple
)
1203 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1205 case GL_SCISSOR_BIT
:
1207 const struct gl_scissor_attrib
*scissor
;
1208 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1209 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1210 scissor
->Width
, scissor
->Height
);
1211 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1214 case GL_STENCIL_BUFFER_BIT
:
1216 const struct gl_stencil_attrib
*stencil
;
1217 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1218 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1219 _mesa_ClearStencil(stencil
->Clear
);
1220 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1221 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1222 stencil
->TestTwoSide
);
1223 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1224 ? GL_BACK
: GL_FRONT
);
1227 _mesa_StencilFuncSeparate(GL_FRONT
,
1228 stencil
->Function
[0],
1230 stencil
->ValueMask
[0]);
1231 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1232 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1233 stencil
->ZFailFunc
[0],
1234 stencil
->ZPassFunc
[0]);
1236 _mesa_StencilFuncSeparate(GL_BACK
,
1237 stencil
->Function
[1],
1239 stencil
->ValueMask
[1]);
1240 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1241 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1242 stencil
->ZFailFunc
[1],
1243 stencil
->ZPassFunc
[1]);
1246 case GL_TRANSFORM_BIT
:
1249 const struct gl_transform_attrib
*xform
;
1250 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1251 _mesa_MatrixMode(xform
->MatrixMode
);
1252 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1253 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1255 /* restore clip planes */
1256 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1257 const GLuint mask
= 1 << i
;
1258 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1259 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1260 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1261 !!(xform
->ClipPlanesEnabled
& mask
));
1262 if (ctx
->Driver
.ClipPlane
)
1263 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1266 /* normalize/rescale */
1267 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1268 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1269 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1270 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1271 ctx
->Transform
.RescaleNormals
);
1272 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1273 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1274 ctx
->Transform
.DepthClamp
);
1277 case GL_TEXTURE_BIT
:
1279 struct texture_state
*texstate
1280 = (struct texture_state
*) attr
->data
;
1281 pop_texture_group(ctx
, texstate
);
1282 ctx
->NewState
|= _NEW_TEXTURE
;
1285 case GL_VIEWPORT_BIT
:
1287 const struct gl_viewport_attrib
*vp
;
1288 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1289 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1290 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1293 case GL_MULTISAMPLE_BIT_ARB
:
1295 const struct gl_multisample_attrib
*ms
;
1296 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1298 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1302 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1304 GL_SAMPLE_COVERAGE
);
1306 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1307 ms
->SampleAlphaToCoverage
,
1308 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1310 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1311 ms
->SampleAlphaToOne
,
1312 GL_SAMPLE_ALPHA_TO_ONE
);
1314 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1315 ms
->SampleCoverageInvert
);
1320 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1333 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1337 copy_pixelstore(struct gl_context
*ctx
,
1338 struct gl_pixelstore_attrib
*dst
,
1339 const struct gl_pixelstore_attrib
*src
)
1341 dst
->Alignment
= src
->Alignment
;
1342 dst
->RowLength
= src
->RowLength
;
1343 dst
->SkipPixels
= src
->SkipPixels
;
1344 dst
->SkipRows
= src
->SkipRows
;
1345 dst
->ImageHeight
= src
->ImageHeight
;
1346 dst
->SkipImages
= src
->SkipImages
;
1347 dst
->SwapBytes
= src
->SwapBytes
;
1348 dst
->LsbFirst
= src
->LsbFirst
;
1349 dst
->Invert
= src
->Invert
;
1350 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1354 #define GL_CLIENT_PACK_BIT (1<<20)
1355 #define GL_CLIENT_UNPACK_BIT (1<<21)
1358 * Copy gl_array_object from src to dest.
1359 * 'dest' must be in an initialized state.
1362 copy_array_object(struct gl_context
*ctx
,
1363 struct gl_array_object
*dest
,
1364 struct gl_array_object
*src
)
1371 /* In theory must be the same anyway, but on recreate make sure it matches */
1372 dest
->ARBsemantics
= src
->ARBsemantics
;
1374 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1375 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1377 /* _Enabled must be the same than on push */
1378 dest
->_Enabled
= src
->_Enabled
;
1379 dest
->_MaxElement
= src
->_MaxElement
;
1383 * Copy gl_array_attrib from src to dest.
1384 * 'dest' must be in an initialized state.
1387 copy_array_attrib(struct gl_context
*ctx
,
1388 struct gl_array_attrib
*dest
,
1389 struct gl_array_attrib
*src
,
1393 /* skip DefaultArrayObj, Objects */
1394 dest
->ActiveTexture
= src
->ActiveTexture
;
1395 dest
->LockFirst
= src
->LockFirst
;
1396 dest
->LockCount
= src
->LockCount
;
1397 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1398 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1399 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1400 dest
->RestartIndex
= src
->RestartIndex
;
1402 /* skip RebindArrays */
1405 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1407 /* skip ArrayBufferObj */
1408 /* skip ElementArrayBufferObj */
1412 * Save the content of src to dest.
1415 save_array_attrib(struct gl_context
*ctx
,
1416 struct gl_array_attrib
*dest
,
1417 struct gl_array_attrib
*src
)
1419 /* Set the Name, needed for restore, but do never overwrite.
1420 * Needs to match value in the object hash. */
1421 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1422 /* And copy all of the rest. */
1423 copy_array_attrib(ctx
, dest
, src
, false);
1425 /* Just reference them here */
1426 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1427 src
->ArrayBufferObj
);
1428 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1429 src
->ArrayObj
->ElementArrayBufferObj
);
1433 * Restore the content of src to dest.
1436 restore_array_attrib(struct gl_context
*ctx
,
1437 struct gl_array_attrib
*dest
,
1438 struct gl_array_attrib
*src
)
1440 /* The ARB_vertex_array_object spec says:
1442 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1443 * if array is not a name returned from a previous call to
1444 * GenVertexArrays, or if such a name has since been deleted with
1445 * DeleteVertexArrays."
1447 * Therefore popping a deleted VAO cannot magically recreate it.
1449 * The semantics of objects created using APPLE_vertex_array_objects behave
1450 * differently. These objects expect to be recreated by pop. Alas.
1452 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1453 && src
->ArrayObj
->ARBsemantics
);
1455 if (arb_vao
&& !_mesa_IsVertexArray(src
->ArrayObj
->Name
))
1458 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1460 /* Restore or recreate the buffer objects by the names ... */
1462 || src
->ArrayBufferObj
->Name
== 0
1463 || _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1464 /* ... and restore its content */
1465 copy_array_attrib(ctx
, dest
, src
, false);
1467 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1468 src
->ArrayBufferObj
->Name
);
1470 copy_array_attrib(ctx
, dest
, src
, true);
1474 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1475 || _mesa_IsBuffer(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1476 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1477 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1481 * init/alloc the fields of 'attrib'.
1482 * Needs to the init part matching free_array_attrib_data below.
1485 init_array_attrib_data(struct gl_context
*ctx
,
1486 struct gl_array_attrib
*attrib
)
1488 /* Get a non driver gl_array_object. */
1489 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1490 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1494 * Free/unreference the fields of 'attrib' but don't delete it (that's
1495 * done later in the calling code).
1496 * Needs to the cleanup part matching init_array_attrib_data above.
1499 free_array_attrib_data(struct gl_context
*ctx
,
1500 struct gl_array_attrib
*attrib
)
1502 /* We use a non driver array object, so don't just unref since we would
1503 * end up using the drivers DeleteArrayObject function for deletion. */
1504 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1505 attrib
->ArrayObj
= 0;
1506 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1511 _mesa_PushClientAttrib(GLbitfield mask
)
1513 struct gl_attrib_node
*head
;
1515 GET_CURRENT_CONTEXT(ctx
);
1517 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1518 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1522 /* Build linked list of attribute nodes which save all attribute
1523 * groups specified by the mask.
1527 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1528 struct gl_pixelstore_attrib
*attr
;
1529 /* packing attribs */
1530 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1531 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1532 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1533 /* unpacking attribs */
1534 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1535 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1536 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1539 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1540 struct gl_array_attrib
*attr
;
1541 attr
= CALLOC_STRUCT( gl_array_attrib
);
1542 init_array_attrib_data(ctx
, attr
);
1543 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1544 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1547 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1548 ctx
->ClientAttribStackDepth
++;
1555 _mesa_PopClientAttrib(void)
1557 struct gl_attrib_node
*node
, *next
;
1559 GET_CURRENT_CONTEXT(ctx
);
1560 FLUSH_VERTICES(ctx
, 0);
1562 if (ctx
->ClientAttribStackDepth
== 0) {
1563 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1567 ctx
->ClientAttribStackDepth
--;
1568 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1571 switch (node
->kind
) {
1572 case GL_CLIENT_PACK_BIT
:
1574 struct gl_pixelstore_attrib
*store
=
1575 (struct gl_pixelstore_attrib
*) node
->data
;
1576 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1577 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1580 case GL_CLIENT_UNPACK_BIT
:
1582 struct gl_pixelstore_attrib
*store
=
1583 (struct gl_pixelstore_attrib
*) node
->data
;
1584 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1585 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1588 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1589 struct gl_array_attrib
* attr
=
1590 (struct gl_array_attrib
*) node
->data
;
1591 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1592 free_array_attrib_data(ctx
, attr
);
1593 ctx
->NewState
|= _NEW_ARRAY
;
1597 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1610 * Free any attribute state data that might be attached to the context.
1613 _mesa_free_attrib_data(struct gl_context
*ctx
)
1615 while (ctx
->AttribStackDepth
> 0) {
1616 struct gl_attrib_node
*attr
, *next
;
1618 ctx
->AttribStackDepth
--;
1619 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1622 if (attr
->kind
== GL_TEXTURE_BIT
) {
1623 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1625 /* clear references to the saved texture objects */
1626 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1627 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1628 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1631 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1634 /* any other chunks of state that requires special handling? */
1646 void _mesa_init_attrib( struct gl_context
*ctx
)
1648 /* Renderer and client attribute stacks */
1649 ctx
->AttribStackDepth
= 0;
1650 ctx
->ClientAttribStackDepth
= 0;