2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
46 #include "mfeatures.h"
47 #include "multisample.h"
61 #include "main/dispatch.h"
67 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
69 struct gl_enable_attrib
74 GLbitfield ClipPlanes
;
75 GLboolean ColorMaterial
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
100 GLboolean Map2TextureCoord1
;
101 GLboolean Map2TextureCoord2
;
102 GLboolean Map2TextureCoord3
;
103 GLboolean Map2TextureCoord4
;
104 GLboolean Map2Vertex3
;
105 GLboolean Map2Vertex4
;
108 GLboolean PixelTexture
;
109 GLboolean PointSmooth
;
110 GLboolean PolygonOffsetPoint
;
111 GLboolean PolygonOffsetLine
;
112 GLboolean PolygonOffsetFill
;
113 GLboolean PolygonSmooth
;
114 GLboolean PolygonStipple
;
115 GLboolean RescaleNormals
;
118 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
119 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
122 GLboolean SampleCoverage
; /* GL_ARB_multisample */
123 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
125 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
126 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
128 /* GL_ARB_vertex_program */
129 GLboolean VertexProgram
;
130 GLboolean VertexProgramPointSize
;
131 GLboolean VertexProgramTwoSide
;
133 /* GL_ARB_fragment_program */
134 GLboolean FragmentProgram
;
136 /* GL_ARB_point_sprite / GL_NV_point_sprite */
137 GLboolean PointSprite
;
138 GLboolean FragmentShaderATI
;
140 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
141 GLboolean sRGBEnabled
;
146 * Node for the attribute stack.
148 struct gl_attrib_node
152 struct gl_attrib_node
*next
;
158 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
162 struct gl_texture_attrib Texture
; /**< The usual context state */
164 /** to save per texture object state (wrap modes, filters, etc): */
165 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
168 * To save references to texture objects (so they don't get accidentally
169 * deleted while saved in the attribute stack).
171 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
173 /* We need to keep a reference to the shared state. That's where the
174 * default texture objects are kept. We don't want that state to be
175 * freed while the attribute stack contains pointers to any default
178 struct gl_shared_state
*SharedRef
;
183 * Allocate new attribute node of given type/kind. Attach payload data.
184 * Insert it into the linked list named by 'head'.
187 save_attrib_data(struct gl_attrib_node
**head
,
188 GLbitfield kind
, void *payload
)
190 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
205 _mesa_PushAttrib(GLbitfield mask
)
207 struct gl_attrib_node
*head
;
209 GET_CURRENT_CONTEXT(ctx
);
211 if (MESA_VERBOSE
& VERBOSE_API
)
212 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
214 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
215 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
219 /* Build linked list of attribute nodes which save all attribute */
220 /* groups specified by the mask. */
223 if (mask
& GL_ACCUM_BUFFER_BIT
) {
224 struct gl_accum_attrib
*attr
;
225 attr
= MALLOC_STRUCT( gl_accum_attrib
);
226 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
227 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
230 if (mask
& GL_COLOR_BUFFER_BIT
) {
232 struct gl_colorbuffer_attrib
*attr
;
233 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
234 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
235 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
236 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
237 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
238 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
241 if (mask
& GL_CURRENT_BIT
) {
242 struct gl_current_attrib
*attr
;
243 FLUSH_CURRENT( ctx
, 0 );
244 attr
= MALLOC_STRUCT( gl_current_attrib
);
245 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
246 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
249 if (mask
& GL_DEPTH_BUFFER_BIT
) {
250 struct gl_depthbuffer_attrib
*attr
;
251 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
252 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
253 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
256 if (mask
& GL_ENABLE_BIT
) {
257 struct gl_enable_attrib
*attr
;
259 attr
= MALLOC_STRUCT( gl_enable_attrib
);
260 /* Copy enable flags from all other attributes into the enable struct. */
261 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
262 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
263 attr
->Blend
= ctx
->Color
.BlendEnabled
;
264 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
265 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
266 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
267 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
268 attr
->DepthTest
= ctx
->Depth
.Test
;
269 attr
->Dither
= ctx
->Color
.DitherFlag
;
270 attr
->Fog
= ctx
->Fog
.Enabled
;
271 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
272 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
274 attr
->Lighting
= ctx
->Light
.Enabled
;
275 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
276 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
277 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
278 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
279 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
280 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
281 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
282 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
283 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
284 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
285 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
286 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
287 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
288 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
289 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
290 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
291 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
292 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
293 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
294 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
295 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
296 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
297 attr
->Normalize
= ctx
->Transform
.Normalize
;
298 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
299 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
300 attr
->PointSprite
= ctx
->Point
.PointSprite
;
301 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
302 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
303 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
304 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
305 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
306 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
307 attr
->Scissor
= ctx
->Scissor
.Enabled
;
308 attr
->Stencil
= ctx
->Stencil
.Enabled
;
309 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
310 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
311 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
312 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
313 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
314 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
315 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
316 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
318 /* GL_ARB_vertex_program */
319 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
320 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
321 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
323 /* GL_ARB_fragment_program */
324 attr
->FragmentProgram
= ctx
->FragmentProgram
.Enabled
;
326 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
328 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
329 attr
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
332 if (mask
& GL_EVAL_BIT
) {
333 struct gl_eval_attrib
*attr
;
334 attr
= MALLOC_STRUCT( gl_eval_attrib
);
335 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
336 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
339 if (mask
& GL_FOG_BIT
) {
340 struct gl_fog_attrib
*attr
;
341 attr
= MALLOC_STRUCT( gl_fog_attrib
);
342 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
343 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
346 if (mask
& GL_HINT_BIT
) {
347 struct gl_hint_attrib
*attr
;
348 attr
= MALLOC_STRUCT( gl_hint_attrib
);
349 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
350 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
353 if (mask
& GL_LIGHTING_BIT
) {
354 struct gl_light_attrib
*attr
;
355 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
356 attr
= MALLOC_STRUCT( gl_light_attrib
);
357 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
358 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
361 if (mask
& GL_LINE_BIT
) {
362 struct gl_line_attrib
*attr
;
363 attr
= MALLOC_STRUCT( gl_line_attrib
);
364 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
365 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
368 if (mask
& GL_LIST_BIT
) {
369 struct gl_list_attrib
*attr
;
370 attr
= MALLOC_STRUCT( gl_list_attrib
);
371 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
372 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
375 if (mask
& GL_PIXEL_MODE_BIT
) {
376 struct gl_pixel_attrib
*attr
;
377 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
378 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
379 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
380 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
381 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
384 if (mask
& GL_POINT_BIT
) {
385 struct gl_point_attrib
*attr
;
386 attr
= MALLOC_STRUCT( gl_point_attrib
);
387 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
388 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
391 if (mask
& GL_POLYGON_BIT
) {
392 struct gl_polygon_attrib
*attr
;
393 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
394 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
395 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
398 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
400 stipple
= malloc( 32*sizeof(GLuint
) );
401 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
402 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
405 if (mask
& GL_SCISSOR_BIT
) {
406 struct gl_scissor_attrib
*attr
;
407 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
408 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
409 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
412 if (mask
& GL_STENCIL_BUFFER_BIT
) {
413 struct gl_stencil_attrib
*attr
;
414 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
415 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
416 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
419 if (mask
& GL_TEXTURE_BIT
) {
420 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
424 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
428 _mesa_lock_context_textures(ctx
);
430 /* copy/save the bulk of texture state here */
431 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
433 /* Save references to the currently bound texture objects so they don't
434 * accidentally get deleted while referenced in the attribute stack.
436 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
437 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
438 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
439 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
443 /* copy state/contents of the currently bound texture objects */
444 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
445 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
446 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
447 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
451 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, ctx
->Shared
);
453 _mesa_unlock_context_textures(ctx
);
455 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
458 if (mask
& GL_TRANSFORM_BIT
) {
459 struct gl_transform_attrib
*attr
;
460 attr
= MALLOC_STRUCT( gl_transform_attrib
);
461 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
462 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
465 if (mask
& GL_VIEWPORT_BIT
) {
466 struct gl_viewport_attrib
*attr
;
467 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
468 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
469 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
472 /* GL_ARB_multisample */
473 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
474 struct gl_multisample_attrib
*attr
;
475 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
476 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
477 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
481 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
482 ctx
->AttribStackDepth
++;
488 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
490 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
493 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
494 if ((VALUE) != (NEWVALUE)) { \
495 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
498 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
499 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
500 if (ctx
->Extensions
.EXT_draw_buffers2
) {
502 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
503 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
507 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
511 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
512 const GLuint mask
= 1 << i
;
513 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
514 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
515 !!(enable
->ClipPlanes
& mask
));
518 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
520 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
521 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
523 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
524 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
525 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
526 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
527 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
528 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
530 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
532 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
539 GL_MAP1_TEXTURE_COORD_1
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
541 GL_MAP1_TEXTURE_COORD_2
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
543 GL_MAP1_TEXTURE_COORD_3
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
545 GL_MAP1_TEXTURE_COORD_4
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
548 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
551 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
552 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
555 GL_MAP2_TEXTURE_COORD_1
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
557 GL_MAP2_TEXTURE_COORD_2
);
558 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
559 GL_MAP2_TEXTURE_COORD_3
);
560 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
561 GL_MAP2_TEXTURE_COORD_4
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
564 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
567 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
568 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
569 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
570 GL_RESCALE_NORMAL_EXT
);
571 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
572 enable
->RasterPositionUnclipped
,
573 GL_RASTER_POSITION_UNCLIPPED_IBM
);
574 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
576 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
577 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
580 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
581 GL_POLYGON_OFFSET_POINT
);
582 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
583 GL_POLYGON_OFFSET_LINE
);
584 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
585 GL_POLYGON_OFFSET_FILL
);
586 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
588 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
590 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
591 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
592 if (ctx
->Extensions
.EXT_stencil_two_side
) {
593 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
595 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
597 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
598 enable
->SampleAlphaToCoverage
,
599 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
600 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
601 enable
->SampleAlphaToOne
,
602 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
603 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
604 enable
->SampleCoverage
,
605 GL_SAMPLE_COVERAGE_ARB
);
606 /* GL_ARB_vertex_program */
607 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
608 enable
->VertexProgram
,
609 GL_VERTEX_PROGRAM_ARB
);
610 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
611 enable
->VertexProgramPointSize
,
612 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
613 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
614 enable
->VertexProgramTwoSide
,
615 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
617 /* GL_ARB_fragment_program */
618 TEST_AND_UPDATE(ctx
->FragmentProgram
.Enabled
,
619 enable
->FragmentProgram
,
620 GL_FRAGMENT_PROGRAM_ARB
);
622 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
623 TEST_AND_UPDATE(ctx
->Color
.sRGBEnabled
, enable
->sRGBEnabled
,
624 GL_FRAMEBUFFER_SRGB
);
626 /* texture unit enables */
627 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
628 const GLbitfield enabled
= enable
->Texture
[i
];
629 const GLbitfield genEnabled
= enable
->TexGen
[i
];
631 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
632 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
634 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
635 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
636 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
637 if (ctx
->Extensions
.NV_texture_rectangle
) {
638 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
639 !!(enabled
& TEXTURE_RECT_BIT
));
641 if (ctx
->Extensions
.ARB_texture_cube_map
) {
642 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
643 !!(enabled
& TEXTURE_CUBE_BIT
));
645 if (ctx
->Extensions
.MESA_texture_array
) {
646 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
647 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
648 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
649 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
653 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
654 _mesa_ActiveTexture(GL_TEXTURE0
+ i
);
655 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
656 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
657 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
658 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
662 _mesa_ActiveTexture(GL_TEXTURE0
+ curTexUnitSave
);
667 * Pop/restore texture attribute/group state.
670 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
674 _mesa_lock_context_textures(ctx
);
676 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
677 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
680 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ u
);
681 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
682 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
683 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
684 if (ctx
->Extensions
.ARB_texture_cube_map
) {
685 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
686 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
688 if (ctx
->Extensions
.NV_texture_rectangle
) {
689 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
690 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
692 if (ctx
->Extensions
.MESA_texture_array
) {
693 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
694 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
695 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
696 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
698 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
699 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
700 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
701 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
702 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
703 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
704 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
705 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
706 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
707 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
708 /* Eye plane done differently to avoid re-transformation */
710 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
711 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
712 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
713 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
714 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
715 if (ctx
->Driver
.TexGen
) {
716 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
717 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
718 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
719 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
722 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
723 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
724 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
725 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
726 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
729 unit
->Combine
.ModeRGB
);
730 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
731 unit
->Combine
.ModeA
);
733 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
735 for (i
= 0; i
< n
; i
++) {
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
737 unit
->Combine
.SourceRGB
[i
]);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
739 unit
->Combine
.SourceA
[i
]);
740 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
741 unit
->Combine
.OperandRGB
[i
]);
742 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
743 unit
->Combine
.OperandA
[i
]);
746 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
747 1 << unit
->Combine
.ScaleShiftRGB
);
748 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
749 1 << unit
->Combine
.ScaleShiftA
);
751 /* Restore texture object state for each target */
752 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
753 const struct gl_texture_object
*obj
= NULL
;
754 const struct gl_sampler_object
*samp
;
757 obj
= &texstate
->SavedObj
[u
][tgt
];
759 /* don't restore state for unsupported targets to prevent
762 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
763 !ctx
->Extensions
.ARB_texture_cube_map
) {
766 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
767 !ctx
->Extensions
.NV_texture_rectangle
) {
770 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
771 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
772 !ctx
->Extensions
.MESA_texture_array
) {
775 else if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
&&
776 !ctx
->Extensions
.ARB_texture_cube_map_array
) {
778 } else if (obj
->Target
== GL_TEXTURE_BUFFER
)
780 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
783 target
= obj
->Target
;
785 _mesa_BindTexture(target
, obj
->Name
);
787 samp
= &obj
->Sampler
;
789 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
790 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
791 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
792 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
793 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
794 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
795 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
796 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
797 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
798 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
799 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
800 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
801 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
802 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
803 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
804 samp
->MaxAnisotropy
);
806 if (ctx
->Extensions
.ARB_shadow
) {
807 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_MODE
,
809 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_FUNC
,
812 if (ctx
->Extensions
.ARB_depth_texture
)
813 _mesa_TexParameteri(target
, GL_DEPTH_TEXTURE_MODE
, obj
->DepthMode
);
816 /* remove saved references to the texture objects */
817 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
818 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
822 _mesa_ActiveTexture(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
824 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
826 _mesa_unlock_context_textures(ctx
);
831 * This function is kind of long just because we have to call a lot
832 * of device driver functions to update device driver state.
834 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
835 * in order to restore GL state. This isn't terribly efficient but it
836 * ensures that dirty flags and any derived state gets updated correctly.
837 * We could at least check if the value to restore equals the current value
838 * and then skip the Mesa call.
841 _mesa_PopAttrib(void)
843 struct gl_attrib_node
*attr
, *next
;
844 GET_CURRENT_CONTEXT(ctx
);
845 FLUSH_VERTICES(ctx
, 0);
847 if (ctx
->AttribStackDepth
== 0) {
848 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
852 ctx
->AttribStackDepth
--;
853 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
857 if (MESA_VERBOSE
& VERBOSE_API
) {
858 _mesa_debug(ctx
, "glPopAttrib %s\n",
859 _mesa_lookup_enum_by_nr(attr
->kind
));
862 switch (attr
->kind
) {
863 case GL_ACCUM_BUFFER_BIT
:
865 const struct gl_accum_attrib
*accum
;
866 accum
= (const struct gl_accum_attrib
*) attr
->data
;
867 _mesa_ClearAccum(accum
->ClearColor
[0],
868 accum
->ClearColor
[1],
869 accum
->ClearColor
[2],
870 accum
->ClearColor
[3]);
873 case GL_COLOR_BUFFER_BIT
:
875 const struct gl_colorbuffer_attrib
*color
;
877 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
878 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
879 _mesa_ClearColor(color
->ClearColor
.f
[0],
880 color
->ClearColor
.f
[1],
881 color
->ClearColor
.f
[2],
882 color
->ClearColor
.f
[3]);
883 _mesa_IndexMask(color
->IndexMask
);
884 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
885 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
886 (GLboolean
) (color
->ColorMask
[0][1] != 0),
887 (GLboolean
) (color
->ColorMask
[0][2] != 0),
888 (GLboolean
) (color
->ColorMask
[0][3] != 0));
892 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
894 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
895 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
896 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
897 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
901 /* Need to determine if more than one color output is
902 * specified. If so, call glDrawBuffersARB, else call
903 * glDrawBuffer(). This is a subtle, but essential point
904 * since GL_FRONT (for example) is illegal for the former
905 * function, but legal for the later.
907 GLboolean multipleBuffers
= GL_FALSE
;
910 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
911 if (color
->DrawBuffer
[i
] != GL_NONE
) {
912 multipleBuffers
= GL_TRUE
;
916 /* Call the API_level functions, not _mesa_drawbuffers()
917 * since we need to do error checking on the pop'd
919 * Ex: if GL_FRONT were pushed, but we're popping with a
920 * user FBO bound, GL_FRONT will be illegal and we'll need
921 * to record that error. Per OpenGL ARB decision.
924 _mesa_DrawBuffers(ctx
->Const
.MaxDrawBuffers
,
927 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
929 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
930 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
931 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
932 if (ctx
->Extensions
.EXT_draw_buffers2
) {
934 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
935 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
936 (color
->BlendEnabled
>> i
) & 1);
940 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
943 if (ctx
->Color
._BlendFuncPerBuffer
||
944 ctx
->Color
._BlendEquationPerBuffer
) {
945 /* set blend per buffer */
947 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
948 _mesa_BlendFuncSeparateiARB(buf
, color
->Blend
[buf
].SrcRGB
,
949 color
->Blend
[buf
].DstRGB
,
950 color
->Blend
[buf
].SrcA
,
951 color
->Blend
[buf
].DstA
);
952 _mesa_BlendEquationSeparateiARB(buf
,
953 color
->Blend
[buf
].EquationRGB
,
954 color
->Blend
[buf
].EquationA
);
958 /* set same blend modes for all buffers */
959 _mesa_BlendFuncSeparate(color
->Blend
[0].SrcRGB
,
960 color
->Blend
[0].DstRGB
,
961 color
->Blend
[0].SrcA
,
962 color
->Blend
[0].DstA
);
963 /* This special case is because glBlendEquationSeparateEXT
964 * cannot take GL_LOGIC_OP as a parameter.
966 if (color
->Blend
[0].EquationRGB
==
967 color
->Blend
[0].EquationA
) {
968 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
971 _mesa_BlendEquationSeparate(
972 color
->Blend
[0].EquationRGB
,
973 color
->Blend
[0].EquationA
);
976 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
977 color
->BlendColorUnclamped
[1],
978 color
->BlendColorUnclamped
[2],
979 color
->BlendColorUnclamped
[3]);
980 _mesa_LogicOp(color
->LogicOp
);
981 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
982 color
->ColorLogicOpEnabled
);
983 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
984 color
->IndexLogicOpEnabled
);
985 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
986 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
987 _mesa_ClampColor(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
989 /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
990 if (ctx
->Extensions
.EXT_framebuffer_sRGB
)
991 _mesa_set_enable(ctx
, GL_FRAMEBUFFER_SRGB
, color
->sRGBEnabled
);
995 FLUSH_CURRENT( ctx
, 0 );
996 memcpy( &ctx
->Current
, attr
->data
,
997 sizeof(struct gl_current_attrib
) );
999 case GL_DEPTH_BUFFER_BIT
:
1001 const struct gl_depthbuffer_attrib
*depth
;
1002 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1003 _mesa_DepthFunc(depth
->Func
);
1004 _mesa_ClearDepth(depth
->Clear
);
1005 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1006 _mesa_DepthMask(depth
->Mask
);
1011 const struct gl_enable_attrib
*enable
;
1012 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1013 pop_enable_group(ctx
, enable
);
1014 ctx
->NewState
|= _NEW_ALL
;
1018 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1019 ctx
->NewState
|= _NEW_EVAL
;
1023 const struct gl_fog_attrib
*fog
;
1024 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1025 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1026 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1027 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1028 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1029 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1030 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1031 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1036 const struct gl_hint_attrib
*hint
;
1037 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1038 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1039 hint
->PerspectiveCorrection
);
1040 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1041 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1042 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1043 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1044 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1045 hint
->ClipVolumeClipping
);
1046 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1047 hint
->TextureCompression
);
1050 case GL_LIGHTING_BIT
:
1053 const struct gl_light_attrib
*light
;
1054 light
= (const struct gl_light_attrib
*) attr
->data
;
1055 /* lighting enable */
1056 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1057 /* per-light state */
1058 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1059 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1061 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1062 const struct gl_light
*l
= &light
->Light
[i
];
1063 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1064 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1065 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1066 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1067 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1068 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1070 GLfloat p
[4] = { 0 };
1071 p
[0] = l
->SpotExponent
;
1072 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1075 GLfloat p
[4] = { 0 };
1076 p
[0] = l
->SpotCutoff
;
1077 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1080 GLfloat p
[4] = { 0 };
1081 p
[0] = l
->ConstantAttenuation
;
1082 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1085 GLfloat p
[4] = { 0 };
1086 p
[0] = l
->LinearAttenuation
;
1087 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1090 GLfloat p
[4] = { 0 };
1091 p
[0] = l
->QuadraticAttenuation
;
1092 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1096 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1097 light
->Model
.Ambient
);
1098 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1099 (GLfloat
) light
->Model
.LocalViewer
);
1100 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1101 (GLfloat
) light
->Model
.TwoSide
);
1102 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1103 (GLfloat
) light
->Model
.ColorControl
);
1105 _mesa_ShadeModel(light
->ShadeModel
);
1106 /* color material */
1107 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1108 light
->ColorMaterialMode
);
1109 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1110 light
->ColorMaterialEnabled
);
1112 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1113 sizeof(struct gl_material
));
1114 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1119 const struct gl_line_attrib
*line
;
1120 line
= (const struct gl_line_attrib
*) attr
->data
;
1121 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1122 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1123 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1124 _mesa_LineWidth(line
->Width
);
1128 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1130 case GL_PIXEL_MODE_BIT
:
1131 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1132 /* XXX what other pixel state needs to be set by function calls? */
1133 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1134 ctx
->NewState
|= _NEW_PIXEL
;
1138 const struct gl_point_attrib
*point
;
1139 point
= (const struct gl_point_attrib
*) attr
->data
;
1140 _mesa_PointSize(point
->Size
);
1141 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1142 if (ctx
->Extensions
.EXT_point_parameters
) {
1143 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1145 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1147 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1149 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1152 if (ctx
->Extensions
.NV_point_sprite
1153 || ctx
->Extensions
.ARB_point_sprite
) {
1155 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1156 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1157 (GLint
) point
->CoordReplace
[u
]);
1159 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1160 if (ctx
->Extensions
.NV_point_sprite
)
1161 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1162 ctx
->Point
.SpriteRMode
);
1164 if ((ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Version
>= 20)
1165 || ctx
->API
== API_OPENGL_CORE
)
1166 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1167 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1171 case GL_POLYGON_BIT
:
1173 const struct gl_polygon_attrib
*polygon
;
1174 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1175 _mesa_CullFace(polygon
->CullFaceMode
);
1176 _mesa_FrontFace(polygon
->FrontFace
);
1177 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1178 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1179 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1180 polygon
->OffsetUnits
);
1181 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1182 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1183 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1184 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1185 polygon
->OffsetPoint
);
1186 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1187 polygon
->OffsetLine
);
1188 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1189 polygon
->OffsetFill
);
1192 case GL_POLYGON_STIPPLE_BIT
:
1193 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1194 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1195 if (ctx
->Driver
.PolygonStipple
)
1196 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1198 case GL_SCISSOR_BIT
:
1200 const struct gl_scissor_attrib
*scissor
;
1201 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1202 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1203 scissor
->Width
, scissor
->Height
);
1204 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1207 case GL_STENCIL_BUFFER_BIT
:
1209 const struct gl_stencil_attrib
*stencil
;
1210 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1211 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1212 _mesa_ClearStencil(stencil
->Clear
);
1213 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1214 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1215 stencil
->TestTwoSide
);
1216 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1217 ? GL_BACK
: GL_FRONT
);
1220 _mesa_StencilFuncSeparate(GL_FRONT
,
1221 stencil
->Function
[0],
1223 stencil
->ValueMask
[0]);
1224 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1225 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1226 stencil
->ZFailFunc
[0],
1227 stencil
->ZPassFunc
[0]);
1229 _mesa_StencilFuncSeparate(GL_BACK
,
1230 stencil
->Function
[1],
1232 stencil
->ValueMask
[1]);
1233 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1234 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1235 stencil
->ZFailFunc
[1],
1236 stencil
->ZPassFunc
[1]);
1239 case GL_TRANSFORM_BIT
:
1242 const struct gl_transform_attrib
*xform
;
1243 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1244 _mesa_MatrixMode(xform
->MatrixMode
);
1245 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1246 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1248 /* restore clip planes */
1249 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1250 const GLuint mask
= 1 << i
;
1251 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1252 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1253 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1254 !!(xform
->ClipPlanesEnabled
& mask
));
1255 if (ctx
->Driver
.ClipPlane
)
1256 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1259 /* normalize/rescale */
1260 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1261 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1262 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1263 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1264 ctx
->Transform
.RescaleNormals
);
1265 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1266 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1267 ctx
->Transform
.DepthClamp
);
1270 case GL_TEXTURE_BIT
:
1272 struct texture_state
*texstate
1273 = (struct texture_state
*) attr
->data
;
1274 pop_texture_group(ctx
, texstate
);
1275 ctx
->NewState
|= _NEW_TEXTURE
;
1278 case GL_VIEWPORT_BIT
:
1280 const struct gl_viewport_attrib
*vp
;
1281 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1282 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1283 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1286 case GL_MULTISAMPLE_BIT_ARB
:
1288 const struct gl_multisample_attrib
*ms
;
1289 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1291 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
,
1295 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
1297 GL_SAMPLE_COVERAGE
);
1299 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
1300 ms
->SampleAlphaToCoverage
,
1301 GL_SAMPLE_ALPHA_TO_COVERAGE
);
1303 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
1304 ms
->SampleAlphaToOne
,
1305 GL_SAMPLE_ALPHA_TO_ONE
);
1307 _mesa_SampleCoverage(ms
->SampleCoverageValue
,
1308 ms
->SampleCoverageInvert
);
1313 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1326 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1330 copy_pixelstore(struct gl_context
*ctx
,
1331 struct gl_pixelstore_attrib
*dst
,
1332 const struct gl_pixelstore_attrib
*src
)
1334 dst
->Alignment
= src
->Alignment
;
1335 dst
->RowLength
= src
->RowLength
;
1336 dst
->SkipPixels
= src
->SkipPixels
;
1337 dst
->SkipRows
= src
->SkipRows
;
1338 dst
->ImageHeight
= src
->ImageHeight
;
1339 dst
->SkipImages
= src
->SkipImages
;
1340 dst
->SwapBytes
= src
->SwapBytes
;
1341 dst
->LsbFirst
= src
->LsbFirst
;
1342 dst
->Invert
= src
->Invert
;
1343 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1347 #define GL_CLIENT_PACK_BIT (1<<20)
1348 #define GL_CLIENT_UNPACK_BIT (1<<21)
1351 * Copy gl_array_object from src to dest.
1352 * 'dest' must be in an initialized state.
1355 copy_array_object(struct gl_context
*ctx
,
1356 struct gl_array_object
*dest
,
1357 struct gl_array_object
*src
)
1364 /* In theory must be the same anyway, but on recreate make sure it matches */
1365 dest
->ARBsemantics
= src
->ARBsemantics
;
1367 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1368 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1370 /* _Enabled must be the same than on push */
1371 dest
->_Enabled
= src
->_Enabled
;
1372 dest
->_MaxElement
= src
->_MaxElement
;
1376 * Copy gl_array_attrib from src to dest.
1377 * 'dest' must be in an initialized state.
1380 copy_array_attrib(struct gl_context
*ctx
,
1381 struct gl_array_attrib
*dest
,
1382 struct gl_array_attrib
*src
,
1386 /* skip DefaultArrayObj, Objects */
1387 dest
->ActiveTexture
= src
->ActiveTexture
;
1388 dest
->LockFirst
= src
->LockFirst
;
1389 dest
->LockCount
= src
->LockCount
;
1390 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1391 dest
->PrimitiveRestartFixedIndex
= src
->PrimitiveRestartFixedIndex
;
1392 dest
->_PrimitiveRestart
= src
->_PrimitiveRestart
;
1393 dest
->RestartIndex
= src
->RestartIndex
;
1394 dest
->_RestartIndex
= src
->_RestartIndex
;
1396 /* skip RebindArrays */
1399 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1401 /* skip ArrayBufferObj */
1402 /* skip ElementArrayBufferObj */
1406 * Save the content of src to dest.
1409 save_array_attrib(struct gl_context
*ctx
,
1410 struct gl_array_attrib
*dest
,
1411 struct gl_array_attrib
*src
)
1413 /* Set the Name, needed for restore, but do never overwrite.
1414 * Needs to match value in the object hash. */
1415 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1416 /* And copy all of the rest. */
1417 copy_array_attrib(ctx
, dest
, src
, false);
1419 /* Just reference them here */
1420 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1421 src
->ArrayBufferObj
);
1422 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1423 src
->ArrayObj
->ElementArrayBufferObj
);
1427 * Restore the content of src to dest.
1430 restore_array_attrib(struct gl_context
*ctx
,
1431 struct gl_array_attrib
*dest
,
1432 struct gl_array_attrib
*src
)
1434 /* The ARB_vertex_array_object spec says:
1436 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1437 * if array is not a name returned from a previous call to
1438 * GenVertexArrays, or if such a name has since been deleted with
1439 * DeleteVertexArrays."
1441 * Therefore popping a deleted VAO cannot magically recreate it.
1443 * The semantics of objects created using APPLE_vertex_array_objects behave
1444 * differently. These objects expect to be recreated by pop. Alas.
1446 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1447 && src
->ArrayObj
->ARBsemantics
);
1449 if (arb_vao
&& !_mesa_IsVertexArray(src
->ArrayObj
->Name
))
1452 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1454 /* Restore or recreate the buffer objects by the names ... */
1456 || src
->ArrayBufferObj
->Name
== 0
1457 || _mesa_IsBuffer(src
->ArrayBufferObj
->Name
)) {
1458 /* ... and restore its content */
1459 copy_array_attrib(ctx
, dest
, src
, false);
1461 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
,
1462 src
->ArrayBufferObj
->Name
);
1464 copy_array_attrib(ctx
, dest
, src
, true);
1468 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1469 || _mesa_IsBuffer(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1470 _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1471 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1475 * init/alloc the fields of 'attrib'.
1476 * Needs to the init part matching free_array_attrib_data below.
1479 init_array_attrib_data(struct gl_context
*ctx
,
1480 struct gl_array_attrib
*attrib
)
1482 /* Get a non driver gl_array_object. */
1483 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1484 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1488 * Free/unreference the fields of 'attrib' but don't delete it (that's
1489 * done later in the calling code).
1490 * Needs to the cleanup part matching init_array_attrib_data above.
1493 free_array_attrib_data(struct gl_context
*ctx
,
1494 struct gl_array_attrib
*attrib
)
1496 /* We use a non driver array object, so don't just unref since we would
1497 * end up using the drivers DeleteArrayObject function for deletion. */
1498 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1499 attrib
->ArrayObj
= 0;
1500 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1505 _mesa_PushClientAttrib(GLbitfield mask
)
1507 struct gl_attrib_node
*head
;
1509 GET_CURRENT_CONTEXT(ctx
);
1511 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1512 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1516 /* Build linked list of attribute nodes which save all attribute
1517 * groups specified by the mask.
1521 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1522 struct gl_pixelstore_attrib
*attr
;
1523 /* packing attribs */
1524 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1525 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1526 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1527 /* unpacking attribs */
1528 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1529 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1530 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1533 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1534 struct gl_array_attrib
*attr
;
1535 attr
= CALLOC_STRUCT( gl_array_attrib
);
1536 init_array_attrib_data(ctx
, attr
);
1537 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1538 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1541 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1542 ctx
->ClientAttribStackDepth
++;
1549 _mesa_PopClientAttrib(void)
1551 struct gl_attrib_node
*node
, *next
;
1553 GET_CURRENT_CONTEXT(ctx
);
1554 FLUSH_VERTICES(ctx
, 0);
1556 if (ctx
->ClientAttribStackDepth
== 0) {
1557 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1561 ctx
->ClientAttribStackDepth
--;
1562 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1565 switch (node
->kind
) {
1566 case GL_CLIENT_PACK_BIT
:
1568 struct gl_pixelstore_attrib
*store
=
1569 (struct gl_pixelstore_attrib
*) node
->data
;
1570 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1571 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1573 ctx
->NewState
|= _NEW_PACKUNPACK
;
1575 case GL_CLIENT_UNPACK_BIT
:
1577 struct gl_pixelstore_attrib
*store
=
1578 (struct gl_pixelstore_attrib
*) node
->data
;
1579 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1580 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1582 ctx
->NewState
|= _NEW_PACKUNPACK
;
1584 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1585 struct gl_array_attrib
* attr
=
1586 (struct gl_array_attrib
*) node
->data
;
1587 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1588 free_array_attrib_data(ctx
, attr
);
1589 ctx
->NewState
|= _NEW_ARRAY
;
1593 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1606 * Free any attribute state data that might be attached to the context.
1609 _mesa_free_attrib_data(struct gl_context
*ctx
)
1611 while (ctx
->AttribStackDepth
> 0) {
1612 struct gl_attrib_node
*attr
, *next
;
1614 ctx
->AttribStackDepth
--;
1615 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1618 if (attr
->kind
== GL_TEXTURE_BIT
) {
1619 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1621 /* clear references to the saved texture objects */
1622 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1623 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1624 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1627 _mesa_reference_shared_state(ctx
, &texstate
->SharedRef
, NULL
);
1630 /* any other chunks of state that requires special handling? */
1642 void _mesa_init_attrib( struct gl_context
*ctx
)
1644 /* Renderer and client attribute stacks */
1645 ctx
->AttribStackDepth
= 0;
1646 ctx
->ClientAttribStackDepth
= 0;