2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
46 #include "multisample.h"
60 #include "main/dispatch.h"
66 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
68 struct gl_enable_attrib
73 GLbitfield ClipPlanes
;
74 GLboolean ColorMaterial
;
80 GLboolean Light
[MAX_LIGHTS
];
83 GLboolean LineStipple
;
84 GLboolean IndexLogicOp
;
85 GLboolean ColorLogicOp
;
90 GLboolean Map1TextureCoord1
;
91 GLboolean Map1TextureCoord2
;
92 GLboolean Map1TextureCoord3
;
93 GLboolean Map1TextureCoord4
;
94 GLboolean Map1Vertex3
;
95 GLboolean Map1Vertex4
;
99 GLboolean Map2TextureCoord1
;
100 GLboolean Map2TextureCoord2
;
101 GLboolean Map2TextureCoord3
;
102 GLboolean Map2TextureCoord4
;
103 GLboolean Map2Vertex3
;
104 GLboolean Map2Vertex4
;
107 GLboolean PixelTexture
;
108 GLboolean PointSmooth
;
109 GLboolean PolygonOffsetPoint
;
110 GLboolean PolygonOffsetLine
;
111 GLboolean PolygonOffsetFill
;
112 GLboolean PolygonSmooth
;
113 GLboolean PolygonStipple
;
114 GLboolean RescaleNormals
;
117 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
118 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
121 GLboolean SampleCoverage
; /* GL_ARB_multisample */
122 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
124 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
125 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
127 /* GL_ARB_vertex_program */
128 GLboolean VertexProgram
;
129 GLboolean VertexProgramPointSize
;
130 GLboolean VertexProgramTwoSide
;
132 /* GL_ARB_fragment_program */
133 GLboolean FragmentProgram
;
135 /* GL_ARB_point_sprite / GL_NV_point_sprite */
136 GLboolean PointSprite
;
137 GLboolean FragmentShaderATI
;
139 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
140 GLboolean sRGBEnabled
;
145 * Node for the attribute stack.
147 struct gl_attrib_node
151 struct gl_attrib_node
*next
;
157 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
161 struct gl_texture_attrib Texture
; /**< The usual context state */
163 /** to save per texture object state (wrap modes, filters, etc): */
164 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
167 * To save references to texture objects (so they don't get accidentally
168 * deleted while saved in the attribute stack).
170 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
172 /* We need to keep a reference to the shared state. That's where the
173 * default texture objects are kept. We don't want that state to be
174 * freed while the attribute stack contains pointers to any default
177 struct gl_shared_state
*SharedRef
;
182 * Allocate new attribute node of given type/kind. Attach payload data.
183 * Insert it into the linked list named by 'head'.
186 save_attrib_data(struct gl_attrib_node
**head
,
187 GLbitfield kind
, void *payload
)
189 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
204 _mesa_PushAttrib(GLbitfield mask
)
206 struct gl_attrib_node
*head
;
208 GET_CURRENT_CONTEXT(ctx
);
210 if (MESA_VERBOSE
& VERBOSE_API
)
211 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
213 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
214 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
218 /* Build linked list of attribute nodes which save all attribute */
219 /* groups specified by the mask. */
222 if (mask
& GL_ACCUM_BUFFER_BIT
) {
223 struct gl_accum_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_accum_attrib
);
225 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
226 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
229 if (mask
& GL_COLOR_BUFFER_BIT
) {
231 struct gl_colorbuffer_attrib
*attr
;
232 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
233 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
234 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
235 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
236 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
237 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
240 if (mask
& GL_CURRENT_BIT
) {
241 struct gl_current_attrib
*attr
;
242 FLUSH_CURRENT( ctx
, 0 );
243 attr
= MALLOC_STRUCT( gl_current_attrib
);
244 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
245 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
248 if (mask
& GL_DEPTH_BUFFER_BIT
) {
249 struct gl_depthbuffer_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
251 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
252 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
255 if (mask
& GL_ENABLE_BIT
) {
256 struct gl_enable_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_enable_attrib
);
259 /* Copy enable flags from all other attributes into the enable struct. */
260 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
261 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
262 attr
->Blend
= ctx
->Color
.BlendEnabled
;
263 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
264 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
265 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
266 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
267 attr
->DepthTest
= ctx
->Depth
.Test
;
268 attr
->Dither
= ctx
->Color
.DitherFlag
;
269 attr
->Fog
= ctx
->Fog
.Enabled
;
270 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
271 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
273 attr
->Lighting
= ctx
->Light
.Enabled
;
274 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
275 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
276 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
277 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
278 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
279 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
280 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
281 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
282 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
283 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
284 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
285 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
286 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
287 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
288 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
289 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
290 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
291 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
292 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
293 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
294 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
295 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
296 attr
->Normalize
= ctx
->Transform
.Normalize
;
297 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
298 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
299 attr
->PointSprite
= ctx
->Point
.PointSprite
;
300 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
301 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
302 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
303 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
304 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
305 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
306 attr
->Scissor
= ctx
->Scissor
.Enabled
;
307 attr
->Stencil
= ctx
->Stencil
.Enabled
;
308 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
309 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
310 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
311 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
312 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
313 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
314 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
315 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
317 /* GL_ARB_vertex_program */
318 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
319 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
320 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
322 /* GL_ARB_fragment_program */
323 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
325 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
327 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
328 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
331 if (mask
& GL_EVAL_BIT
) {
332 struct gl_eval_attrib
*attr
;
333 attr
= MALLOC_STRUCT( gl_eval_attrib
);
334 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
335 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
338 if (mask
& GL_FOG_BIT
) {
339 struct gl_fog_attrib
*attr
;
340 attr
= MALLOC_STRUCT( gl_fog_attrib
);
341 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
342 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
345 if (mask
& GL_HINT_BIT
) {
346 struct gl_hint_attrib
*attr
;
347 attr
= MALLOC_STRUCT( gl_hint_attrib
);
348 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
349 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
352 if (mask
& GL_LIGHTING_BIT
) {
353 struct gl_light_attrib
*attr
;
354 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
355 attr
= MALLOC_STRUCT( gl_light_attrib
);
356 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
357 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
360 if (mask
& GL_LINE_BIT
) {
361 struct gl_line_attrib
*attr
;
362 attr
= MALLOC_STRUCT( gl_line_attrib
);
363 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
364 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
367 if (mask
& GL_LIST_BIT
) {
368 struct gl_list_attrib
*attr
;
369 attr
= MALLOC_STRUCT( gl_list_attrib
);
370 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
371 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
374 if (mask
& GL_PIXEL_MODE_BIT
) {
375 struct gl_pixel_attrib
*attr
;
376 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
377 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
378 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
379 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
380 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
383 if (mask
& GL_POINT_BIT
) {
384 struct gl_point_attrib
*attr
;
385 attr
= MALLOC_STRUCT( gl_point_attrib
);
386 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
387 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
390 if (mask
& GL_POLYGON_BIT
) {
391 struct gl_polygon_attrib
*attr
;
392 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
393 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
394 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
397 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
399 stipple
= malloc( 32*sizeof(GLuint
) );
400 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
401 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
404 if (mask
& GL_SCISSOR_BIT
) {
405 struct gl_scissor_attrib
*attr
;
406 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
407 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
408 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
411 if (mask
& GL_STENCIL_BUFFER_BIT
) {
412 struct gl_stencil_attrib
*attr
;
413 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
414 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
415 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
418 if (mask
& GL_TEXTURE_BIT
) {
419 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
427 _mesa_lock_context_textures(ctx
);
429 /* copy/save the bulk of texture state here */
430 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
432 /* Save references to the currently bound texture objects so they don't
433 * accidentally get deleted while referenced in the attribute stack.
435 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
436 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
437 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
438 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
442 /* copy state/contents of the currently bound texture objects */
443 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
444 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
445 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
446 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
450 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
452 _mesa_unlock_context_textures(ctx
);
454 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
457 if (mask
& GL_TRANSFORM_BIT
) {
458 struct gl_transform_attrib
*attr
;
459 attr
= MALLOC_STRUCT( gl_transform_attrib
);
460 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
461 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
464 if (mask
& GL_VIEWPORT_BIT
) {
465 struct gl_viewport_attrib
*attr
;
466 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
467 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
468 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
471 /* GL_ARB_multisample */
472 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
473 struct gl_multisample_attrib
*attr
;
474 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
475 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
476 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
480 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
481 ctx
->AttribStackDepth
++;
487 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
489 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
492 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
493 if ((VALUE) != (NEWVALUE)) { \
494 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
497 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
498 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
499 if (ctx
->Extensions
.EXT_draw_buffers2
) {
501 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
502 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
506 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
510 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
511 const GLuint mask
= 1 << i
;
512 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
513 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
514 !!(enable
->ClipPlanes
& mask
));
517 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
519 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
520 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
522 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
523 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
524 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
525 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
526 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
527 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
529 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
531 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
534 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
538 GL_MAP1_TEXTURE_COORD_1
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
540 GL_MAP1_TEXTURE_COORD_2
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
542 GL_MAP1_TEXTURE_COORD_3
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
544 GL_MAP1_TEXTURE_COORD_4
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
547 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
550 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
552 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
554 GL_MAP2_TEXTURE_COORD_1
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
556 GL_MAP2_TEXTURE_COORD_2
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
558 GL_MAP2_TEXTURE_COORD_3
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
560 GL_MAP2_TEXTURE_COORD_4
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
563 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
566 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
567 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
568 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
569 GL_RESCALE_NORMAL_EXT
);
570 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
571 enable
->RasterPositionUnclipped
,
572 GL_RASTER_POSITION_UNCLIPPED_IBM
);
573 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
575 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
576 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
579 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
580 GL_POLYGON_OFFSET_POINT
);
581 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
582 GL_POLYGON_OFFSET_LINE
);
583 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
584 GL_POLYGON_OFFSET_FILL
);
585 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
587 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
589 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
590 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
591 if (ctx
->Extensions
.EXT_stencil_two_side
) {
592 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
594 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
596 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
597 enable
->SampleAlphaToCoverage
,
598 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
599 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
600 enable
->SampleAlphaToOne
,
601 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
602 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
603 enable
->SampleCoverage
,
604 GL_SAMPLE_COVERAGE_ARB
);
605 /* GL_ARB_vertex_program */
606 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
607 enable
->VertexProgram
,
608 GL_VERTEX_PROGRAM_ARB
);
609 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
610 enable
->VertexProgramPointSize
,
611 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
612 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
613 enable
->VertexProgramTwoSide
,
614 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
616 /* GL_ARB_fragment_program */
617 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
618 enable
->FragmentProgram
,
619 GL_FRAGMENT_PROGRAM_ARB
);
621 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
622 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
623 GL_FRAMEBUFFER_SRGB
);
625 /* texture unit enables */
626 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
627 const GLbitfield enabled
= enable
->Texture
[i
];
628 const GLbitfield genEnabled
= enable
->TexGen
[i
];
630 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
631 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
633 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
634 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
635 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
636 if (ctx
->Extensions
.NV_texture_rectangle
) {
637 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
638 !!(enabled
& TEXTURE_RECT_BIT
));
640 if (ctx
->Extensions
.ARB_texture_cube_map
) {
641 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
642 !!(enabled
& TEXTURE_CUBE_BIT
));
646 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
647 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
648 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
649 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
650 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
651 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
655 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
660 * Pop/restore texture attribute/group state.
663 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
667 _mesa_lock_context_textures(ctx
);
669 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
670 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
673 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
674 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
675 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
676 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
677 if (ctx
->Extensions
.ARB_texture_cube_map
) {
678 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
679 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
681 if (ctx
->Extensions
.NV_texture_rectangle
) {
682 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
683 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
685 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
686 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
687 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
688 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
689 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
690 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
691 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
692 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
693 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
694 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
695 /* Eye plane done differently to avoid re-transformation */
697 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
698 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
699 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
700 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
701 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
702 if (ctx
->Driver
.TexGen
) {
703 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
704 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
705 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
706 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
709 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
710 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
711 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
712 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
713 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
715 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
716 unit
->Combine
.ModeRGB
);
717 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
718 unit
->Combine
.ModeA
);
720 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
722 for (i
= 0; i
< n
; i
++) {
723 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
724 unit
->Combine
.SourceRGB
[i
]);
725 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
726 unit
->Combine
.SourceA
[i
]);
727 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
728 unit
->Combine
.OperandRGB
[i
]);
729 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
730 unit
->Combine
.OperandA
[i
]);
733 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
734 1 << unit
->Combine
.ScaleShiftRGB
);
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
736 1 << unit
->Combine
.ScaleShiftA
);
738 /* Restore texture object state for each target */
739 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
740 const struct gl_texture_object
*obj
= NULL
;
741 const struct gl_sampler_object
*samp
;
744 obj
= &texstate
->SavedObj
[u
][tgt
];
746 /* don't restore state for unsupported targets to prevent
749 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
750 !ctx
->Extensions
.ARB_texture_cube_map
) {
753 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
754 !ctx
->Extensions
.NV_texture_rectangle
) {
757 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
758 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
759 !ctx
->Extensions
.EXT_texture_array
) {
762 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
763 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
765 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
767 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
769 else if (obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE
||
770 obj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
773 target
= obj
->Target
;
775 _mesa_BindTexture(target
, obj
->Name
);
777 samp
= &obj
->Sampler
;
779 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
780 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
781 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
782 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
783 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
784 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
785 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
786 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
787 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
788 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
789 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
790 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
791 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
792 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
793 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
794 samp
->MaxAnisotropy
);
796 if (ctx
->Extensions
.ARB_shadow
) {
797 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
799 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
802 if (ctx
->Extensions
.ARB_depth_texture
)
803 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
806 /* remove saved references to the texture objects */
807 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
808 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
812 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
814 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
816 _mesa_unlock_context_textures(ctx
);
821 * This function is kind of long just because we have to call a lot
822 * of device driver functions to update device driver state.
824 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
825 * in order to restore GL state. This isn't terribly efficient but it
826 * ensures that dirty flags and any derived state gets updated correctly.
827 * We could at least check if the value to restore equals the current value
828 * and then skip the Mesa call.
831 _mesa_PopAttrib(void)
833 struct gl_attrib_node
*attr
, *next
;
834 GET_CURRENT_CONTEXT(ctx
);
835 FLUSH_VERTICES(ctx
, 0);
837 if (ctx
->AttribStackDepth
== 0) {
838 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
842 ctx
->AttribStackDepth
--;
843 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
847 if (MESA_VERBOSE
& VERBOSE_API
) {
848 _mesa_debug(ctx
, "glPopAttrib %s\n",
849 _mesa_lookup_enum_by_nr(attr
->kind
));
852 switch (attr
->kind
) {
853 case GL_ACCUM_BUFFER_BIT
:
855 const struct gl_accum_attrib
*accum
;
856 accum
= (const struct gl_accum_attrib
*) attr
->data
;
857 _mesa_ClearAccum(accum
->ClearColor
[0],
858 accum
->ClearColor
[1],
859 accum
->ClearColor
[2],
860 accum
->ClearColor
[3]);
863 case GL_COLOR_BUFFER_BIT
:
865 const struct gl_colorbuffer_attrib
*color
;
867 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
868 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
869 _mesa_ClearColor(color
->ClearColor
.f
[0],
870 color
->ClearColor
.f
[1],
871 color
->ClearColor
.f
[2],
872 color
->ClearColor
.f
[3]);
873 _mesa_IndexMask(color
->IndexMask
);
874 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
875 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
876 (GLboolean
) (color
->ColorMask
[0][1] != 0),
877 (GLboolean
) (color
->ColorMask
[0][2] != 0),
878 (GLboolean
) (color
->ColorMask
[0][3] != 0));
882 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
884 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
885 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
886 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
887 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
891 /* Need to determine if more than one color output is
892 * specified. If so, call glDrawBuffersARB, else call
893 * glDrawBuffer(). This is a subtle, but essential point
894 * since GL_FRONT (for example) is illegal for the former
895 * function, but legal for the later.
897 GLboolean multipleBuffers
= GL_FALSE
;
900 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
901 if (color
->DrawBuffer
[i
] != GL_NONE
) {
902 multipleBuffers
= GL_TRUE
;
906 /* Call the API_level functions, not _mesa_drawbuffers()
907 * since we need to do error checking on the pop'd
909 * Ex: if GL_FRONT were pushed, but we're popping with a
910 * user FBO bound, GL_FRONT will be illegal and we'll need
911 * to record that error. Per OpenGL ARB decision.
914 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
,
917 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
919 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
920 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
921 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
922 if (ctx
->Extensions
.EXT_draw_buffers2
) {
924 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
925 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
926 (color
->BlendEnabled
>> i
) & 1);
930 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
933 if (ctx
->Color
._BlendFuncPerBuffer
||
934 ctx
->Color
._BlendEquationPerBuffer
) {
935 /* set blend per buffer */
937 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
938 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
939 color
->Blend
[buf
].DstRGB
,
940 color
->Blend
[buf
].SrcA
,
941 color
->Blend
[buf
].DstA
);
942 _mesa_BlendEquationSeparateiARB(buf
,
943 color
->Blend
[buf
].EquationRGB
,
944 color
->Blend
[buf
].EquationA
);
948 /* set same blend modes for all buffers */
949 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
950 color
->Blend
[0].DstRGB
,
951 color
->Blend
[0].SrcA
,
952 color
->Blend
[0].DstA
);
953 /* This special case is because glBlendEquationSeparateEXT
954 * cannot take GL_LOGIC_OP as a parameter.
956 if (color
->Blend
[0].EquationRGB
==
957 color
->Blend
[0].EquationA
) {
958 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
961 _mesa_BlendEquationSeparate(
962 color
->Blend
[0].EquationRGB
,
963 color
->Blend
[0].EquationA
);
966 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
967 color
->BlendColorUnclamped
[1],
968 color
->BlendColorUnclamped
[2],
969 color
->BlendColorUnclamped
[3]);
970 _mesa_LogicOp(color
->LogicOp
);
971 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
972 color
->ColorLogicOpEnabled
);
973 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
974 color
->IndexLogicOpEnabled
);
975 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
976 if (ctx
->Extensions
.ARB_color_buffer_float
)
977 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
,
978 color
->ClampFragmentColor
);
979 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
981 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
982 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
983 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
987 FLUSH_CURRENT( ctx
, 0 );
988 memcpy( &ctx
->Current
, attr
->data
,
989 sizeof(struct gl_current_attrib
) );
991 case GL_DEPTH_BUFFER_BIT
:
993 const struct gl_depthbuffer_attrib
*depth
;
994 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
995 _mesa_DepthFunc(depth
->Func
);
996 _mesa_ClearDepth(depth
->Clear
);
997 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
998 _mesa_DepthMask(depth
->Mask
);
1003 const struct gl_enable_attrib
*enable
;
1004 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1005 pop_enable_group(ctx
, enable
);
1006 ctx
->NewState
|= _NEW_ALL
;
1010 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1011 ctx
->NewState
|= _NEW_EVAL
;
1015 const struct gl_fog_attrib
*fog
;
1016 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1017 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1018 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1019 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1020 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1021 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1022 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1023 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1028 const struct gl_hint_attrib
*hint
;
1029 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1030 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1031 hint
->PerspectiveCorrection
);
1032 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1033 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1034 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1035 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1036 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1037 hint
->TextureCompression
);
1040 case GL_LIGHTING_BIT
:
1043 const struct gl_light_attrib
*light
;
1044 light
= (const struct gl_light_attrib
*) attr
->data
;
1045 /* lighting enable */
1046 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1047 /* per-light state */
1048 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1049 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1051 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1052 const struct gl_light
*l
= &light
->Light
[i
];
1053 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1054 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1055 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1056 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1057 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1058 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1060 GLfloat p
[4] = { 0 };
1061 p
[0] = l
->SpotExponent
;
1062 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1065 GLfloat p
[4] = { 0 };
1066 p
[0] = l
->SpotCutoff
;
1067 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1070 GLfloat p
[4] = { 0 };
1071 p
[0] = l
->ConstantAttenuation
;
1072 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1075 GLfloat p
[4] = { 0 };
1076 p
[0] = l
->LinearAttenuation
;
1077 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1080 GLfloat p
[4] = { 0 };
1081 p
[0] = l
->QuadraticAttenuation
;
1082 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1086 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1087 light
->Model
.Ambient
);
1088 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1089 (GLfloat
) light
->Model
.LocalViewer
);
1090 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1091 (GLfloat
) light
->Model
.TwoSide
);
1092 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1093 (GLfloat
) light
->Model
.ColorControl
);
1095 _mesa_ShadeModel(light
->ShadeModel
);
1096 /* color material */
1097 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1098 light
->ColorMaterialMode
);
1099 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1100 light
->ColorMaterialEnabled
);
1102 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1103 sizeof(struct gl_material
));
1104 if (ctx
->Extensions
.ARB_color_buffer_float
) {
1105 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
,
1106 light
->ClampVertexColor
);
1112 const struct gl_line_attrib
*line
;
1113 line
= (const struct gl_line_attrib
*) attr
->data
;
1114 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1115 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1116 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1117 _mesa_LineWidth(line
->Width
);
1121 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1123 case GL_PIXEL_MODE_BIT
:
1124 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1125 /* XXX what other pixel state needs to be set by function calls? */
1126 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1127 ctx
->NewState
|= _NEW_PIXEL
;
1131 const struct gl_point_attrib
*point
;
1132 point
= (const struct gl_point_attrib
*) attr
->data
;
1133 _mesa_PointSize(point
->Size
);
1134 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1135 if (ctx
->Extensions
.EXT_point_parameters
) {
1136 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1138 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1140 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1142 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1145 if (ctx
->Extensions
.NV_point_sprite
1146 || ctx
->Extensions
.ARB_point_sprite
) {
1148 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1149 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1150 (GLint
) point
->CoordReplace
[u
]);
1152 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1153 if (ctx
->Extensions
.NV_point_sprite
)
1154 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1155 ctx
->Point
.SpriteRMode
);
1157 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1158 || ctx
->API
== API_OPENGL_CORE
)
1159 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1160 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1164 case GL_POLYGON_BIT
:
1166 const struct gl_polygon_attrib
*polygon
;
1167 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1168 _mesa_CullFace(polygon
->CullFaceMode
);
1169 _mesa_FrontFace(polygon
->FrontFace
);
1170 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1171 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1172 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1173 polygon
->OffsetUnits
);
1174 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1175 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1176 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1177 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1178 polygon
->OffsetPoint
);
1179 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1180 polygon
->OffsetLine
);
1181 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1182 polygon
->OffsetFill
);
1185 case GL_POLYGON_STIPPLE_BIT
:
1186 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1187 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1188 if (ctx
->Driver
.PolygonStipple
)
1189 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1191 case GL_SCISSOR_BIT
:
1193 const struct gl_scissor_attrib
*scissor
;
1194 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1195 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1196 scissor
->Width
, scissor
->Height
);
1197 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1200 case GL_STENCIL_BUFFER_BIT
:
1202 const struct gl_stencil_attrib
*stencil
;
1203 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1204 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1205 _mesa_ClearStencil(stencil
->Clear
);
1206 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1207 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1208 stencil
->TestTwoSide
);
1209 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1210 ? GL_BACK
: GL_FRONT
);
1213 _mesa_StencilFuncSeparate(GL_FRONT
,
1214 stencil
->Function
[0],
1216 stencil
->ValueMask
[0]);
1217 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1218 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1219 stencil
->ZFailFunc
[0],
1220 stencil
->ZPassFunc
[0]);
1222 _mesa_StencilFuncSeparate(GL_BACK
,
1223 stencil
->Function
[1],
1225 stencil
->ValueMask
[1]);
1226 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1227 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1228 stencil
->ZFailFunc
[1],
1229 stencil
->ZPassFunc
[1]);
1232 case GL_TRANSFORM_BIT
:
1235 const struct gl_transform_attrib
*xform
;
1236 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1237 _mesa_MatrixMode(xform
->MatrixMode
);
1238 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1239 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1241 /* restore clip planes */
1242 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1243 const GLuint mask
= 1 << i
;
1244 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1245 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1246 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1247 !!(xform
->ClipPlanesEnabled
& mask
));
1248 if (ctx
->Driver
.ClipPlane
)
1249 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1252 /* normalize/rescale */
1253 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1254 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1255 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1256 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1257 ctx
->Transform
.RescaleNormals
);
1258 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1259 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1260 ctx
->Transform
.DepthClamp
);
1263 case GL_TEXTURE_BIT
:
1265 struct texture_state
*texstate
1266 = (struct texture_state
*) attr
->data
;
1267 pop_texture_group(ctx
, texstate
);
1268 ctx
->NewState
|= _NEW_TEXTURE
;
1271 case GL_VIEWPORT_BIT
:
1273 const struct gl_viewport_attrib
*vp
;
1274 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1275 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1276 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1279 case GL_MULTISAMPLE_BIT_ARB
:
1281 const struct gl_multisample_attrib
*ms
;
1282 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1284 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1288 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1290 GL_SAMPLE_COVERAGE
);
1292 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1293 ms
->SampleAlphaToCoverage
,
1294 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1296 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1297 ms
->SampleAlphaToOne
,
1298 GL_SAMPLE_ALPHA_TO_ONE
);
1300 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1301 ms
->SampleCoverageInvert
);
1306 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1319 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1323 copy_pixelstore(struct gl_context
*ctx
,
1324 struct gl_pixelstore_attrib
*dst
,
1325 const struct gl_pixelstore_attrib
*src
)
1327 dst
->Alignment
= src
->Alignment
;
1328 dst
->RowLength
= src
->RowLength
;
1329 dst
->SkipPixels
= src
->SkipPixels
;
1330 dst
->SkipRows
= src
->SkipRows
;
1331 dst
->ImageHeight
= src
->ImageHeight
;
1332 dst
->SkipImages
= src
->SkipImages
;
1333 dst
->SwapBytes
= src
->SwapBytes
;
1334 dst
->LsbFirst
= src
->LsbFirst
;
1335 dst
->Invert
= src
->Invert
;
1336 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1340 #define GL_CLIENT_PACK_BIT (1<<20)
1341 #define GL_CLIENT_UNPACK_BIT (1<<21)
1344 * Copy gl_array_object from src to dest.
1345 * 'dest' must be in an initialized state.
1348 copy_array_object(struct gl_context
*ctx
,
1349 struct gl_array_object
*dest
,
1350 struct gl_array_object
*src
)
1357 /* In theory must be the same anyway, but on recreate make sure it matches */
1358 dest
->ARBsemantics
= src
->ARBsemantics
;
1360 for (i
= 0; i
< Elements(src
->_VertexAttrib
); i
++) {
1361 _mesa_copy_client_array(ctx
, &dest
->_VertexAttrib
[i
], &src
->_VertexAttrib
[i
]);
1362 _mesa_copy_vertex_attrib_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1363 _mesa_copy_vertex_buffer_binding(ctx
, &dest
->VertexBinding
[i
], &src
->VertexBinding
[i
]);
1366 /* _Enabled must be the same than on push */
1367 dest
->_Enabled
= src
->_Enabled
;
1368 dest
->_MaxElement
= src
->_MaxElement
;
1372 * Copy gl_array_attrib from src to dest.
1373 * 'dest' must be in an initialized state.
1376 copy_array_attrib(struct gl_context
*ctx
,
1377 struct gl_array_attrib
*dest
,
1378 struct gl_array_attrib
*src
,
1382 /* skip DefaultArrayObj, Objects */
1383 dest
->ActiveTexture
= src
->ActiveTexture
;
1384 dest
->LockFirst
= src
->LockFirst
;
1385 dest
->LockCount
= src
->LockCount
;
1386 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1387 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
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_IsVertexArray(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_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1453 /* ... and restore its content */
1454 copy_array_attrib(ctx
, dest
, src
, false);
1456 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1457 src
->ArrayBufferObj
->Name
);
1459 copy_array_attrib(ctx
, dest
, src
, true);
1463 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1464 || _mesa_IsBuffer(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1465 _mesa_BindBuffer(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
);
1506 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1507 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1511 /* Build linked list of attribute nodes which save all attribute
1512 * groups specified by the mask.
1516 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1517 struct gl_pixelstore_attrib
*attr
;
1518 /* packing attribs */
1519 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1520 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1521 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1522 /* unpacking attribs */
1523 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1524 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1525 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1528 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1529 struct gl_array_attrib
*attr
;
1530 attr
= CALLOC_STRUCT( gl_array_attrib
);
1531 init_array_attrib_data(ctx
, attr
);
1532 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1533 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1536 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1537 ctx
->ClientAttribStackDepth
++;
1544 _mesa_PopClientAttrib(void)
1546 struct gl_attrib_node
*node
, *next
;
1548 GET_CURRENT_CONTEXT(ctx
);
1549 FLUSH_VERTICES(ctx
, 0);
1551 if (ctx
->ClientAttribStackDepth
== 0) {
1552 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1556 ctx
->ClientAttribStackDepth
--;
1557 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1560 switch (node
->kind
) {
1561 case GL_CLIENT_PACK_BIT
:
1563 struct gl_pixelstore_attrib
*store
=
1564 (struct gl_pixelstore_attrib
*) node
->data
;
1565 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1566 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1569 case GL_CLIENT_UNPACK_BIT
:
1571 struct gl_pixelstore_attrib
*store
=
1572 (struct gl_pixelstore_attrib
*) node
->data
;
1573 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1574 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1577 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1578 struct gl_array_attrib
* attr
=
1579 (struct gl_array_attrib
*) node
->data
;
1580 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1581 free_array_attrib_data(ctx
, attr
);
1582 ctx
->NewState
|= _NEW_ARRAY
;
1586 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1599 * Free any attribute state data that might be attached to the context.
1602 _mesa_free_attrib_data(struct gl_context
*ctx
)
1604 while (ctx
->AttribStackDepth
> 0) {
1605 struct gl_attrib_node
*attr
, *next
;
1607 ctx
->AttribStackDepth
--;
1608 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1611 if (attr
->kind
== GL_TEXTURE_BIT
) {
1612 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1614 /* clear references to the saved texture objects */
1615 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1616 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1617 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1620 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1623 /* any other chunks of state that requires special handling? */
1635 void _mesa_init_attrib( struct gl_context
*ctx
)
1637 /* Renderer and client attribute stacks */
1638 ctx
->AttribStackDepth
= 0;
1639 ctx
->ClientAttribStackDepth
= 0;