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 "multisample.h"
50 #include "simple_list.h"
60 #include "glapi/dispatch.h"
64 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
66 struct gl_enable_attrib
71 GLbitfield ClipPlanes
;
72 GLboolean ColorMaterial
;
73 GLboolean ColorTable
[COLORTABLE_MAX
];
74 GLboolean Convolution1D
;
75 GLboolean Convolution2D
;
76 GLboolean Separable2D
;
83 GLboolean Light
[MAX_LIGHTS
];
86 GLboolean LineStipple
;
87 GLboolean IndexLogicOp
;
88 GLboolean ColorLogicOp
;
93 GLboolean Map1TextureCoord1
;
94 GLboolean Map1TextureCoord2
;
95 GLboolean Map1TextureCoord3
;
96 GLboolean Map1TextureCoord4
;
97 GLboolean Map1Vertex3
;
98 GLboolean Map1Vertex4
;
99 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2Color4
;
102 GLboolean Map2Normal
;
103 GLboolean Map2TextureCoord1
;
104 GLboolean Map2TextureCoord2
;
105 GLboolean Map2TextureCoord3
;
106 GLboolean Map2TextureCoord4
;
107 GLboolean Map2Vertex3
;
108 GLboolean Map2Vertex4
;
109 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
113 GLboolean PixelTexture
;
114 GLboolean PointSmooth
;
115 GLboolean PolygonOffsetPoint
;
116 GLboolean PolygonOffsetLine
;
117 GLboolean PolygonOffsetFill
;
118 GLboolean PolygonSmooth
;
119 GLboolean PolygonStipple
;
120 GLboolean RescaleNormals
;
123 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
124 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
125 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
126 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
127 GLboolean SampleCoverage
; /* GL_ARB_multisample */
128 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
129 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
131 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
132 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
134 /* SGI_texture_color_table */
135 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
137 /* GL_ARB_vertex_program / GL_NV_vertex_program */
138 GLboolean VertexProgram
;
139 GLboolean VertexProgramPointSize
;
140 GLboolean VertexProgramTwoSide
;
142 /* GL_ARB_point_sprite / GL_NV_point_sprite */
143 GLboolean PointSprite
;
144 GLboolean FragmentShaderATI
;
149 * Node for the attribute stack.
151 struct gl_attrib_node
155 struct gl_attrib_node
*next
;
161 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
165 struct gl_texture_attrib Texture
; /**< The usual context state */
167 /** to save per texture object state (wrap modes, filters, etc): */
168 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
171 * To save references to texture objects (so they don't get accidentally
172 * deleted while saved in the attribute stack).
174 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
178 #if FEATURE_attrib_stack
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
);
209 ASSERT_OUTSIDE_BEGIN_END(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 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
267 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
269 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
270 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
271 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
272 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
273 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
274 attr
->DepthTest
= ctx
->Depth
.Test
;
275 attr
->Dither
= ctx
->Color
.DitherFlag
;
276 attr
->Fog
= ctx
->Fog
.Enabled
;
277 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
278 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
280 attr
->Lighting
= ctx
->Light
.Enabled
;
281 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
282 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
283 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
284 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
285 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
286 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
287 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
288 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
289 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
290 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
291 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
292 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
293 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
294 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
295 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
296 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
297 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
298 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
299 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
300 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
301 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
302 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
303 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
304 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
305 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
306 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
307 attr
->Normalize
= ctx
->Transform
.Normalize
;
308 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
309 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
310 attr
->PointSprite
= ctx
->Point
.PointSprite
;
311 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
312 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
313 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
314 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
315 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
316 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
317 attr
->Scissor
= ctx
->Scissor
.Enabled
;
318 attr
->Stencil
= ctx
->Stencil
.Enabled
;
319 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
320 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
321 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
322 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
323 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
324 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
325 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
326 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
327 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
328 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
330 /* GL_NV_vertex_program */
331 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
332 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
333 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
334 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
337 if (mask
& GL_EVAL_BIT
) {
338 struct gl_eval_attrib
*attr
;
339 attr
= MALLOC_STRUCT( gl_eval_attrib
);
340 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
341 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
344 if (mask
& GL_FOG_BIT
) {
345 struct gl_fog_attrib
*attr
;
346 attr
= MALLOC_STRUCT( gl_fog_attrib
);
347 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
348 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
351 if (mask
& GL_HINT_BIT
) {
352 struct gl_hint_attrib
*attr
;
353 attr
= MALLOC_STRUCT( gl_hint_attrib
);
354 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
355 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
358 if (mask
& GL_LIGHTING_BIT
) {
359 struct gl_light_attrib
*attr
;
360 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
361 attr
= MALLOC_STRUCT( gl_light_attrib
);
362 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
363 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
366 if (mask
& GL_LINE_BIT
) {
367 struct gl_line_attrib
*attr
;
368 attr
= MALLOC_STRUCT( gl_line_attrib
);
369 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
370 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
373 if (mask
& GL_LIST_BIT
) {
374 struct gl_list_attrib
*attr
;
375 attr
= MALLOC_STRUCT( gl_list_attrib
);
376 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
377 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
380 if (mask
& GL_PIXEL_MODE_BIT
) {
381 struct gl_pixel_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
383 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
384 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
385 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
386 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
389 if (mask
& GL_POINT_BIT
) {
390 struct gl_point_attrib
*attr
;
391 attr
= MALLOC_STRUCT( gl_point_attrib
);
392 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
393 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
396 if (mask
& GL_POLYGON_BIT
) {
397 struct gl_polygon_attrib
*attr
;
398 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
399 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
400 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
403 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
405 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
406 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
407 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
410 if (mask
& GL_SCISSOR_BIT
) {
411 struct gl_scissor_attrib
*attr
;
412 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
413 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
414 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
417 if (mask
& GL_STENCIL_BUFFER_BIT
) {
418 struct gl_stencil_attrib
*attr
;
419 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
420 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
421 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
424 if (mask
& GL_TEXTURE_BIT
) {
425 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
429 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
433 _mesa_lock_context_textures(ctx
);
435 /* copy/save the bulk of texture state here */
436 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
438 /* Save references to the currently bound texture objects so they don't
439 * accidentally get deleted while referenced in the attribute stack.
441 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
442 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
443 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
444 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
448 /* copy state/contents of the currently bound texture objects */
449 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
450 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
451 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
452 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
456 _mesa_unlock_context_textures(ctx
);
458 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
461 if (mask
& GL_TRANSFORM_BIT
) {
462 struct gl_transform_attrib
*attr
;
463 attr
= MALLOC_STRUCT( gl_transform_attrib
);
464 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
465 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
468 if (mask
& GL_VIEWPORT_BIT
) {
469 struct gl_viewport_attrib
*attr
;
470 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
471 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
472 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
475 /* GL_ARB_multisample */
476 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
477 struct gl_multisample_attrib
*attr
;
478 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
479 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
480 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
484 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
485 ctx
->AttribStackDepth
++;
491 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
493 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
496 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
497 if ((VALUE) != (NEWVALUE)) { \
498 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
501 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
502 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
504 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
505 const GLuint mask
= 1 << i
;
506 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
507 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
508 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
511 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
513 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
514 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
516 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
517 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
518 GL_POST_CONVOLUTION_COLOR_TABLE
);
519 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
520 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
521 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
522 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
523 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
525 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
526 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
527 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
529 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
531 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
533 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
534 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
535 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
536 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
538 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
540 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
543 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
547 GL_MAP1_TEXTURE_COORD_1
);
548 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
549 GL_MAP1_TEXTURE_COORD_2
);
550 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
551 GL_MAP1_TEXTURE_COORD_3
);
552 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
553 GL_MAP1_TEXTURE_COORD_4
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
556 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
558 for (i
= 0; i
< 16; i
++) {
559 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
560 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
563 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
565 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
566 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
567 GL_MAP2_TEXTURE_COORD_1
);
568 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
569 GL_MAP2_TEXTURE_COORD_2
);
570 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
571 GL_MAP2_TEXTURE_COORD_3
);
572 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
573 GL_MAP2_TEXTURE_COORD_4
);
574 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
576 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
578 for (i
= 0; i
< 16; i
++) {
579 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
580 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
583 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
584 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
585 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
586 GL_RESCALE_NORMAL_EXT
);
587 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
588 enable
->RasterPositionUnclipped
,
589 GL_RASTER_POSITION_UNCLIPPED_IBM
);
590 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
592 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
593 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
596 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
597 GL_POLYGON_OFFSET_POINT
);
598 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
599 GL_POLYGON_OFFSET_LINE
);
600 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
601 GL_POLYGON_OFFSET_FILL
);
602 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
604 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
606 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
607 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
608 if (ctx
->Extensions
.EXT_stencil_two_side
) {
609 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
611 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
613 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
614 enable
->SampleAlphaToCoverage
,
615 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
616 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
617 enable
->SampleAlphaToOne
,
618 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
619 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
620 enable
->SampleCoverage
,
621 GL_SAMPLE_COVERAGE_ARB
);
622 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
623 enable
->SampleCoverageInvert
,
624 GL_SAMPLE_COVERAGE_INVERT_ARB
);
625 /* GL_ARB_vertex_program, GL_NV_vertex_program */
626 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
627 enable
->VertexProgram
,
628 GL_VERTEX_PROGRAM_ARB
);
629 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
630 enable
->VertexProgramPointSize
,
631 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
632 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
633 enable
->VertexProgramTwoSide
,
634 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
636 #undef TEST_AND_UPDATE
638 /* texture unit enables */
639 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
640 const GLbitfield enabled
= enable
->Texture
[i
];
641 const GLbitfield genEnabled
= enable
->TexGen
[i
];
643 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
644 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
646 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
647 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
648 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
649 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
650 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
651 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
652 if (ctx
->Extensions
.NV_texture_rectangle
) {
653 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
654 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
656 if (ctx
->Extensions
.ARB_texture_cube_map
) {
657 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
658 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
660 if (ctx
->Extensions
.MESA_texture_array
) {
661 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
662 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
663 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
664 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
668 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
669 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
670 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
671 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
672 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
673 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
674 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
675 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
676 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
677 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
680 /* GL_SGI_texture_color_table */
681 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
684 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
689 * Pop/restore texture attribute/group state.
692 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
696 _mesa_lock_context_textures(ctx
);
698 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
699 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
702 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
703 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
704 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
705 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
706 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
707 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
708 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
709 if (ctx
->Extensions
.ARB_texture_cube_map
) {
710 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
711 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
713 if (ctx
->Extensions
.NV_texture_rectangle
) {
714 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
715 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
717 if (ctx
->Extensions
.MESA_texture_array
) {
718 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
719 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
720 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
721 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
724 if (ctx
->Extensions
.SGI_texture_color_table
) {
725 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
726 unit
->ColorTableEnabled
);
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
729 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
730 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
731 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
732 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
733 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
734 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
735 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
736 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
737 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
738 /* Eye plane done differently to avoid re-transformation */
740 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
741 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
742 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
743 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
744 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
745 if (ctx
->Driver
.TexGen
) {
746 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
747 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
748 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
749 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
752 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
753 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
754 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
755 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
756 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
757 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
758 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
759 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
760 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
761 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
762 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
764 if (ctx
->Extensions
.EXT_texture_env_combine
||
765 ctx
->Extensions
.ARB_texture_env_combine
) {
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
767 unit
->Combine
.ModeRGB
);
768 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
769 unit
->Combine
.ModeA
);
770 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
771 unit
->Combine
.SourceRGB
[0]);
772 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
773 unit
->Combine
.SourceRGB
[1]);
774 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
775 unit
->Combine
.SourceRGB
[2]);
776 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
777 unit
->Combine
.SourceA
[0]);
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
779 unit
->Combine
.SourceA
[1]);
780 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
781 unit
->Combine
.SourceA
[2]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
783 unit
->Combine
.OperandRGB
[0]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
785 unit
->Combine
.OperandRGB
[1]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
787 unit
->Combine
.OperandRGB
[2]);
788 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
789 unit
->Combine
.OperandA
[0]);
790 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
791 unit
->Combine
.OperandA
[1]);
792 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
793 unit
->Combine
.OperandA
[2]);
794 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
795 1 << unit
->Combine
.ScaleShiftRGB
);
796 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
797 1 << unit
->Combine
.ScaleShiftA
);
800 /* Restore texture object state for each target */
801 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
802 const struct gl_texture_object
*obj
= NULL
;
805 obj
= &texstate
->SavedObj
[u
][tgt
];
807 /* don't restore state for unsupported targets to prevent
810 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
811 !ctx
->Extensions
.ARB_texture_cube_map
) {
814 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
815 !ctx
->Extensions
.NV_texture_rectangle
) {
818 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
819 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
820 !ctx
->Extensions
.MESA_texture_array
) {
824 target
= obj
->Target
;
826 _mesa_BindTexture(target
, obj
->Name
);
828 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
);
829 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
831 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
832 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
833 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
834 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
835 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
836 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
837 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
838 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
839 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
840 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
841 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
842 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
845 if (ctx
->Extensions
.ARB_shadow_ambient
) {
846 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
847 obj
->CompareFailValue
);
851 /* remove saved references to the texture objects */
852 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
853 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
857 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
859 _mesa_unlock_context_textures(ctx
);
864 * This function is kind of long just because we have to call a lot
865 * of device driver functions to update device driver state.
867 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
868 * in order to restore GL state. This isn't terribly efficient but it
869 * ensures that dirty flags and any derived state gets updated correctly.
870 * We could at least check if the value to restore equals the current value
871 * and then skip the Mesa call.
874 _mesa_PopAttrib(void)
876 struct gl_attrib_node
*attr
, *next
;
877 GET_CURRENT_CONTEXT(ctx
);
878 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
880 if (ctx
->AttribStackDepth
== 0) {
881 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
885 ctx
->AttribStackDepth
--;
886 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
890 if (MESA_VERBOSE
& VERBOSE_API
) {
891 _mesa_debug(ctx
, "glPopAttrib %s\n",
892 _mesa_lookup_enum_by_nr(attr
->kind
));
895 switch (attr
->kind
) {
896 case GL_ACCUM_BUFFER_BIT
:
898 const struct gl_accum_attrib
*accum
;
899 accum
= (const struct gl_accum_attrib
*) attr
->data
;
900 _mesa_ClearAccum(accum
->ClearColor
[0],
901 accum
->ClearColor
[1],
902 accum
->ClearColor
[2],
903 accum
->ClearColor
[3]);
906 case GL_COLOR_BUFFER_BIT
:
908 const struct gl_colorbuffer_attrib
*color
;
909 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
910 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
911 _mesa_ClearColor(color
->ClearColor
[0],
912 color
->ClearColor
[1],
913 color
->ClearColor
[2],
914 color
->ClearColor
[3]);
915 _mesa_IndexMask(color
->IndexMask
);
916 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
917 (GLboolean
) (color
->ColorMask
[1] != 0),
918 (GLboolean
) (color
->ColorMask
[2] != 0),
919 (GLboolean
) (color
->ColorMask
[3] != 0));
921 /* Need to determine if more than one color output is
922 * specified. If so, call glDrawBuffersARB, else call
923 * glDrawBuffer(). This is a subtle, but essential point
924 * since GL_FRONT (for example) is illegal for the former
925 * function, but legal for the later.
927 GLboolean multipleBuffers
= GL_FALSE
;
930 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
931 if (color
->DrawBuffer
[i
] != GL_NONE
) {
932 multipleBuffers
= GL_TRUE
;
936 /* Call the API_level functions, not _mesa_drawbuffers()
937 * since we need to do error checking on the pop'd
939 * Ex: if GL_FRONT were pushed, but we're popping with a
940 * user FBO bound, GL_FRONT will be illegal and we'll need
941 * to record that error. Per OpenGL ARB decision.
944 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
947 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
949 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
950 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
951 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
952 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
956 /* This special case is because glBlendEquationSeparateEXT
957 * cannot take GL_LOGIC_OP as a parameter.
959 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
960 _mesa_BlendEquation(color
->BlendEquationRGB
);
963 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
964 color
->BlendEquationA
);
966 _mesa_BlendColor(color
->BlendColor
[0],
967 color
->BlendColor
[1],
968 color
->BlendColor
[2],
969 color
->BlendColor
[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
);
979 FLUSH_CURRENT( ctx
, 0 );
980 MEMCPY( &ctx
->Current
, attr
->data
,
981 sizeof(struct gl_current_attrib
) );
983 case GL_DEPTH_BUFFER_BIT
:
985 const struct gl_depthbuffer_attrib
*depth
;
986 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
987 _mesa_DepthFunc(depth
->Func
);
988 _mesa_ClearDepth(depth
->Clear
);
989 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
990 _mesa_DepthMask(depth
->Mask
);
995 const struct gl_enable_attrib
*enable
;
996 enable
= (const struct gl_enable_attrib
*) attr
->data
;
997 pop_enable_group(ctx
, enable
);
998 ctx
->NewState
|= _NEW_ALL
;
1002 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1003 ctx
->NewState
|= _NEW_EVAL
;
1007 const struct gl_fog_attrib
*fog
;
1008 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1009 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1010 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1011 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1012 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1013 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1014 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1015 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1020 const struct gl_hint_attrib
*hint
;
1021 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1022 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1023 hint
->PerspectiveCorrection
);
1024 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1025 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1026 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1027 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1028 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1029 hint
->ClipVolumeClipping
);
1030 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1031 hint
->TextureCompression
);
1034 case GL_LIGHTING_BIT
:
1037 const struct gl_light_attrib
*light
;
1038 light
= (const struct gl_light_attrib
*) attr
->data
;
1039 /* lighting enable */
1040 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1041 /* per-light state */
1042 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1043 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1045 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1046 const struct gl_light
*l
= &light
->Light
[i
];
1047 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1048 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1049 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1050 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1051 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1052 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1054 GLfloat p
[4] = { 0 };
1055 p
[0] = l
->SpotExponent
;
1056 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1059 GLfloat p
[4] = { 0 };
1060 p
[0] = l
->SpotCutoff
;
1061 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1064 GLfloat p
[4] = { 0 };
1065 p
[0] = l
->ConstantAttenuation
;
1066 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1069 GLfloat p
[4] = { 0 };
1070 p
[0] = l
->LinearAttenuation
;
1071 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1074 GLfloat p
[4] = { 0 };
1075 p
[0] = l
->QuadraticAttenuation
;
1076 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1080 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1081 light
->Model
.Ambient
);
1082 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1083 (GLfloat
) light
->Model
.LocalViewer
);
1084 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1085 (GLfloat
) light
->Model
.TwoSide
);
1086 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1087 (GLfloat
) light
->Model
.ColorControl
);
1089 _mesa_ShadeModel(light
->ShadeModel
);
1090 /* color material */
1091 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1092 light
->ColorMaterialMode
);
1093 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1094 light
->ColorMaterialEnabled
);
1096 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1097 sizeof(struct gl_material
));
1102 const struct gl_line_attrib
*line
;
1103 line
= (const struct gl_line_attrib
*) attr
->data
;
1104 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1105 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1106 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1107 _mesa_LineWidth(line
->Width
);
1111 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1113 case GL_PIXEL_MODE_BIT
:
1114 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1115 /* XXX what other pixel state needs to be set by function calls? */
1116 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1117 ctx
->NewState
|= _NEW_PIXEL
;
1121 const struct gl_point_attrib
*point
;
1122 point
= (const struct gl_point_attrib
*) attr
->data
;
1123 _mesa_PointSize(point
->Size
);
1124 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1125 if (ctx
->Extensions
.EXT_point_parameters
) {
1126 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1128 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1130 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1132 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1135 if (ctx
->Extensions
.NV_point_sprite
1136 || ctx
->Extensions
.ARB_point_sprite
) {
1138 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1139 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1140 (GLint
) point
->CoordReplace
[u
]);
1142 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1143 if (ctx
->Extensions
.NV_point_sprite
)
1144 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1145 ctx
->Point
.SpriteRMode
);
1146 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1147 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1151 case GL_POLYGON_BIT
:
1153 const struct gl_polygon_attrib
*polygon
;
1154 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1155 _mesa_CullFace(polygon
->CullFaceMode
);
1156 _mesa_FrontFace(polygon
->FrontFace
);
1157 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1158 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1159 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1160 polygon
->OffsetUnits
);
1161 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1162 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1163 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1164 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1165 polygon
->OffsetPoint
);
1166 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1167 polygon
->OffsetLine
);
1168 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1169 polygon
->OffsetFill
);
1172 case GL_POLYGON_STIPPLE_BIT
:
1173 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1174 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1175 if (ctx
->Driver
.PolygonStipple
)
1176 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1178 case GL_SCISSOR_BIT
:
1180 const struct gl_scissor_attrib
*scissor
;
1181 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1182 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1183 scissor
->Width
, scissor
->Height
);
1184 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1187 case GL_STENCIL_BUFFER_BIT
:
1189 const struct gl_stencil_attrib
*stencil
;
1190 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1191 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1192 _mesa_ClearStencil(stencil
->Clear
);
1193 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1194 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1195 stencil
->TestTwoSide
);
1196 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1197 ? GL_BACK
: GL_FRONT
);
1200 _mesa_StencilFuncSeparate(GL_FRONT
,
1201 stencil
->Function
[0],
1203 stencil
->ValueMask
[0]);
1204 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1205 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1206 stencil
->ZFailFunc
[0],
1207 stencil
->ZPassFunc
[0]);
1209 _mesa_StencilFuncSeparate(GL_BACK
,
1210 stencil
->Function
[1],
1212 stencil
->ValueMask
[1]);
1213 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1214 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1215 stencil
->ZFailFunc
[1],
1216 stencil
->ZPassFunc
[1]);
1219 case GL_TRANSFORM_BIT
:
1222 const struct gl_transform_attrib
*xform
;
1223 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1224 _mesa_MatrixMode(xform
->MatrixMode
);
1225 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1226 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1228 /* restore clip planes */
1229 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1230 const GLuint mask
= 1 << i
;
1231 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1232 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1233 if (xform
->ClipPlanesEnabled
& mask
) {
1234 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1237 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1239 if (ctx
->Driver
.ClipPlane
)
1240 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1243 /* normalize/rescale */
1244 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1245 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1246 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1247 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1248 ctx
->Transform
.RescaleNormals
);
1249 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1250 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1251 ctx
->Transform
.DepthClamp
);
1254 case GL_TEXTURE_BIT
:
1255 /* Take care of texture object reference counters */
1257 struct texture_state
*texstate
1258 = (struct texture_state
*) attr
->data
;
1259 pop_texture_group(ctx
, texstate
);
1260 ctx
->NewState
|= _NEW_TEXTURE
;
1263 case GL_VIEWPORT_BIT
:
1265 const struct gl_viewport_attrib
*vp
;
1266 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1267 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1268 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1271 case GL_MULTISAMPLE_BIT_ARB
:
1273 const struct gl_multisample_attrib
*ms
;
1274 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1275 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1276 ms
->SampleCoverageInvert
);
1281 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1294 * Helper for incrementing/decrementing vertex buffer object reference
1295 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1298 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1302 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1303 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1304 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1305 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1306 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1307 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1308 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1309 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1310 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1311 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1312 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1313 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1318 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1322 copy_pixelstore(GLcontext
*ctx
,
1323 struct gl_pixelstore_attrib
*dst
,
1324 const struct gl_pixelstore_attrib
*src
)
1326 dst
->Alignment
= src
->Alignment
;
1327 dst
->RowLength
= src
->RowLength
;
1328 dst
->SkipPixels
= src
->SkipPixels
;
1329 dst
->SkipRows
= src
->SkipRows
;
1330 dst
->ImageHeight
= src
->ImageHeight
;
1331 dst
->SkipImages
= src
->SkipImages
;
1332 dst
->SwapBytes
= src
->SwapBytes
;
1333 dst
->LsbFirst
= src
->LsbFirst
;
1334 dst
->ClientStorage
= src
->ClientStorage
;
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)
1345 _mesa_PushClientAttrib(GLbitfield mask
)
1347 struct gl_attrib_node
*head
;
1349 GET_CURRENT_CONTEXT(ctx
);
1350 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1352 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1353 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1357 /* Build linked list of attribute nodes which save all attribute
1358 * groups specified by the mask.
1362 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1363 struct gl_pixelstore_attrib
*attr
;
1364 /* packing attribs */
1365 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1366 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1367 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1368 /* unpacking attribs */
1369 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1370 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1371 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1374 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1375 struct gl_array_attrib
*attr
;
1376 struct gl_array_object
*obj
;
1378 attr
= MALLOC_STRUCT( gl_array_attrib
);
1379 obj
= MALLOC_STRUCT( gl_array_object
);
1381 #if FEATURE_ARB_vertex_buffer_object
1382 /* increment ref counts since we're copying pointers to these objects */
1383 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1384 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1387 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1388 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1390 attr
->ArrayObj
= obj
;
1392 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1394 /* bump reference counts on buffer objects */
1395 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1398 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1399 ctx
->ClientAttribStackDepth
++;
1406 _mesa_PopClientAttrib(void)
1408 struct gl_attrib_node
*node
, *next
;
1410 GET_CURRENT_CONTEXT(ctx
);
1411 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1413 if (ctx
->ClientAttribStackDepth
== 0) {
1414 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1418 ctx
->ClientAttribStackDepth
--;
1419 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1422 switch (node
->kind
) {
1423 case GL_CLIENT_PACK_BIT
:
1425 struct gl_pixelstore_attrib
*store
=
1426 (struct gl_pixelstore_attrib
*) node
->data
;
1427 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1428 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1430 ctx
->NewState
|= _NEW_PACKUNPACK
;
1432 case GL_CLIENT_UNPACK_BIT
:
1434 struct gl_pixelstore_attrib
*store
=
1435 (struct gl_pixelstore_attrib
*) node
->data
;
1436 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1437 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1439 ctx
->NewState
|= _NEW_PACKUNPACK
;
1441 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1442 struct gl_array_attrib
* data
=
1443 (struct gl_array_attrib
*) node
->data
;
1445 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1447 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1448 if (data
->LockCount
!= 0)
1449 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1450 else if (ctx
->Array
.LockCount
)
1451 _mesa_UnlockArraysEXT();
1453 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1455 #if FEATURE_ARB_vertex_buffer_object
1456 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1457 data
->ArrayBufferObj
->Name
);
1458 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1459 data
->ElementArrayBufferObj
->Name
);
1462 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1463 sizeof( struct gl_array_object
) );
1465 FREE( data
->ArrayObj
);
1467 /* FIXME: Should some bits in ctx->Array->NewState also be set
1468 * FIXME: here? It seems like it should be set to inclusive-or
1469 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1472 ctx
->NewState
|= _NEW_ARRAY
;
1476 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1489 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1491 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1492 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1493 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1494 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1498 #endif /* FEATURE_attrib_stack */
1502 * Free any attribute state data that might be attached to the context.
1505 _mesa_free_attrib_data(GLcontext
*ctx
)
1507 while (ctx
->AttribStackDepth
> 0) {
1508 struct gl_attrib_node
*attr
, *next
;
1510 ctx
->AttribStackDepth
--;
1511 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1514 if (attr
->kind
== GL_TEXTURE_BIT
) {
1515 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1517 /* clear references to the saved texture objects */
1518 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1519 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1520 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1525 /* any other chunks of state that requires special handling? */
1529 _mesa_free(attr
->data
);
1537 void _mesa_init_attrib( GLcontext
*ctx
)
1539 /* Renderer and client attribute stacks */
1540 ctx
->AttribStackDepth
= 0;
1541 ctx
->ClientAttribStackDepth
= 0;