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
);
206 _mesa_PushAttrib(GLbitfield mask
)
208 struct gl_attrib_node
*head
;
210 GET_CURRENT_CONTEXT(ctx
);
212 if (MESA_VERBOSE
& VERBOSE_API
)
213 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
215 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
216 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
220 /* Build linked list of attribute nodes which save all attribute */
221 /* groups specified by the mask. */
224 if (mask
& GL_ACCUM_BUFFER_BIT
) {
225 struct gl_accum_attrib
*attr
;
226 attr
= MALLOC_STRUCT( gl_accum_attrib
);
227 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
228 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
231 if (mask
& GL_COLOR_BUFFER_BIT
) {
233 struct gl_colorbuffer_attrib
*attr
;
234 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
235 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
236 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
237 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
238 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
239 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
242 if (mask
& GL_CURRENT_BIT
) {
243 struct gl_current_attrib
*attr
;
244 FLUSH_CURRENT( ctx
, 0 );
245 attr
= MALLOC_STRUCT( gl_current_attrib
);
246 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
247 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
250 if (mask
& GL_DEPTH_BUFFER_BIT
) {
251 struct gl_depthbuffer_attrib
*attr
;
252 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
253 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
254 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
257 if (mask
& GL_ENABLE_BIT
) {
258 struct gl_enable_attrib
*attr
;
260 attr
= MALLOC_STRUCT( gl_enable_attrib
);
261 /* Copy enable flags from all other attributes into the enable struct. */
262 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
263 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
264 attr
->Blend
= ctx
->Color
.BlendEnabled
;
265 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
266 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
267 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
268 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
269 attr
->DepthTest
= ctx
->Depth
.Test
;
270 attr
->Dither
= ctx
->Color
.DitherFlag
;
271 attr
->Fog
= ctx
->Fog
.Enabled
;
272 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
273 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
275 attr
->Lighting
= ctx
->Light
.Enabled
;
276 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
277 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
278 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
279 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
280 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
281 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
282 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
283 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
284 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
285 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
286 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
287 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
288 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
289 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
290 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
291 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
292 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
293 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
294 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
295 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
296 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
297 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
298 attr
->Normalize
= ctx
->Transform
.Normalize
;
299 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
300 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
301 attr
->PointSprite
= ctx
->Point
.PointSprite
;
302 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
303 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
304 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
305 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
306 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
307 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
308 attr
->Scissor
= ctx
->Scissor
.Enabled
;
309 attr
->Stencil
= ctx
->Stencil
.Enabled
;
310 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
311 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
312 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
313 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
314 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
315 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
316 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
317 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
319 /* GL_ARB_vertex_program */
320 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
321 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
322 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
324 /* GL_ARB_fragment_program */
325 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
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
= 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
,
552 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
556 GL_MAP2_TEXTURE_COORD_1
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
558 GL_MAP2_TEXTURE_COORD_2
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
560 GL_MAP2_TEXTURE_COORD_3
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
562 GL_MAP2_TEXTURE_COORD_4
);
563 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
565 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
568 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
569 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
570 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
571 GL_RESCALE_NORMAL_EXT
);
572 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
573 enable
->RasterPositionUnclipped
,
574 GL_RASTER_POSITION_UNCLIPPED_IBM
);
575 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
577 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
578 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
581 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
582 GL_POLYGON_OFFSET_POINT
);
583 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
584 GL_POLYGON_OFFSET_LINE
);
585 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
586 GL_POLYGON_OFFSET_FILL
);
587 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
589 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
591 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
592 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
593 if (ctx
->Extensions
.EXT_stencil_two_side
) {
594 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
596 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
598 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
599 enable
->SampleAlphaToCoverage
,
600 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
601 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
602 enable
->SampleAlphaToOne
,
603 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
604 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
605 enable
->SampleCoverage
,
606 GL_SAMPLE_COVERAGE_ARB
);
607 /* GL_ARB_vertex_program */
608 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
609 enable
->VertexProgram
,
610 GL_VERTEX_PROGRAM_ARB
);
611 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
612 enable
->VertexProgramPointSize
,
613 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
614 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
615 enable
->VertexProgramTwoSide
,
616 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
618 /* GL_ARB_fragment_program */
619 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
620 enable
->FragmentProgram
,
621 GL_FRAGMENT_PROGRAM_ARB
);
623 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
624 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
625 GL_FRAMEBUFFER_SRGB
);
627 /* texture unit enables */
628 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
629 const GLbitfield enabled
= enable
->Texture
[i
];
630 const GLbitfield genEnabled
= enable
->TexGen
[i
];
632 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
633 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
635 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
636 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
637 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
638 if (ctx
->Extensions
.NV_texture_rectangle
) {
639 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
640 !!(enabled
& TEXTURE_RECT_BIT
));
642 if (ctx
->Extensions
.ARB_texture_cube_map
) {
643 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
644 !!(enabled
& TEXTURE_CUBE_BIT
));
648 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
649 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
650 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
651 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
652 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
653 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
657 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
662 * Pop/restore texture attribute/group state.
665 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
669 _mesa_lock_context_textures(ctx
);
671 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
672 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
675 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
676 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
677 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
678 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
679 if (ctx
->Extensions
.ARB_texture_cube_map
) {
680 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
681 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
683 if (ctx
->Extensions
.NV_texture_rectangle
) {
684 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
685 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
687 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
688 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
689 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
690 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
691 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
692 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
693 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
694 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
695 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
696 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
697 /* Eye plane done differently to avoid re-transformation */
699 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
700 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
701 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
702 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
703 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
704 if (ctx
->Driver
.TexGen
) {
705 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
706 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
707 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
708 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
711 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
712 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
713 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
714 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
715 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
717 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
718 unit
->Combine
.ModeRGB
);
719 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
720 unit
->Combine
.ModeA
);
722 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
724 for (i
= 0; i
< n
; i
++) {
725 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
726 unit
->Combine
.SourceRGB
[i
]);
727 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
728 unit
->Combine
.SourceA
[i
]);
729 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
730 unit
->Combine
.OperandRGB
[i
]);
731 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
732 unit
->Combine
.OperandA
[i
]);
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
736 1 << unit
->Combine
.ScaleShiftRGB
);
737 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
738 1 << unit
->Combine
.ScaleShiftA
);
740 /* Restore texture object state for each target */
741 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
742 const struct gl_texture_object
*obj
= NULL
;
743 const struct gl_sampler_object
*samp
;
746 obj
= &texstate
->SavedObj
[u
][tgt
];
748 /* don't restore state for unsupported targets to prevent
751 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
752 !ctx
->Extensions
.ARB_texture_cube_map
) {
755 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
756 !ctx
->Extensions
.NV_texture_rectangle
) {
759 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
760 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
761 !ctx
->Extensions
.EXT_texture_array
) {
764 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
765 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
767 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
769 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
771 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
772 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
775 target
= obj
->Target
;
777 _mesa_BindTexture(target
, obj
->Name
);
779 samp
= &obj
->Sampler
;
781 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
782 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
783 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
784 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
785 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
786 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
787 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
788 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
789 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
790 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
791 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
792 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
793 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
794 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
795 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
796 samp
->MaxAnisotropy
);
798 if (ctx
->Extensions
.ARB_shadow
) {
799 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
801 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
804 if (ctx
->Extensions
.ARB_depth_texture
)
805 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
808 /* remove saved references to the texture objects */
809 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
810 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
814 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
816 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
818 _mesa_unlock_context_textures(ctx
);
823 * This function is kind of long just because we have to call a lot
824 * of device driver functions to update device driver state.
826 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
827 * in order to restore GL state. This isn't terribly efficient but it
828 * ensures that dirty flags and any derived state gets updated correctly.
829 * We could at least check if the value to restore equals the current value
830 * and then skip the Mesa call.
833 _mesa_PopAttrib(void)
835 struct gl_attrib_node
*attr
, *next
;
836 GET_CURRENT_CONTEXT(ctx
);
837 FLUSH_VERTICES(ctx
, 0);
839 if (ctx
->AttribStackDepth
== 0) {
840 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
844 ctx
->AttribStackDepth
--;
845 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
849 if (MESA_VERBOSE
& VERBOSE_API
) {
850 _mesa_debug(ctx
, "glPopAttrib %s\n",
851 _mesa_lookup_enum_by_nr(attr
->kind
));
854 switch (attr
->kind
) {
855 case GL_ACCUM_BUFFER_BIT
:
857 const struct gl_accum_attrib
*accum
;
858 accum
= (const struct gl_accum_attrib
*) attr
->data
;
859 _mesa_ClearAccum(accum
->ClearColor
[0],
860 accum
->ClearColor
[1],
861 accum
->ClearColor
[2],
862 accum
->ClearColor
[3]);
865 case GL_COLOR_BUFFER_BIT
:
867 const struct gl_colorbuffer_attrib
*color
;
869 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
870 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
871 _mesa_ClearColor(color
->ClearColor
.f
[0],
872 color
->ClearColor
.f
[1],
873 color
->ClearColor
.f
[2],
874 color
->ClearColor
.f
[3]);
875 _mesa_IndexMask(color
->IndexMask
);
876 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
877 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
878 (GLboolean
) (color
->ColorMask
[0][1] != 0),
879 (GLboolean
) (color
->ColorMask
[0][2] != 0),
880 (GLboolean
) (color
->ColorMask
[0][3] != 0));
884 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
886 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
887 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
888 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
889 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
893 /* Need to determine if more than one color output is
894 * specified. If so, call glDrawBuffersARB, else call
895 * glDrawBuffer(). This is a subtle, but essential point
896 * since GL_FRONT (for example) is illegal for the former
897 * function, but legal for the later.
899 GLboolean multipleBuffers
= GL_FALSE
;
902 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
903 if (color
->DrawBuffer
[i
] != GL_NONE
) {
904 multipleBuffers
= GL_TRUE
;
908 /* Call the API_level functions, not _mesa_drawbuffers()
909 * since we need to do error checking on the pop'd
911 * Ex: if GL_FRONT were pushed, but we're popping with a
912 * user FBO bound, GL_FRONT will be illegal and we'll need
913 * to record that error. Per OpenGL ARB decision.
916 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
,
919 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
921 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
922 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
923 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
924 if (ctx
->Extensions
.EXT_draw_buffers2
) {
926 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
927 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
928 (color
->BlendEnabled
>> i
) & 1);
932 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
935 if (ctx
->Color
._BlendFuncPerBuffer
||
936 ctx
->Color
._BlendEquationPerBuffer
) {
937 /* set blend per buffer */
939 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
940 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
941 color
->Blend
[buf
].DstRGB
,
942 color
->Blend
[buf
].SrcA
,
943 color
->Blend
[buf
].DstA
);
944 _mesa_BlendEquationSeparateiARB(buf
,
945 color
->Blend
[buf
].EquationRGB
,
946 color
->Blend
[buf
].EquationA
);
950 /* set same blend modes for all buffers */
951 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
952 color
->Blend
[0].DstRGB
,
953 color
->Blend
[0].SrcA
,
954 color
->Blend
[0].DstA
);
955 /* This special case is because glBlendEquationSeparateEXT
956 * cannot take GL_LOGIC_OP as a parameter.
958 if (color
->Blend
[0].EquationRGB
==
959 color
->Blend
[0].EquationA
) {
960 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
963 _mesa_BlendEquationSeparate(
964 color
->Blend
[0].EquationRGB
,
965 color
->Blend
[0].EquationA
);
968 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
969 color
->BlendColorUnclamped
[1],
970 color
->BlendColorUnclamped
[2],
971 color
->BlendColorUnclamped
[3]);
972 _mesa_LogicOp(color
->LogicOp
);
973 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
974 color
->ColorLogicOpEnabled
);
975 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
976 color
->IndexLogicOpEnabled
);
977 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
978 if (ctx
->Extensions
.ARB_color_buffer_float
)
979 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
980 color
->ClampFragmentColor
);
981 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
983 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
984 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
985 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
989 FLUSH_CURRENT( ctx
, 0 );
990 memcpy( &ctx
->Current
, attr
->data
,
991 sizeof(struct gl_current_attrib
) );
993 case GL_DEPTH_BUFFER_BIT
:
995 const struct gl_depthbuffer_attrib
*depth
;
996 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
997 _mesa_DepthFunc(depth
->Func
);
998 _mesa_ClearDepth(depth
->Clear
);
999 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1000 _mesa_DepthMask(depth
->Mask
);
1005 const struct gl_enable_attrib
*enable
;
1006 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1007 pop_enable_group(ctx
, enable
);
1008 ctx
->NewState
|= _NEW_ALL
;
1012 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1013 ctx
->NewState
|= _NEW_EVAL
;
1017 const struct gl_fog_attrib
*fog
;
1018 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1019 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1020 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1021 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1022 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1023 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1024 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1025 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1030 const struct gl_hint_attrib
*hint
;
1031 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1032 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1033 hint
->PerspectiveCorrection
);
1034 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1035 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1036 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1037 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1038 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1039 hint
->TextureCompression
);
1042 case GL_LIGHTING_BIT
:
1045 const struct gl_light_attrib
*light
;
1046 light
= (const struct gl_light_attrib
*) attr
->data
;
1047 /* lighting enable */
1048 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1049 /* per-light state */
1050 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1051 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1053 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1054 const struct gl_light
*l
= &light
->Light
[i
];
1055 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1056 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1057 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1058 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1059 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1060 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1062 GLfloat p
[4] = { 0 };
1063 p
[0] = l
->SpotExponent
;
1064 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1067 GLfloat p
[4] = { 0 };
1068 p
[0] = l
->SpotCutoff
;
1069 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1072 GLfloat p
[4] = { 0 };
1073 p
[0] = l
->ConstantAttenuation
;
1074 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1077 GLfloat p
[4] = { 0 };
1078 p
[0] = l
->LinearAttenuation
;
1079 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1082 GLfloat p
[4] = { 0 };
1083 p
[0] = l
->QuadraticAttenuation
;
1084 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1088 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1089 light
->Model
.Ambient
);
1090 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1091 (GLfloat
) light
->Model
.LocalViewer
);
1092 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1093 (GLfloat
) light
->Model
.TwoSide
);
1094 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1095 (GLfloat
) light
->Model
.ColorControl
);
1097 _mesa_ShadeModel(light
->ShadeModel
);
1098 /* color material */
1099 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1100 light
->ColorMaterialMode
);
1101 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1102 light
->ColorMaterialEnabled
);
1104 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1105 sizeof(struct gl_material
));
1106 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1107 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1108 light
->ClampVertexColor
);
1114 const struct gl_line_attrib
*line
;
1115 line
= (const struct gl_line_attrib
*) attr
->data
;
1116 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1117 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1118 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1119 _mesa_LineWidth(line
->Width
);
1123 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1125 case GL_PIXEL_MODE_BIT
:
1126 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1127 /* XXX what other pixel state needs to be set by function calls? */
1128 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1129 ctx
->NewState
|= _NEW_PIXEL
;
1133 const struct gl_point_attrib
*point
;
1134 point
= (const struct gl_point_attrib
*) attr
->data
;
1135 _mesa_PointSize(point
->Size
);
1136 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1137 if (ctx
->Extensions
.EXT_point_parameters
) {
1138 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1140 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1142 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1144 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1147 if (ctx
->Extensions
.NV_point_sprite
1148 || ctx
->Extensions
.ARB_point_sprite
) {
1150 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1151 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1152 (GLint
) point
->CoordReplace
[u
]);
1154 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1155 if (ctx
->Extensions
.NV_point_sprite
)
1156 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1157 ctx
->Point
.SpriteRMode
);
1159 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1160 || ctx
->API
== API_OPENGL_CORE
)
1161 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1162 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1166 case GL_POLYGON_BIT
:
1168 const struct gl_polygon_attrib
*polygon
;
1169 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1170 _mesa_CullFace(polygon
->CullFaceMode
);
1171 _mesa_FrontFace(polygon
->FrontFace
);
1172 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1173 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1174 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1175 polygon
->OffsetUnits
);
1176 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1177 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1178 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1179 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1180 polygon
->OffsetPoint
);
1181 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1182 polygon
->OffsetLine
);
1183 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1184 polygon
->OffsetFill
);
1187 case GL_POLYGON_STIPPLE_BIT
:
1188 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1189 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1190 if (ctx
->Driver
.PolygonStipple
)
1191 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1193 case GL_SCISSOR_BIT
:
1195 const struct gl_scissor_attrib
*scissor
;
1196 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1197 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1198 scissor
->Width
, scissor
->Height
);
1199 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1202 case GL_STENCIL_BUFFER_BIT
:
1204 const struct gl_stencil_attrib
*stencil
;
1205 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1206 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1207 _mesa_ClearStencil(stencil
->Clear
);
1208 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1209 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1210 stencil
->TestTwoSide
);
1211 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1212 ? GL_BACK
: GL_FRONT
);
1215 _mesa_StencilFuncSeparate(GL_FRONT
,
1216 stencil
->Function
[0],
1218 stencil
->ValueMask
[0]);
1219 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1220 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1221 stencil
->ZFailFunc
[0],
1222 stencil
->ZPassFunc
[0]);
1224 _mesa_StencilFuncSeparate(GL_BACK
,
1225 stencil
->Function
[1],
1227 stencil
->ValueMask
[1]);
1228 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1229 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1230 stencil
->ZFailFunc
[1],
1231 stencil
->ZPassFunc
[1]);
1234 case GL_TRANSFORM_BIT
:
1237 const struct gl_transform_attrib
*xform
;
1238 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1239 _mesa_MatrixMode(xform
->MatrixMode
);
1240 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1241 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1243 /* restore clip planes */
1244 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1245 const GLuint mask
= 1 << i
;
1246 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1247 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1248 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1249 !!(xform
->ClipPlanesEnabled
& mask
));
1250 if (ctx
->Driver
.ClipPlane
)
1251 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1254 /* normalize/rescale */
1255 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1256 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1257 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1258 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1259 ctx
->Transform
.RescaleNormals
);
1260 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1261 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1262 ctx
->Transform
.DepthClamp
);
1265 case GL_TEXTURE_BIT
:
1267 struct texture_state
*texstate
1268 = (struct texture_state
*) attr
->data
;
1269 pop_texture_group(ctx
, texstate
);
1270 ctx
->NewState
|= _NEW_TEXTURE
;
1273 case GL_VIEWPORT_BIT
:
1275 const struct gl_viewport_attrib
*vp
;
1276 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1277 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1278 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1281 case GL_MULTISAMPLE_BIT_ARB
:
1283 const struct gl_multisample_attrib
*ms
;
1284 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1286 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1290 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1292 GL_SAMPLE_COVERAGE
);
1294 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1295 ms
->SampleAlphaToCoverage
,
1296 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1298 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1299 ms
->SampleAlphaToOne
,
1300 GL_SAMPLE_ALPHA_TO_ONE
);
1302 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1303 ms
->SampleCoverageInvert
);
1308 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1321 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1325 copy_pixelstore(struct gl_context
*ctx
,
1326 struct gl_pixelstore_attrib
*dst
,
1327 const struct gl_pixelstore_attrib
*src
)
1329 dst
->Alignment
= src
->Alignment
;
1330 dst
->RowLength
= src
->RowLength
;
1331 dst
->SkipPixels
= src
->SkipPixels
;
1332 dst
->SkipRows
= src
->SkipRows
;
1333 dst
->ImageHeight
= src
->ImageHeight
;
1334 dst
->SkipImages
= src
->SkipImages
;
1335 dst
->SwapBytes
= src
->SwapBytes
;
1336 dst
->LsbFirst
= src
->LsbFirst
;
1337 dst
->Invert
= src
->Invert
;
1338 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1342 #define GL_CLIENT_PACK_BIT (1<<20)
1343 #define GL_CLIENT_UNPACK_BIT (1<<21)
1346 * Copy gl_array_object from src to dest.
1347 * 'dest' must be in an initialized state.
1350 copy_array_object(struct gl_context
*ctx
,
1351 struct gl_array_object
*dest
,
1352 struct gl_array_object
*src
)
1359 /* In theory must be the same anyway, but on recreate make sure it matches */
1360 dest
->ARBsemantics
= src
->ARBsemantics
;
1362 for (i
= 0; i
< Elements(src
->_VertexAttrib
); i
++) {
1363 _mesa_copy_client_array(ctx
, &dest
->_VertexAttrib
[i
], &src
->_VertexAttrib
[i
]);
1364 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1365 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->VertexBinding
[i
], &src
->VertexBinding
[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
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1390 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1391 dest
->RestartIndex
= src
->RestartIndex
;
1393 /* skip RebindArrays */
1396 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1398 /* skip ArrayBufferObj */
1399 /* skip ElementArrayBufferObj */
1403 * Save the content of src to dest.
1406 save_array_attrib(struct gl_context
*ctx
,
1407 struct gl_array_attrib
*dest
,
1408 struct gl_array_attrib
*src
)
1410 /* Set the Name, needed for restore, but do never overwrite.
1411 * Needs to match value in the object hash. */
1412 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1413 /* And copy all of the rest. */
1414 copy_array_attrib(ctx
, dest
, src
, false);
1416 /* Just reference them here */
1417 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1418 src
->ArrayBufferObj
);
1419 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1420 src
->ArrayObj
->ElementArrayBufferObj
);
1424 * Restore the content of src to dest.
1427 restore_array_attrib(struct gl_context
*ctx
,
1428 struct gl_array_attrib
*dest
,
1429 struct gl_array_attrib
*src
)
1431 /* The ARB_vertex_array_object spec says:
1433 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1434 * if array is not a name returned from a previous call to
1435 * GenVertexArrays, or if such a name has since been deleted with
1436 * DeleteVertexArrays."
1438 * Therefore popping a deleted VAO cannot magically recreate it.
1440 * The semantics of objects created using APPLE_vertex_array_objects behave
1441 * differently. These objects expect to be recreated by pop. Alas.
1443 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1444 && src
->ArrayObj
->ARBsemantics
);
1446 if (arb_vao
&& !_mesa_IsVertexArray(src
->ArrayObj
->Name
))
1449 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1451 /* Restore or recreate the buffer objects by the names ... */
1453 || src
->ArrayBufferObj
->Name
== 0
1454 || _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1455 /* ... and restore its content */
1456 copy_array_attrib(ctx
, dest
, src
, false);
1458 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1459 src
->ArrayBufferObj
->Name
);
1461 copy_array_attrib(ctx
, dest
, src
, true);
1465 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1466 || _mesa_IsBuffer(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1467 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1468 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1472 * init/alloc the fields of 'attrib'.
1473 * Needs to the init part matching free_array_attrib_data below.
1476 init_array_attrib_data(struct gl_context
*ctx
,
1477 struct gl_array_attrib
*attrib
)
1479 /* Get a non driver gl_array_object. */
1480 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1481 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1485 * Free/unreference the fields of 'attrib' but don't delete it (that's
1486 * done later in the calling code).
1487 * Needs to the cleanup part matching init_array_attrib_data above.
1490 free_array_attrib_data(struct gl_context
*ctx
,
1491 struct gl_array_attrib
*attrib
)
1493 /* We use a non driver array object, so don't just unref since we would
1494 * end up using the drivers DeleteArrayObject function for deletion. */
1495 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1496 attrib
->ArrayObj
= 0;
1497 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1502 _mesa_PushClientAttrib(GLbitfield mask
)
1504 struct gl_attrib_node
*head
;
1506 GET_CURRENT_CONTEXT(ctx
);
1508 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1509 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1513 /* Build linked list of attribute nodes which save all attribute
1514 * groups specified by the mask.
1518 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1519 struct gl_pixelstore_attrib
*attr
;
1520 /* packing attribs */
1521 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1522 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1523 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1524 /* unpacking attribs */
1525 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1526 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1527 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1530 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1531 struct gl_array_attrib
*attr
;
1532 attr
= CALLOC_STRUCT( gl_array_attrib
);
1533 init_array_attrib_data(ctx
, attr
);
1534 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1535 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1538 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1539 ctx
->ClientAttribStackDepth
++;
1546 _mesa_PopClientAttrib(void)
1548 struct gl_attrib_node
*node
, *next
;
1550 GET_CURRENT_CONTEXT(ctx
);
1551 FLUSH_VERTICES(ctx
, 0);
1553 if (ctx
->ClientAttribStackDepth
== 0) {
1554 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1558 ctx
->ClientAttribStackDepth
--;
1559 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1562 switch (node
->kind
) {
1563 case GL_CLIENT_PACK_BIT
:
1565 struct gl_pixelstore_attrib
*store
=
1566 (struct gl_pixelstore_attrib
*) node
->data
;
1567 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1568 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
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
);
1579 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1580 struct gl_array_attrib
* attr
=
1581 (struct gl_array_attrib
*) node
->data
;
1582 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1583 free_array_attrib_data(ctx
, attr
);
1584 ctx
->NewState
|= _NEW_ARRAY
;
1588 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1601 * Free any attribute state data that might be attached to the context.
1604 _mesa_free_attrib_data(struct gl_context
*ctx
)
1606 while (ctx
->AttribStackDepth
> 0) {
1607 struct gl_attrib_node
*attr
, *next
;
1609 ctx
->AttribStackDepth
--;
1610 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1613 if (attr
->kind
== GL_TEXTURE_BIT
) {
1614 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1616 /* clear references to the saved texture objects */
1617 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1618 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1619 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1622 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1625 /* any other chunks of state that requires special handling? */
1637 void _mesa_init_attrib( struct gl_context
*ctx
)
1639 /* Renderer and client attribute stacks */
1640 ctx
->AttribStackDepth
= 0;
1641 ctx
->ClientAttribStackDepth
= 0;