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"
62 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
66 struct gl_texture_attrib Texture
; /**< The usual context state */
68 /** to save per texture object state (wrap modes, filters, etc): */
69 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
72 * To save references to texture objects (so they don't get accidentally
73 * deleted while saved in the attribute stack).
75 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
80 * Allocate a new attribute state node. These nodes have a
81 * "kind" value and a pointer to a struct of state data.
83 static struct gl_attrib_node
*
84 new_attrib_node( GLbitfield kind
)
86 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
95 _mesa_PushAttrib(GLbitfield mask
)
97 struct gl_attrib_node
*newnode
;
98 struct gl_attrib_node
*head
;
100 GET_CURRENT_CONTEXT(ctx
);
101 ASSERT_OUTSIDE_BEGIN_END(ctx
);
103 if (MESA_VERBOSE
& VERBOSE_API
)
104 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
106 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
107 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
111 /* Build linked list of attribute nodes which save all attribute */
112 /* groups specified by the mask. */
115 if (mask
& GL_ACCUM_BUFFER_BIT
) {
116 struct gl_accum_attrib
*attr
;
117 attr
= MALLOC_STRUCT( gl_accum_attrib
);
118 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
119 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
120 newnode
->data
= attr
;
121 newnode
->next
= head
;
125 if (mask
& GL_COLOR_BUFFER_BIT
) {
127 struct gl_colorbuffer_attrib
*attr
;
128 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
129 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
130 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
131 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
132 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
133 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
134 newnode
->data
= attr
;
135 newnode
->next
= head
;
139 if (mask
& GL_CURRENT_BIT
) {
140 struct gl_current_attrib
*attr
;
141 FLUSH_CURRENT( ctx
, 0 );
142 attr
= MALLOC_STRUCT( gl_current_attrib
);
143 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
144 newnode
= new_attrib_node( GL_CURRENT_BIT
);
145 newnode
->data
= attr
;
146 newnode
->next
= head
;
150 if (mask
& GL_DEPTH_BUFFER_BIT
) {
151 struct gl_depthbuffer_attrib
*attr
;
152 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
153 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
154 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
155 newnode
->data
= attr
;
156 newnode
->next
= head
;
160 if (mask
& GL_ENABLE_BIT
) {
161 struct gl_enable_attrib
*attr
;
163 attr
= MALLOC_STRUCT( gl_enable_attrib
);
164 /* Copy enable flags from all other attributes into the enable struct. */
165 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
166 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
167 attr
->Blend
= ctx
->Color
.BlendEnabled
;
168 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
169 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
170 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
171 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
173 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
174 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
175 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
176 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
177 attr
->DepthTest
= ctx
->Depth
.Test
;
178 attr
->Dither
= ctx
->Color
.DitherFlag
;
179 attr
->Fog
= ctx
->Fog
.Enabled
;
180 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
181 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
183 attr
->Lighting
= ctx
->Light
.Enabled
;
184 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
185 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
186 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
187 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
188 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
189 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
190 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
191 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
192 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
193 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
194 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
195 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
196 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
197 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
198 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
199 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
200 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
201 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
202 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
203 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
204 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
205 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
206 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
207 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
208 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
209 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
210 attr
->Normalize
= ctx
->Transform
.Normalize
;
211 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
212 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
213 attr
->PointSprite
= ctx
->Point
.PointSprite
;
214 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
215 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
216 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
217 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
218 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
219 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
220 attr
->Scissor
= ctx
->Scissor
.Enabled
;
221 attr
->Stencil
= ctx
->Stencil
.Enabled
;
222 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
223 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
224 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
225 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
226 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
227 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
228 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
229 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
230 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
231 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
233 /* GL_NV_vertex_program */
234 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
235 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
236 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
237 newnode
= new_attrib_node( GL_ENABLE_BIT
);
238 newnode
->data
= attr
;
239 newnode
->next
= head
;
243 if (mask
& GL_EVAL_BIT
) {
244 struct gl_eval_attrib
*attr
;
245 attr
= MALLOC_STRUCT( gl_eval_attrib
);
246 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
247 newnode
= new_attrib_node( GL_EVAL_BIT
);
248 newnode
->data
= attr
;
249 newnode
->next
= head
;
253 if (mask
& GL_FOG_BIT
) {
254 struct gl_fog_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_fog_attrib
);
256 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
257 newnode
= new_attrib_node( GL_FOG_BIT
);
258 newnode
->data
= attr
;
259 newnode
->next
= head
;
263 if (mask
& GL_HINT_BIT
) {
264 struct gl_hint_attrib
*attr
;
265 attr
= MALLOC_STRUCT( gl_hint_attrib
);
266 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
267 newnode
= new_attrib_node( GL_HINT_BIT
);
268 newnode
->data
= attr
;
269 newnode
->next
= head
;
273 if (mask
& GL_LIGHTING_BIT
) {
274 struct gl_light_attrib
*attr
;
275 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
276 attr
= MALLOC_STRUCT( gl_light_attrib
);
277 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
278 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
279 newnode
->data
= attr
;
280 newnode
->next
= head
;
284 if (mask
& GL_LINE_BIT
) {
285 struct gl_line_attrib
*attr
;
286 attr
= MALLOC_STRUCT( gl_line_attrib
);
287 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
288 newnode
= new_attrib_node( GL_LINE_BIT
);
289 newnode
->data
= attr
;
290 newnode
->next
= head
;
294 if (mask
& GL_LIST_BIT
) {
295 struct gl_list_attrib
*attr
;
296 attr
= MALLOC_STRUCT( gl_list_attrib
);
297 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
298 newnode
= new_attrib_node( GL_LIST_BIT
);
299 newnode
->data
= attr
;
300 newnode
->next
= head
;
304 if (mask
& GL_PIXEL_MODE_BIT
) {
305 struct gl_pixel_attrib
*attr
;
306 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
307 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
308 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
309 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
310 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
311 newnode
->data
= attr
;
312 newnode
->next
= head
;
316 if (mask
& GL_POINT_BIT
) {
317 struct gl_point_attrib
*attr
;
318 attr
= MALLOC_STRUCT( gl_point_attrib
);
319 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
320 newnode
= new_attrib_node( GL_POINT_BIT
);
321 newnode
->data
= attr
;
322 newnode
->next
= head
;
326 if (mask
& GL_POLYGON_BIT
) {
327 struct gl_polygon_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
329 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
330 newnode
= new_attrib_node( GL_POLYGON_BIT
);
331 newnode
->data
= attr
;
332 newnode
->next
= head
;
336 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
338 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
339 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
340 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
341 newnode
->data
= stipple
;
342 newnode
->next
= head
;
346 if (mask
& GL_SCISSOR_BIT
) {
347 struct gl_scissor_attrib
*attr
;
348 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
349 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
350 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
351 newnode
->data
= attr
;
352 newnode
->next
= head
;
356 if (mask
& GL_STENCIL_BUFFER_BIT
) {
357 struct gl_stencil_attrib
*attr
;
358 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
359 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
360 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
361 newnode
->data
= attr
;
362 newnode
->next
= head
;
366 if (mask
& GL_TEXTURE_BIT
) {
367 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
371 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
375 _mesa_lock_context_textures(ctx
);
377 /* copy/save the bulk of texture state here */
378 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
380 /* Save references to the currently bound texture objects so they don't
381 * accidentally get deleted while referenced in the attribute stack.
383 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
384 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_INDEX
],
385 ctx
->Texture
.Unit
[u
].Current1D
);
386 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_INDEX
],
387 ctx
->Texture
.Unit
[u
].Current2D
);
388 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_3D_INDEX
],
389 ctx
->Texture
.Unit
[u
].Current3D
);
390 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_CUBE_INDEX
],
391 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
392 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_RECT_INDEX
],
393 ctx
->Texture
.Unit
[u
].CurrentRect
);
394 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_ARRAY_INDEX
],
395 ctx
->Texture
.Unit
[u
].Current1DArray
);
396 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_ARRAY_INDEX
],
397 ctx
->Texture
.Unit
[u
].Current2DArray
);
400 /* copy state/contents of the currently bound texture objects */
401 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
402 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_INDEX
],
403 ctx
->Texture
.Unit
[u
].Current1D
);
404 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_INDEX
],
405 ctx
->Texture
.Unit
[u
].Current2D
);
406 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_3D_INDEX
],
407 ctx
->Texture
.Unit
[u
].Current3D
);
408 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_CUBE_INDEX
],
409 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
410 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_RECT_INDEX
],
411 ctx
->Texture
.Unit
[u
].CurrentRect
);
412 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_ARRAY_INDEX
],
413 ctx
->Texture
.Unit
[u
].Current1DArray
);
414 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_ARRAY_INDEX
],
415 ctx
->Texture
.Unit
[u
].Current2DArray
);
418 _mesa_unlock_context_textures(ctx
);
420 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
421 newnode
->data
= texstate
;
422 newnode
->next
= head
;
426 if (mask
& GL_TRANSFORM_BIT
) {
427 struct gl_transform_attrib
*attr
;
428 attr
= MALLOC_STRUCT( gl_transform_attrib
);
429 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
430 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
431 newnode
->data
= attr
;
432 newnode
->next
= head
;
436 if (mask
& GL_VIEWPORT_BIT
) {
437 struct gl_viewport_attrib
*attr
;
438 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
439 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
440 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
441 newnode
->data
= attr
;
442 newnode
->next
= head
;
446 /* GL_ARB_multisample */
447 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
448 struct gl_multisample_attrib
*attr
;
449 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
450 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
451 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
452 newnode
->data
= attr
;
453 newnode
->next
= head
;
458 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
459 ctx
->AttribStackDepth
++;
465 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
469 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
470 if ((VALUE) != (NEWVALUE)) { \
471 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
474 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
475 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
477 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
478 const GLuint mask
= 1 << i
;
479 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
480 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
481 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
484 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
486 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
487 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
489 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
490 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
491 GL_POST_CONVOLUTION_COLOR_TABLE
);
492 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
493 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
494 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
495 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
496 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
497 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
498 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
500 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
502 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
504 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
505 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
506 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
507 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
509 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
511 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
514 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
515 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
518 GL_MAP1_TEXTURE_COORD_1
);
519 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
520 GL_MAP1_TEXTURE_COORD_2
);
521 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
522 GL_MAP1_TEXTURE_COORD_3
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
524 GL_MAP1_TEXTURE_COORD_4
);
525 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
527 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
529 for (i
= 0; i
< 16; i
++) {
530 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
531 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
534 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
538 GL_MAP2_TEXTURE_COORD_1
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
540 GL_MAP2_TEXTURE_COORD_2
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
542 GL_MAP2_TEXTURE_COORD_3
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
544 GL_MAP2_TEXTURE_COORD_4
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
547 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
549 for (i
= 0; i
< 16; i
++) {
550 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
551 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
554 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
555 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
556 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
557 GL_RESCALE_NORMAL_EXT
);
558 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
559 enable
->RasterPositionUnclipped
,
560 GL_RASTER_POSITION_UNCLIPPED_IBM
);
561 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
563 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
564 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
567 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
568 GL_POLYGON_OFFSET_POINT
);
569 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
570 GL_POLYGON_OFFSET_LINE
);
571 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
572 GL_POLYGON_OFFSET_FILL
);
573 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
575 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
577 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
578 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
579 if (ctx
->Extensions
.EXT_stencil_two_side
) {
580 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
582 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
584 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
585 enable
->SampleAlphaToCoverage
,
586 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
587 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
588 enable
->SampleAlphaToOne
,
589 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
590 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
591 enable
->SampleCoverage
,
592 GL_SAMPLE_COVERAGE_ARB
);
593 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
594 enable
->SampleCoverageInvert
,
595 GL_SAMPLE_COVERAGE_INVERT_ARB
);
596 /* GL_ARB_vertex_program, GL_NV_vertex_program */
597 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
598 enable
->VertexProgram
,
599 GL_VERTEX_PROGRAM_ARB
);
600 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
601 enable
->VertexProgramPointSize
,
602 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
603 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
604 enable
->VertexProgramTwoSide
,
605 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
607 #undef TEST_AND_UPDATE
609 /* texture unit enables */
610 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
611 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
612 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
613 if (ctx
->Driver
.Enable
) {
614 if (ctx
->Driver
.ActiveTexture
) {
615 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
617 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
618 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
619 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
620 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
621 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
622 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
623 if (ctx
->Extensions
.ARB_texture_cube_map
)
624 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
625 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
626 if (ctx
->Extensions
.NV_texture_rectangle
)
627 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
628 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
632 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
633 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
634 if (ctx
->Driver
.Enable
) {
635 if (ctx
->Driver
.ActiveTexture
) {
636 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
638 if (enable
->TexGen
[i
] & S_BIT
)
639 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
641 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
642 if (enable
->TexGen
[i
] & T_BIT
)
643 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
645 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
646 if (enable
->TexGen
[i
] & R_BIT
)
647 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
649 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
650 if (enable
->TexGen
[i
] & Q_BIT
)
651 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
653 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
657 /* GL_SGI_texture_color_table */
658 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
661 if (ctx
->Driver
.ActiveTexture
) {
662 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
668 * Pop/restore texture attribute/group state.
671 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
675 _mesa_lock_context_textures(ctx
);
677 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
678 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
681 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
682 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
683 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
684 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
685 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
686 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
687 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
688 if (ctx
->Extensions
.ARB_texture_cube_map
) {
689 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
690 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
692 if (ctx
->Extensions
.NV_texture_rectangle
) {
693 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
694 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
696 if (ctx
->Extensions
.SGI_texture_color_table
) {
697 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
698 unit
->ColorTableEnabled
);
700 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
701 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
702 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
703 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
704 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
705 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
706 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
707 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
708 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
709 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
710 /* Eye plane done differently to avoid re-transformation */
712 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
713 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
714 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
715 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
716 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
717 if (ctx
->Driver
.TexGen
) {
718 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
719 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
720 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
721 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
724 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
725 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
726 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
727 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
728 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
729 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
730 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
731 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
732 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
733 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
734 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
736 if (ctx
->Extensions
.EXT_texture_env_combine
||
737 ctx
->Extensions
.ARB_texture_env_combine
) {
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
739 unit
->Combine
.ModeRGB
);
740 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
741 unit
->Combine
.ModeA
);
742 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
743 unit
->Combine
.SourceRGB
[0]);
744 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
745 unit
->Combine
.SourceRGB
[1]);
746 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
747 unit
->Combine
.SourceRGB
[2]);
748 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
749 unit
->Combine
.SourceA
[0]);
750 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
751 unit
->Combine
.SourceA
[1]);
752 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
753 unit
->Combine
.SourceA
[2]);
754 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
755 unit
->Combine
.OperandRGB
[0]);
756 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
757 unit
->Combine
.OperandRGB
[1]);
758 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
759 unit
->Combine
.OperandRGB
[2]);
760 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
761 unit
->Combine
.OperandA
[0]);
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
763 unit
->Combine
.OperandA
[1]);
764 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
765 unit
->Combine
.OperandA
[2]);
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
767 1 << unit
->Combine
.ScaleShiftRGB
);
768 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
769 1 << unit
->Combine
.ScaleShiftA
);
772 /* Restore texture object state for each target */
773 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
774 const struct gl_texture_object
*obj
= NULL
;
775 GLfloat bordColor
[4];
778 obj
= &texstate
->SavedObj
[u
][tgt
];
780 /* don't restore state for unsupported targets to prevent
783 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
784 !ctx
->Extensions
.ARB_texture_cube_map
) {
787 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
788 !ctx
->Extensions
.NV_texture_rectangle
) {
791 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
792 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
793 !ctx
->Extensions
.MESA_texture_array
) {
797 target
= obj
->Target
;
799 _mesa_BindTexture(target
, obj
->Name
);
801 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
802 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
803 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
804 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
806 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
807 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
808 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
809 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
810 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
811 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
812 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
813 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
814 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
815 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
816 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
817 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
818 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
819 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
820 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
823 if (ctx
->Extensions
.ARB_shadow_ambient
) {
824 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
825 obj
->CompareFailValue
);
829 /* remove saved references to the texture objects */
830 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
831 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
835 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
837 _mesa_unlock_context_textures(ctx
);
842 * This function is kind of long just because we have to call a lot
843 * of device driver functions to update device driver state.
845 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
846 * in order to restore GL state. This isn't terribly efficient but it
847 * ensures that dirty flags and any derived state gets updated correctly.
848 * We could at least check if the value to restore equals the current value
849 * and then skip the Mesa call.
852 _mesa_PopAttrib(void)
854 struct gl_attrib_node
*attr
, *next
;
855 GET_CURRENT_CONTEXT(ctx
);
856 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
858 if (ctx
->AttribStackDepth
== 0) {
859 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
863 ctx
->AttribStackDepth
--;
864 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
868 if (MESA_VERBOSE
& VERBOSE_API
) {
869 _mesa_debug(ctx
, "glPopAttrib %s\n",
870 _mesa_lookup_enum_by_nr(attr
->kind
));
873 switch (attr
->kind
) {
874 case GL_ACCUM_BUFFER_BIT
:
876 const struct gl_accum_attrib
*accum
;
877 accum
= (const struct gl_accum_attrib
*) attr
->data
;
878 _mesa_ClearAccum(accum
->ClearColor
[0],
879 accum
->ClearColor
[1],
880 accum
->ClearColor
[2],
881 accum
->ClearColor
[3]);
884 case GL_COLOR_BUFFER_BIT
:
886 const struct gl_colorbuffer_attrib
*color
;
887 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
888 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
889 _mesa_ClearColor(color
->ClearColor
[0],
890 color
->ClearColor
[1],
891 color
->ClearColor
[2],
892 color
->ClearColor
[3]);
893 _mesa_IndexMask(color
->IndexMask
);
894 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
895 (GLboolean
) (color
->ColorMask
[1] != 0),
896 (GLboolean
) (color
->ColorMask
[2] != 0),
897 (GLboolean
) (color
->ColorMask
[3] != 0));
899 /* Need to determine if more than one color output is
900 * specified. If so, call glDrawBuffersARB, else call
901 * glDrawBuffer(). This is a subtle, but essential point
902 * since GL_FRONT (for example) is illegal for the former
903 * function, but legal for the later.
905 GLboolean multipleBuffers
= GL_FALSE
;
908 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
909 if (color
->DrawBuffer
[i
] != GL_NONE
) {
910 multipleBuffers
= GL_TRUE
;
914 /* Call the API_level functions, not _mesa_drawbuffers()
915 * since we need to do error checking on the pop'd
917 * Ex: if GL_FRONT were pushed, but we're popping with a
918 * user FBO bound, GL_FRONT will be illegal and we'll need
919 * to record that error. Per OpenGL ARB decision.
922 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
925 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
927 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
928 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
929 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
930 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
934 /* This special case is because glBlendEquationSeparateEXT
935 * cannot take GL_LOGIC_OP as a parameter.
937 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
938 _mesa_BlendEquation(color
->BlendEquationRGB
);
941 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
942 color
->BlendEquationA
);
944 _mesa_BlendColor(color
->BlendColor
[0],
945 color
->BlendColor
[1],
946 color
->BlendColor
[2],
947 color
->BlendColor
[3]);
948 _mesa_LogicOp(color
->LogicOp
);
949 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
950 color
->ColorLogicOpEnabled
);
951 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
952 color
->IndexLogicOpEnabled
);
953 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
957 FLUSH_CURRENT( ctx
, 0 );
958 MEMCPY( &ctx
->Current
, attr
->data
,
959 sizeof(struct gl_current_attrib
) );
961 case GL_DEPTH_BUFFER_BIT
:
963 const struct gl_depthbuffer_attrib
*depth
;
964 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
965 _mesa_DepthFunc(depth
->Func
);
966 _mesa_ClearDepth(depth
->Clear
);
967 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
968 _mesa_DepthMask(depth
->Mask
);
973 const struct gl_enable_attrib
*enable
;
974 enable
= (const struct gl_enable_attrib
*) attr
->data
;
975 pop_enable_group(ctx
, enable
);
976 ctx
->NewState
|= _NEW_ALL
;
980 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
981 ctx
->NewState
|= _NEW_EVAL
;
985 const struct gl_fog_attrib
*fog
;
986 fog
= (const struct gl_fog_attrib
*) attr
->data
;
987 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
988 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
989 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
990 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
991 _mesa_Fogf(GL_FOG_END
, fog
->End
);
992 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
993 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
998 const struct gl_hint_attrib
*hint
;
999 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1000 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1001 hint
->PerspectiveCorrection
);
1002 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1003 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1004 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1005 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1006 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1007 hint
->ClipVolumeClipping
);
1008 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1009 hint
->TextureCompression
);
1012 case GL_LIGHTING_BIT
:
1015 const struct gl_light_attrib
*light
;
1016 light
= (const struct gl_light_attrib
*) attr
->data
;
1017 /* lighting enable */
1018 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1019 /* per-light state */
1020 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1021 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1023 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1024 const struct gl_light
*l
= &light
->Light
[i
];
1025 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1026 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1027 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1028 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1029 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1030 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
1031 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1032 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1033 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1034 &l
->ConstantAttenuation
);
1035 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1036 &l
->LinearAttenuation
);
1037 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1038 &l
->QuadraticAttenuation
);
1041 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1042 light
->Model
.Ambient
);
1043 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1044 (GLfloat
) light
->Model
.LocalViewer
);
1045 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1046 (GLfloat
) light
->Model
.TwoSide
);
1047 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1048 (GLfloat
) light
->Model
.ColorControl
);
1050 _mesa_ShadeModel(light
->ShadeModel
);
1051 /* color material */
1052 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1053 light
->ColorMaterialMode
);
1054 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1055 light
->ColorMaterialEnabled
);
1057 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1058 sizeof(struct gl_material
));
1063 const struct gl_line_attrib
*line
;
1064 line
= (const struct gl_line_attrib
*) attr
->data
;
1065 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1066 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1067 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1068 _mesa_LineWidth(line
->Width
);
1072 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1074 case GL_PIXEL_MODE_BIT
:
1075 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1076 /* XXX what other pixel state needs to be set by function calls? */
1077 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1078 ctx
->NewState
|= _NEW_PIXEL
;
1082 const struct gl_point_attrib
*point
;
1083 point
= (const struct gl_point_attrib
*) attr
->data
;
1084 _mesa_PointSize(point
->Size
);
1085 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1086 if (ctx
->Extensions
.EXT_point_parameters
) {
1087 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1089 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1091 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1093 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1096 if (ctx
->Extensions
.NV_point_sprite
1097 || ctx
->Extensions
.ARB_point_sprite
) {
1099 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1100 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1101 (GLint
) point
->CoordReplace
[u
]);
1103 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1104 if (ctx
->Extensions
.NV_point_sprite
)
1105 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1106 ctx
->Point
.SpriteRMode
);
1107 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1108 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1112 case GL_POLYGON_BIT
:
1114 const struct gl_polygon_attrib
*polygon
;
1115 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1116 _mesa_CullFace(polygon
->CullFaceMode
);
1117 _mesa_FrontFace(polygon
->FrontFace
);
1118 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1119 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1120 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1121 polygon
->OffsetUnits
);
1122 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1123 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1124 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1125 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1126 polygon
->OffsetPoint
);
1127 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1128 polygon
->OffsetLine
);
1129 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1130 polygon
->OffsetFill
);
1133 case GL_POLYGON_STIPPLE_BIT
:
1134 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1135 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1136 if (ctx
->Driver
.PolygonStipple
)
1137 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1139 case GL_SCISSOR_BIT
:
1141 const struct gl_scissor_attrib
*scissor
;
1142 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1143 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1144 scissor
->Width
, scissor
->Height
);
1145 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1148 case GL_STENCIL_BUFFER_BIT
:
1150 const struct gl_stencil_attrib
*stencil
;
1151 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1152 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1153 _mesa_ClearStencil(stencil
->Clear
);
1154 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1155 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1156 stencil
->TestTwoSide
);
1157 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1158 ? GL_BACK
: GL_FRONT
);
1161 _mesa_StencilFuncSeparate(GL_FRONT
,
1162 stencil
->Function
[0],
1164 stencil
->ValueMask
[0]);
1165 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1166 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1167 stencil
->ZFailFunc
[0],
1168 stencil
->ZPassFunc
[0]);
1170 _mesa_StencilFuncSeparate(GL_BACK
,
1171 stencil
->Function
[1],
1173 stencil
->ValueMask
[1]);
1174 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1175 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1176 stencil
->ZFailFunc
[1],
1177 stencil
->ZPassFunc
[1]);
1180 case GL_TRANSFORM_BIT
:
1183 const struct gl_transform_attrib
*xform
;
1184 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1185 _mesa_MatrixMode(xform
->MatrixMode
);
1186 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1187 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1189 /* restore clip planes */
1190 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1191 const GLuint mask
= 1 << 1;
1192 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1193 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1194 if (xform
->ClipPlanesEnabled
& mask
) {
1195 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1198 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1200 if (ctx
->Driver
.ClipPlane
)
1201 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1204 /* normalize/rescale */
1205 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1206 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1207 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1208 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1209 ctx
->Transform
.RescaleNormals
);
1212 case GL_TEXTURE_BIT
:
1213 /* Take care of texture object reference counters */
1215 struct texture_state
*texstate
1216 = (struct texture_state
*) attr
->data
;
1217 pop_texture_group(ctx
, texstate
);
1218 ctx
->NewState
|= _NEW_TEXTURE
;
1221 case GL_VIEWPORT_BIT
:
1223 const struct gl_viewport_attrib
*vp
;
1224 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1225 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1226 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1229 case GL_MULTISAMPLE_BIT_ARB
:
1231 const struct gl_multisample_attrib
*ms
;
1232 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1233 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1234 ms
->SampleCoverageInvert
);
1239 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1252 * Helper for incrementing/decrementing vertex buffer object reference
1253 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1256 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1259 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1260 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1261 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1262 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1263 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1264 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1265 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1266 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1267 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1268 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1269 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1274 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1278 copy_pixelstore(GLcontext
*ctx
,
1279 struct gl_pixelstore_attrib
*dst
,
1280 const struct gl_pixelstore_attrib
*src
)
1282 dst
->Alignment
= src
->Alignment
;
1283 dst
->RowLength
= src
->RowLength
;
1284 dst
->SkipPixels
= src
->SkipPixels
;
1285 dst
->SkipRows
= src
->SkipRows
;
1286 dst
->ImageHeight
= src
->ImageHeight
;
1287 dst
->SkipImages
= src
->SkipImages
;
1288 dst
->SwapBytes
= src
->SwapBytes
;
1289 dst
->LsbFirst
= src
->LsbFirst
;
1290 dst
->ClientStorage
= src
->ClientStorage
;
1291 dst
->Invert
= src
->Invert
;
1292 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1296 #define GL_CLIENT_PACK_BIT (1<<20)
1297 #define GL_CLIENT_UNPACK_BIT (1<<21)
1301 _mesa_PushClientAttrib(GLbitfield mask
)
1303 struct gl_attrib_node
*newnode
;
1304 struct gl_attrib_node
*head
;
1306 GET_CURRENT_CONTEXT(ctx
);
1307 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1309 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1310 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1314 /* Build linked list of attribute nodes which save all attribute
1315 * groups specified by the mask.
1319 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1320 struct gl_pixelstore_attrib
*attr
;
1321 /* packing attribs */
1322 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1323 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1324 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1325 newnode
->data
= attr
;
1326 newnode
->next
= head
;
1328 /* unpacking attribs */
1329 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1330 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1331 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1332 newnode
->data
= attr
;
1333 newnode
->next
= head
;
1337 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1338 struct gl_array_attrib
*attr
;
1339 struct gl_array_object
*obj
;
1341 attr
= MALLOC_STRUCT( gl_array_attrib
);
1342 obj
= MALLOC_STRUCT( gl_array_object
);
1344 #if FEATURE_ARB_vertex_buffer_object
1345 /* increment ref counts since we're copying pointers to these objects */
1346 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1347 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1350 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1351 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1353 attr
->ArrayObj
= obj
;
1355 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1356 newnode
->data
= attr
;
1357 newnode
->next
= head
;
1359 /* bump reference counts on buffer objects */
1360 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1363 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1364 ctx
->ClientAttribStackDepth
++;
1371 _mesa_PopClientAttrib(void)
1373 struct gl_attrib_node
*node
, *next
;
1375 GET_CURRENT_CONTEXT(ctx
);
1376 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1378 if (ctx
->ClientAttribStackDepth
== 0) {
1379 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1383 ctx
->ClientAttribStackDepth
--;
1384 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1387 switch (node
->kind
) {
1388 case GL_CLIENT_PACK_BIT
:
1390 struct gl_pixelstore_attrib
*store
=
1391 (struct gl_pixelstore_attrib
*) node
->data
;
1392 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1393 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1395 ctx
->NewState
|= _NEW_PACKUNPACK
;
1397 case GL_CLIENT_UNPACK_BIT
:
1399 struct gl_pixelstore_attrib
*store
=
1400 (struct gl_pixelstore_attrib
*) node
->data
;
1401 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1402 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1404 ctx
->NewState
|= _NEW_PACKUNPACK
;
1406 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1407 struct gl_array_attrib
* data
=
1408 (struct gl_array_attrib
*) node
->data
;
1410 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1412 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1413 if (data
->LockCount
!= 0)
1414 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1415 else if (ctx
->Array
.LockCount
)
1416 _mesa_UnlockArraysEXT();
1418 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1420 #if FEATURE_ARB_vertex_buffer_object
1421 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1422 data
->ArrayBufferObj
->Name
);
1423 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1424 data
->ElementArrayBufferObj
->Name
);
1427 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1428 sizeof( struct gl_array_object
) );
1430 FREE( data
->ArrayObj
);
1432 /* FIXME: Should some bits in ctx->Array->NewState also be set
1433 * FIXME: here? It seems like it should be set to inclusive-or
1434 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1437 ctx
->NewState
|= _NEW_ARRAY
;
1441 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1454 * Free any attribute state data that might be attached to the context.
1457 _mesa_free_attrib_data(GLcontext
*ctx
)
1459 while (ctx
->AttribStackDepth
> 0) {
1460 struct gl_attrib_node
*attr
, *next
;
1462 ctx
->AttribStackDepth
--;
1463 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1466 if (attr
->kind
== GL_TEXTURE_BIT
) {
1467 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1469 /* clear references to the saved texture objects */
1470 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1471 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1472 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1477 /* any other chunks of state that requires special handling? */
1481 _mesa_free(attr
->data
);
1489 void _mesa_init_attrib( GLcontext
*ctx
)
1491 /* Renderer and client attribute stacks */
1492 ctx
->AttribStackDepth
= 0;
1493 ctx
->ClientAttribStackDepth
= 0;