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"
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
];
178 * Allocate new attribute node of given type/kind. Attach payload data.
179 * Insert it into the linked list named by 'head'.
182 save_attrib_data(struct gl_attrib_node
**head
,
183 GLbitfield kind
, void *payload
)
185 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
200 _mesa_PushAttrib(GLbitfield mask
)
202 struct gl_attrib_node
*head
;
204 GET_CURRENT_CONTEXT(ctx
);
205 ASSERT_OUTSIDE_BEGIN_END(ctx
);
207 if (MESA_VERBOSE
& VERBOSE_API
)
208 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
210 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
211 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
215 /* Build linked list of attribute nodes which save all attribute */
216 /* groups specified by the mask. */
219 if (mask
& GL_ACCUM_BUFFER_BIT
) {
220 struct gl_accum_attrib
*attr
;
221 attr
= MALLOC_STRUCT( gl_accum_attrib
);
222 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
223 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
226 if (mask
& GL_COLOR_BUFFER_BIT
) {
228 struct gl_colorbuffer_attrib
*attr
;
229 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
230 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
231 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
232 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
233 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
234 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
237 if (mask
& GL_CURRENT_BIT
) {
238 struct gl_current_attrib
*attr
;
239 FLUSH_CURRENT( ctx
, 0 );
240 attr
= MALLOC_STRUCT( gl_current_attrib
);
241 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
242 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
245 if (mask
& GL_DEPTH_BUFFER_BIT
) {
246 struct gl_depthbuffer_attrib
*attr
;
247 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
248 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
249 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
252 if (mask
& GL_ENABLE_BIT
) {
253 struct gl_enable_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_enable_attrib
);
256 /* Copy enable flags from all other attributes into the enable struct. */
257 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
258 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
259 attr
->Blend
= ctx
->Color
.BlendEnabled
;
260 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
261 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
262 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
263 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
265 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
266 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
267 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
268 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
269 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
270 attr
->DepthTest
= ctx
->Depth
.Test
;
271 attr
->Dither
= ctx
->Color
.DitherFlag
;
272 attr
->Fog
= ctx
->Fog
.Enabled
;
273 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
274 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
276 attr
->Lighting
= ctx
->Light
.Enabled
;
277 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
278 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
279 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
280 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
281 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
282 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
283 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
284 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
285 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
286 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
287 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
288 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
289 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
290 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
291 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
292 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
293 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
294 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
295 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
296 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
297 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
298 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
299 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
300 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
301 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
302 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
303 attr
->Normalize
= ctx
->Transform
.Normalize
;
304 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
305 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
306 attr
->PointSprite
= ctx
->Point
.PointSprite
;
307 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
308 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
309 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
310 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
311 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
312 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
313 attr
->Scissor
= ctx
->Scissor
.Enabled
;
314 attr
->Stencil
= ctx
->Stencil
.Enabled
;
315 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
316 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
317 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
318 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
319 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
320 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
321 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
322 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
323 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
324 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
326 /* GL_NV_vertex_program */
327 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
328 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
329 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
330 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
333 if (mask
& GL_EVAL_BIT
) {
334 struct gl_eval_attrib
*attr
;
335 attr
= MALLOC_STRUCT( gl_eval_attrib
);
336 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
337 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
340 if (mask
& GL_FOG_BIT
) {
341 struct gl_fog_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_fog_attrib
);
343 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
344 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
347 if (mask
& GL_HINT_BIT
) {
348 struct gl_hint_attrib
*attr
;
349 attr
= MALLOC_STRUCT( gl_hint_attrib
);
350 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
351 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
354 if (mask
& GL_LIGHTING_BIT
) {
355 struct gl_light_attrib
*attr
;
356 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
357 attr
= MALLOC_STRUCT( gl_light_attrib
);
358 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
359 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
362 if (mask
& GL_LINE_BIT
) {
363 struct gl_line_attrib
*attr
;
364 attr
= MALLOC_STRUCT( gl_line_attrib
);
365 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
366 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
369 if (mask
& GL_LIST_BIT
) {
370 struct gl_list_attrib
*attr
;
371 attr
= MALLOC_STRUCT( gl_list_attrib
);
372 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
373 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
376 if (mask
& GL_PIXEL_MODE_BIT
) {
377 struct gl_pixel_attrib
*attr
;
378 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
379 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
380 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
381 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
382 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
385 if (mask
& GL_POINT_BIT
) {
386 struct gl_point_attrib
*attr
;
387 attr
= MALLOC_STRUCT( gl_point_attrib
);
388 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
389 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
392 if (mask
& GL_POLYGON_BIT
) {
393 struct gl_polygon_attrib
*attr
;
394 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
395 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
396 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
399 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
401 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
402 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
403 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
406 if (mask
& GL_SCISSOR_BIT
) {
407 struct gl_scissor_attrib
*attr
;
408 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
409 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
410 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
413 if (mask
& GL_STENCIL_BUFFER_BIT
) {
414 struct gl_stencil_attrib
*attr
;
415 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
416 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
417 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
420 if (mask
& GL_TEXTURE_BIT
) {
421 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
425 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
429 _mesa_lock_context_textures(ctx
);
431 /* copy/save the bulk of texture state here */
432 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
434 /* Save references to the currently bound texture objects so they don't
435 * accidentally get deleted while referenced in the attribute stack.
437 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
438 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
439 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
440 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
444 /* copy state/contents of the currently bound texture objects */
445 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
446 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
447 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
448 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
452 _mesa_unlock_context_textures(ctx
);
454 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
457 if (mask
& GL_TRANSFORM_BIT
) {
458 struct gl_transform_attrib
*attr
;
459 attr
= MALLOC_STRUCT( gl_transform_attrib
);
460 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
461 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
464 if (mask
& GL_VIEWPORT_BIT
) {
465 struct gl_viewport_attrib
*attr
;
466 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
467 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
468 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
471 /* GL_ARB_multisample */
472 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
473 struct gl_multisample_attrib
*attr
;
474 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
475 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
476 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
480 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
481 ctx
->AttribStackDepth
++;
487 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
489 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
492 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
493 if ((VALUE) != (NEWVALUE)) { \
494 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
497 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
498 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
500 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
501 const GLuint mask
= 1 << i
;
502 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
503 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
504 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
507 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
509 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
510 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
512 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
513 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
514 GL_POST_CONVOLUTION_COLOR_TABLE
);
515 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
516 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
517 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
518 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
519 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
521 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
522 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
523 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
525 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
527 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
529 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
530 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
531 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
532 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
534 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
536 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
539 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
543 GL_MAP1_TEXTURE_COORD_1
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
545 GL_MAP1_TEXTURE_COORD_2
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
547 GL_MAP1_TEXTURE_COORD_3
);
548 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
549 GL_MAP1_TEXTURE_COORD_4
);
550 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
552 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
554 for (i
= 0; i
< 16; i
++) {
555 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
556 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
560 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
563 GL_MAP2_TEXTURE_COORD_1
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
565 GL_MAP2_TEXTURE_COORD_2
);
566 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
567 GL_MAP2_TEXTURE_COORD_3
);
568 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
569 GL_MAP2_TEXTURE_COORD_4
);
570 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
572 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
574 for (i
= 0; i
< 16; i
++) {
575 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
576 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
579 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
580 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
581 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
582 GL_RESCALE_NORMAL_EXT
);
583 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
584 enable
->RasterPositionUnclipped
,
585 GL_RASTER_POSITION_UNCLIPPED_IBM
);
586 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
588 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
589 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
592 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
593 GL_POLYGON_OFFSET_POINT
);
594 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
595 GL_POLYGON_OFFSET_LINE
);
596 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
597 GL_POLYGON_OFFSET_FILL
);
598 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
600 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
602 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
603 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
604 if (ctx
->Extensions
.EXT_stencil_two_side
) {
605 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
607 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
609 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
610 enable
->SampleAlphaToCoverage
,
611 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
612 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
613 enable
->SampleAlphaToOne
,
614 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
615 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
616 enable
->SampleCoverage
,
617 GL_SAMPLE_COVERAGE_ARB
);
618 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
619 enable
->SampleCoverageInvert
,
620 GL_SAMPLE_COVERAGE_INVERT_ARB
);
621 /* GL_ARB_vertex_program, GL_NV_vertex_program */
622 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
623 enable
->VertexProgram
,
624 GL_VERTEX_PROGRAM_ARB
);
625 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
626 enable
->VertexProgramPointSize
,
627 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
628 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
629 enable
->VertexProgramTwoSide
,
630 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
632 #undef TEST_AND_UPDATE
634 /* texture unit enables */
635 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
636 const GLbitfield enabled
= enable
->Texture
[i
];
637 const GLbitfield genEnabled
= enable
->TexGen
[i
];
639 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
640 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
642 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
643 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
644 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
645 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
646 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
647 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
648 if (ctx
->Extensions
.NV_texture_rectangle
) {
649 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
650 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
652 if (ctx
->Extensions
.ARB_texture_cube_map
) {
653 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
654 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
656 if (ctx
->Extensions
.MESA_texture_array
) {
657 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
658 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
659 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
660 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
664 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
665 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
666 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
667 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
668 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
669 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
670 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
671 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
672 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
673 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
676 /* GL_SGI_texture_color_table */
677 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
680 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
685 * Pop/restore texture attribute/group state.
688 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
692 _mesa_lock_context_textures(ctx
);
694 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
695 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
698 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
699 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
700 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
701 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
702 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
703 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
704 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
705 if (ctx
->Extensions
.ARB_texture_cube_map
) {
706 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
707 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
709 if (ctx
->Extensions
.NV_texture_rectangle
) {
710 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
711 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
713 if (ctx
->Extensions
.MESA_texture_array
) {
714 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
715 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
716 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
717 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
720 if (ctx
->Extensions
.SGI_texture_color_table
) {
721 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
722 unit
->ColorTableEnabled
);
724 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
725 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
726 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
727 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
728 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
729 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
730 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
731 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
732 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
733 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
734 /* Eye plane done differently to avoid re-transformation */
736 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
737 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
738 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
739 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
740 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
741 if (ctx
->Driver
.TexGen
) {
742 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
743 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
744 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
745 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
748 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
749 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
750 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
751 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
752 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
753 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
754 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
755 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
756 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
757 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
758 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
760 if (ctx
->Extensions
.EXT_texture_env_combine
||
761 ctx
->Extensions
.ARB_texture_env_combine
) {
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
763 unit
->Combine
.ModeRGB
);
764 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
765 unit
->Combine
.ModeA
);
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
767 unit
->Combine
.SourceRGB
[0]);
768 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
769 unit
->Combine
.SourceRGB
[1]);
770 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
771 unit
->Combine
.SourceRGB
[2]);
772 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
773 unit
->Combine
.SourceA
[0]);
774 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
775 unit
->Combine
.SourceA
[1]);
776 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
777 unit
->Combine
.SourceA
[2]);
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
779 unit
->Combine
.OperandRGB
[0]);
780 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
781 unit
->Combine
.OperandRGB
[1]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
783 unit
->Combine
.OperandRGB
[2]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
785 unit
->Combine
.OperandA
[0]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
787 unit
->Combine
.OperandA
[1]);
788 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
789 unit
->Combine
.OperandA
[2]);
790 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
791 1 << unit
->Combine
.ScaleShiftRGB
);
792 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
793 1 << unit
->Combine
.ScaleShiftA
);
796 /* Restore texture object state for each target */
797 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
798 const struct gl_texture_object
*obj
= NULL
;
801 obj
= &texstate
->SavedObj
[u
][tgt
];
803 /* don't restore state for unsupported targets to prevent
806 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
807 !ctx
->Extensions
.ARB_texture_cube_map
) {
810 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
811 !ctx
->Extensions
.NV_texture_rectangle
) {
814 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
815 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
816 !ctx
->Extensions
.MESA_texture_array
) {
820 target
= obj
->Target
;
822 _mesa_BindTexture(target
, obj
->Name
);
824 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
);
825 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
826 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
827 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
828 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
829 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
831 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
832 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
833 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
834 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
835 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
836 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
837 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
838 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
841 if (ctx
->Extensions
.ARB_shadow_ambient
) {
842 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
843 obj
->CompareFailValue
);
847 /* remove saved references to the texture objects */
848 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
849 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
853 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
855 _mesa_unlock_context_textures(ctx
);
860 * This function is kind of long just because we have to call a lot
861 * of device driver functions to update device driver state.
863 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
864 * in order to restore GL state. This isn't terribly efficient but it
865 * ensures that dirty flags and any derived state gets updated correctly.
866 * We could at least check if the value to restore equals the current value
867 * and then skip the Mesa call.
870 _mesa_PopAttrib(void)
872 struct gl_attrib_node
*attr
, *next
;
873 GET_CURRENT_CONTEXT(ctx
);
874 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
876 if (ctx
->AttribStackDepth
== 0) {
877 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
881 ctx
->AttribStackDepth
--;
882 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
886 if (MESA_VERBOSE
& VERBOSE_API
) {
887 _mesa_debug(ctx
, "glPopAttrib %s\n",
888 _mesa_lookup_enum_by_nr(attr
->kind
));
891 switch (attr
->kind
) {
892 case GL_ACCUM_BUFFER_BIT
:
894 const struct gl_accum_attrib
*accum
;
895 accum
= (const struct gl_accum_attrib
*) attr
->data
;
896 _mesa_ClearAccum(accum
->ClearColor
[0],
897 accum
->ClearColor
[1],
898 accum
->ClearColor
[2],
899 accum
->ClearColor
[3]);
902 case GL_COLOR_BUFFER_BIT
:
904 const struct gl_colorbuffer_attrib
*color
;
905 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
906 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
907 _mesa_ClearColor(color
->ClearColor
[0],
908 color
->ClearColor
[1],
909 color
->ClearColor
[2],
910 color
->ClearColor
[3]);
911 _mesa_IndexMask(color
->IndexMask
);
912 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
913 (GLboolean
) (color
->ColorMask
[1] != 0),
914 (GLboolean
) (color
->ColorMask
[2] != 0),
915 (GLboolean
) (color
->ColorMask
[3] != 0));
917 /* Need to determine if more than one color output is
918 * specified. If so, call glDrawBuffersARB, else call
919 * glDrawBuffer(). This is a subtle, but essential point
920 * since GL_FRONT (for example) is illegal for the former
921 * function, but legal for the later.
923 GLboolean multipleBuffers
= GL_FALSE
;
926 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
927 if (color
->DrawBuffer
[i
] != GL_NONE
) {
928 multipleBuffers
= GL_TRUE
;
932 /* Call the API_level functions, not _mesa_drawbuffers()
933 * since we need to do error checking on the pop'd
935 * Ex: if GL_FRONT were pushed, but we're popping with a
936 * user FBO bound, GL_FRONT will be illegal and we'll need
937 * to record that error. Per OpenGL ARB decision.
940 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
943 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
945 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
946 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
947 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
948 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
952 /* This special case is because glBlendEquationSeparateEXT
953 * cannot take GL_LOGIC_OP as a parameter.
955 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
956 _mesa_BlendEquation(color
->BlendEquationRGB
);
959 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
960 color
->BlendEquationA
);
962 _mesa_BlendColor(color
->BlendColor
[0],
963 color
->BlendColor
[1],
964 color
->BlendColor
[2],
965 color
->BlendColor
[3]);
966 _mesa_LogicOp(color
->LogicOp
);
967 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
968 color
->ColorLogicOpEnabled
);
969 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
970 color
->IndexLogicOpEnabled
);
971 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
975 FLUSH_CURRENT( ctx
, 0 );
976 MEMCPY( &ctx
->Current
, attr
->data
,
977 sizeof(struct gl_current_attrib
) );
979 case GL_DEPTH_BUFFER_BIT
:
981 const struct gl_depthbuffer_attrib
*depth
;
982 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
983 _mesa_DepthFunc(depth
->Func
);
984 _mesa_ClearDepth(depth
->Clear
);
985 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
986 _mesa_DepthMask(depth
->Mask
);
991 const struct gl_enable_attrib
*enable
;
992 enable
= (const struct gl_enable_attrib
*) attr
->data
;
993 pop_enable_group(ctx
, enable
);
994 ctx
->NewState
|= _NEW_ALL
;
998 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
999 ctx
->NewState
|= _NEW_EVAL
;
1003 const struct gl_fog_attrib
*fog
;
1004 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1005 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1006 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1007 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1008 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1009 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1010 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1011 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1016 const struct gl_hint_attrib
*hint
;
1017 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1018 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1019 hint
->PerspectiveCorrection
);
1020 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1021 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1022 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1023 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1024 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1025 hint
->ClipVolumeClipping
);
1026 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1027 hint
->TextureCompression
);
1030 case GL_LIGHTING_BIT
:
1033 const struct gl_light_attrib
*light
;
1034 light
= (const struct gl_light_attrib
*) attr
->data
;
1035 /* lighting enable */
1036 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1037 /* per-light state */
1038 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1039 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1041 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1042 const struct gl_light
*l
= &light
->Light
[i
];
1043 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1044 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1045 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1046 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1047 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1048 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1049 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1050 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1051 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1052 &l
->ConstantAttenuation
);
1053 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1054 &l
->LinearAttenuation
);
1055 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1056 &l
->QuadraticAttenuation
);
1059 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1060 light
->Model
.Ambient
);
1061 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1062 (GLfloat
) light
->Model
.LocalViewer
);
1063 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1064 (GLfloat
) light
->Model
.TwoSide
);
1065 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1066 (GLfloat
) light
->Model
.ColorControl
);
1068 _mesa_ShadeModel(light
->ShadeModel
);
1069 /* color material */
1070 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1071 light
->ColorMaterialMode
);
1072 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1073 light
->ColorMaterialEnabled
);
1075 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1076 sizeof(struct gl_material
));
1081 const struct gl_line_attrib
*line
;
1082 line
= (const struct gl_line_attrib
*) attr
->data
;
1083 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1084 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1085 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1086 _mesa_LineWidth(line
->Width
);
1090 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1092 case GL_PIXEL_MODE_BIT
:
1093 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1094 /* XXX what other pixel state needs to be set by function calls? */
1095 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1096 ctx
->NewState
|= _NEW_PIXEL
;
1100 const struct gl_point_attrib
*point
;
1101 point
= (const struct gl_point_attrib
*) attr
->data
;
1102 _mesa_PointSize(point
->Size
);
1103 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1104 if (ctx
->Extensions
.EXT_point_parameters
) {
1105 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1107 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1109 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1111 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1114 if (ctx
->Extensions
.NV_point_sprite
1115 || ctx
->Extensions
.ARB_point_sprite
) {
1117 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1118 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1119 (GLint
) point
->CoordReplace
[u
]);
1121 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1122 if (ctx
->Extensions
.NV_point_sprite
)
1123 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1124 ctx
->Point
.SpriteRMode
);
1125 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1126 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1130 case GL_POLYGON_BIT
:
1132 const struct gl_polygon_attrib
*polygon
;
1133 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1134 _mesa_CullFace(polygon
->CullFaceMode
);
1135 _mesa_FrontFace(polygon
->FrontFace
);
1136 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1137 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1138 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1139 polygon
->OffsetUnits
);
1140 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1141 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1142 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1143 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1144 polygon
->OffsetPoint
);
1145 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1146 polygon
->OffsetLine
);
1147 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1148 polygon
->OffsetFill
);
1151 case GL_POLYGON_STIPPLE_BIT
:
1152 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1153 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1154 if (ctx
->Driver
.PolygonStipple
)
1155 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1157 case GL_SCISSOR_BIT
:
1159 const struct gl_scissor_attrib
*scissor
;
1160 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1161 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1162 scissor
->Width
, scissor
->Height
);
1163 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1166 case GL_STENCIL_BUFFER_BIT
:
1168 const struct gl_stencil_attrib
*stencil
;
1169 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1170 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1171 _mesa_ClearStencil(stencil
->Clear
);
1172 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1173 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1174 stencil
->TestTwoSide
);
1175 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1176 ? GL_BACK
: GL_FRONT
);
1179 _mesa_StencilFuncSeparate(GL_FRONT
,
1180 stencil
->Function
[0],
1182 stencil
->ValueMask
[0]);
1183 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1184 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1185 stencil
->ZFailFunc
[0],
1186 stencil
->ZPassFunc
[0]);
1188 _mesa_StencilFuncSeparate(GL_BACK
,
1189 stencil
->Function
[1],
1191 stencil
->ValueMask
[1]);
1192 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1193 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1194 stencil
->ZFailFunc
[1],
1195 stencil
->ZPassFunc
[1]);
1198 case GL_TRANSFORM_BIT
:
1201 const struct gl_transform_attrib
*xform
;
1202 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1203 _mesa_MatrixMode(xform
->MatrixMode
);
1204 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1205 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1207 /* restore clip planes */
1208 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1209 const GLuint mask
= 1 << i
;
1210 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1211 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1212 if (xform
->ClipPlanesEnabled
& mask
) {
1213 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1216 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1218 if (ctx
->Driver
.ClipPlane
)
1219 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1222 /* normalize/rescale */
1223 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1224 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1225 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1226 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1227 ctx
->Transform
.RescaleNormals
);
1228 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1229 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1230 ctx
->Transform
.DepthClamp
);
1233 case GL_TEXTURE_BIT
:
1234 /* Take care of texture object reference counters */
1236 struct texture_state
*texstate
1237 = (struct texture_state
*) attr
->data
;
1238 pop_texture_group(ctx
, texstate
);
1239 ctx
->NewState
|= _NEW_TEXTURE
;
1242 case GL_VIEWPORT_BIT
:
1244 const struct gl_viewport_attrib
*vp
;
1245 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1246 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1247 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1250 case GL_MULTISAMPLE_BIT_ARB
:
1252 const struct gl_multisample_attrib
*ms
;
1253 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1254 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1255 ms
->SampleCoverageInvert
);
1260 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1273 * Helper for incrementing/decrementing vertex buffer object reference
1274 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1277 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1281 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1282 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1283 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1284 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1285 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1286 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1287 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1288 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1289 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1290 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1291 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1292 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1297 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1301 copy_pixelstore(GLcontext
*ctx
,
1302 struct gl_pixelstore_attrib
*dst
,
1303 const struct gl_pixelstore_attrib
*src
)
1305 dst
->Alignment
= src
->Alignment
;
1306 dst
->RowLength
= src
->RowLength
;
1307 dst
->SkipPixels
= src
->SkipPixels
;
1308 dst
->SkipRows
= src
->SkipRows
;
1309 dst
->ImageHeight
= src
->ImageHeight
;
1310 dst
->SkipImages
= src
->SkipImages
;
1311 dst
->SwapBytes
= src
->SwapBytes
;
1312 dst
->LsbFirst
= src
->LsbFirst
;
1313 dst
->ClientStorage
= src
->ClientStorage
;
1314 dst
->Invert
= src
->Invert
;
1315 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1319 #define GL_CLIENT_PACK_BIT (1<<20)
1320 #define GL_CLIENT_UNPACK_BIT (1<<21)
1324 _mesa_PushClientAttrib(GLbitfield mask
)
1326 struct gl_attrib_node
*head
;
1328 GET_CURRENT_CONTEXT(ctx
);
1329 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1331 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1332 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1336 /* Build linked list of attribute nodes which save all attribute
1337 * groups specified by the mask.
1341 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1342 struct gl_pixelstore_attrib
*attr
;
1343 /* packing attribs */
1344 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1345 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1346 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1347 /* unpacking attribs */
1348 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1349 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1350 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1353 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1354 struct gl_array_attrib
*attr
;
1355 struct gl_array_object
*obj
;
1357 attr
= MALLOC_STRUCT( gl_array_attrib
);
1358 obj
= MALLOC_STRUCT( gl_array_object
);
1360 #if FEATURE_ARB_vertex_buffer_object
1361 /* increment ref counts since we're copying pointers to these objects */
1362 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1363 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1366 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1367 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1369 attr
->ArrayObj
= obj
;
1371 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1373 /* bump reference counts on buffer objects */
1374 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1377 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1378 ctx
->ClientAttribStackDepth
++;
1385 _mesa_PopClientAttrib(void)
1387 struct gl_attrib_node
*node
, *next
;
1389 GET_CURRENT_CONTEXT(ctx
);
1390 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1392 if (ctx
->ClientAttribStackDepth
== 0) {
1393 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1397 ctx
->ClientAttribStackDepth
--;
1398 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1401 switch (node
->kind
) {
1402 case GL_CLIENT_PACK_BIT
:
1404 struct gl_pixelstore_attrib
*store
=
1405 (struct gl_pixelstore_attrib
*) node
->data
;
1406 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1407 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1409 ctx
->NewState
|= _NEW_PACKUNPACK
;
1411 case GL_CLIENT_UNPACK_BIT
:
1413 struct gl_pixelstore_attrib
*store
=
1414 (struct gl_pixelstore_attrib
*) node
->data
;
1415 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1416 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1418 ctx
->NewState
|= _NEW_PACKUNPACK
;
1420 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1421 struct gl_array_attrib
* data
=
1422 (struct gl_array_attrib
*) node
->data
;
1424 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1426 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1427 if (data
->LockCount
!= 0)
1428 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1429 else if (ctx
->Array
.LockCount
)
1430 _mesa_UnlockArraysEXT();
1432 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1434 #if FEATURE_ARB_vertex_buffer_object
1435 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1436 data
->ArrayBufferObj
->Name
);
1437 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1438 data
->ElementArrayBufferObj
->Name
);
1441 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1442 sizeof( struct gl_array_object
) );
1444 FREE( data
->ArrayObj
);
1446 /* FIXME: Should some bits in ctx->Array->NewState also be set
1447 * FIXME: here? It seems like it should be set to inclusive-or
1448 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1451 ctx
->NewState
|= _NEW_ARRAY
;
1455 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1468 * Free any attribute state data that might be attached to the context.
1471 _mesa_free_attrib_data(GLcontext
*ctx
)
1473 while (ctx
->AttribStackDepth
> 0) {
1474 struct gl_attrib_node
*attr
, *next
;
1476 ctx
->AttribStackDepth
--;
1477 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1480 if (attr
->kind
== GL_TEXTURE_BIT
) {
1481 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1483 /* clear references to the saved texture objects */
1484 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1485 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1486 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1491 /* any other chunks of state that requires special handling? */
1495 _mesa_free(attr
->data
);
1503 void _mesa_init_attrib( GLcontext
*ctx
)
1505 /* Renderer and client attribute stacks */
1506 ctx
->AttribStackDepth
= 0;
1507 ctx
->ClientAttribStackDepth
= 0;