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 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
504 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
505 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
509 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
510 const GLuint mask
= 1 << i
;
511 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
512 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
513 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
516 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
518 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
519 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
521 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
522 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
523 GL_POST_CONVOLUTION_COLOR_TABLE
);
524 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
525 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
526 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
527 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
528 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
530 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
531 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
532 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
534 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
536 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
538 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
539 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
540 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
541 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
543 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
545 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
548 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
549 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
550 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
552 GL_MAP1_TEXTURE_COORD_1
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
554 GL_MAP1_TEXTURE_COORD_2
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
556 GL_MAP1_TEXTURE_COORD_3
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
558 GL_MAP1_TEXTURE_COORD_4
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
561 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
563 for (i
= 0; i
< 16; i
++) {
564 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
565 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
568 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
569 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
570 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
571 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
572 GL_MAP2_TEXTURE_COORD_1
);
573 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
574 GL_MAP2_TEXTURE_COORD_2
);
575 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
576 GL_MAP2_TEXTURE_COORD_3
);
577 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
578 GL_MAP2_TEXTURE_COORD_4
);
579 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
581 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
583 for (i
= 0; i
< 16; i
++) {
584 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
585 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
588 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
589 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
590 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
591 GL_RESCALE_NORMAL_EXT
);
592 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
593 enable
->RasterPositionUnclipped
,
594 GL_RASTER_POSITION_UNCLIPPED_IBM
);
595 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
597 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
598 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
601 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
602 GL_POLYGON_OFFSET_POINT
);
603 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
604 GL_POLYGON_OFFSET_LINE
);
605 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
606 GL_POLYGON_OFFSET_FILL
);
607 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
609 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
611 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
612 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
613 if (ctx
->Extensions
.EXT_stencil_two_side
) {
614 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
616 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
618 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
619 enable
->SampleAlphaToCoverage
,
620 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
621 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
622 enable
->SampleAlphaToOne
,
623 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
624 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
625 enable
->SampleCoverage
,
626 GL_SAMPLE_COVERAGE_ARB
);
627 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
628 enable
->SampleCoverageInvert
,
629 GL_SAMPLE_COVERAGE_INVERT_ARB
);
630 /* GL_ARB_vertex_program, GL_NV_vertex_program */
631 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
632 enable
->VertexProgram
,
633 GL_VERTEX_PROGRAM_ARB
);
634 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
635 enable
->VertexProgramPointSize
,
636 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
637 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
638 enable
->VertexProgramTwoSide
,
639 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
641 #undef TEST_AND_UPDATE
643 /* texture unit enables */
644 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
645 const GLbitfield enabled
= enable
->Texture
[i
];
646 const GLbitfield genEnabled
= enable
->TexGen
[i
];
648 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
649 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
651 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
652 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
653 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
654 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
655 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
656 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
657 if (ctx
->Extensions
.NV_texture_rectangle
) {
658 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
659 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
661 if (ctx
->Extensions
.ARB_texture_cube_map
) {
662 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
663 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
665 if (ctx
->Extensions
.MESA_texture_array
) {
666 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
667 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
668 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
669 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
673 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
674 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
675 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
676 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
677 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
678 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
679 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
680 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
681 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
682 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
685 /* GL_SGI_texture_color_table */
686 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
689 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
694 * Pop/restore texture attribute/group state.
697 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
701 _mesa_lock_context_textures(ctx
);
703 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
704 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
707 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
708 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
709 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
710 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
711 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
713 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
714 if (ctx
->Extensions
.ARB_texture_cube_map
) {
715 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
716 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
718 if (ctx
->Extensions
.NV_texture_rectangle
) {
719 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
720 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
722 if (ctx
->Extensions
.MESA_texture_array
) {
723 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
724 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
725 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
726 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
729 if (ctx
->Extensions
.SGI_texture_color_table
) {
730 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
731 unit
->ColorTableEnabled
);
733 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
734 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
735 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
736 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
737 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
738 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
739 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
740 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
741 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
742 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
743 /* Eye plane done differently to avoid re-transformation */
745 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
746 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
747 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
748 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
749 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
750 if (ctx
->Driver
.TexGen
) {
751 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
752 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
753 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
754 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
757 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
758 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
759 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
760 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
761 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
762 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
763 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
764 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
765 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
766 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
767 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
769 if (ctx
->Extensions
.EXT_texture_env_combine
||
770 ctx
->Extensions
.ARB_texture_env_combine
) {
771 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
772 unit
->Combine
.ModeRGB
);
773 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
774 unit
->Combine
.ModeA
);
775 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
776 unit
->Combine
.SourceRGB
[0]);
777 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
778 unit
->Combine
.SourceRGB
[1]);
779 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
780 unit
->Combine
.SourceRGB
[2]);
781 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
782 unit
->Combine
.SourceA
[0]);
783 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
784 unit
->Combine
.SourceA
[1]);
785 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
786 unit
->Combine
.SourceA
[2]);
787 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
788 unit
->Combine
.OperandRGB
[0]);
789 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
790 unit
->Combine
.OperandRGB
[1]);
791 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
792 unit
->Combine
.OperandRGB
[2]);
793 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
794 unit
->Combine
.OperandA
[0]);
795 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
796 unit
->Combine
.OperandA
[1]);
797 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
798 unit
->Combine
.OperandA
[2]);
799 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
800 1 << unit
->Combine
.ScaleShiftRGB
);
801 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
802 1 << unit
->Combine
.ScaleShiftA
);
805 /* Restore texture object state for each target */
806 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
807 const struct gl_texture_object
*obj
= NULL
;
810 obj
= &texstate
->SavedObj
[u
][tgt
];
812 /* don't restore state for unsupported targets to prevent
815 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
816 !ctx
->Extensions
.ARB_texture_cube_map
) {
819 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
820 !ctx
->Extensions
.NV_texture_rectangle
) {
823 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
824 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
825 !ctx
->Extensions
.MESA_texture_array
) {
829 target
= obj
->Target
;
831 _mesa_BindTexture(target
, obj
->Name
);
833 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
);
834 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
835 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
836 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
837 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
838 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
839 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
840 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
841 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
842 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
843 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
844 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
845 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
846 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
847 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
850 if (ctx
->Extensions
.ARB_shadow_ambient
) {
851 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
852 obj
->CompareFailValue
);
856 /* remove saved references to the texture objects */
857 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
858 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
862 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
864 _mesa_unlock_context_textures(ctx
);
869 * This function is kind of long just because we have to call a lot
870 * of device driver functions to update device driver state.
872 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
873 * in order to restore GL state. This isn't terribly efficient but it
874 * ensures that dirty flags and any derived state gets updated correctly.
875 * We could at least check if the value to restore equals the current value
876 * and then skip the Mesa call.
879 _mesa_PopAttrib(void)
881 struct gl_attrib_node
*attr
, *next
;
882 GET_CURRENT_CONTEXT(ctx
);
883 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
885 if (ctx
->AttribStackDepth
== 0) {
886 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
890 ctx
->AttribStackDepth
--;
891 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
895 if (MESA_VERBOSE
& VERBOSE_API
) {
896 _mesa_debug(ctx
, "glPopAttrib %s\n",
897 _mesa_lookup_enum_by_nr(attr
->kind
));
900 switch (attr
->kind
) {
901 case GL_ACCUM_BUFFER_BIT
:
903 const struct gl_accum_attrib
*accum
;
904 accum
= (const struct gl_accum_attrib
*) attr
->data
;
905 _mesa_ClearAccum(accum
->ClearColor
[0],
906 accum
->ClearColor
[1],
907 accum
->ClearColor
[2],
908 accum
->ClearColor
[3]);
911 case GL_COLOR_BUFFER_BIT
:
913 const struct gl_colorbuffer_attrib
*color
;
915 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
916 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
917 _mesa_ClearColor(color
->ClearColor
[0],
918 color
->ClearColor
[1],
919 color
->ClearColor
[2],
920 color
->ClearColor
[3]);
921 _mesa_IndexMask(color
->IndexMask
);
922 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
923 (GLboolean
) (color
->ColorMask
[1] != 0),
924 (GLboolean
) (color
->ColorMask
[2] != 0),
925 (GLboolean
) (color
->ColorMask
[3] != 0));
927 /* Need to determine if more than one color output is
928 * specified. If so, call glDrawBuffersARB, else call
929 * glDrawBuffer(). This is a subtle, but essential point
930 * since GL_FRONT (for example) is illegal for the former
931 * function, but legal for the later.
933 GLboolean multipleBuffers
= GL_FALSE
;
936 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
937 if (color
->DrawBuffer
[i
] != GL_NONE
) {
938 multipleBuffers
= GL_TRUE
;
942 /* Call the API_level functions, not _mesa_drawbuffers()
943 * since we need to do error checking on the pop'd
945 * Ex: if GL_FRONT were pushed, but we're popping with a
946 * user FBO bound, GL_FRONT will be illegal and we'll need
947 * to record that error. Per OpenGL ARB decision.
950 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
953 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
955 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
956 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
957 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
959 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
960 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
961 (color
->BlendEnabled
>> i
) & 1);
964 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
968 /* This special case is because glBlendEquationSeparateEXT
969 * cannot take GL_LOGIC_OP as a parameter.
971 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
972 _mesa_BlendEquation(color
->BlendEquationRGB
);
975 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
976 color
->BlendEquationA
);
978 _mesa_BlendColor(color
->BlendColor
[0],
979 color
->BlendColor
[1],
980 color
->BlendColor
[2],
981 color
->BlendColor
[3]);
982 _mesa_LogicOp(color
->LogicOp
);
983 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
984 color
->ColorLogicOpEnabled
);
985 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
986 color
->IndexLogicOpEnabled
);
987 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
991 FLUSH_CURRENT( ctx
, 0 );
992 MEMCPY( &ctx
->Current
, attr
->data
,
993 sizeof(struct gl_current_attrib
) );
995 case GL_DEPTH_BUFFER_BIT
:
997 const struct gl_depthbuffer_attrib
*depth
;
998 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
999 _mesa_DepthFunc(depth
->Func
);
1000 _mesa_ClearDepth(depth
->Clear
);
1001 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1002 _mesa_DepthMask(depth
->Mask
);
1007 const struct gl_enable_attrib
*enable
;
1008 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1009 pop_enable_group(ctx
, enable
);
1010 ctx
->NewState
|= _NEW_ALL
;
1014 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1015 ctx
->NewState
|= _NEW_EVAL
;
1019 const struct gl_fog_attrib
*fog
;
1020 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1021 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1022 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1023 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1024 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1025 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1026 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1027 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1032 const struct gl_hint_attrib
*hint
;
1033 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1034 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1035 hint
->PerspectiveCorrection
);
1036 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1037 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1038 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1039 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1040 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1041 hint
->ClipVolumeClipping
);
1042 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1043 hint
->TextureCompression
);
1046 case GL_LIGHTING_BIT
:
1049 const struct gl_light_attrib
*light
;
1050 light
= (const struct gl_light_attrib
*) attr
->data
;
1051 /* lighting enable */
1052 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1053 /* per-light state */
1054 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1055 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1057 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1058 const struct gl_light
*l
= &light
->Light
[i
];
1059 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1060 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1061 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1062 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1063 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1064 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1065 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1066 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1067 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1068 &l
->ConstantAttenuation
);
1069 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1070 &l
->LinearAttenuation
);
1071 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1072 &l
->QuadraticAttenuation
);
1075 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1076 light
->Model
.Ambient
);
1077 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1078 (GLfloat
) light
->Model
.LocalViewer
);
1079 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1080 (GLfloat
) light
->Model
.TwoSide
);
1081 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1082 (GLfloat
) light
->Model
.ColorControl
);
1084 _mesa_ShadeModel(light
->ShadeModel
);
1085 /* color material */
1086 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1087 light
->ColorMaterialMode
);
1088 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1089 light
->ColorMaterialEnabled
);
1091 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1092 sizeof(struct gl_material
));
1097 const struct gl_line_attrib
*line
;
1098 line
= (const struct gl_line_attrib
*) attr
->data
;
1099 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1100 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1101 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1102 _mesa_LineWidth(line
->Width
);
1106 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1108 case GL_PIXEL_MODE_BIT
:
1109 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1110 /* XXX what other pixel state needs to be set by function calls? */
1111 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1112 ctx
->NewState
|= _NEW_PIXEL
;
1116 const struct gl_point_attrib
*point
;
1117 point
= (const struct gl_point_attrib
*) attr
->data
;
1118 _mesa_PointSize(point
->Size
);
1119 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1120 if (ctx
->Extensions
.EXT_point_parameters
) {
1121 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1123 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1125 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1127 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1130 if (ctx
->Extensions
.NV_point_sprite
1131 || ctx
->Extensions
.ARB_point_sprite
) {
1133 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1134 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1135 (GLint
) point
->CoordReplace
[u
]);
1137 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1138 if (ctx
->Extensions
.NV_point_sprite
)
1139 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1140 ctx
->Point
.SpriteRMode
);
1141 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1142 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1146 case GL_POLYGON_BIT
:
1148 const struct gl_polygon_attrib
*polygon
;
1149 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1150 _mesa_CullFace(polygon
->CullFaceMode
);
1151 _mesa_FrontFace(polygon
->FrontFace
);
1152 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1153 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1154 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1155 polygon
->OffsetUnits
);
1156 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1157 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1158 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1159 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1160 polygon
->OffsetPoint
);
1161 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1162 polygon
->OffsetLine
);
1163 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1164 polygon
->OffsetFill
);
1167 case GL_POLYGON_STIPPLE_BIT
:
1168 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1169 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1170 if (ctx
->Driver
.PolygonStipple
)
1171 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1173 case GL_SCISSOR_BIT
:
1175 const struct gl_scissor_attrib
*scissor
;
1176 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1177 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1178 scissor
->Width
, scissor
->Height
);
1179 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1182 case GL_STENCIL_BUFFER_BIT
:
1184 const struct gl_stencil_attrib
*stencil
;
1185 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1186 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1187 _mesa_ClearStencil(stencil
->Clear
);
1188 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1189 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1190 stencil
->TestTwoSide
);
1191 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1192 ? GL_BACK
: GL_FRONT
);
1195 _mesa_StencilFuncSeparate(GL_FRONT
,
1196 stencil
->Function
[0],
1198 stencil
->ValueMask
[0]);
1199 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1200 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1201 stencil
->ZFailFunc
[0],
1202 stencil
->ZPassFunc
[0]);
1204 _mesa_StencilFuncSeparate(GL_BACK
,
1205 stencil
->Function
[1],
1207 stencil
->ValueMask
[1]);
1208 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1209 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1210 stencil
->ZFailFunc
[1],
1211 stencil
->ZPassFunc
[1]);
1214 case GL_TRANSFORM_BIT
:
1217 const struct gl_transform_attrib
*xform
;
1218 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1219 _mesa_MatrixMode(xform
->MatrixMode
);
1220 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1221 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1223 /* restore clip planes */
1224 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1225 const GLuint mask
= 1 << i
;
1226 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1227 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1228 if (xform
->ClipPlanesEnabled
& mask
) {
1229 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1232 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1234 if (ctx
->Driver
.ClipPlane
)
1235 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1238 /* normalize/rescale */
1239 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1240 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1241 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1242 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1243 ctx
->Transform
.RescaleNormals
);
1244 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1245 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1246 ctx
->Transform
.DepthClamp
);
1249 case GL_TEXTURE_BIT
:
1250 /* Take care of texture object reference counters */
1252 struct texture_state
*texstate
1253 = (struct texture_state
*) attr
->data
;
1254 pop_texture_group(ctx
, texstate
);
1255 ctx
->NewState
|= _NEW_TEXTURE
;
1258 case GL_VIEWPORT_BIT
:
1260 const struct gl_viewport_attrib
*vp
;
1261 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1262 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1263 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1266 case GL_MULTISAMPLE_BIT_ARB
:
1268 const struct gl_multisample_attrib
*ms
;
1269 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1270 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1271 ms
->SampleCoverageInvert
);
1276 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1289 * Helper for incrementing/decrementing vertex buffer object reference
1290 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1293 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1297 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1298 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1299 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1300 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1301 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1302 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1303 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1304 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1305 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1306 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1307 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1308 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1313 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1317 copy_pixelstore(GLcontext
*ctx
,
1318 struct gl_pixelstore_attrib
*dst
,
1319 const struct gl_pixelstore_attrib
*src
)
1321 dst
->Alignment
= src
->Alignment
;
1322 dst
->RowLength
= src
->RowLength
;
1323 dst
->SkipPixels
= src
->SkipPixels
;
1324 dst
->SkipRows
= src
->SkipRows
;
1325 dst
->ImageHeight
= src
->ImageHeight
;
1326 dst
->SkipImages
= src
->SkipImages
;
1327 dst
->SwapBytes
= src
->SwapBytes
;
1328 dst
->LsbFirst
= src
->LsbFirst
;
1329 dst
->ClientStorage
= src
->ClientStorage
;
1330 dst
->Invert
= src
->Invert
;
1331 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1335 #define GL_CLIENT_PACK_BIT (1<<20)
1336 #define GL_CLIENT_UNPACK_BIT (1<<21)
1340 _mesa_PushClientAttrib(GLbitfield mask
)
1342 struct gl_attrib_node
*head
;
1344 GET_CURRENT_CONTEXT(ctx
);
1345 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1347 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1348 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1352 /* Build linked list of attribute nodes which save all attribute
1353 * groups specified by the mask.
1357 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1358 struct gl_pixelstore_attrib
*attr
;
1359 /* packing attribs */
1360 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1361 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1362 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1363 /* unpacking attribs */
1364 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1365 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1366 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1369 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1370 struct gl_array_attrib
*attr
;
1371 struct gl_array_object
*obj
;
1373 attr
= MALLOC_STRUCT( gl_array_attrib
);
1374 obj
= MALLOC_STRUCT( gl_array_object
);
1376 #if FEATURE_ARB_vertex_buffer_object
1377 /* increment ref counts since we're copying pointers to these objects */
1378 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1379 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1382 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1383 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1385 attr
->ArrayObj
= obj
;
1387 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1389 /* bump reference counts on buffer objects */
1390 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1393 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1394 ctx
->ClientAttribStackDepth
++;
1401 _mesa_PopClientAttrib(void)
1403 struct gl_attrib_node
*node
, *next
;
1405 GET_CURRENT_CONTEXT(ctx
);
1406 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1408 if (ctx
->ClientAttribStackDepth
== 0) {
1409 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1413 ctx
->ClientAttribStackDepth
--;
1414 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1417 switch (node
->kind
) {
1418 case GL_CLIENT_PACK_BIT
:
1420 struct gl_pixelstore_attrib
*store
=
1421 (struct gl_pixelstore_attrib
*) node
->data
;
1422 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1423 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1425 ctx
->NewState
|= _NEW_PACKUNPACK
;
1427 case GL_CLIENT_UNPACK_BIT
:
1429 struct gl_pixelstore_attrib
*store
=
1430 (struct gl_pixelstore_attrib
*) node
->data
;
1431 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1432 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1434 ctx
->NewState
|= _NEW_PACKUNPACK
;
1436 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1437 struct gl_array_attrib
* data
=
1438 (struct gl_array_attrib
*) node
->data
;
1440 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1442 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1443 if (data
->LockCount
!= 0)
1444 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1445 else if (ctx
->Array
.LockCount
)
1446 _mesa_UnlockArraysEXT();
1448 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1450 #if FEATURE_ARB_vertex_buffer_object
1451 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1452 data
->ArrayBufferObj
->Name
);
1453 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1454 data
->ElementArrayBufferObj
->Name
);
1457 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1458 sizeof( struct gl_array_object
) );
1460 FREE( data
->ArrayObj
);
1462 /* FIXME: Should some bits in ctx->Array->NewState also be set
1463 * FIXME: here? It seems like it should be set to inclusive-or
1464 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1467 ctx
->NewState
|= _NEW_ARRAY
;
1471 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1484 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1486 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1487 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1488 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1489 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1493 #endif /* FEATURE_attrib_stack */
1497 * Free any attribute state data that might be attached to the context.
1500 _mesa_free_attrib_data(GLcontext
*ctx
)
1502 while (ctx
->AttribStackDepth
> 0) {
1503 struct gl_attrib_node
*attr
, *next
;
1505 ctx
->AttribStackDepth
--;
1506 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1509 if (attr
->kind
== GL_TEXTURE_BIT
) {
1510 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1512 /* clear references to the saved texture objects */
1513 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1514 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1515 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1520 /* any other chunks of state that requires special handling? */
1524 _mesa_free(attr
->data
);
1532 void _mesa_init_attrib( GLcontext
*ctx
)
1534 /* Renderer and client attribute stacks */
1535 ctx
->AttribStackDepth
= 0;
1536 ctx
->ClientAttribStackDepth
= 0;