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"
45 #include "multisample.h"
49 #include "simple_list.h"
59 #include "glapi/dispatch.h"
63 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
65 struct gl_enable_attrib
70 GLbitfield ClipPlanes
;
71 GLboolean ColorMaterial
;
72 GLboolean ColorTable
[COLORTABLE_MAX
];
73 GLboolean Convolution1D
;
74 GLboolean Convolution2D
;
75 GLboolean Separable2D
;
82 GLboolean Light
[MAX_LIGHTS
];
85 GLboolean LineStipple
;
86 GLboolean IndexLogicOp
;
87 GLboolean ColorLogicOp
;
92 GLboolean Map1TextureCoord1
;
93 GLboolean Map1TextureCoord2
;
94 GLboolean Map1TextureCoord3
;
95 GLboolean Map1TextureCoord4
;
96 GLboolean Map1Vertex3
;
97 GLboolean Map1Vertex4
;
98 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
101 GLboolean Map2Normal
;
102 GLboolean Map2TextureCoord1
;
103 GLboolean Map2TextureCoord2
;
104 GLboolean Map2TextureCoord3
;
105 GLboolean Map2TextureCoord4
;
106 GLboolean Map2Vertex3
;
107 GLboolean Map2Vertex4
;
108 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
112 GLboolean PixelTexture
;
113 GLboolean PointSmooth
;
114 GLboolean PolygonOffsetPoint
;
115 GLboolean PolygonOffsetLine
;
116 GLboolean PolygonOffsetFill
;
117 GLboolean PolygonSmooth
;
118 GLboolean PolygonStipple
;
119 GLboolean RescaleNormals
;
122 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
123 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
124 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
125 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
126 GLboolean SampleCoverage
; /* GL_ARB_multisample */
127 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
128 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
130 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
131 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
133 /* SGI_texture_color_table */
134 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
136 /* GL_ARB_vertex_program / GL_NV_vertex_program */
137 GLboolean VertexProgram
;
138 GLboolean VertexProgramPointSize
;
139 GLboolean VertexProgramTwoSide
;
141 /* GL_ARB_point_sprite / GL_NV_point_sprite */
142 GLboolean PointSprite
;
143 GLboolean FragmentShaderATI
;
148 * Node for the attribute stack.
150 struct gl_attrib_node
154 struct gl_attrib_node
*next
;
160 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
164 struct gl_texture_attrib Texture
; /**< The usual context state */
166 /** to save per texture object state (wrap modes, filters, etc): */
167 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
170 * To save references to texture objects (so they don't get accidentally
171 * deleted while saved in the attribute stack).
173 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
177 #if FEATURE_attrib_stack
181 * Allocate new attribute node of given type/kind. Attach payload data.
182 * Insert it into the linked list named by 'head'.
185 save_attrib_data(struct gl_attrib_node
**head
,
186 GLbitfield kind
, void *payload
)
188 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
203 _mesa_PushAttrib(GLbitfield mask
)
205 struct gl_attrib_node
*head
;
207 GET_CURRENT_CONTEXT(ctx
);
208 ASSERT_OUTSIDE_BEGIN_END(ctx
);
210 if (MESA_VERBOSE
& VERBOSE_API
)
211 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
213 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
214 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
218 /* Build linked list of attribute nodes which save all attribute */
219 /* groups specified by the mask. */
222 if (mask
& GL_ACCUM_BUFFER_BIT
) {
223 struct gl_accum_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_accum_attrib
);
225 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
226 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
229 if (mask
& GL_COLOR_BUFFER_BIT
) {
231 struct gl_colorbuffer_attrib
*attr
;
232 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
233 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
234 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
235 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
236 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
237 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
240 if (mask
& GL_CURRENT_BIT
) {
241 struct gl_current_attrib
*attr
;
242 FLUSH_CURRENT( ctx
, 0 );
243 attr
= MALLOC_STRUCT( gl_current_attrib
);
244 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
245 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
248 if (mask
& GL_DEPTH_BUFFER_BIT
) {
249 struct gl_depthbuffer_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
251 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
252 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
255 if (mask
& GL_ENABLE_BIT
) {
256 struct gl_enable_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_enable_attrib
);
259 /* Copy enable flags from all other attributes into the enable struct. */
260 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
261 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
262 attr
->Blend
= ctx
->Color
.BlendEnabled
;
263 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
264 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
265 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
266 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
268 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
269 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
270 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
271 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
272 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
273 attr
->DepthTest
= ctx
->Depth
.Test
;
274 attr
->Dither
= ctx
->Color
.DitherFlag
;
275 attr
->Fog
= ctx
->Fog
.Enabled
;
276 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
277 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
279 attr
->Lighting
= ctx
->Light
.Enabled
;
280 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
281 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
282 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
283 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
284 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
285 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
286 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
287 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
288 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
289 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
290 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
291 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
292 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
293 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
294 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
295 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
296 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
297 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
298 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
299 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
300 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
301 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
302 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
303 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
304 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
305 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
306 attr
->Normalize
= ctx
->Transform
.Normalize
;
307 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
308 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
309 attr
->PointSprite
= ctx
->Point
.PointSprite
;
310 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
311 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
312 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
313 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
314 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
315 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
316 attr
->Scissor
= ctx
->Scissor
.Enabled
;
317 attr
->Stencil
= ctx
->Stencil
.Enabled
;
318 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
319 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
320 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
321 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
322 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
323 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
324 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
325 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
326 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
327 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
329 /* GL_NV_vertex_program */
330 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
331 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
332 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
333 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
336 if (mask
& GL_EVAL_BIT
) {
337 struct gl_eval_attrib
*attr
;
338 attr
= MALLOC_STRUCT( gl_eval_attrib
);
339 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
340 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
343 if (mask
& GL_FOG_BIT
) {
344 struct gl_fog_attrib
*attr
;
345 attr
= MALLOC_STRUCT( gl_fog_attrib
);
346 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
347 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
350 if (mask
& GL_HINT_BIT
) {
351 struct gl_hint_attrib
*attr
;
352 attr
= MALLOC_STRUCT( gl_hint_attrib
);
353 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
354 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
357 if (mask
& GL_LIGHTING_BIT
) {
358 struct gl_light_attrib
*attr
;
359 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
360 attr
= MALLOC_STRUCT( gl_light_attrib
);
361 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
362 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
365 if (mask
& GL_LINE_BIT
) {
366 struct gl_line_attrib
*attr
;
367 attr
= MALLOC_STRUCT( gl_line_attrib
);
368 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
369 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
372 if (mask
& GL_LIST_BIT
) {
373 struct gl_list_attrib
*attr
;
374 attr
= MALLOC_STRUCT( gl_list_attrib
);
375 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
376 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
379 if (mask
& GL_PIXEL_MODE_BIT
) {
380 struct gl_pixel_attrib
*attr
;
381 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
382 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
383 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
384 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
385 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
388 if (mask
& GL_POINT_BIT
) {
389 struct gl_point_attrib
*attr
;
390 attr
= MALLOC_STRUCT( gl_point_attrib
);
391 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
392 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
395 if (mask
& GL_POLYGON_BIT
) {
396 struct gl_polygon_attrib
*attr
;
397 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
398 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
399 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
402 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
404 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
405 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
406 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
409 if (mask
& GL_SCISSOR_BIT
) {
410 struct gl_scissor_attrib
*attr
;
411 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
412 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
413 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
416 if (mask
& GL_STENCIL_BUFFER_BIT
) {
417 struct gl_stencil_attrib
*attr
;
418 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
419 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
420 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
423 if (mask
& GL_TEXTURE_BIT
) {
424 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
428 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
432 _mesa_lock_context_textures(ctx
);
434 /* copy/save the bulk of texture state here */
435 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
437 /* Save references to the currently bound texture objects so they don't
438 * accidentally get deleted while referenced in the attribute stack.
440 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
441 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
442 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
443 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
447 /* copy state/contents of the currently bound texture objects */
448 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
449 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
450 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
451 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
455 _mesa_unlock_context_textures(ctx
);
457 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
460 if (mask
& GL_TRANSFORM_BIT
) {
461 struct gl_transform_attrib
*attr
;
462 attr
= MALLOC_STRUCT( gl_transform_attrib
);
463 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
464 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
467 if (mask
& GL_VIEWPORT_BIT
) {
468 struct gl_viewport_attrib
*attr
;
469 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
470 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
471 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
474 /* GL_ARB_multisample */
475 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
476 struct gl_multisample_attrib
*attr
;
477 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
478 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
479 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
483 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
484 ctx
->AttribStackDepth
++;
490 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
492 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
495 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
496 if ((VALUE) != (NEWVALUE)) { \
497 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
500 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
501 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
503 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
504 const GLuint mask
= 1 << i
;
505 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
506 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
507 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
510 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
512 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
513 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
515 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
516 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
517 GL_POST_CONVOLUTION_COLOR_TABLE
);
518 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
519 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
520 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
521 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
522 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
524 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
525 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
526 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
528 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
530 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
532 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
533 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
534 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
535 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
537 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
539 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
542 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
546 GL_MAP1_TEXTURE_COORD_1
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
548 GL_MAP1_TEXTURE_COORD_2
);
549 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
550 GL_MAP1_TEXTURE_COORD_3
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
552 GL_MAP1_TEXTURE_COORD_4
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
555 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
557 for (i
= 0; i
< 16; i
++) {
558 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
559 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
563 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
565 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
566 GL_MAP2_TEXTURE_COORD_1
);
567 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
568 GL_MAP2_TEXTURE_COORD_2
);
569 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
570 GL_MAP2_TEXTURE_COORD_3
);
571 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
572 GL_MAP2_TEXTURE_COORD_4
);
573 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
575 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
577 for (i
= 0; i
< 16; i
++) {
578 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
579 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
582 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
583 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
584 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
585 GL_RESCALE_NORMAL_EXT
);
586 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
587 enable
->RasterPositionUnclipped
,
588 GL_RASTER_POSITION_UNCLIPPED_IBM
);
589 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
591 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
592 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
595 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
596 GL_POLYGON_OFFSET_POINT
);
597 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
598 GL_POLYGON_OFFSET_LINE
);
599 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
600 GL_POLYGON_OFFSET_FILL
);
601 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
603 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
605 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
606 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
607 if (ctx
->Extensions
.EXT_stencil_two_side
) {
608 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
610 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
612 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
613 enable
->SampleAlphaToCoverage
,
614 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
615 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
616 enable
->SampleAlphaToOne
,
617 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
618 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
619 enable
->SampleCoverage
,
620 GL_SAMPLE_COVERAGE_ARB
);
621 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
622 enable
->SampleCoverageInvert
,
623 GL_SAMPLE_COVERAGE_INVERT_ARB
);
624 /* GL_ARB_vertex_program, GL_NV_vertex_program */
625 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
626 enable
->VertexProgram
,
627 GL_VERTEX_PROGRAM_ARB
);
628 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
629 enable
->VertexProgramPointSize
,
630 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
631 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
632 enable
->VertexProgramTwoSide
,
633 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
635 #undef TEST_AND_UPDATE
637 /* texture unit enables */
638 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
639 const GLbitfield enabled
= enable
->Texture
[i
];
640 const GLbitfield genEnabled
= enable
->TexGen
[i
];
642 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
643 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
645 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
646 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
647 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
648 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
649 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
650 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
651 if (ctx
->Extensions
.NV_texture_rectangle
) {
652 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
653 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
655 if (ctx
->Extensions
.ARB_texture_cube_map
) {
656 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
657 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
659 if (ctx
->Extensions
.MESA_texture_array
) {
660 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
661 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
662 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
663 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
667 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
668 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
669 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
670 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
671 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
672 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
673 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
674 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
675 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
676 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
679 /* GL_SGI_texture_color_table */
680 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
683 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
688 * Pop/restore texture attribute/group state.
691 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
695 _mesa_lock_context_textures(ctx
);
697 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
698 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
701 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
702 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
703 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
704 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
705 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
706 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
707 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
708 if (ctx
->Extensions
.ARB_texture_cube_map
) {
709 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
710 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
712 if (ctx
->Extensions
.NV_texture_rectangle
) {
713 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
714 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
716 if (ctx
->Extensions
.MESA_texture_array
) {
717 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
718 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
719 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
720 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
723 if (ctx
->Extensions
.SGI_texture_color_table
) {
724 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
725 unit
->ColorTableEnabled
);
727 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
728 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
729 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
730 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
731 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
732 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
733 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
734 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
735 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
736 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
737 /* Eye plane done differently to avoid re-transformation */
739 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
740 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
741 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
742 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
743 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
744 if (ctx
->Driver
.TexGen
) {
745 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
746 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
747 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
748 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
751 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
752 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
753 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
754 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
755 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
756 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
757 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
758 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
759 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
760 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
761 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
763 if (ctx
->Extensions
.EXT_texture_env_combine
||
764 ctx
->Extensions
.ARB_texture_env_combine
) {
765 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
766 unit
->Combine
.ModeRGB
);
767 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
768 unit
->Combine
.ModeA
);
769 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
770 unit
->Combine
.SourceRGB
[0]);
771 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
772 unit
->Combine
.SourceRGB
[1]);
773 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
774 unit
->Combine
.SourceRGB
[2]);
775 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
776 unit
->Combine
.SourceA
[0]);
777 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
778 unit
->Combine
.SourceA
[1]);
779 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
780 unit
->Combine
.SourceA
[2]);
781 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
782 unit
->Combine
.OperandRGB
[0]);
783 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
784 unit
->Combine
.OperandRGB
[1]);
785 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
786 unit
->Combine
.OperandRGB
[2]);
787 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
788 unit
->Combine
.OperandA
[0]);
789 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
790 unit
->Combine
.OperandA
[1]);
791 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
792 unit
->Combine
.OperandA
[2]);
793 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
794 1 << unit
->Combine
.ScaleShiftRGB
);
795 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
796 1 << unit
->Combine
.ScaleShiftA
);
799 /* Restore texture object state for each target */
800 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
801 const struct gl_texture_object
*obj
= NULL
;
804 obj
= &texstate
->SavedObj
[u
][tgt
];
806 /* don't restore state for unsupported targets to prevent
809 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
810 !ctx
->Extensions
.ARB_texture_cube_map
) {
813 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
814 !ctx
->Extensions
.NV_texture_rectangle
) {
817 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
818 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
819 !ctx
->Extensions
.MESA_texture_array
) {
823 target
= obj
->Target
;
825 _mesa_BindTexture(target
, obj
->Name
);
827 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
);
828 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
829 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
831 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
832 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
833 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
834 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
835 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
836 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
837 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
838 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
839 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
840 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
841 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
844 if (ctx
->Extensions
.ARB_shadow_ambient
) {
845 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
846 obj
->CompareFailValue
);
850 /* remove saved references to the texture objects */
851 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
852 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
856 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
858 _mesa_unlock_context_textures(ctx
);
863 * This function is kind of long just because we have to call a lot
864 * of device driver functions to update device driver state.
866 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
867 * in order to restore GL state. This isn't terribly efficient but it
868 * ensures that dirty flags and any derived state gets updated correctly.
869 * We could at least check if the value to restore equals the current value
870 * and then skip the Mesa call.
873 _mesa_PopAttrib(void)
875 struct gl_attrib_node
*attr
, *next
;
876 GET_CURRENT_CONTEXT(ctx
);
877 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
879 if (ctx
->AttribStackDepth
== 0) {
880 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
884 ctx
->AttribStackDepth
--;
885 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
889 if (MESA_VERBOSE
& VERBOSE_API
) {
890 _mesa_debug(ctx
, "glPopAttrib %s\n",
891 _mesa_lookup_enum_by_nr(attr
->kind
));
894 switch (attr
->kind
) {
895 case GL_ACCUM_BUFFER_BIT
:
897 const struct gl_accum_attrib
*accum
;
898 accum
= (const struct gl_accum_attrib
*) attr
->data
;
899 _mesa_ClearAccum(accum
->ClearColor
[0],
900 accum
->ClearColor
[1],
901 accum
->ClearColor
[2],
902 accum
->ClearColor
[3]);
905 case GL_COLOR_BUFFER_BIT
:
907 const struct gl_colorbuffer_attrib
*color
;
908 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
909 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
910 _mesa_ClearColor(color
->ClearColor
[0],
911 color
->ClearColor
[1],
912 color
->ClearColor
[2],
913 color
->ClearColor
[3]);
914 _mesa_IndexMask(color
->IndexMask
);
915 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
916 (GLboolean
) (color
->ColorMask
[1] != 0),
917 (GLboolean
) (color
->ColorMask
[2] != 0),
918 (GLboolean
) (color
->ColorMask
[3] != 0));
920 /* Need to determine if more than one color output is
921 * specified. If so, call glDrawBuffersARB, else call
922 * glDrawBuffer(). This is a subtle, but essential point
923 * since GL_FRONT (for example) is illegal for the former
924 * function, but legal for the later.
926 GLboolean multipleBuffers
= GL_FALSE
;
929 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
930 if (color
->DrawBuffer
[i
] != GL_NONE
) {
931 multipleBuffers
= GL_TRUE
;
935 /* Call the API_level functions, not _mesa_drawbuffers()
936 * since we need to do error checking on the pop'd
938 * Ex: if GL_FRONT were pushed, but we're popping with a
939 * user FBO bound, GL_FRONT will be illegal and we'll need
940 * to record that error. Per OpenGL ARB decision.
943 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
946 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
948 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
949 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
950 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
951 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
955 /* This special case is because glBlendEquationSeparateEXT
956 * cannot take GL_LOGIC_OP as a parameter.
958 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
959 _mesa_BlendEquation(color
->BlendEquationRGB
);
962 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
963 color
->BlendEquationA
);
965 _mesa_BlendColor(color
->BlendColor
[0],
966 color
->BlendColor
[1],
967 color
->BlendColor
[2],
968 color
->BlendColor
[3]);
969 _mesa_LogicOp(color
->LogicOp
);
970 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
971 color
->ColorLogicOpEnabled
);
972 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
973 color
->IndexLogicOpEnabled
);
974 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
978 FLUSH_CURRENT( ctx
, 0 );
979 MEMCPY( &ctx
->Current
, attr
->data
,
980 sizeof(struct gl_current_attrib
) );
982 case GL_DEPTH_BUFFER_BIT
:
984 const struct gl_depthbuffer_attrib
*depth
;
985 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
986 _mesa_DepthFunc(depth
->Func
);
987 _mesa_ClearDepth(depth
->Clear
);
988 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
989 _mesa_DepthMask(depth
->Mask
);
994 const struct gl_enable_attrib
*enable
;
995 enable
= (const struct gl_enable_attrib
*) attr
->data
;
996 pop_enable_group(ctx
, enable
);
997 ctx
->NewState
|= _NEW_ALL
;
1001 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1002 ctx
->NewState
|= _NEW_EVAL
;
1006 const struct gl_fog_attrib
*fog
;
1007 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1008 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1009 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1010 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1011 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1012 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1013 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1014 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1019 const struct gl_hint_attrib
*hint
;
1020 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1021 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1022 hint
->PerspectiveCorrection
);
1023 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1024 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1025 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1026 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1027 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1028 hint
->ClipVolumeClipping
);
1029 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1030 hint
->TextureCompression
);
1033 case GL_LIGHTING_BIT
:
1036 const struct gl_light_attrib
*light
;
1037 light
= (const struct gl_light_attrib
*) attr
->data
;
1038 /* lighting enable */
1039 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1040 /* per-light state */
1041 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1042 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1044 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1045 const struct gl_light
*l
= &light
->Light
[i
];
1046 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1047 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1048 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1049 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1050 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1051 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1053 GLfloat p
[4] = { 0 };
1054 p
[0] = l
->SpotExponent
;
1055 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1058 GLfloat p
[4] = { 0 };
1059 p
[0] = l
->SpotCutoff
;
1060 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1063 GLfloat p
[4] = { 0 };
1064 p
[0] = l
->ConstantAttenuation
;
1065 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1068 GLfloat p
[4] = { 0 };
1069 p
[0] = l
->LinearAttenuation
;
1070 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1073 GLfloat p
[4] = { 0 };
1074 p
[0] = l
->QuadraticAttenuation
;
1075 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1079 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1080 light
->Model
.Ambient
);
1081 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1082 (GLfloat
) light
->Model
.LocalViewer
);
1083 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1084 (GLfloat
) light
->Model
.TwoSide
);
1085 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1086 (GLfloat
) light
->Model
.ColorControl
);
1088 _mesa_ShadeModel(light
->ShadeModel
);
1089 /* color material */
1090 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1091 light
->ColorMaterialMode
);
1092 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1093 light
->ColorMaterialEnabled
);
1095 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1096 sizeof(struct gl_material
));
1101 const struct gl_line_attrib
*line
;
1102 line
= (const struct gl_line_attrib
*) attr
->data
;
1103 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1104 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1105 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1106 _mesa_LineWidth(line
->Width
);
1110 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1112 case GL_PIXEL_MODE_BIT
:
1113 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1114 /* XXX what other pixel state needs to be set by function calls? */
1115 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1116 ctx
->NewState
|= _NEW_PIXEL
;
1120 const struct gl_point_attrib
*point
;
1121 point
= (const struct gl_point_attrib
*) attr
->data
;
1122 _mesa_PointSize(point
->Size
);
1123 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1124 if (ctx
->Extensions
.EXT_point_parameters
) {
1125 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1127 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1129 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1131 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1134 if (ctx
->Extensions
.NV_point_sprite
1135 || ctx
->Extensions
.ARB_point_sprite
) {
1137 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1138 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1139 (GLint
) point
->CoordReplace
[u
]);
1141 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1142 if (ctx
->Extensions
.NV_point_sprite
)
1143 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1144 ctx
->Point
.SpriteRMode
);
1145 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1146 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1150 case GL_POLYGON_BIT
:
1152 const struct gl_polygon_attrib
*polygon
;
1153 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1154 _mesa_CullFace(polygon
->CullFaceMode
);
1155 _mesa_FrontFace(polygon
->FrontFace
);
1156 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1157 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1158 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1159 polygon
->OffsetUnits
);
1160 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1161 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1162 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1163 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1164 polygon
->OffsetPoint
);
1165 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1166 polygon
->OffsetLine
);
1167 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1168 polygon
->OffsetFill
);
1171 case GL_POLYGON_STIPPLE_BIT
:
1172 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1173 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1174 if (ctx
->Driver
.PolygonStipple
)
1175 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1177 case GL_SCISSOR_BIT
:
1179 const struct gl_scissor_attrib
*scissor
;
1180 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1181 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1182 scissor
->Width
, scissor
->Height
);
1183 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1186 case GL_STENCIL_BUFFER_BIT
:
1188 const struct gl_stencil_attrib
*stencil
;
1189 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1190 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1191 _mesa_ClearStencil(stencil
->Clear
);
1192 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1193 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1194 stencil
->TestTwoSide
);
1195 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1196 ? GL_BACK
: GL_FRONT
);
1199 _mesa_StencilFuncSeparate(GL_FRONT
,
1200 stencil
->Function
[0],
1202 stencil
->ValueMask
[0]);
1203 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1204 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1205 stencil
->ZFailFunc
[0],
1206 stencil
->ZPassFunc
[0]);
1208 _mesa_StencilFuncSeparate(GL_BACK
,
1209 stencil
->Function
[1],
1211 stencil
->ValueMask
[1]);
1212 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1213 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1214 stencil
->ZFailFunc
[1],
1215 stencil
->ZPassFunc
[1]);
1218 case GL_TRANSFORM_BIT
:
1221 const struct gl_transform_attrib
*xform
;
1222 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1223 _mesa_MatrixMode(xform
->MatrixMode
);
1224 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1225 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1227 /* restore clip planes */
1228 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1229 const GLuint mask
= 1 << i
;
1230 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1231 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1232 if (xform
->ClipPlanesEnabled
& mask
) {
1233 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1236 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1238 if (ctx
->Driver
.ClipPlane
)
1239 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1242 /* normalize/rescale */
1243 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1244 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1245 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1246 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1247 ctx
->Transform
.RescaleNormals
);
1248 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1249 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1250 ctx
->Transform
.DepthClamp
);
1253 case GL_TEXTURE_BIT
:
1254 /* Take care of texture object reference counters */
1256 struct texture_state
*texstate
1257 = (struct texture_state
*) attr
->data
;
1258 pop_texture_group(ctx
, texstate
);
1259 ctx
->NewState
|= _NEW_TEXTURE
;
1262 case GL_VIEWPORT_BIT
:
1264 const struct gl_viewport_attrib
*vp
;
1265 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1266 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1267 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1270 case GL_MULTISAMPLE_BIT_ARB
:
1272 const struct gl_multisample_attrib
*ms
;
1273 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1274 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1275 ms
->SampleCoverageInvert
);
1280 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1293 * Helper for incrementing/decrementing vertex buffer object reference
1294 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1297 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1301 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1302 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1303 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1304 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1305 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1306 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1307 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1308 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1309 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1310 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1311 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1312 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1317 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1321 copy_pixelstore(GLcontext
*ctx
,
1322 struct gl_pixelstore_attrib
*dst
,
1323 const struct gl_pixelstore_attrib
*src
)
1325 dst
->Alignment
= src
->Alignment
;
1326 dst
->RowLength
= src
->RowLength
;
1327 dst
->SkipPixels
= src
->SkipPixels
;
1328 dst
->SkipRows
= src
->SkipRows
;
1329 dst
->ImageHeight
= src
->ImageHeight
;
1330 dst
->SkipImages
= src
->SkipImages
;
1331 dst
->SwapBytes
= src
->SwapBytes
;
1332 dst
->LsbFirst
= src
->LsbFirst
;
1333 dst
->ClientStorage
= src
->ClientStorage
;
1334 dst
->Invert
= src
->Invert
;
1335 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1339 #define GL_CLIENT_PACK_BIT (1<<20)
1340 #define GL_CLIENT_UNPACK_BIT (1<<21)
1344 _mesa_PushClientAttrib(GLbitfield mask
)
1346 struct gl_attrib_node
*head
;
1348 GET_CURRENT_CONTEXT(ctx
);
1349 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1351 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1352 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1356 /* Build linked list of attribute nodes which save all attribute
1357 * groups specified by the mask.
1361 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1362 struct gl_pixelstore_attrib
*attr
;
1363 /* packing attribs */
1364 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1365 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1366 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1367 /* unpacking attribs */
1368 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1369 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1370 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1373 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1374 struct gl_array_attrib
*attr
;
1375 struct gl_array_object
*obj
;
1377 attr
= MALLOC_STRUCT( gl_array_attrib
);
1378 obj
= MALLOC_STRUCT( gl_array_object
);
1380 #if FEATURE_ARB_vertex_buffer_object
1381 /* increment ref counts since we're copying pointers to these objects */
1382 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1383 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1386 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1387 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1389 attr
->ArrayObj
= obj
;
1391 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1393 /* bump reference counts on buffer objects */
1394 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1397 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1398 ctx
->ClientAttribStackDepth
++;
1405 _mesa_PopClientAttrib(void)
1407 struct gl_attrib_node
*node
, *next
;
1409 GET_CURRENT_CONTEXT(ctx
);
1410 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1412 if (ctx
->ClientAttribStackDepth
== 0) {
1413 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1417 ctx
->ClientAttribStackDepth
--;
1418 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1421 switch (node
->kind
) {
1422 case GL_CLIENT_PACK_BIT
:
1424 struct gl_pixelstore_attrib
*store
=
1425 (struct gl_pixelstore_attrib
*) node
->data
;
1426 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1427 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1429 ctx
->NewState
|= _NEW_PACKUNPACK
;
1431 case GL_CLIENT_UNPACK_BIT
:
1433 struct gl_pixelstore_attrib
*store
=
1434 (struct gl_pixelstore_attrib
*) node
->data
;
1435 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1436 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1438 ctx
->NewState
|= _NEW_PACKUNPACK
;
1440 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1441 struct gl_array_attrib
* data
=
1442 (struct gl_array_attrib
*) node
->data
;
1444 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1446 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1447 if (data
->LockCount
!= 0)
1448 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1449 else if (ctx
->Array
.LockCount
)
1450 _mesa_UnlockArraysEXT();
1452 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1454 #if FEATURE_ARB_vertex_buffer_object
1455 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1456 data
->ArrayBufferObj
->Name
);
1457 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1458 data
->ElementArrayBufferObj
->Name
);
1461 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1462 sizeof( struct gl_array_object
) );
1464 FREE( data
->ArrayObj
);
1466 /* FIXME: Should some bits in ctx->Array->NewState also be set
1467 * FIXME: here? It seems like it should be set to inclusive-or
1468 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1471 ctx
->NewState
|= _NEW_ARRAY
;
1475 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1488 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1490 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1491 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1492 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1493 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1497 #endif /* FEATURE_attrib_stack */
1501 * Free any attribute state data that might be attached to the context.
1504 _mesa_free_attrib_data(GLcontext
*ctx
)
1506 while (ctx
->AttribStackDepth
> 0) {
1507 struct gl_attrib_node
*attr
, *next
;
1509 ctx
->AttribStackDepth
--;
1510 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1513 if (attr
->kind
== GL_TEXTURE_BIT
) {
1514 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1516 /* clear references to the saved texture objects */
1517 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1518 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1519 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1524 /* any other chunks of state that requires special handling? */
1528 _mesa_free(attr
->data
);
1536 void _mesa_init_attrib( GLcontext
*ctx
)
1538 /* Renderer and client attribute stacks */
1539 ctx
->AttribStackDepth
= 0;
1540 ctx
->ClientAttribStackDepth
= 0;