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
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
97 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2Normal
;
101 GLboolean Map2TextureCoord1
;
102 GLboolean Map2TextureCoord2
;
103 GLboolean Map2TextureCoord3
;
104 GLboolean Map2TextureCoord4
;
105 GLboolean Map2Vertex3
;
106 GLboolean Map2Vertex4
;
107 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
111 GLboolean PixelTexture
;
112 GLboolean PointSmooth
;
113 GLboolean PolygonOffsetPoint
;
114 GLboolean PolygonOffsetLine
;
115 GLboolean PolygonOffsetFill
;
116 GLboolean PolygonSmooth
;
117 GLboolean PolygonStipple
;
118 GLboolean RescaleNormals
;
121 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
122 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
123 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
124 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
125 GLboolean SampleCoverage
; /* GL_ARB_multisample */
126 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
127 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
129 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
130 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
132 /* SGI_texture_color_table */
133 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
135 /* GL_ARB_vertex_program / GL_NV_vertex_program */
136 GLboolean VertexProgram
;
137 GLboolean VertexProgramPointSize
;
138 GLboolean VertexProgramTwoSide
;
140 /* GL_ARB_point_sprite / GL_NV_point_sprite */
141 GLboolean PointSprite
;
142 GLboolean FragmentShaderATI
;
147 * Node for the attribute stack.
149 struct gl_attrib_node
153 struct gl_attrib_node
*next
;
159 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
163 struct gl_texture_attrib Texture
; /**< The usual context state */
165 /** to save per texture object state (wrap modes, filters, etc): */
166 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
169 * To save references to texture objects (so they don't get accidentally
170 * deleted while saved in the attribute stack).
172 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
177 * Allocate new attribute node of given type/kind. Attach payload data.
178 * Insert it into the linked list named by 'head'.
181 save_attrib_data(struct gl_attrib_node
**head
,
182 GLbitfield kind
, void *payload
)
184 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
199 _mesa_PushAttrib(GLbitfield mask
)
201 struct gl_attrib_node
*head
;
203 GET_CURRENT_CONTEXT(ctx
);
204 ASSERT_OUTSIDE_BEGIN_END(ctx
);
206 if (MESA_VERBOSE
& VERBOSE_API
)
207 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
209 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
210 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
214 /* Build linked list of attribute nodes which save all attribute */
215 /* groups specified by the mask. */
218 if (mask
& GL_ACCUM_BUFFER_BIT
) {
219 struct gl_accum_attrib
*attr
;
220 attr
= MALLOC_STRUCT( gl_accum_attrib
);
221 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
222 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
225 if (mask
& GL_COLOR_BUFFER_BIT
) {
227 struct gl_colorbuffer_attrib
*attr
;
228 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
229 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
230 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
231 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
232 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
233 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
236 if (mask
& GL_CURRENT_BIT
) {
237 struct gl_current_attrib
*attr
;
238 FLUSH_CURRENT( ctx
, 0 );
239 attr
= MALLOC_STRUCT( gl_current_attrib
);
240 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
241 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
244 if (mask
& GL_DEPTH_BUFFER_BIT
) {
245 struct gl_depthbuffer_attrib
*attr
;
246 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
247 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
248 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
251 if (mask
& GL_ENABLE_BIT
) {
252 struct gl_enable_attrib
*attr
;
254 attr
= MALLOC_STRUCT( gl_enable_attrib
);
255 /* Copy enable flags from all other attributes into the enable struct. */
256 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
257 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
258 attr
->Blend
= ctx
->Color
.BlendEnabled
;
259 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
260 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
261 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
262 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
264 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
265 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
266 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
267 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
268 attr
->DepthTest
= ctx
->Depth
.Test
;
269 attr
->Dither
= ctx
->Color
.DitherFlag
;
270 attr
->Fog
= ctx
->Fog
.Enabled
;
271 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
272 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
274 attr
->Lighting
= ctx
->Light
.Enabled
;
275 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
276 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
277 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
278 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
279 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
280 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
281 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
282 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
283 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
284 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
285 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
286 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
287 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
288 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
289 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
290 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
291 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
292 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
293 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
294 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
295 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
296 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
297 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
298 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
299 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
300 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
301 attr
->Normalize
= ctx
->Transform
.Normalize
;
302 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
303 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
304 attr
->PointSprite
= ctx
->Point
.PointSprite
;
305 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
306 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
307 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
308 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
309 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
310 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
311 attr
->Scissor
= ctx
->Scissor
.Enabled
;
312 attr
->Stencil
= ctx
->Stencil
.Enabled
;
313 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
314 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
315 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
316 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
317 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
318 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
319 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
320 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
321 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
322 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
324 /* GL_NV_vertex_program */
325 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
326 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
327 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
328 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
331 if (mask
& GL_EVAL_BIT
) {
332 struct gl_eval_attrib
*attr
;
333 attr
= MALLOC_STRUCT( gl_eval_attrib
);
334 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
335 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
338 if (mask
& GL_FOG_BIT
) {
339 struct gl_fog_attrib
*attr
;
340 attr
= MALLOC_STRUCT( gl_fog_attrib
);
341 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
342 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
345 if (mask
& GL_HINT_BIT
) {
346 struct gl_hint_attrib
*attr
;
347 attr
= MALLOC_STRUCT( gl_hint_attrib
);
348 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
349 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
352 if (mask
& GL_LIGHTING_BIT
) {
353 struct gl_light_attrib
*attr
;
354 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
355 attr
= MALLOC_STRUCT( gl_light_attrib
);
356 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
357 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
360 if (mask
& GL_LINE_BIT
) {
361 struct gl_line_attrib
*attr
;
362 attr
= MALLOC_STRUCT( gl_line_attrib
);
363 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
364 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
367 if (mask
& GL_LIST_BIT
) {
368 struct gl_list_attrib
*attr
;
369 attr
= MALLOC_STRUCT( gl_list_attrib
);
370 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
371 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
374 if (mask
& GL_PIXEL_MODE_BIT
) {
375 struct gl_pixel_attrib
*attr
;
376 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
377 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
378 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
379 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
380 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
383 if (mask
& GL_POINT_BIT
) {
384 struct gl_point_attrib
*attr
;
385 attr
= MALLOC_STRUCT( gl_point_attrib
);
386 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
387 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
390 if (mask
& GL_POLYGON_BIT
) {
391 struct gl_polygon_attrib
*attr
;
392 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
393 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
394 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
397 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
399 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
400 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
401 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
404 if (mask
& GL_SCISSOR_BIT
) {
405 struct gl_scissor_attrib
*attr
;
406 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
407 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
408 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
411 if (mask
& GL_STENCIL_BUFFER_BIT
) {
412 struct gl_stencil_attrib
*attr
;
413 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
414 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
415 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
418 if (mask
& GL_TEXTURE_BIT
) {
419 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
427 _mesa_lock_context_textures(ctx
);
429 /* copy/save the bulk of texture state here */
430 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
432 /* Save references to the currently bound texture objects so they don't
433 * accidentally get deleted while referenced in the attribute stack.
435 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
436 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
437 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
438 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
442 /* copy state/contents of the currently bound texture objects */
443 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
444 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
445 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
446 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
450 _mesa_unlock_context_textures(ctx
);
452 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
455 if (mask
& GL_TRANSFORM_BIT
) {
456 struct gl_transform_attrib
*attr
;
457 attr
= MALLOC_STRUCT( gl_transform_attrib
);
458 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
459 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
462 if (mask
& GL_VIEWPORT_BIT
) {
463 struct gl_viewport_attrib
*attr
;
464 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
465 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
466 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
469 /* GL_ARB_multisample */
470 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
471 struct gl_multisample_attrib
*attr
;
472 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
473 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
474 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
478 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
479 ctx
->AttribStackDepth
++;
485 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
487 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
490 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
491 if ((VALUE) != (NEWVALUE)) { \
492 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
495 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
496 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
498 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
499 const GLuint mask
= 1 << i
;
500 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
501 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
502 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
505 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
507 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
508 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
510 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
511 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
512 GL_POST_CONVOLUTION_COLOR_TABLE
);
513 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
514 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
515 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
516 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
517 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
518 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
519 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
521 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
523 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
525 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
526 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
527 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
528 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
530 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
532 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
539 GL_MAP1_TEXTURE_COORD_1
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
541 GL_MAP1_TEXTURE_COORD_2
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
543 GL_MAP1_TEXTURE_COORD_3
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
545 GL_MAP1_TEXTURE_COORD_4
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
548 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
550 for (i
= 0; i
< 16; i
++) {
551 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
552 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
558 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
559 GL_MAP2_TEXTURE_COORD_1
);
560 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
561 GL_MAP2_TEXTURE_COORD_2
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
563 GL_MAP2_TEXTURE_COORD_3
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
565 GL_MAP2_TEXTURE_COORD_4
);
566 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
568 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
570 for (i
= 0; i
< 16; i
++) {
571 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
572 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
575 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
576 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
577 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
578 GL_RESCALE_NORMAL_EXT
);
579 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
580 enable
->RasterPositionUnclipped
,
581 GL_RASTER_POSITION_UNCLIPPED_IBM
);
582 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
584 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
585 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
588 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
589 GL_POLYGON_OFFSET_POINT
);
590 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
591 GL_POLYGON_OFFSET_LINE
);
592 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
593 GL_POLYGON_OFFSET_FILL
);
594 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
596 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
598 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
599 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
600 if (ctx
->Extensions
.EXT_stencil_two_side
) {
601 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
603 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
605 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
606 enable
->SampleAlphaToCoverage
,
607 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
608 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
609 enable
->SampleAlphaToOne
,
610 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
611 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
612 enable
->SampleCoverage
,
613 GL_SAMPLE_COVERAGE_ARB
);
614 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
615 enable
->SampleCoverageInvert
,
616 GL_SAMPLE_COVERAGE_INVERT_ARB
);
617 /* GL_ARB_vertex_program, GL_NV_vertex_program */
618 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
619 enable
->VertexProgram
,
620 GL_VERTEX_PROGRAM_ARB
);
621 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
622 enable
->VertexProgramPointSize
,
623 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
624 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
625 enable
->VertexProgramTwoSide
,
626 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
628 #undef TEST_AND_UPDATE
630 /* texture unit enables */
631 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
632 const GLbitfield enabled
= enable
->Texture
[i
];
633 const GLbitfield genEnabled
= enable
->TexGen
[i
];
635 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
636 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
638 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
639 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
640 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
641 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
642 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
643 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
644 if (ctx
->Extensions
.NV_texture_rectangle
) {
645 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
646 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
648 if (ctx
->Extensions
.ARB_texture_cube_map
) {
649 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
650 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
652 if (ctx
->Extensions
.MESA_texture_array
) {
653 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
654 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
655 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
656 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
660 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
661 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
662 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
663 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
664 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
665 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
666 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
667 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
668 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
669 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
672 /* GL_SGI_texture_color_table */
673 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
676 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
681 * Pop/restore texture attribute/group state.
684 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
688 _mesa_lock_context_textures(ctx
);
690 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
691 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
694 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
695 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
696 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
697 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
698 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
699 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
700 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
701 if (ctx
->Extensions
.ARB_texture_cube_map
) {
702 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
703 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
705 if (ctx
->Extensions
.NV_texture_rectangle
) {
706 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
707 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
709 if (ctx
->Extensions
.MESA_texture_array
) {
710 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
711 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
713 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
716 if (ctx
->Extensions
.SGI_texture_color_table
) {
717 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
718 unit
->ColorTableEnabled
);
720 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
721 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
722 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
723 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
724 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
725 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
726 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
727 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
728 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
729 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
730 /* Eye plane done differently to avoid re-transformation */
732 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
733 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
734 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
735 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
736 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
737 if (ctx
->Driver
.TexGen
) {
738 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
739 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
740 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
741 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
744 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
745 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
746 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
747 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
748 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
749 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
750 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
751 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
752 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
753 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
754 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
756 if (ctx
->Extensions
.EXT_texture_env_combine
||
757 ctx
->Extensions
.ARB_texture_env_combine
) {
758 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
759 unit
->Combine
.ModeRGB
);
760 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
761 unit
->Combine
.ModeA
);
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
763 unit
->Combine
.SourceRGB
[0]);
764 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
765 unit
->Combine
.SourceRGB
[1]);
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
767 unit
->Combine
.SourceRGB
[2]);
768 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
769 unit
->Combine
.SourceA
[0]);
770 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
771 unit
->Combine
.SourceA
[1]);
772 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
773 unit
->Combine
.SourceA
[2]);
774 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
775 unit
->Combine
.OperandRGB
[0]);
776 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
777 unit
->Combine
.OperandRGB
[1]);
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
779 unit
->Combine
.OperandRGB
[2]);
780 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
781 unit
->Combine
.OperandA
[0]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
783 unit
->Combine
.OperandA
[1]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
785 unit
->Combine
.OperandA
[2]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
787 1 << unit
->Combine
.ScaleShiftRGB
);
788 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
789 1 << unit
->Combine
.ScaleShiftA
);
792 /* Restore texture object state for each target */
793 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
794 const struct gl_texture_object
*obj
= NULL
;
797 obj
= &texstate
->SavedObj
[u
][tgt
];
799 /* don't restore state for unsupported targets to prevent
802 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
803 !ctx
->Extensions
.ARB_texture_cube_map
) {
806 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
807 !ctx
->Extensions
.NV_texture_rectangle
) {
810 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
811 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
812 !ctx
->Extensions
.MESA_texture_array
) {
816 target
= obj
->Target
;
818 _mesa_BindTexture(target
, obj
->Name
);
820 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
);
821 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
822 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
823 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
824 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
825 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
826 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
827 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
828 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
829 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
831 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
832 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
833 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
834 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
837 if (ctx
->Extensions
.ARB_shadow_ambient
) {
838 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
839 obj
->CompareFailValue
);
843 /* remove saved references to the texture objects */
844 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
845 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
849 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
851 _mesa_unlock_context_textures(ctx
);
856 * This function is kind of long just because we have to call a lot
857 * of device driver functions to update device driver state.
859 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
860 * in order to restore GL state. This isn't terribly efficient but it
861 * ensures that dirty flags and any derived state gets updated correctly.
862 * We could at least check if the value to restore equals the current value
863 * and then skip the Mesa call.
866 _mesa_PopAttrib(void)
868 struct gl_attrib_node
*attr
, *next
;
869 GET_CURRENT_CONTEXT(ctx
);
870 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
872 if (ctx
->AttribStackDepth
== 0) {
873 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
877 ctx
->AttribStackDepth
--;
878 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
882 if (MESA_VERBOSE
& VERBOSE_API
) {
883 _mesa_debug(ctx
, "glPopAttrib %s\n",
884 _mesa_lookup_enum_by_nr(attr
->kind
));
887 switch (attr
->kind
) {
888 case GL_ACCUM_BUFFER_BIT
:
890 const struct gl_accum_attrib
*accum
;
891 accum
= (const struct gl_accum_attrib
*) attr
->data
;
892 _mesa_ClearAccum(accum
->ClearColor
[0],
893 accum
->ClearColor
[1],
894 accum
->ClearColor
[2],
895 accum
->ClearColor
[3]);
898 case GL_COLOR_BUFFER_BIT
:
900 const struct gl_colorbuffer_attrib
*color
;
901 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
902 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
903 _mesa_ClearColor(color
->ClearColor
[0],
904 color
->ClearColor
[1],
905 color
->ClearColor
[2],
906 color
->ClearColor
[3]);
907 _mesa_IndexMask(color
->IndexMask
);
908 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
909 (GLboolean
) (color
->ColorMask
[1] != 0),
910 (GLboolean
) (color
->ColorMask
[2] != 0),
911 (GLboolean
) (color
->ColorMask
[3] != 0));
913 /* Need to determine if more than one color output is
914 * specified. If so, call glDrawBuffersARB, else call
915 * glDrawBuffer(). This is a subtle, but essential point
916 * since GL_FRONT (for example) is illegal for the former
917 * function, but legal for the later.
919 GLboolean multipleBuffers
= GL_FALSE
;
922 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
923 if (color
->DrawBuffer
[i
] != GL_NONE
) {
924 multipleBuffers
= GL_TRUE
;
928 /* Call the API_level functions, not _mesa_drawbuffers()
929 * since we need to do error checking on the pop'd
931 * Ex: if GL_FRONT were pushed, but we're popping with a
932 * user FBO bound, GL_FRONT will be illegal and we'll need
933 * to record that error. Per OpenGL ARB decision.
936 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
939 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
941 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
942 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
943 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
944 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
948 /* This special case is because glBlendEquationSeparateEXT
949 * cannot take GL_LOGIC_OP as a parameter.
951 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
952 _mesa_BlendEquation(color
->BlendEquationRGB
);
955 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
956 color
->BlendEquationA
);
958 _mesa_BlendColor(color
->BlendColor
[0],
959 color
->BlendColor
[1],
960 color
->BlendColor
[2],
961 color
->BlendColor
[3]);
962 _mesa_LogicOp(color
->LogicOp
);
963 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
964 color
->ColorLogicOpEnabled
);
965 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
966 color
->IndexLogicOpEnabled
);
967 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
971 FLUSH_CURRENT( ctx
, 0 );
972 MEMCPY( &ctx
->Current
, attr
->data
,
973 sizeof(struct gl_current_attrib
) );
975 case GL_DEPTH_BUFFER_BIT
:
977 const struct gl_depthbuffer_attrib
*depth
;
978 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
979 _mesa_DepthFunc(depth
->Func
);
980 _mesa_ClearDepth(depth
->Clear
);
981 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
982 _mesa_DepthMask(depth
->Mask
);
987 const struct gl_enable_attrib
*enable
;
988 enable
= (const struct gl_enable_attrib
*) attr
->data
;
989 pop_enable_group(ctx
, enable
);
990 ctx
->NewState
|= _NEW_ALL
;
994 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
995 ctx
->NewState
|= _NEW_EVAL
;
999 const struct gl_fog_attrib
*fog
;
1000 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1001 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1002 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1003 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1004 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1005 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1006 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1007 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1012 const struct gl_hint_attrib
*hint
;
1013 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1014 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1015 hint
->PerspectiveCorrection
);
1016 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1017 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1018 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1019 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1020 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1021 hint
->ClipVolumeClipping
);
1022 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1023 hint
->TextureCompression
);
1026 case GL_LIGHTING_BIT
:
1029 const struct gl_light_attrib
*light
;
1030 light
= (const struct gl_light_attrib
*) attr
->data
;
1031 /* lighting enable */
1032 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1033 /* per-light state */
1034 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1035 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1037 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1038 const struct gl_light
*l
= &light
->Light
[i
];
1039 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1040 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1041 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1042 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1043 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1044 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1045 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1046 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1047 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1048 &l
->ConstantAttenuation
);
1049 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1050 &l
->LinearAttenuation
);
1051 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1052 &l
->QuadraticAttenuation
);
1055 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1056 light
->Model
.Ambient
);
1057 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1058 (GLfloat
) light
->Model
.LocalViewer
);
1059 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1060 (GLfloat
) light
->Model
.TwoSide
);
1061 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1062 (GLfloat
) light
->Model
.ColorControl
);
1064 _mesa_ShadeModel(light
->ShadeModel
);
1065 /* color material */
1066 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1067 light
->ColorMaterialMode
);
1068 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1069 light
->ColorMaterialEnabled
);
1071 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1072 sizeof(struct gl_material
));
1077 const struct gl_line_attrib
*line
;
1078 line
= (const struct gl_line_attrib
*) attr
->data
;
1079 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1080 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1081 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1082 _mesa_LineWidth(line
->Width
);
1086 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1088 case GL_PIXEL_MODE_BIT
:
1089 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1090 /* XXX what other pixel state needs to be set by function calls? */
1091 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1092 ctx
->NewState
|= _NEW_PIXEL
;
1096 const struct gl_point_attrib
*point
;
1097 point
= (const struct gl_point_attrib
*) attr
->data
;
1098 _mesa_PointSize(point
->Size
);
1099 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1100 if (ctx
->Extensions
.EXT_point_parameters
) {
1101 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1103 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1105 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1107 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1110 if (ctx
->Extensions
.NV_point_sprite
1111 || ctx
->Extensions
.ARB_point_sprite
) {
1113 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1114 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1115 (GLint
) point
->CoordReplace
[u
]);
1117 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1118 if (ctx
->Extensions
.NV_point_sprite
)
1119 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1120 ctx
->Point
.SpriteRMode
);
1121 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1122 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1126 case GL_POLYGON_BIT
:
1128 const struct gl_polygon_attrib
*polygon
;
1129 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1130 _mesa_CullFace(polygon
->CullFaceMode
);
1131 _mesa_FrontFace(polygon
->FrontFace
);
1132 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1133 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1134 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1135 polygon
->OffsetUnits
);
1136 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1137 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1138 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1139 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1140 polygon
->OffsetPoint
);
1141 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1142 polygon
->OffsetLine
);
1143 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1144 polygon
->OffsetFill
);
1147 case GL_POLYGON_STIPPLE_BIT
:
1148 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1149 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1150 if (ctx
->Driver
.PolygonStipple
)
1151 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1153 case GL_SCISSOR_BIT
:
1155 const struct gl_scissor_attrib
*scissor
;
1156 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1157 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1158 scissor
->Width
, scissor
->Height
);
1159 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1162 case GL_STENCIL_BUFFER_BIT
:
1164 const struct gl_stencil_attrib
*stencil
;
1165 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1166 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1167 _mesa_ClearStencil(stencil
->Clear
);
1168 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1169 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1170 stencil
->TestTwoSide
);
1171 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1172 ? GL_BACK
: GL_FRONT
);
1175 _mesa_StencilFuncSeparate(GL_FRONT
,
1176 stencil
->Function
[0],
1178 stencil
->ValueMask
[0]);
1179 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1180 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1181 stencil
->ZFailFunc
[0],
1182 stencil
->ZPassFunc
[0]);
1184 _mesa_StencilFuncSeparate(GL_BACK
,
1185 stencil
->Function
[1],
1187 stencil
->ValueMask
[1]);
1188 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1189 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1190 stencil
->ZFailFunc
[1],
1191 stencil
->ZPassFunc
[1]);
1194 case GL_TRANSFORM_BIT
:
1197 const struct gl_transform_attrib
*xform
;
1198 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1199 _mesa_MatrixMode(xform
->MatrixMode
);
1200 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1201 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1203 /* restore clip planes */
1204 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1205 const GLuint mask
= 1 << i
;
1206 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1207 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1208 if (xform
->ClipPlanesEnabled
& mask
) {
1209 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1212 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1214 if (ctx
->Driver
.ClipPlane
)
1215 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1218 /* normalize/rescale */
1219 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1220 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1221 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1222 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1223 ctx
->Transform
.RescaleNormals
);
1226 case GL_TEXTURE_BIT
:
1227 /* Take care of texture object reference counters */
1229 struct texture_state
*texstate
1230 = (struct texture_state
*) attr
->data
;
1231 pop_texture_group(ctx
, texstate
);
1232 ctx
->NewState
|= _NEW_TEXTURE
;
1235 case GL_VIEWPORT_BIT
:
1237 const struct gl_viewport_attrib
*vp
;
1238 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1239 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1240 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1243 case GL_MULTISAMPLE_BIT_ARB
:
1245 const struct gl_multisample_attrib
*ms
;
1246 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1247 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1248 ms
->SampleCoverageInvert
);
1253 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1266 * Helper for incrementing/decrementing vertex buffer object reference
1267 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1270 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1274 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1275 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1276 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1277 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1278 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1279 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1280 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1281 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1282 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1283 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1284 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1285 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1290 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1294 copy_pixelstore(GLcontext
*ctx
,
1295 struct gl_pixelstore_attrib
*dst
,
1296 const struct gl_pixelstore_attrib
*src
)
1298 dst
->Alignment
= src
->Alignment
;
1299 dst
->RowLength
= src
->RowLength
;
1300 dst
->SkipPixels
= src
->SkipPixels
;
1301 dst
->SkipRows
= src
->SkipRows
;
1302 dst
->ImageHeight
= src
->ImageHeight
;
1303 dst
->SkipImages
= src
->SkipImages
;
1304 dst
->SwapBytes
= src
->SwapBytes
;
1305 dst
->LsbFirst
= src
->LsbFirst
;
1306 dst
->ClientStorage
= src
->ClientStorage
;
1307 dst
->Invert
= src
->Invert
;
1308 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1312 #define GL_CLIENT_PACK_BIT (1<<20)
1313 #define GL_CLIENT_UNPACK_BIT (1<<21)
1317 _mesa_PushClientAttrib(GLbitfield mask
)
1319 struct gl_attrib_node
*head
;
1321 GET_CURRENT_CONTEXT(ctx
);
1322 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1324 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1325 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1329 /* Build linked list of attribute nodes which save all attribute
1330 * groups specified by the mask.
1334 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1335 struct gl_pixelstore_attrib
*attr
;
1336 /* packing attribs */
1337 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1338 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1339 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1340 /* unpacking attribs */
1341 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1342 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1343 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1346 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1347 struct gl_array_attrib
*attr
;
1348 struct gl_array_object
*obj
;
1350 attr
= MALLOC_STRUCT( gl_array_attrib
);
1351 obj
= MALLOC_STRUCT( gl_array_object
);
1353 #if FEATURE_ARB_vertex_buffer_object
1354 /* increment ref counts since we're copying pointers to these objects */
1355 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1356 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1359 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1360 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1362 attr
->ArrayObj
= obj
;
1364 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1366 /* bump reference counts on buffer objects */
1367 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1370 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1371 ctx
->ClientAttribStackDepth
++;
1378 _mesa_PopClientAttrib(void)
1380 struct gl_attrib_node
*node
, *next
;
1382 GET_CURRENT_CONTEXT(ctx
);
1383 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1385 if (ctx
->ClientAttribStackDepth
== 0) {
1386 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1390 ctx
->ClientAttribStackDepth
--;
1391 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1394 switch (node
->kind
) {
1395 case GL_CLIENT_PACK_BIT
:
1397 struct gl_pixelstore_attrib
*store
=
1398 (struct gl_pixelstore_attrib
*) node
->data
;
1399 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1400 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1402 ctx
->NewState
|= _NEW_PACKUNPACK
;
1404 case GL_CLIENT_UNPACK_BIT
:
1406 struct gl_pixelstore_attrib
*store
=
1407 (struct gl_pixelstore_attrib
*) node
->data
;
1408 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1409 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1411 ctx
->NewState
|= _NEW_PACKUNPACK
;
1413 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1414 struct gl_array_attrib
* data
=
1415 (struct gl_array_attrib
*) node
->data
;
1417 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1419 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1420 if (data
->LockCount
!= 0)
1421 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1422 else if (ctx
->Array
.LockCount
)
1423 _mesa_UnlockArraysEXT();
1425 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1427 #if FEATURE_ARB_vertex_buffer_object
1428 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1429 data
->ArrayBufferObj
->Name
);
1430 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1431 data
->ElementArrayBufferObj
->Name
);
1434 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1435 sizeof( struct gl_array_object
) );
1437 FREE( data
->ArrayObj
);
1439 /* FIXME: Should some bits in ctx->Array->NewState also be set
1440 * FIXME: here? It seems like it should be set to inclusive-or
1441 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1444 ctx
->NewState
|= _NEW_ARRAY
;
1448 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1461 * Free any attribute state data that might be attached to the context.
1464 _mesa_free_attrib_data(GLcontext
*ctx
)
1466 while (ctx
->AttribStackDepth
> 0) {
1467 struct gl_attrib_node
*attr
, *next
;
1469 ctx
->AttribStackDepth
--;
1470 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1473 if (attr
->kind
== GL_TEXTURE_BIT
) {
1474 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1476 /* clear references to the saved texture objects */
1477 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1478 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1479 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1484 /* any other chunks of state that requires special handling? */
1488 _mesa_free(attr
->data
);
1496 void _mesa_init_attrib( GLcontext
*ctx
)
1498 /* Renderer and client attribute stacks */
1499 ctx
->AttribStackDepth
= 0;
1500 ctx
->ClientAttribStackDepth
= 0;