2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
46 #include "mfeatures.h"
47 #include "multisample.h"
61 #include "main/dispatch.h"
67 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
69 struct gl_enable_attrib
74 GLbitfield ClipPlanes
;
75 GLboolean ColorMaterial
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
97 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2Normal
;
101 GLboolean Map2TextureCoord1
;
102 GLboolean Map2TextureCoord2
;
103 GLboolean Map2TextureCoord3
;
104 GLboolean Map2TextureCoord4
;
105 GLboolean Map2Vertex3
;
106 GLboolean Map2Vertex4
;
107 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
110 GLboolean PixelTexture
;
111 GLboolean PointSmooth
;
112 GLboolean PolygonOffsetPoint
;
113 GLboolean PolygonOffsetLine
;
114 GLboolean PolygonOffsetFill
;
115 GLboolean PolygonSmooth
;
116 GLboolean PolygonStipple
;
117 GLboolean RescaleNormals
;
120 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
121 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
122 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
123 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
124 GLboolean SampleCoverage
; /* GL_ARB_multisample */
125 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
127 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
128 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
130 /* GL_ARB_vertex_program / GL_NV_vertex_program */
131 GLboolean VertexProgram
;
132 GLboolean VertexProgramPointSize
;
133 GLboolean VertexProgramTwoSide
;
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
;
181 #if FEATURE_attrib_stack
185 * Allocate new attribute node of given type/kind. Attach payload data.
186 * Insert it into the linked list named by 'head'.
189 save_attrib_data(struct gl_attrib_node
**head
,
190 GLbitfield kind
, void *payload
)
192 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
207 _mesa_PushAttrib(GLbitfield mask
)
209 struct gl_attrib_node
*head
;
211 GET_CURRENT_CONTEXT(ctx
);
212 ASSERT_OUTSIDE_BEGIN_END(ctx
);
214 if (MESA_VERBOSE
& VERBOSE_API
)
215 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
217 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
218 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
222 /* Build linked list of attribute nodes which save all attribute */
223 /* groups specified by the mask. */
226 if (mask
& GL_ACCUM_BUFFER_BIT
) {
227 struct gl_accum_attrib
*attr
;
228 attr
= MALLOC_STRUCT( gl_accum_attrib
);
229 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
230 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
233 if (mask
& GL_COLOR_BUFFER_BIT
) {
235 struct gl_colorbuffer_attrib
*attr
;
236 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
237 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
238 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
239 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
240 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
241 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
244 if (mask
& GL_CURRENT_BIT
) {
245 struct gl_current_attrib
*attr
;
246 FLUSH_CURRENT( ctx
, 0 );
247 attr
= MALLOC_STRUCT( gl_current_attrib
);
248 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
249 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
252 if (mask
& GL_DEPTH_BUFFER_BIT
) {
253 struct gl_depthbuffer_attrib
*attr
;
254 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
255 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
256 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
259 if (mask
& GL_ENABLE_BIT
) {
260 struct gl_enable_attrib
*attr
;
262 attr
= MALLOC_STRUCT( gl_enable_attrib
);
263 /* Copy enable flags from all other attributes into the enable struct. */
264 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
265 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
266 attr
->Blend
= ctx
->Color
.BlendEnabled
;
267 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
268 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
269 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
270 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
271 attr
->DepthTest
= ctx
->Depth
.Test
;
272 attr
->Dither
= ctx
->Color
.DitherFlag
;
273 attr
->Fog
= ctx
->Fog
.Enabled
;
274 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
275 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
277 attr
->Lighting
= ctx
->Light
.Enabled
;
278 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
279 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
280 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
281 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
282 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
283 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
284 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
285 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
286 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
287 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
288 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
289 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
290 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
291 memcpy(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
292 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
293 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
294 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
295 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
296 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
297 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
298 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
299 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
300 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
301 memcpy(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
302 attr
->Normalize
= ctx
->Transform
.Normalize
;
303 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
304 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
305 attr
->PointSprite
= ctx
->Point
.PointSprite
;
306 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
307 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
308 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
309 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
310 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
311 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
312 attr
->Scissor
= ctx
->Scissor
.Enabled
;
313 attr
->Stencil
= ctx
->Stencil
.Enabled
;
314 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
315 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
316 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
317 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
318 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
319 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
320 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
321 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
323 /* GL_NV_vertex_program */
324 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
325 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
326 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
327 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
329 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
330 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
333 if (mask
& GL_EVAL_BIT
) {
334 struct gl_eval_attrib
*attr
;
335 attr
= MALLOC_STRUCT( gl_eval_attrib
);
336 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
337 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
340 if (mask
& GL_FOG_BIT
) {
341 struct gl_fog_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_fog_attrib
);
343 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
344 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
347 if (mask
& GL_HINT_BIT
) {
348 struct gl_hint_attrib
*attr
;
349 attr
= MALLOC_STRUCT( gl_hint_attrib
);
350 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
351 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
354 if (mask
& GL_LIGHTING_BIT
) {
355 struct gl_light_attrib
*attr
;
356 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
357 attr
= MALLOC_STRUCT( gl_light_attrib
);
358 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
359 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
362 if (mask
& GL_LINE_BIT
) {
363 struct gl_line_attrib
*attr
;
364 attr
= MALLOC_STRUCT( gl_line_attrib
);
365 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
366 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
369 if (mask
& GL_LIST_BIT
) {
370 struct gl_list_attrib
*attr
;
371 attr
= MALLOC_STRUCT( gl_list_attrib
);
372 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
373 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
376 if (mask
& GL_PIXEL_MODE_BIT
) {
377 struct gl_pixel_attrib
*attr
;
378 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
379 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
380 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
381 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
382 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
385 if (mask
& GL_POINT_BIT
) {
386 struct gl_point_attrib
*attr
;
387 attr
= MALLOC_STRUCT( gl_point_attrib
);
388 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
389 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
392 if (mask
& GL_POLYGON_BIT
) {
393 struct gl_polygon_attrib
*attr
;
394 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
395 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
396 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
399 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
401 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
402 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
403 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
406 if (mask
& GL_SCISSOR_BIT
) {
407 struct gl_scissor_attrib
*attr
;
408 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
409 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
410 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
413 if (mask
& GL_STENCIL_BUFFER_BIT
) {
414 struct gl_stencil_attrib
*attr
;
415 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
416 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
417 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
420 if (mask
& GL_TEXTURE_BIT
) {
421 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
425 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
429 _mesa_lock_context_textures(ctx
);
431 /* copy/save the bulk of texture state here */
432 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
434 /* Save references to the currently bound texture objects so they don't
435 * accidentally get deleted while referenced in the attribute stack.
437 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
438 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
439 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
440 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
444 /* copy state/contents of the currently bound texture objects */
445 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
446 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
447 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
448 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
452 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
454 _mesa_unlock_context_textures(ctx
);
456 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
459 if (mask
& GL_TRANSFORM_BIT
) {
460 struct gl_transform_attrib
*attr
;
461 attr
= MALLOC_STRUCT( gl_transform_attrib
);
462 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
463 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
466 if (mask
& GL_VIEWPORT_BIT
) {
467 struct gl_viewport_attrib
*attr
;
468 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
469 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
470 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
473 /* GL_ARB_multisample */
474 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
475 struct gl_multisample_attrib
*attr
;
476 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
477 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
478 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
482 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
483 ctx
->AttribStackDepth
++;
489 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
491 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
494 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
495 if ((VALUE) != (NEWVALUE)) { \
496 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
499 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
500 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
501 if (ctx
->Extensions
.EXT_draw_buffers2
) {
503 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
504 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
508 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
512 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
513 const GLuint mask
= 1 << i
;
514 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
515 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
516 !!(enable
->ClipPlanes
& mask
));
519 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
521 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
522 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
524 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
525 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
526 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
527 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
528 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
529 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
531 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
533 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
540 GL_MAP1_TEXTURE_COORD_1
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
542 GL_MAP1_TEXTURE_COORD_2
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
544 GL_MAP1_TEXTURE_COORD_3
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
546 GL_MAP1_TEXTURE_COORD_4
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
549 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
551 for (i
= 0; i
< 16; i
++) {
552 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
553 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
558 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
560 GL_MAP2_TEXTURE_COORD_1
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
562 GL_MAP2_TEXTURE_COORD_2
);
563 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
564 GL_MAP2_TEXTURE_COORD_3
);
565 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
566 GL_MAP2_TEXTURE_COORD_4
);
567 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
569 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
571 for (i
= 0; i
< 16; i
++) {
572 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
573 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
576 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
577 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
578 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
579 GL_RESCALE_NORMAL_EXT
);
580 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
581 enable
->RasterPositionUnclipped
,
582 GL_RASTER_POSITION_UNCLIPPED_IBM
);
583 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
585 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
586 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
589 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
590 GL_POLYGON_OFFSET_POINT
);
591 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
592 GL_POLYGON_OFFSET_LINE
);
593 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
594 GL_POLYGON_OFFSET_FILL
);
595 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
597 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
599 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
600 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
601 if (ctx
->Extensions
.EXT_stencil_two_side
) {
602 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
604 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
606 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
607 enable
->SampleAlphaToCoverage
,
608 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
609 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
610 enable
->SampleAlphaToOne
,
611 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
612 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
613 enable
->SampleCoverage
,
614 GL_SAMPLE_COVERAGE_ARB
);
615 /* GL_ARB_vertex_program, GL_NV_vertex_program */
616 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
617 enable
->VertexProgram
,
618 GL_VERTEX_PROGRAM_ARB
);
619 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
620 enable
->VertexProgramPointSize
,
621 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
622 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
623 enable
->VertexProgramTwoSide
,
624 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
626 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
627 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
628 GL_FRAMEBUFFER_SRGB
);
630 /* texture unit enables */
631 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
632 const GLbitfield enabled
= enable
->Texture
[i
];
633 const GLbitfield genEnabled
= enable
->TexGen
[i
];
635 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
636 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
638 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
639 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
640 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
641 if (ctx
->Extensions
.NV_texture_rectangle
) {
642 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
643 !!(enabled
& TEXTURE_RECT_BIT
));
645 if (ctx
->Extensions
.ARB_texture_cube_map
) {
646 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
647 !!(enabled
& TEXTURE_CUBE_BIT
));
649 if (ctx
->Extensions
.MESA_texture_array
) {
650 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
651 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
652 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
653 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
657 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
658 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
659 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
660 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
661 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
662 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
666 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
671 * Pop/restore texture attribute/group state.
674 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
678 _mesa_lock_context_textures(ctx
);
680 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
681 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
684 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
685 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
686 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
687 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
688 if (ctx
->Extensions
.ARB_texture_cube_map
) {
689 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
690 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
692 if (ctx
->Extensions
.NV_texture_rectangle
) {
693 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
694 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
696 if (ctx
->Extensions
.MESA_texture_array
) {
697 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
698 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
699 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
700 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
703 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
704 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
705 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
706 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
707 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
708 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
709 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
710 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
711 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
712 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
713 /* Eye plane done differently to avoid re-transformation */
715 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
716 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
717 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
718 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
719 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
720 if (ctx
->Driver
.TexGen
) {
721 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
722 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
723 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
724 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
727 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
728 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
729 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
730 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
731 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
733 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
734 unit
->Combine
.ModeRGB
);
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
736 unit
->Combine
.ModeA
);
738 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
740 for (i
= 0; i
< n
; i
++) {
741 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
742 unit
->Combine
.SourceRGB
[i
]);
743 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
744 unit
->Combine
.SourceA
[i
]);
745 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
746 unit
->Combine
.OperandRGB
[i
]);
747 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
748 unit
->Combine
.OperandA
[i
]);
751 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
752 1 << unit
->Combine
.ScaleShiftRGB
);
753 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
754 1 << unit
->Combine
.ScaleShiftA
);
756 /* Restore texture object state for each target */
757 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
758 const struct gl_texture_object
*obj
= NULL
;
759 const struct gl_sampler_object
*samp
;
762 obj
= &texstate
->SavedObj
[u
][tgt
];
764 /* don't restore state for unsupported targets to prevent
767 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
768 !ctx
->Extensions
.ARB_texture_cube_map
) {
771 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
772 !ctx
->Extensions
.NV_texture_rectangle
) {
775 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
776 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
777 !ctx
->Extensions
.MESA_texture_array
) {
780 else if (obj
->Target
== GL_TEXTURE_BUFFER
)
782 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
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_ActiveTextureARB(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 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
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
++) {
895 _mesa_ColorMaskIndexed(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_DrawBuffersARB(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_BlendFuncSeparatei(buf
, color
->Blend
[buf
].SrcRGB
,
951 color
->Blend
[buf
].DstRGB
,
952 color
->Blend
[buf
].SrcA
,
953 color
->Blend
[buf
].DstA
);
954 _mesa_BlendEquationSeparatei(buf
,
955 color
->Blend
[buf
].EquationRGB
,
956 color
->Blend
[buf
].EquationA
);
960 /* set same blend modes for all buffers */
961 _mesa_BlendFuncSeparateEXT(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_BlendEquationSeparateEXT(
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 _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
989 _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
991 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
992 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
996 FLUSH_CURRENT( ctx
, 0 );
997 memcpy( &ctx
->Current
, attr
->data
,
998 sizeof(struct gl_current_attrib
) );
1000 case GL_DEPTH_BUFFER_BIT
:
1002 const struct gl_depthbuffer_attrib
*depth
;
1003 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1004 _mesa_DepthFunc(depth
->Func
);
1005 _mesa_ClearDepth(depth
->Clear
);
1006 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1007 _mesa_DepthMask(depth
->Mask
);
1012 const struct gl_enable_attrib
*enable
;
1013 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1014 pop_enable_group(ctx
, enable
);
1015 ctx
->NewState
|= _NEW_ALL
;
1019 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1020 ctx
->NewState
|= _NEW_EVAL
;
1024 const struct gl_fog_attrib
*fog
;
1025 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1026 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1027 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1028 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1029 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1030 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1031 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1032 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1037 const struct gl_hint_attrib
*hint
;
1038 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1039 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1040 hint
->PerspectiveCorrection
);
1041 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1042 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1043 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1044 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1045 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1046 hint
->ClipVolumeClipping
);
1047 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1048 hint
->TextureCompression
);
1051 case GL_LIGHTING_BIT
:
1054 const struct gl_light_attrib
*light
;
1055 light
= (const struct gl_light_attrib
*) attr
->data
;
1056 /* lighting enable */
1057 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1058 /* per-light state */
1059 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1060 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1062 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1063 const struct gl_light
*l
= &light
->Light
[i
];
1064 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1065 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1066 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1067 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1068 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1069 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1071 GLfloat p
[4] = { 0 };
1072 p
[0] = l
->SpotExponent
;
1073 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1076 GLfloat p
[4] = { 0 };
1077 p
[0] = l
->SpotCutoff
;
1078 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1081 GLfloat p
[4] = { 0 };
1082 p
[0] = l
->ConstantAttenuation
;
1083 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1086 GLfloat p
[4] = { 0 };
1087 p
[0] = l
->LinearAttenuation
;
1088 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1091 GLfloat p
[4] = { 0 };
1092 p
[0] = l
->QuadraticAttenuation
;
1093 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1097 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1098 light
->Model
.Ambient
);
1099 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1100 (GLfloat
) light
->Model
.LocalViewer
);
1101 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1102 (GLfloat
) light
->Model
.TwoSide
);
1103 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1104 (GLfloat
) light
->Model
.ColorControl
);
1106 _mesa_ShadeModel(light
->ShadeModel
);
1107 /* color material */
1108 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1109 light
->ColorMaterialMode
);
1110 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1111 light
->ColorMaterialEnabled
);
1113 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1114 sizeof(struct gl_material
));
1115 _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1120 const struct gl_line_attrib
*line
;
1121 line
= (const struct gl_line_attrib
*) attr
->data
;
1122 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1123 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1124 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1125 _mesa_LineWidth(line
->Width
);
1129 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1131 case GL_PIXEL_MODE_BIT
:
1132 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1133 /* XXX what other pixel state needs to be set by function calls? */
1134 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1135 ctx
->NewState
|= _NEW_PIXEL
;
1139 const struct gl_point_attrib
*point
;
1140 point
= (const struct gl_point_attrib
*) attr
->data
;
1141 _mesa_PointSize(point
->Size
);
1142 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1143 if (ctx
->Extensions
.EXT_point_parameters
) {
1144 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1146 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1148 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1150 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1153 if (ctx
->Extensions
.NV_point_sprite
1154 || ctx
->Extensions
.ARB_point_sprite
) {
1156 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1157 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1158 (GLint
) point
->CoordReplace
[u
]);
1160 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1161 if (ctx
->Extensions
.NV_point_sprite
)
1162 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1163 ctx
->Point
.SpriteRMode
);
1164 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1165 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1169 case GL_POLYGON_BIT
:
1171 const struct gl_polygon_attrib
*polygon
;
1172 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1173 _mesa_CullFace(polygon
->CullFaceMode
);
1174 _mesa_FrontFace(polygon
->FrontFace
);
1175 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1176 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1177 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1178 polygon
->OffsetUnits
);
1179 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1180 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1181 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1182 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1183 polygon
->OffsetPoint
);
1184 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1185 polygon
->OffsetLine
);
1186 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1187 polygon
->OffsetFill
);
1190 case GL_POLYGON_STIPPLE_BIT
:
1191 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1192 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1193 if (ctx
->Driver
.PolygonStipple
)
1194 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1196 case GL_SCISSOR_BIT
:
1198 const struct gl_scissor_attrib
*scissor
;
1199 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1200 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1201 scissor
->Width
, scissor
->Height
);
1202 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1205 case GL_STENCIL_BUFFER_BIT
:
1207 const struct gl_stencil_attrib
*stencil
;
1208 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1209 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1210 _mesa_ClearStencil(stencil
->Clear
);
1211 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1212 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1213 stencil
->TestTwoSide
);
1214 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1215 ? GL_BACK
: GL_FRONT
);
1218 _mesa_StencilFuncSeparate(GL_FRONT
,
1219 stencil
->Function
[0],
1221 stencil
->ValueMask
[0]);
1222 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1223 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1224 stencil
->ZFailFunc
[0],
1225 stencil
->ZPassFunc
[0]);
1227 _mesa_StencilFuncSeparate(GL_BACK
,
1228 stencil
->Function
[1],
1230 stencil
->ValueMask
[1]);
1231 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1232 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1233 stencil
->ZFailFunc
[1],
1234 stencil
->ZPassFunc
[1]);
1237 case GL_TRANSFORM_BIT
:
1240 const struct gl_transform_attrib
*xform
;
1241 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1242 _mesa_MatrixMode(xform
->MatrixMode
);
1243 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1244 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1246 /* restore clip planes */
1247 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1248 const GLuint mask
= 1 << i
;
1249 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1250 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1251 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1252 !!(xform
->ClipPlanesEnabled
& mask
));
1253 if (ctx
->Driver
.ClipPlane
)
1254 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1257 /* normalize/rescale */
1258 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1259 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1260 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1261 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1262 ctx
->Transform
.RescaleNormals
);
1263 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1264 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1265 ctx
->Transform
.DepthClamp
);
1268 case GL_TEXTURE_BIT
:
1270 struct texture_state
*texstate
1271 = (struct texture_state
*) attr
->data
;
1272 pop_texture_group(ctx
, texstate
);
1273 ctx
->NewState
|= _NEW_TEXTURE
;
1276 case GL_VIEWPORT_BIT
:
1278 const struct gl_viewport_attrib
*vp
;
1279 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1280 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1281 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1284 case GL_MULTISAMPLE_BIT_ARB
:
1286 const struct gl_multisample_attrib
*ms
;
1287 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1289 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1293 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1295 GL_SAMPLE_COVERAGE
);
1297 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1298 ms
->SampleAlphaToCoverage
,
1299 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1301 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1302 ms
->SampleAlphaToOne
,
1303 GL_SAMPLE_ALPHA_TO_ONE
);
1305 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1306 ms
->SampleCoverageInvert
);
1311 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1324 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1328 copy_pixelstore(struct gl_context
*ctx
,
1329 struct gl_pixelstore_attrib
*dst
,
1330 const struct gl_pixelstore_attrib
*src
)
1332 dst
->Alignment
= src
->Alignment
;
1333 dst
->RowLength
= src
->RowLength
;
1334 dst
->SkipPixels
= src
->SkipPixels
;
1335 dst
->SkipRows
= src
->SkipRows
;
1336 dst
->ImageHeight
= src
->ImageHeight
;
1337 dst
->SkipImages
= src
->SkipImages
;
1338 dst
->SwapBytes
= src
->SwapBytes
;
1339 dst
->LsbFirst
= src
->LsbFirst
;
1340 dst
->Invert
= src
->Invert
;
1341 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1345 #define GL_CLIENT_PACK_BIT (1<<20)
1346 #define GL_CLIENT_UNPACK_BIT (1<<21)
1349 * Copy gl_array_object from src to dest.
1350 * 'dest' must be in an initialized state.
1353 copy_array_object(struct gl_context
*ctx
,
1354 struct gl_array_object
*dest
,
1355 struct gl_array_object
*src
)
1362 /* In theory must be the same anyway, but on recreate make sure it matches */
1363 dest
->ARBsemantics
= src
->ARBsemantics
;
1365 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1366 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1368 /* _Enabled must be the same than on push */
1369 dest
->_Enabled
= src
->_Enabled
;
1370 dest
->_MaxElement
= src
->_MaxElement
;
1374 * Copy gl_array_attrib from src to dest.
1375 * 'dest' must be in an initialized state.
1378 copy_array_attrib(struct gl_context
*ctx
,
1379 struct gl_array_attrib
*dest
,
1380 struct gl_array_attrib
*src
,
1384 /* skip DefaultArrayObj, Objects */
1385 dest
->ActiveTexture
= src
->ActiveTexture
;
1386 dest
->LockFirst
= src
->LockFirst
;
1387 dest
->LockCount
= src
->LockCount
;
1388 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1389 dest
->RestartIndex
= src
->RestartIndex
;
1391 /* skip RebindArrays */
1394 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1396 /* skip ArrayBufferObj */
1397 /* skip ElementArrayBufferObj */
1401 * Save the content of src to dest.
1404 save_array_attrib(struct gl_context
*ctx
,
1405 struct gl_array_attrib
*dest
,
1406 struct gl_array_attrib
*src
)
1408 /* Set the Name, needed for restore, but do never overwrite.
1409 * Needs to match value in the object hash. */
1410 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1411 /* And copy all of the rest. */
1412 copy_array_attrib(ctx
, dest
, src
, false);
1414 /* Just reference them here */
1415 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1416 src
->ArrayBufferObj
);
1417 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1418 src
->ArrayObj
->ElementArrayBufferObj
);
1422 * Restore the content of src to dest.
1425 restore_array_attrib(struct gl_context
*ctx
,
1426 struct gl_array_attrib
*dest
,
1427 struct gl_array_attrib
*src
)
1429 /* The ARB_vertex_array_object spec says:
1431 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1432 * if array is not a name returned from a previous call to
1433 * GenVertexArrays, or if such a name has since been deleted with
1434 * DeleteVertexArrays."
1436 * Therefore popping a deleted VAO cannot magically recreate it.
1438 * The semantics of objects created using APPLE_vertex_array_objects behave
1439 * differently. These objects expect to be recreated by pop. Alas.
1441 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1442 && src
->ArrayObj
->ARBsemantics
);
1444 if (arb_vao
&& !_mesa_IsVertexArrayAPPLE(src
->ArrayObj
->Name
))
1447 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1449 /* Restore or recreate the buffer objects by the names ... */
1451 || src
->ArrayBufferObj
->Name
== 0
1452 || _mesa_IsBufferARB(src
->ArrayBufferObj
->Name
)) {
1453 /* ... and restore its content */
1454 copy_array_attrib(ctx
, dest
, src
, false);
1456 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1457 src
->ArrayBufferObj
->Name
);
1459 copy_array_attrib(ctx
, dest
, src
, true);
1463 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1464 || _mesa_IsBufferARB(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1465 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1466 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1470 * init/alloc the fields of 'attrib'.
1471 * Needs to the init part matching free_array_attrib_data below.
1474 init_array_attrib_data(struct gl_context
*ctx
,
1475 struct gl_array_attrib
*attrib
)
1477 /* Get a non driver gl_array_object. */
1478 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1479 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1483 * Free/unreference the fields of 'attrib' but don't delete it (that's
1484 * done later in the calling code).
1485 * Needs to the cleanup part matching init_array_attrib_data above.
1488 free_array_attrib_data(struct gl_context
*ctx
,
1489 struct gl_array_attrib
*attrib
)
1491 /* We use a non driver array object, so don't just unref since we would
1492 * end up using the drivers DeleteArrayObject function for deletion. */
1493 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1494 attrib
->ArrayObj
= 0;
1495 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1500 _mesa_PushClientAttrib(GLbitfield mask
)
1502 struct gl_attrib_node
*head
;
1504 GET_CURRENT_CONTEXT(ctx
);
1505 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1507 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1508 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1512 /* Build linked list of attribute nodes which save all attribute
1513 * groups specified by the mask.
1517 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1518 struct gl_pixelstore_attrib
*attr
;
1519 /* packing attribs */
1520 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1521 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1522 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1523 /* unpacking attribs */
1524 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1525 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1526 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1529 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1530 struct gl_array_attrib
*attr
;
1531 attr
= CALLOC_STRUCT( gl_array_attrib
);
1532 init_array_attrib_data(ctx
, attr
);
1533 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1534 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1537 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1538 ctx
->ClientAttribStackDepth
++;
1545 _mesa_PopClientAttrib(void)
1547 struct gl_attrib_node
*node
, *next
;
1549 GET_CURRENT_CONTEXT(ctx
);
1550 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1552 if (ctx
->ClientAttribStackDepth
== 0) {
1553 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1557 ctx
->ClientAttribStackDepth
--;
1558 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1561 switch (node
->kind
) {
1562 case GL_CLIENT_PACK_BIT
:
1564 struct gl_pixelstore_attrib
*store
=
1565 (struct gl_pixelstore_attrib
*) node
->data
;
1566 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1567 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1569 ctx
->NewState
|= _NEW_PACKUNPACK
;
1571 case GL_CLIENT_UNPACK_BIT
:
1573 struct gl_pixelstore_attrib
*store
=
1574 (struct gl_pixelstore_attrib
*) node
->data
;
1575 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1576 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1578 ctx
->NewState
|= _NEW_PACKUNPACK
;
1580 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1581 struct gl_array_attrib
* attr
=
1582 (struct gl_array_attrib
*) node
->data
;
1583 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1584 free_array_attrib_data(ctx
, attr
);
1585 ctx
->NewState
|= _NEW_ARRAY
;
1589 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1602 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1604 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1605 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1606 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1607 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1611 #endif /* FEATURE_attrib_stack */
1615 * Free any attribute state data that might be attached to the context.
1618 _mesa_free_attrib_data(struct gl_context
*ctx
)
1620 while (ctx
->AttribStackDepth
> 0) {
1621 struct gl_attrib_node
*attr
, *next
;
1623 ctx
->AttribStackDepth
--;
1624 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1627 if (attr
->kind
== GL_TEXTURE_BIT
) {
1628 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1630 /* clear references to the saved texture objects */
1631 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1632 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1633 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1636 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1639 /* any other chunks of state that requires special handling? */
1651 void _mesa_init_attrib( struct gl_context
*ctx
)
1653 /* Renderer and client attribute stacks */
1654 ctx
->AttribStackDepth
= 0;
1655 ctx
->ClientAttribStackDepth
= 0;