2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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"
48 #include "simple_list.h"
54 #include "math/m_xform.h"
57 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
61 struct gl_texture_attrib Texture
; /**< The usual context state */
63 /** to save per texture object state (wrap modes, filters, etc): */
64 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
67 * To save references to texture objects (so they don't get accidentally
68 * deleted while saved in the attribute stack).
70 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
75 * Allocate a new attribute state node. These nodes have a
76 * "kind" value and a pointer to a struct of state data.
78 static struct gl_attrib_node
*
79 new_attrib_node( GLbitfield kind
)
81 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
90 _mesa_PushAttrib(GLbitfield mask
)
92 struct gl_attrib_node
*newnode
;
93 struct gl_attrib_node
*head
;
95 GET_CURRENT_CONTEXT(ctx
);
96 ASSERT_OUTSIDE_BEGIN_END(ctx
);
98 if (MESA_VERBOSE
& VERBOSE_API
)
99 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
101 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
102 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
106 /* Build linked list of attribute nodes which save all attribute */
107 /* groups specified by the mask. */
110 if (mask
& GL_ACCUM_BUFFER_BIT
) {
111 struct gl_accum_attrib
*attr
;
112 attr
= MALLOC_STRUCT( gl_accum_attrib
);
113 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
114 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
115 newnode
->data
= attr
;
116 newnode
->next
= head
;
120 if (mask
& GL_COLOR_BUFFER_BIT
) {
122 struct gl_colorbuffer_attrib
*attr
;
123 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
124 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
125 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
126 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
127 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
128 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
129 newnode
->data
= attr
;
130 newnode
->next
= head
;
134 if (mask
& GL_CURRENT_BIT
) {
135 struct gl_current_attrib
*attr
;
136 FLUSH_CURRENT( ctx
, 0 );
137 attr
= MALLOC_STRUCT( gl_current_attrib
);
138 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
139 newnode
= new_attrib_node( GL_CURRENT_BIT
);
140 newnode
->data
= attr
;
141 newnode
->next
= head
;
145 if (mask
& GL_DEPTH_BUFFER_BIT
) {
146 struct gl_depthbuffer_attrib
*attr
;
147 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
148 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
149 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
150 newnode
->data
= attr
;
151 newnode
->next
= head
;
155 if (mask
& GL_ENABLE_BIT
) {
156 struct gl_enable_attrib
*attr
;
158 attr
= MALLOC_STRUCT( gl_enable_attrib
);
159 /* Copy enable flags from all other attributes into the enable struct. */
160 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
161 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
162 attr
->Blend
= ctx
->Color
.BlendEnabled
;
163 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
164 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
165 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
166 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
168 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
169 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
170 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
171 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
172 attr
->DepthTest
= ctx
->Depth
.Test
;
173 attr
->Dither
= ctx
->Color
.DitherFlag
;
174 attr
->Fog
= ctx
->Fog
.Enabled
;
175 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
176 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
178 attr
->Lighting
= ctx
->Light
.Enabled
;
179 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
180 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
181 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
182 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
183 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
184 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
185 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
186 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
187 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
188 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
189 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
190 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
191 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
192 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
193 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
194 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
195 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
196 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
197 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
198 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
199 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
200 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
201 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
202 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
203 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
204 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
205 attr
->Normalize
= ctx
->Transform
.Normalize
;
206 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
207 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
208 attr
->PointSprite
= ctx
->Point
.PointSprite
;
209 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
210 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
211 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
212 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
213 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
214 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
215 attr
->Scissor
= ctx
->Scissor
.Enabled
;
216 attr
->Stencil
= ctx
->Stencil
.Enabled
;
217 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
218 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
219 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
220 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
221 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
222 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
223 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
224 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
225 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
226 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
228 /* GL_NV_vertex_program */
229 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
230 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
231 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
232 newnode
= new_attrib_node( GL_ENABLE_BIT
);
233 newnode
->data
= attr
;
234 newnode
->next
= head
;
238 if (mask
& GL_EVAL_BIT
) {
239 struct gl_eval_attrib
*attr
;
240 attr
= MALLOC_STRUCT( gl_eval_attrib
);
241 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
242 newnode
= new_attrib_node( GL_EVAL_BIT
);
243 newnode
->data
= attr
;
244 newnode
->next
= head
;
248 if (mask
& GL_FOG_BIT
) {
249 struct gl_fog_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_fog_attrib
);
251 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
252 newnode
= new_attrib_node( GL_FOG_BIT
);
253 newnode
->data
= attr
;
254 newnode
->next
= head
;
258 if (mask
& GL_HINT_BIT
) {
259 struct gl_hint_attrib
*attr
;
260 attr
= MALLOC_STRUCT( gl_hint_attrib
);
261 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
262 newnode
= new_attrib_node( GL_HINT_BIT
);
263 newnode
->data
= attr
;
264 newnode
->next
= head
;
268 if (mask
& GL_LIGHTING_BIT
) {
269 struct gl_light_attrib
*attr
;
270 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
271 attr
= MALLOC_STRUCT( gl_light_attrib
);
272 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
273 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
274 newnode
->data
= attr
;
275 newnode
->next
= head
;
279 if (mask
& GL_LINE_BIT
) {
280 struct gl_line_attrib
*attr
;
281 attr
= MALLOC_STRUCT( gl_line_attrib
);
282 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
283 newnode
= new_attrib_node( GL_LINE_BIT
);
284 newnode
->data
= attr
;
285 newnode
->next
= head
;
289 if (mask
& GL_LIST_BIT
) {
290 struct gl_list_attrib
*attr
;
291 attr
= MALLOC_STRUCT( gl_list_attrib
);
292 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
293 newnode
= new_attrib_node( GL_LIST_BIT
);
294 newnode
->data
= attr
;
295 newnode
->next
= head
;
299 if (mask
& GL_PIXEL_MODE_BIT
) {
300 struct gl_pixel_attrib
*attr
;
301 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
302 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
303 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
304 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
305 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
306 newnode
->data
= attr
;
307 newnode
->next
= head
;
311 if (mask
& GL_POINT_BIT
) {
312 struct gl_point_attrib
*attr
;
313 attr
= MALLOC_STRUCT( gl_point_attrib
);
314 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
315 newnode
= new_attrib_node( GL_POINT_BIT
);
316 newnode
->data
= attr
;
317 newnode
->next
= head
;
321 if (mask
& GL_POLYGON_BIT
) {
322 struct gl_polygon_attrib
*attr
;
323 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
324 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
325 newnode
= new_attrib_node( GL_POLYGON_BIT
);
326 newnode
->data
= attr
;
327 newnode
->next
= head
;
331 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
333 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
334 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
335 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
336 newnode
->data
= stipple
;
337 newnode
->next
= head
;
341 if (mask
& GL_SCISSOR_BIT
) {
342 struct gl_scissor_attrib
*attr
;
343 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
344 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
345 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
346 newnode
->data
= attr
;
347 newnode
->next
= head
;
351 if (mask
& GL_STENCIL_BUFFER_BIT
) {
352 struct gl_stencil_attrib
*attr
;
353 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
354 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
355 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
356 newnode
->data
= attr
;
357 newnode
->next
= head
;
361 if (mask
& GL_TEXTURE_BIT
) {
362 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
366 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
370 _mesa_lock_context_textures(ctx
);
372 /* copy/save the bulk of texture state here */
373 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
375 /* Save references to the currently bound texture objects so they don't
376 * accidentally get deleted while referenced in the attribute stack.
378 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
379 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_INDEX
],
380 ctx
->Texture
.Unit
[u
].Current1D
);
381 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_INDEX
],
382 ctx
->Texture
.Unit
[u
].Current2D
);
383 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_3D_INDEX
],
384 ctx
->Texture
.Unit
[u
].Current3D
);
385 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_CUBE_INDEX
],
386 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
387 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_RECT_INDEX
],
388 ctx
->Texture
.Unit
[u
].CurrentRect
);
389 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_ARRAY_INDEX
],
390 ctx
->Texture
.Unit
[u
].Current1DArray
);
391 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_ARRAY_INDEX
],
392 ctx
->Texture
.Unit
[u
].Current2DArray
);
395 /* copy state/contents of the currently bound texture objects */
396 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
397 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_INDEX
],
398 ctx
->Texture
.Unit
[u
].Current1D
);
399 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_INDEX
],
400 ctx
->Texture
.Unit
[u
].Current2D
);
401 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_3D_INDEX
],
402 ctx
->Texture
.Unit
[u
].Current3D
);
403 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_CUBE_INDEX
],
404 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
405 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_RECT_INDEX
],
406 ctx
->Texture
.Unit
[u
].CurrentRect
);
407 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_ARRAY_INDEX
],
408 ctx
->Texture
.Unit
[u
].Current1DArray
);
409 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_ARRAY_INDEX
],
410 ctx
->Texture
.Unit
[u
].Current2DArray
);
413 _mesa_unlock_context_textures(ctx
);
415 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
416 newnode
->data
= texstate
;
417 newnode
->next
= head
;
421 if (mask
& GL_TRANSFORM_BIT
) {
422 struct gl_transform_attrib
*attr
;
423 attr
= MALLOC_STRUCT( gl_transform_attrib
);
424 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
425 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
426 newnode
->data
= attr
;
427 newnode
->next
= head
;
431 if (mask
& GL_VIEWPORT_BIT
) {
432 struct gl_viewport_attrib
*attr
;
433 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
434 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
435 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
436 newnode
->data
= attr
;
437 newnode
->next
= head
;
441 /* GL_ARB_multisample */
442 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
443 struct gl_multisample_attrib
*attr
;
444 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
445 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
446 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
447 newnode
->data
= attr
;
448 newnode
->next
= head
;
453 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
454 ctx
->AttribStackDepth
++;
460 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
464 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
465 if ((VALUE) != (NEWVALUE)) { \
466 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
469 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
470 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
472 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
473 const GLuint mask
= 1 << i
;
474 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
475 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
476 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
479 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
481 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
482 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
484 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
485 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
486 GL_POST_CONVOLUTION_COLOR_TABLE
);
487 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
488 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
489 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
490 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
491 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
492 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
493 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
495 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
497 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
499 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
500 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
501 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
502 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
504 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
506 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
509 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
511 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
512 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
513 GL_MAP1_TEXTURE_COORD_1
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
515 GL_MAP1_TEXTURE_COORD_2
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
517 GL_MAP1_TEXTURE_COORD_3
);
518 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
519 GL_MAP1_TEXTURE_COORD_4
);
520 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
522 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
524 for (i
= 0; i
< 16; i
++) {
525 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
526 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
532 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
533 GL_MAP2_TEXTURE_COORD_1
);
534 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
535 GL_MAP2_TEXTURE_COORD_2
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
537 GL_MAP2_TEXTURE_COORD_3
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
539 GL_MAP2_TEXTURE_COORD_4
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
542 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
544 for (i
= 0; i
< 16; i
++) {
545 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
546 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
549 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
550 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
551 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
552 GL_RESCALE_NORMAL_EXT
);
553 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
554 enable
->RasterPositionUnclipped
,
555 GL_RASTER_POSITION_UNCLIPPED_IBM
);
556 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
558 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
559 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
562 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
563 GL_POLYGON_OFFSET_POINT
);
564 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
565 GL_POLYGON_OFFSET_LINE
);
566 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
567 GL_POLYGON_OFFSET_FILL
);
568 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
570 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
572 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
573 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
574 if (ctx
->Extensions
.EXT_stencil_two_side
) {
575 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
577 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
579 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
580 enable
->SampleAlphaToCoverage
,
581 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
582 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
583 enable
->SampleAlphaToOne
,
584 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
585 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
586 enable
->SampleCoverage
,
587 GL_SAMPLE_COVERAGE_ARB
);
588 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
589 enable
->SampleCoverageInvert
,
590 GL_SAMPLE_COVERAGE_INVERT_ARB
);
591 /* GL_ARB_vertex_program, GL_NV_vertex_program */
592 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
593 enable
->VertexProgram
,
594 GL_VERTEX_PROGRAM_ARB
);
595 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
596 enable
->VertexProgramPointSize
,
597 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
598 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
599 enable
->VertexProgramTwoSide
,
600 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
602 #undef TEST_AND_UPDATE
604 /* texture unit enables */
605 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
606 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
607 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
608 if (ctx
->Driver
.Enable
) {
609 if (ctx
->Driver
.ActiveTexture
) {
610 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
612 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
613 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
614 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
615 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
616 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
617 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
618 if (ctx
->Extensions
.ARB_texture_cube_map
)
619 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
620 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
621 if (ctx
->Extensions
.NV_texture_rectangle
)
622 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
623 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
627 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
628 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
629 if (ctx
->Driver
.Enable
) {
630 if (ctx
->Driver
.ActiveTexture
) {
631 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
633 if (enable
->TexGen
[i
] & S_BIT
)
634 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
636 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
637 if (enable
->TexGen
[i
] & T_BIT
)
638 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
640 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
641 if (enable
->TexGen
[i
] & R_BIT
)
642 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
644 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
645 if (enable
->TexGen
[i
] & Q_BIT
)
646 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
648 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
652 /* GL_SGI_texture_color_table */
653 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
656 if (ctx
->Driver
.ActiveTexture
) {
657 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
663 * Pop/restore texture attribute/group state.
666 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
670 _mesa_lock_context_textures(ctx
);
672 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
673 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
676 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
677 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
678 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
679 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
680 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
681 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
682 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
683 if (ctx
->Extensions
.ARB_texture_cube_map
) {
684 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
685 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
687 if (ctx
->Extensions
.NV_texture_rectangle
) {
688 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
689 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
691 if (ctx
->Extensions
.SGI_texture_color_table
) {
692 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
693 unit
->ColorTableEnabled
);
695 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
696 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
697 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
698 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
699 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
700 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
701 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
702 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
703 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
704 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
705 /* Eye plane done differently to avoid re-transformation */
707 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
708 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
709 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
710 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
711 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
712 if (ctx
->Driver
.TexGen
) {
713 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
714 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
715 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
716 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
719 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
720 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
721 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
722 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
723 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
724 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
725 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
726 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
727 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
728 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
729 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
731 if (ctx
->Extensions
.EXT_texture_env_combine
||
732 ctx
->Extensions
.ARB_texture_env_combine
) {
733 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
734 unit
->Combine
.ModeRGB
);
735 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
736 unit
->Combine
.ModeA
);
737 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
738 unit
->Combine
.SourceRGB
[0]);
739 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
740 unit
->Combine
.SourceRGB
[1]);
741 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
742 unit
->Combine
.SourceRGB
[2]);
743 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
744 unit
->Combine
.SourceA
[0]);
745 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
746 unit
->Combine
.SourceA
[1]);
747 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
748 unit
->Combine
.SourceA
[2]);
749 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
750 unit
->Combine
.OperandRGB
[0]);
751 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
752 unit
->Combine
.OperandRGB
[1]);
753 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
754 unit
->Combine
.OperandRGB
[2]);
755 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
756 unit
->Combine
.OperandA
[0]);
757 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
758 unit
->Combine
.OperandA
[1]);
759 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
760 unit
->Combine
.OperandA
[2]);
761 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
762 1 << unit
->Combine
.ScaleShiftRGB
);
763 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
764 1 << unit
->Combine
.ScaleShiftA
);
767 /* Restore texture object state for each target */
768 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
769 const struct gl_texture_object
*obj
= NULL
;
770 GLfloat bordColor
[4];
773 obj
= &texstate
->SavedObj
[u
][tgt
];
775 /* don't restore state for unsupported targets to prevent
778 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
779 !ctx
->Extensions
.ARB_texture_cube_map
) {
782 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
783 !ctx
->Extensions
.NV_texture_rectangle
) {
786 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
787 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
788 !ctx
->Extensions
.MESA_texture_array
) {
792 target
= obj
->Target
;
794 _mesa_BindTexture(target
, obj
->Name
);
796 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
797 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
798 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
799 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
801 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
802 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
803 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
804 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
805 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
806 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
807 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
808 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
809 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
810 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
811 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
812 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
813 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
814 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
815 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
818 if (ctx
->Extensions
.SGIX_shadow
) {
819 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
821 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
822 obj
->CompareOperator
);
824 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
825 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
830 /* remove saved references to the texture objects */
831 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
832 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
836 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
838 _mesa_unlock_context_textures(ctx
);
843 * This function is kind of long just because we have to call a lot
844 * of device driver functions to update device driver state.
846 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
847 * in order to restore GL state. This isn't terribly efficient but it
848 * ensures that dirty flags and any derived state gets updated correctly.
849 * We could at least check if the value to restore equals the current value
850 * and then skip the Mesa call.
853 _mesa_PopAttrib(void)
855 struct gl_attrib_node
*attr
, *next
;
856 GET_CURRENT_CONTEXT(ctx
);
857 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
859 if (ctx
->AttribStackDepth
== 0) {
860 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
864 ctx
->AttribStackDepth
--;
865 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
869 if (MESA_VERBOSE
& VERBOSE_API
) {
870 _mesa_debug(ctx
, "glPopAttrib %s\n",
871 _mesa_lookup_enum_by_nr(attr
->kind
));
874 switch (attr
->kind
) {
875 case GL_ACCUM_BUFFER_BIT
:
877 const struct gl_accum_attrib
*accum
;
878 accum
= (const struct gl_accum_attrib
*) attr
->data
;
879 _mesa_ClearAccum(accum
->ClearColor
[0],
880 accum
->ClearColor
[1],
881 accum
->ClearColor
[2],
882 accum
->ClearColor
[3]);
885 case GL_COLOR_BUFFER_BIT
:
887 const struct gl_colorbuffer_attrib
*color
;
888 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
889 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
890 _mesa_ClearColor(color
->ClearColor
[0],
891 color
->ClearColor
[1],
892 color
->ClearColor
[2],
893 color
->ClearColor
[3]);
894 _mesa_IndexMask(color
->IndexMask
);
895 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
896 (GLboolean
) (color
->ColorMask
[1] != 0),
897 (GLboolean
) (color
->ColorMask
[2] != 0),
898 (GLboolean
) (color
->ColorMask
[3] != 0));
900 /* Need to determine if more than one color output is
901 * specified. If so, call glDrawBuffersARB, else call
902 * glDrawBuffer(). This is a subtle, but essential point
903 * since GL_FRONT (for example) is illegal for the former
904 * function, but legal for the later.
906 GLboolean multipleBuffers
= GL_FALSE
;
907 if (ctx
->Extensions
.ARB_draw_buffers
) {
909 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
910 if (color
->DrawBuffer
[i
] != GL_NONE
) {
911 multipleBuffers
= GL_TRUE
;
916 /* Call the API_level functions, not _mesa_drawbuffers()
917 * since we need to do error checking on the pop'd
919 * Ex: if GL_FRONT were pushed, but we're popping with a
920 * user FBO bound, GL_FRONT will be illegal and we'll need
921 * to record that error. Per OpenGL ARB decision.
924 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
927 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
929 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
930 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
931 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
932 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
936 /* This special case is because glBlendEquationSeparateEXT
937 * cannot take GL_LOGIC_OP as a parameter.
939 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
940 _mesa_BlendEquation(color
->BlendEquationRGB
);
943 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
944 color
->BlendEquationA
);
946 _mesa_BlendColor(color
->BlendColor
[0],
947 color
->BlendColor
[1],
948 color
->BlendColor
[2],
949 color
->BlendColor
[3]);
950 _mesa_LogicOp(color
->LogicOp
);
951 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
952 color
->ColorLogicOpEnabled
);
953 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
954 color
->IndexLogicOpEnabled
);
955 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
959 FLUSH_CURRENT( ctx
, 0 );
960 MEMCPY( &ctx
->Current
, attr
->data
,
961 sizeof(struct gl_current_attrib
) );
963 case GL_DEPTH_BUFFER_BIT
:
965 const struct gl_depthbuffer_attrib
*depth
;
966 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
967 _mesa_DepthFunc(depth
->Func
);
968 _mesa_ClearDepth(depth
->Clear
);
969 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
970 _mesa_DepthMask(depth
->Mask
);
975 const struct gl_enable_attrib
*enable
;
976 enable
= (const struct gl_enable_attrib
*) attr
->data
;
977 pop_enable_group(ctx
, enable
);
978 ctx
->NewState
|= _NEW_ALL
;
982 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
983 ctx
->NewState
|= _NEW_EVAL
;
987 const struct gl_fog_attrib
*fog
;
988 fog
= (const struct gl_fog_attrib
*) attr
->data
;
989 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
990 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
991 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
992 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
993 _mesa_Fogf(GL_FOG_END
, fog
->End
);
994 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
995 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1000 const struct gl_hint_attrib
*hint
;
1001 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1002 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1003 hint
->PerspectiveCorrection
);
1004 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1005 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1006 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1007 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1008 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1009 hint
->ClipVolumeClipping
);
1010 if (ctx
->Extensions
.ARB_texture_compression
)
1011 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1012 hint
->TextureCompression
);
1015 case GL_LIGHTING_BIT
:
1018 const struct gl_light_attrib
*light
;
1019 light
= (const struct gl_light_attrib
*) attr
->data
;
1020 /* lighting enable */
1021 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1022 /* per-light state */
1023 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1024 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1026 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1027 const struct gl_light
*l
= &light
->Light
[i
];
1028 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1029 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1030 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1031 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1032 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1033 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
1034 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1035 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1036 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1037 &l
->ConstantAttenuation
);
1038 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1039 &l
->LinearAttenuation
);
1040 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1041 &l
->QuadraticAttenuation
);
1044 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1045 light
->Model
.Ambient
);
1046 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1047 (GLfloat
) light
->Model
.LocalViewer
);
1048 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1049 (GLfloat
) light
->Model
.TwoSide
);
1050 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1051 (GLfloat
) light
->Model
.ColorControl
);
1053 _mesa_ShadeModel(light
->ShadeModel
);
1054 /* color material */
1055 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1056 light
->ColorMaterialMode
);
1057 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1058 light
->ColorMaterialEnabled
);
1060 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1061 sizeof(struct gl_material
));
1066 const struct gl_line_attrib
*line
;
1067 line
= (const struct gl_line_attrib
*) attr
->data
;
1068 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1069 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1070 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1071 _mesa_LineWidth(line
->Width
);
1075 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1077 case GL_PIXEL_MODE_BIT
:
1078 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1079 /* XXX what other pixel state needs to be set by function calls? */
1080 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1081 ctx
->NewState
|= _NEW_PIXEL
;
1085 const struct gl_point_attrib
*point
;
1086 point
= (const struct gl_point_attrib
*) attr
->data
;
1087 _mesa_PointSize(point
->Size
);
1088 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1089 if (ctx
->Extensions
.EXT_point_parameters
) {
1090 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1092 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1094 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1096 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1099 if (ctx
->Extensions
.NV_point_sprite
1100 || ctx
->Extensions
.ARB_point_sprite
) {
1102 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1103 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1104 (GLint
) point
->CoordReplace
[u
]);
1106 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1107 if (ctx
->Extensions
.NV_point_sprite
)
1108 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1109 ctx
->Point
.SpriteRMode
);
1110 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1111 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1115 case GL_POLYGON_BIT
:
1117 const struct gl_polygon_attrib
*polygon
;
1118 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1119 _mesa_CullFace(polygon
->CullFaceMode
);
1120 _mesa_FrontFace(polygon
->FrontFace
);
1121 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1122 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1123 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1124 polygon
->OffsetUnits
);
1125 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1126 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1127 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1128 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1129 polygon
->OffsetPoint
);
1130 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1131 polygon
->OffsetLine
);
1132 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1133 polygon
->OffsetFill
);
1136 case GL_POLYGON_STIPPLE_BIT
:
1137 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1138 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1139 if (ctx
->Driver
.PolygonStipple
)
1140 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1142 case GL_SCISSOR_BIT
:
1144 const struct gl_scissor_attrib
*scissor
;
1145 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1146 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1147 scissor
->Width
, scissor
->Height
);
1148 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1151 case GL_STENCIL_BUFFER_BIT
:
1153 const struct gl_stencil_attrib
*stencil
;
1154 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1155 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1156 _mesa_ClearStencil(stencil
->Clear
);
1157 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1158 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1159 stencil
->TestTwoSide
);
1160 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1161 ? GL_BACK
: GL_FRONT
);
1164 _mesa_StencilFuncSeparate(GL_FRONT
,
1165 stencil
->Function
[0],
1167 stencil
->ValueMask
[0]);
1168 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1169 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1170 stencil
->ZFailFunc
[0],
1171 stencil
->ZPassFunc
[0]);
1173 _mesa_StencilFuncSeparate(GL_BACK
,
1174 stencil
->Function
[1],
1176 stencil
->ValueMask
[1]);
1177 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1178 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1179 stencil
->ZFailFunc
[1],
1180 stencil
->ZPassFunc
[1]);
1183 case GL_TRANSFORM_BIT
:
1186 const struct gl_transform_attrib
*xform
;
1187 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1188 _mesa_MatrixMode(xform
->MatrixMode
);
1189 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1190 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1192 /* restore clip planes */
1193 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1194 const GLuint mask
= 1 << 1;
1195 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1196 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1197 if (xform
->ClipPlanesEnabled
& mask
) {
1198 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1201 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1203 if (ctx
->Driver
.ClipPlane
)
1204 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1207 /* normalize/rescale */
1208 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1209 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1210 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1211 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1212 ctx
->Transform
.RescaleNormals
);
1215 case GL_TEXTURE_BIT
:
1216 /* Take care of texture object reference counters */
1218 struct texture_state
*texstate
1219 = (struct texture_state
*) attr
->data
;
1220 pop_texture_group(ctx
, texstate
);
1221 ctx
->NewState
|= _NEW_TEXTURE
;
1224 case GL_VIEWPORT_BIT
:
1226 const struct gl_viewport_attrib
*vp
;
1227 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1228 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1229 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1232 case GL_MULTISAMPLE_BIT_ARB
:
1234 const struct gl_multisample_attrib
*ms
;
1235 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1236 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1237 ms
->SampleCoverageInvert
);
1242 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1255 * Helper for incrementing/decrementing vertex buffer object reference
1256 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1259 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1262 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1263 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1264 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1265 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1266 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1267 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1268 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1269 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1270 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1271 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1272 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1274 array
->ArrayBufferObj
->RefCount
+= step
;
1275 array
->ElementArrayBufferObj
->RefCount
+= step
;
1280 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1284 copy_pixelstore(GLcontext
*ctx
,
1285 struct gl_pixelstore_attrib
*dst
,
1286 const struct gl_pixelstore_attrib
*src
)
1288 dst
->Alignment
= src
->Alignment
;
1289 dst
->RowLength
= src
->RowLength
;
1290 dst
->SkipPixels
= src
->SkipPixels
;
1291 dst
->SkipRows
= src
->SkipRows
;
1292 dst
->ImageHeight
= src
->ImageHeight
;
1293 dst
->SkipImages
= src
->SkipImages
;
1294 dst
->SwapBytes
= src
->SwapBytes
;
1295 dst
->LsbFirst
= src
->LsbFirst
;
1296 dst
->ClientStorage
= src
->ClientStorage
;
1297 dst
->Invert
= src
->Invert
;
1298 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1302 #define GL_CLIENT_PACK_BIT (1<<20)
1303 #define GL_CLIENT_UNPACK_BIT (1<<21)
1307 _mesa_PushClientAttrib(GLbitfield mask
)
1309 struct gl_attrib_node
*newnode
;
1310 struct gl_attrib_node
*head
;
1312 GET_CURRENT_CONTEXT(ctx
);
1313 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1315 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1316 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1320 /* Build linked list of attribute nodes which save all attribute
1321 * groups specified by the mask.
1325 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1326 struct gl_pixelstore_attrib
*attr
;
1327 /* packing attribs */
1328 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1329 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1330 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1331 newnode
->data
= attr
;
1332 newnode
->next
= head
;
1334 /* unpacking attribs */
1335 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1336 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1337 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1338 newnode
->data
= attr
;
1339 newnode
->next
= head
;
1343 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1344 struct gl_array_attrib
*attr
;
1345 struct gl_array_object
*obj
;
1347 attr
= MALLOC_STRUCT( gl_array_attrib
);
1348 obj
= MALLOC_STRUCT( gl_array_object
);
1350 #if FEATURE_ARB_vertex_buffer_object
1351 /* increment ref counts since we're copying pointers to these objects */
1352 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1353 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1356 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1357 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1359 attr
->ArrayObj
= obj
;
1361 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1362 newnode
->data
= attr
;
1363 newnode
->next
= head
;
1365 /* bump reference counts on buffer objects */
1366 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1369 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1370 ctx
->ClientAttribStackDepth
++;
1377 _mesa_PopClientAttrib(void)
1379 struct gl_attrib_node
*node
, *next
;
1381 GET_CURRENT_CONTEXT(ctx
);
1382 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1384 if (ctx
->ClientAttribStackDepth
== 0) {
1385 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1389 ctx
->ClientAttribStackDepth
--;
1390 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1393 switch (node
->kind
) {
1394 case GL_CLIENT_PACK_BIT
:
1396 struct gl_pixelstore_attrib
*store
=
1397 (struct gl_pixelstore_attrib
*) node
->data
;
1398 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1399 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1401 ctx
->NewState
|= _NEW_PACKUNPACK
;
1403 case GL_CLIENT_UNPACK_BIT
:
1405 struct gl_pixelstore_attrib
*store
=
1406 (struct gl_pixelstore_attrib
*) node
->data
;
1407 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1408 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1410 ctx
->NewState
|= _NEW_PACKUNPACK
;
1412 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1413 struct gl_array_attrib
* data
=
1414 (struct gl_array_attrib
*) node
->data
;
1416 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1418 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1419 if (data
->LockCount
!= 0)
1420 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1421 else if (ctx
->Array
.LockCount
)
1422 _mesa_UnlockArraysEXT();
1424 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1426 #if FEATURE_ARB_vertex_buffer_object
1427 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1428 data
->ArrayBufferObj
->Name
);
1429 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1430 data
->ElementArrayBufferObj
->Name
);
1433 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1434 sizeof( struct gl_array_object
) );
1436 FREE( data
->ArrayObj
);
1438 /* FIXME: Should some bits in ctx->Array->NewState also be set
1439 * FIXME: here? It seems like it should be set to inclusive-or
1440 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1443 ctx
->NewState
|= _NEW_ARRAY
;
1447 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1460 * Free any attribute state data that might be attached to the context.
1463 _mesa_free_attrib_data(GLcontext
*ctx
)
1465 while (ctx
->AttribStackDepth
> 0) {
1466 struct gl_attrib_node
*attr
, *next
;
1468 ctx
->AttribStackDepth
--;
1469 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1472 if (attr
->kind
== GL_TEXTURE_BIT
) {
1473 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1475 /* clear references to the saved texture objects */
1476 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1477 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1478 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1483 /* any other chunks of state that requires special handling? */
1487 _mesa_free(attr
->data
);
1495 void _mesa_init_attrib( GLcontext
*ctx
)
1497 /* Renderer and client attribute stacks */
1498 ctx
->AttribStackDepth
= 0;
1499 ctx
->ClientAttribStackDepth
= 0;