2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "bufferobj.h"
46 #include "simple_list.h"
51 #include "math/m_xform.h"
55 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
59 struct gl_texture_attrib Texture
; /**< The usual context state */
61 /** to save per texture object state (wrap modes, filters, etc): */
62 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
65 * To save references to texture objects (so they don't get accidentally
66 * deleted while saved in the attribute stack).
68 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
73 * Allocate a new attribute state node. These nodes have a
74 * "kind" value and a pointer to a struct of state data.
76 static struct gl_attrib_node
*
77 new_attrib_node( GLbitfield kind
)
79 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
88 _mesa_PushAttrib(GLbitfield mask
)
90 struct gl_attrib_node
*newnode
;
91 struct gl_attrib_node
*head
;
93 GET_CURRENT_CONTEXT(ctx
);
94 ASSERT_OUTSIDE_BEGIN_END(ctx
);
96 if (MESA_VERBOSE
& VERBOSE_API
)
97 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
99 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
100 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
104 /* Build linked list of attribute nodes which save all attribute */
105 /* groups specified by the mask. */
108 if (mask
& GL_ACCUM_BUFFER_BIT
) {
109 struct gl_accum_attrib
*attr
;
110 attr
= MALLOC_STRUCT( gl_accum_attrib
);
111 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
112 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
113 newnode
->data
= attr
;
114 newnode
->next
= head
;
118 if (mask
& GL_COLOR_BUFFER_BIT
) {
120 struct gl_colorbuffer_attrib
*attr
;
121 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
122 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
123 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
124 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
125 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
126 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
127 newnode
->data
= attr
;
128 newnode
->next
= head
;
132 if (mask
& GL_CURRENT_BIT
) {
133 struct gl_current_attrib
*attr
;
134 FLUSH_CURRENT( ctx
, 0 );
135 attr
= MALLOC_STRUCT( gl_current_attrib
);
136 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
137 newnode
= new_attrib_node( GL_CURRENT_BIT
);
138 newnode
->data
= attr
;
139 newnode
->next
= head
;
143 if (mask
& GL_DEPTH_BUFFER_BIT
) {
144 struct gl_depthbuffer_attrib
*attr
;
145 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
146 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
147 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
148 newnode
->data
= attr
;
149 newnode
->next
= head
;
153 if (mask
& GL_ENABLE_BIT
) {
154 struct gl_enable_attrib
*attr
;
156 attr
= MALLOC_STRUCT( gl_enable_attrib
);
157 /* Copy enable flags from all other attributes into the enable struct. */
158 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
159 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
160 attr
->Blend
= ctx
->Color
.BlendEnabled
;
161 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
162 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
163 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
164 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
166 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
167 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
168 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
169 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
170 attr
->DepthTest
= ctx
->Depth
.Test
;
171 attr
->Dither
= ctx
->Color
.DitherFlag
;
172 attr
->Fog
= ctx
->Fog
.Enabled
;
173 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
174 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
176 attr
->Lighting
= ctx
->Light
.Enabled
;
177 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
178 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
179 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
180 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
181 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
182 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
183 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
184 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
185 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
186 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
187 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
188 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
189 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
190 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
191 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
192 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
193 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
194 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
195 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
196 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
197 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
198 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
199 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
200 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
201 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
202 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
203 attr
->Normalize
= ctx
->Transform
.Normalize
;
204 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
205 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
206 attr
->PointSprite
= ctx
->Point
.PointSprite
;
207 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
208 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
209 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
210 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
211 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
212 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
213 attr
->Scissor
= ctx
->Scissor
.Enabled
;
214 attr
->Stencil
= ctx
->Stencil
.Enabled
;
215 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
216 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
217 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
218 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
219 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
220 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
221 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
222 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
223 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
224 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
226 /* GL_NV_vertex_program */
227 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
228 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
229 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
230 newnode
= new_attrib_node( GL_ENABLE_BIT
);
231 newnode
->data
= attr
;
232 newnode
->next
= head
;
236 if (mask
& GL_EVAL_BIT
) {
237 struct gl_eval_attrib
*attr
;
238 attr
= MALLOC_STRUCT( gl_eval_attrib
);
239 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
240 newnode
= new_attrib_node( GL_EVAL_BIT
);
241 newnode
->data
= attr
;
242 newnode
->next
= head
;
246 if (mask
& GL_FOG_BIT
) {
247 struct gl_fog_attrib
*attr
;
248 attr
= MALLOC_STRUCT( gl_fog_attrib
);
249 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
250 newnode
= new_attrib_node( GL_FOG_BIT
);
251 newnode
->data
= attr
;
252 newnode
->next
= head
;
256 if (mask
& GL_HINT_BIT
) {
257 struct gl_hint_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_hint_attrib
);
259 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
260 newnode
= new_attrib_node( GL_HINT_BIT
);
261 newnode
->data
= attr
;
262 newnode
->next
= head
;
266 if (mask
& GL_LIGHTING_BIT
) {
267 struct gl_light_attrib
*attr
;
268 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
269 attr
= MALLOC_STRUCT( gl_light_attrib
);
270 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
271 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
272 newnode
->data
= attr
;
273 newnode
->next
= head
;
277 if (mask
& GL_LINE_BIT
) {
278 struct gl_line_attrib
*attr
;
279 attr
= MALLOC_STRUCT( gl_line_attrib
);
280 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
281 newnode
= new_attrib_node( GL_LINE_BIT
);
282 newnode
->data
= attr
;
283 newnode
->next
= head
;
287 if (mask
& GL_LIST_BIT
) {
288 struct gl_list_attrib
*attr
;
289 attr
= MALLOC_STRUCT( gl_list_attrib
);
290 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
291 newnode
= new_attrib_node( GL_LIST_BIT
);
292 newnode
->data
= attr
;
293 newnode
->next
= head
;
297 if (mask
& GL_PIXEL_MODE_BIT
) {
298 struct gl_pixel_attrib
*attr
;
299 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
300 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
301 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
302 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
303 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
304 newnode
->data
= attr
;
305 newnode
->next
= head
;
309 if (mask
& GL_POINT_BIT
) {
310 struct gl_point_attrib
*attr
;
311 attr
= MALLOC_STRUCT( gl_point_attrib
);
312 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
313 newnode
= new_attrib_node( GL_POINT_BIT
);
314 newnode
->data
= attr
;
315 newnode
->next
= head
;
319 if (mask
& GL_POLYGON_BIT
) {
320 struct gl_polygon_attrib
*attr
;
321 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
322 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
323 newnode
= new_attrib_node( GL_POLYGON_BIT
);
324 newnode
->data
= attr
;
325 newnode
->next
= head
;
329 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
331 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
332 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
333 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
334 newnode
->data
= stipple
;
335 newnode
->next
= head
;
339 if (mask
& GL_SCISSOR_BIT
) {
340 struct gl_scissor_attrib
*attr
;
341 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
342 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
343 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
344 newnode
->data
= attr
;
345 newnode
->next
= head
;
349 if (mask
& GL_STENCIL_BUFFER_BIT
) {
350 struct gl_stencil_attrib
*attr
;
351 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
352 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
353 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
354 newnode
->data
= attr
;
355 newnode
->next
= head
;
359 if (mask
& GL_TEXTURE_BIT
) {
360 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
364 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
368 _mesa_lock_context_textures(ctx
);
370 /* copy/save the bulk of texture state here */
371 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
373 /* Save references to the currently bound texture objects so they don't
374 * accidentally get deleted while referenced in the attribute stack.
376 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
377 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_INDEX
],
378 ctx
->Texture
.Unit
[u
].Current1D
);
379 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_INDEX
],
380 ctx
->Texture
.Unit
[u
].Current2D
);
381 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_3D_INDEX
],
382 ctx
->Texture
.Unit
[u
].Current3D
);
383 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_CUBE_INDEX
],
384 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
385 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_RECT_INDEX
],
386 ctx
->Texture
.Unit
[u
].CurrentRect
);
387 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_ARRAY_INDEX
],
388 ctx
->Texture
.Unit
[u
].Current1DArray
);
389 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_ARRAY_INDEX
],
390 ctx
->Texture
.Unit
[u
].Current2DArray
);
393 /* copy state/contents of the currently bound texture objects */
394 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
395 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_INDEX
],
396 ctx
->Texture
.Unit
[u
].Current1D
);
397 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_INDEX
],
398 ctx
->Texture
.Unit
[u
].Current2D
);
399 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_3D_INDEX
],
400 ctx
->Texture
.Unit
[u
].Current3D
);
401 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_CUBE_INDEX
],
402 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
403 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_RECT_INDEX
],
404 ctx
->Texture
.Unit
[u
].CurrentRect
);
405 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_ARRAY_INDEX
],
406 ctx
->Texture
.Unit
[u
].Current1DArray
);
407 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_ARRAY_INDEX
],
408 ctx
->Texture
.Unit
[u
].Current2DArray
);
411 _mesa_unlock_context_textures(ctx
);
413 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
414 newnode
->data
= texstate
;
415 newnode
->next
= head
;
419 if (mask
& GL_TRANSFORM_BIT
) {
420 struct gl_transform_attrib
*attr
;
421 attr
= MALLOC_STRUCT( gl_transform_attrib
);
422 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
423 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
424 newnode
->data
= attr
;
425 newnode
->next
= head
;
429 if (mask
& GL_VIEWPORT_BIT
) {
430 struct gl_viewport_attrib
*attr
;
431 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
432 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
433 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
434 newnode
->data
= attr
;
435 newnode
->next
= head
;
439 /* GL_ARB_multisample */
440 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
441 struct gl_multisample_attrib
*attr
;
442 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
443 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
444 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
445 newnode
->data
= attr
;
446 newnode
->next
= head
;
451 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
452 ctx
->AttribStackDepth
++;
458 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
462 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
463 if ((VALUE) != (NEWVALUE)) { \
464 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
467 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
468 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
470 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
471 const GLuint mask
= 1 << i
;
472 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
473 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
474 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
477 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
479 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
480 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
482 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
483 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
484 GL_POST_CONVOLUTION_COLOR_TABLE
);
485 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
486 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
487 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
488 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
489 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
490 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
491 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
493 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
495 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
497 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
498 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
499 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
500 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
502 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
504 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
507 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
508 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
509 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
511 GL_MAP1_TEXTURE_COORD_1
);
512 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
513 GL_MAP1_TEXTURE_COORD_2
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
515 GL_MAP1_TEXTURE_COORD_3
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
517 GL_MAP1_TEXTURE_COORD_4
);
518 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
520 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
522 for (i
= 0; i
< 16; i
++) {
523 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
524 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
527 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
528 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
531 GL_MAP2_TEXTURE_COORD_1
);
532 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
533 GL_MAP2_TEXTURE_COORD_2
);
534 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
535 GL_MAP2_TEXTURE_COORD_3
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
537 GL_MAP2_TEXTURE_COORD_4
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
540 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
542 for (i
= 0; i
< 16; i
++) {
543 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
544 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
547 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
548 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
549 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
550 GL_RESCALE_NORMAL_EXT
);
551 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
552 enable
->RasterPositionUnclipped
,
553 GL_RASTER_POSITION_UNCLIPPED_IBM
);
554 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
556 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
557 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
560 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
561 GL_POLYGON_OFFSET_POINT
);
562 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
563 GL_POLYGON_OFFSET_LINE
);
564 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
565 GL_POLYGON_OFFSET_FILL
);
566 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
568 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
570 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
571 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
572 if (ctx
->Extensions
.EXT_stencil_two_side
) {
573 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
575 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
577 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
578 enable
->SampleAlphaToCoverage
,
579 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
580 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
581 enable
->SampleAlphaToOne
,
582 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
583 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
584 enable
->SampleCoverage
,
585 GL_SAMPLE_COVERAGE_ARB
);
586 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
587 enable
->SampleCoverageInvert
,
588 GL_SAMPLE_COVERAGE_INVERT_ARB
);
589 /* GL_ARB_vertex_program, GL_NV_vertex_program */
590 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
591 enable
->VertexProgram
,
592 GL_VERTEX_PROGRAM_ARB
);
593 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
594 enable
->VertexProgramPointSize
,
595 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
596 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
597 enable
->VertexProgramTwoSide
,
598 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
600 #undef TEST_AND_UPDATE
602 /* texture unit enables */
603 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
604 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
605 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
606 if (ctx
->Driver
.Enable
) {
607 if (ctx
->Driver
.ActiveTexture
) {
608 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
610 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
611 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
612 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
613 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
614 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
615 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
616 if (ctx
->Extensions
.ARB_texture_cube_map
)
617 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
618 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
619 if (ctx
->Extensions
.NV_texture_rectangle
)
620 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
621 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
625 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
626 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
627 if (ctx
->Driver
.Enable
) {
628 if (ctx
->Driver
.ActiveTexture
) {
629 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
631 if (enable
->TexGen
[i
] & S_BIT
)
632 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
634 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
635 if (enable
->TexGen
[i
] & T_BIT
)
636 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
638 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
639 if (enable
->TexGen
[i
] & R_BIT
)
640 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
642 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
643 if (enable
->TexGen
[i
] & Q_BIT
)
644 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
646 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
650 /* GL_SGI_texture_color_table */
651 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
654 if (ctx
->Driver
.ActiveTexture
) {
655 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
661 * Pop/restore texture attribute/group state.
664 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
668 _mesa_lock_context_textures(ctx
);
670 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
671 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
674 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
675 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
676 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
677 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
678 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
679 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
680 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
681 if (ctx
->Extensions
.ARB_texture_cube_map
) {
682 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
683 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
685 if (ctx
->Extensions
.NV_texture_rectangle
) {
686 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
687 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
689 if (ctx
->Extensions
.SGI_texture_color_table
) {
690 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
691 unit
->ColorTableEnabled
);
693 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
694 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
695 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
696 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
697 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
698 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
699 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
700 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
701 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
702 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
703 /* Eye plane done differently to avoid re-transformation */
705 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
706 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
707 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
708 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
709 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
710 if (ctx
->Driver
.TexGen
) {
711 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
712 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
713 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
714 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
717 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
718 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
719 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
720 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
721 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
722 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
723 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
724 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
725 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
726 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
727 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
729 if (ctx
->Extensions
.EXT_texture_env_combine
||
730 ctx
->Extensions
.ARB_texture_env_combine
) {
731 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
732 unit
->Combine
.ModeRGB
);
733 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
734 unit
->Combine
.ModeA
);
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
736 unit
->Combine
.SourceRGB
[0]);
737 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
738 unit
->Combine
.SourceRGB
[1]);
739 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
740 unit
->Combine
.SourceRGB
[2]);
741 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
742 unit
->Combine
.SourceA
[0]);
743 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
744 unit
->Combine
.SourceA
[1]);
745 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
746 unit
->Combine
.SourceA
[2]);
747 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
748 unit
->Combine
.OperandRGB
[0]);
749 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
750 unit
->Combine
.OperandRGB
[1]);
751 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
752 unit
->Combine
.OperandRGB
[2]);
753 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
754 unit
->Combine
.OperandA
[0]);
755 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
756 unit
->Combine
.OperandA
[1]);
757 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
758 unit
->Combine
.OperandA
[2]);
759 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
760 1 << unit
->Combine
.ScaleShiftRGB
);
761 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
762 1 << unit
->Combine
.ScaleShiftA
);
765 /* Restore texture object state for each target */
766 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
767 const struct gl_texture_object
*obj
= NULL
;
768 GLfloat bordColor
[4];
771 obj
= &texstate
->SavedObj
[u
][tgt
];
773 /* don't restore state for unsupported targets to prevent
776 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
777 !ctx
->Extensions
.ARB_texture_cube_map
) {
780 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
781 !ctx
->Extensions
.NV_texture_rectangle
) {
784 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
785 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
786 !ctx
->Extensions
.MESA_texture_array
) {
790 target
= obj
->Target
;
792 _mesa_BindTexture(target
, obj
->Name
);
794 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
795 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
796 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
797 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
799 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
800 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
801 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
802 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
803 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
804 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
805 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
806 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
807 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
808 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
809 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
810 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
811 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
812 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
813 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
816 if (ctx
->Extensions
.SGIX_shadow
) {
817 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
819 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
820 obj
->CompareOperator
);
822 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
823 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
828 /* remove saved references to the texture objects */
829 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
830 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
834 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
836 _mesa_unlock_context_textures(ctx
);
841 * This function is kind of long just because we have to call a lot
842 * of device driver functions to update device driver state.
844 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
845 * in order to restore GL state. This isn't terribly efficient but it
846 * ensures that dirty flags and any derived state gets updated correctly.
847 * We could at least check if the value to restore equals the current value
848 * and then skip the Mesa call.
851 _mesa_PopAttrib(void)
853 struct gl_attrib_node
*attr
, *next
;
854 GET_CURRENT_CONTEXT(ctx
);
855 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
857 if (ctx
->AttribStackDepth
== 0) {
858 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
862 ctx
->AttribStackDepth
--;
863 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
867 if (MESA_VERBOSE
& VERBOSE_API
) {
868 _mesa_debug(ctx
, "glPopAttrib %s\n",
869 _mesa_lookup_enum_by_nr(attr
->kind
));
872 switch (attr
->kind
) {
873 case GL_ACCUM_BUFFER_BIT
:
875 const struct gl_accum_attrib
*accum
;
876 accum
= (const struct gl_accum_attrib
*) attr
->data
;
877 _mesa_ClearAccum(accum
->ClearColor
[0],
878 accum
->ClearColor
[1],
879 accum
->ClearColor
[2],
880 accum
->ClearColor
[3]);
883 case GL_COLOR_BUFFER_BIT
:
885 const struct gl_colorbuffer_attrib
*color
;
886 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
887 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
888 _mesa_ClearColor(color
->ClearColor
[0],
889 color
->ClearColor
[1],
890 color
->ClearColor
[2],
891 color
->ClearColor
[3]);
892 _mesa_IndexMask(color
->IndexMask
);
893 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
894 (GLboolean
) (color
->ColorMask
[1] != 0),
895 (GLboolean
) (color
->ColorMask
[2] != 0),
896 (GLboolean
) (color
->ColorMask
[3] != 0));
898 /* Need to determine if more than one color output is
899 * specified. If so, call glDrawBuffersARB, else call
900 * glDrawBuffer(). This is a subtle, but essential point
901 * since GL_FRONT (for example) is illegal for the former
902 * function, but legal for the later.
904 GLboolean multipleBuffers
= GL_FALSE
;
905 if (ctx
->Extensions
.ARB_draw_buffers
) {
907 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
908 if (color
->DrawBuffer
[i
] != GL_NONE
) {
909 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 if (ctx
->Extensions
.ARB_texture_compression
)
1009 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1010 hint
->TextureCompression
);
1013 case GL_LIGHTING_BIT
:
1016 const struct gl_light_attrib
*light
;
1017 light
= (const struct gl_light_attrib
*) attr
->data
;
1018 /* lighting enable */
1019 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1020 /* per-light state */
1021 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1022 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1024 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1025 const struct gl_light
*l
= &light
->Light
[i
];
1026 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1027 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1028 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1029 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1030 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1031 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
1032 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1033 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1034 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1035 &l
->ConstantAttenuation
);
1036 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1037 &l
->LinearAttenuation
);
1038 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1039 &l
->QuadraticAttenuation
);
1042 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1043 light
->Model
.Ambient
);
1044 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1045 (GLfloat
) light
->Model
.LocalViewer
);
1046 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1047 (GLfloat
) light
->Model
.TwoSide
);
1048 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1049 (GLfloat
) light
->Model
.ColorControl
);
1051 _mesa_ShadeModel(light
->ShadeModel
);
1052 /* color material */
1053 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1054 light
->ColorMaterialMode
);
1055 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1056 light
->ColorMaterialEnabled
);
1058 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1059 sizeof(struct gl_material
));
1064 const struct gl_line_attrib
*line
;
1065 line
= (const struct gl_line_attrib
*) attr
->data
;
1066 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1067 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1068 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1069 _mesa_LineWidth(line
->Width
);
1073 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1075 case GL_PIXEL_MODE_BIT
:
1076 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1077 /* XXX what other pixel state needs to be set by function calls? */
1078 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1079 ctx
->NewState
|= _NEW_PIXEL
;
1083 const struct gl_point_attrib
*point
;
1084 point
= (const struct gl_point_attrib
*) attr
->data
;
1085 _mesa_PointSize(point
->Size
);
1086 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1087 if (ctx
->Extensions
.EXT_point_parameters
) {
1088 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
1090 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
1092 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
1094 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1097 if (ctx
->Extensions
.NV_point_sprite
1098 || ctx
->Extensions
.ARB_point_sprite
) {
1100 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1101 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1102 (GLint
) point
->CoordReplace
[u
]);
1104 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1105 if (ctx
->Extensions
.NV_point_sprite
)
1106 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1107 ctx
->Point
.SpriteRMode
);
1108 _mesa_PointParameterfEXT(GL_POINT_SPRITE_COORD_ORIGIN
,
1109 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1113 case GL_POLYGON_BIT
:
1115 const struct gl_polygon_attrib
*polygon
;
1116 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1117 _mesa_CullFace(polygon
->CullFaceMode
);
1118 _mesa_FrontFace(polygon
->FrontFace
);
1119 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1120 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1121 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1122 polygon
->OffsetUnits
);
1123 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1124 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1125 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1126 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1127 polygon
->OffsetPoint
);
1128 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1129 polygon
->OffsetLine
);
1130 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1131 polygon
->OffsetFill
);
1134 case GL_POLYGON_STIPPLE_BIT
:
1135 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1136 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1137 if (ctx
->Driver
.PolygonStipple
)
1138 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1140 case GL_SCISSOR_BIT
:
1142 const struct gl_scissor_attrib
*scissor
;
1143 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1144 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1145 scissor
->Width
, scissor
->Height
);
1146 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1149 case GL_STENCIL_BUFFER_BIT
:
1151 const struct gl_stencil_attrib
*stencil
;
1152 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1153 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1154 _mesa_ClearStencil(stencil
->Clear
);
1155 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1156 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1157 stencil
->TestTwoSide
);
1158 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1159 ? GL_BACK
: GL_FRONT
);
1162 _mesa_StencilFuncSeparate(GL_FRONT
,
1163 stencil
->Function
[0],
1165 stencil
->ValueMask
[0]);
1166 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1167 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1168 stencil
->ZFailFunc
[0],
1169 stencil
->ZPassFunc
[0]);
1171 _mesa_StencilFuncSeparate(GL_BACK
,
1172 stencil
->Function
[1],
1174 stencil
->ValueMask
[1]);
1175 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1176 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1177 stencil
->ZFailFunc
[1],
1178 stencil
->ZPassFunc
[1]);
1181 case GL_TRANSFORM_BIT
:
1184 const struct gl_transform_attrib
*xform
;
1185 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1186 _mesa_MatrixMode(xform
->MatrixMode
);
1187 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1188 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1190 /* restore clip planes */
1191 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1192 const GLuint mask
= 1 << 1;
1193 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1194 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1195 if (xform
->ClipPlanesEnabled
& mask
) {
1196 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1199 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1201 if (ctx
->Driver
.ClipPlane
)
1202 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1205 /* normalize/rescale */
1206 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1207 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1208 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1209 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1210 ctx
->Transform
.RescaleNormals
);
1213 case GL_TEXTURE_BIT
:
1214 /* Take care of texture object reference counters */
1216 struct texture_state
*texstate
1217 = (struct texture_state
*) attr
->data
;
1218 pop_texture_group(ctx
, texstate
);
1219 ctx
->NewState
|= _NEW_TEXTURE
;
1222 case GL_VIEWPORT_BIT
:
1224 const struct gl_viewport_attrib
*vp
;
1225 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1226 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1227 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1230 case GL_MULTISAMPLE_BIT_ARB
:
1232 const struct gl_multisample_attrib
*ms
;
1233 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1234 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1235 ms
->SampleCoverageInvert
);
1240 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1253 * Helper for incrementing/decrementing vertex buffer object reference
1254 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1257 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1260 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1261 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1262 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1263 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1264 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1265 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1266 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1267 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1268 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1269 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1270 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1272 array
->ArrayBufferObj
->RefCount
+= step
;
1273 array
->ElementArrayBufferObj
->RefCount
+= step
;
1277 #define GL_CLIENT_PACK_BIT (1<<20)
1278 #define GL_CLIENT_UNPACK_BIT (1<<21)
1282 _mesa_PushClientAttrib(GLbitfield mask
)
1284 struct gl_attrib_node
*newnode
;
1285 struct gl_attrib_node
*head
;
1287 GET_CURRENT_CONTEXT(ctx
);
1288 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1290 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1291 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1295 /* Build linked list of attribute nodes which save all attribute */
1296 /* groups specified by the mask. */
1299 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1300 struct gl_pixelstore_attrib
*attr
;
1301 #if FEATURE_EXT_pixel_buffer_object
1302 ctx
->Pack
.BufferObj
->RefCount
++;
1303 ctx
->Unpack
.BufferObj
->RefCount
++;
1305 /* packing attribs */
1306 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1307 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1308 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1309 newnode
->data
= attr
;
1310 newnode
->next
= head
;
1312 /* unpacking attribs */
1313 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1314 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1315 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1316 newnode
->data
= attr
;
1317 newnode
->next
= head
;
1320 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1321 struct gl_array_attrib
*attr
;
1322 struct gl_array_object
*obj
;
1324 attr
= MALLOC_STRUCT( gl_array_attrib
);
1325 obj
= MALLOC_STRUCT( gl_array_object
);
1327 #if FEATURE_ARB_vertex_buffer_object
1328 /* increment ref counts since we're copying pointers to these objects */
1329 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1330 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1333 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1334 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1336 attr
->ArrayObj
= obj
;
1338 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1339 newnode
->data
= attr
;
1340 newnode
->next
= head
;
1342 /* bump reference counts on buffer objects */
1343 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1346 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1347 ctx
->ClientAttribStackDepth
++;
1354 _mesa_PopClientAttrib(void)
1356 struct gl_attrib_node
*attr
, *next
;
1358 GET_CURRENT_CONTEXT(ctx
);
1359 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1361 if (ctx
->ClientAttribStackDepth
== 0) {
1362 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1366 ctx
->ClientAttribStackDepth
--;
1367 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1370 switch (attr
->kind
) {
1371 case GL_CLIENT_PACK_BIT
:
1372 #if FEATURE_EXT_pixel_buffer_object
1373 ctx
->Pack
.BufferObj
->RefCount
--;
1374 if (ctx
->Pack
.BufferObj
->RefCount
<= 0) {
1375 _mesa_remove_buffer_object( ctx
, ctx
->Pack
.BufferObj
);
1376 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Pack
.BufferObj
);
1379 MEMCPY( &ctx
->Pack
, attr
->data
,
1380 sizeof(struct gl_pixelstore_attrib
) );
1381 ctx
->NewState
|= _NEW_PACKUNPACK
;
1383 case GL_CLIENT_UNPACK_BIT
:
1384 #if FEATURE_EXT_pixel_buffer_object
1385 ctx
->Unpack
.BufferObj
->RefCount
--;
1386 if (ctx
->Unpack
.BufferObj
->RefCount
<= 0) {
1387 _mesa_remove_buffer_object( ctx
, ctx
->Unpack
.BufferObj
);
1388 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Unpack
.BufferObj
);
1391 MEMCPY( &ctx
->Unpack
, attr
->data
,
1392 sizeof(struct gl_pixelstore_attrib
) );
1393 ctx
->NewState
|= _NEW_PACKUNPACK
;
1395 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1396 struct gl_array_attrib
* data
=
1397 (struct gl_array_attrib
*) attr
->data
;
1399 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1401 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1402 ctx
->Array
.LockFirst
= data
->LockFirst
;
1403 ctx
->Array
.LockCount
= data
->LockCount
;
1405 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1407 #if FEATURE_ARB_vertex_buffer_object
1408 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1409 data
->ArrayBufferObj
->Name
);
1410 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1411 data
->ElementArrayBufferObj
->Name
);
1414 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1415 sizeof( struct gl_array_object
) );
1417 FREE( data
->ArrayObj
);
1419 /* FIXME: Should some bits in ctx->Array->NewState also be set
1420 * FIXME: here? It seems like it should be set to inclusive-or
1421 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1424 ctx
->NewState
|= _NEW_ARRAY
;
1428 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1441 * Free any attribute state data that might be attached to the context.
1444 _mesa_free_attrib_data(GLcontext
*ctx
)
1446 while (ctx
->AttribStackDepth
> 0) {
1447 struct gl_attrib_node
*attr
, *next
;
1449 ctx
->AttribStackDepth
--;
1450 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1453 if (attr
->kind
== GL_TEXTURE_BIT
) {
1454 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1456 /* clear references to the saved texture objects */
1457 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1458 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1459 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1464 /* any other chunks of state that requires special handling? */
1468 _mesa_free(attr
->data
);
1476 void _mesa_init_attrib( GLcontext
*ctx
)
1478 /* Renderer and client attribute stacks */
1479 ctx
->AttribStackDepth
= 0;
1480 ctx
->ClientAttribStackDepth
= 0;