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"
47 #include "simple_list.h"
53 #include "math/m_xform.h"
56 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
60 struct gl_texture_attrib Texture
; /**< The usual context state */
62 /** to save per texture object state (wrap modes, filters, etc): */
63 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
66 * To save references to texture objects (so they don't get accidentally
67 * deleted while saved in the attribute stack).
69 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
74 * Allocate a new attribute state node. These nodes have a
75 * "kind" value and a pointer to a struct of state data.
77 static struct gl_attrib_node
*
78 new_attrib_node( GLbitfield kind
)
80 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
89 _mesa_PushAttrib(GLbitfield mask
)
91 struct gl_attrib_node
*newnode
;
92 struct gl_attrib_node
*head
;
94 GET_CURRENT_CONTEXT(ctx
);
95 ASSERT_OUTSIDE_BEGIN_END(ctx
);
97 if (MESA_VERBOSE
& VERBOSE_API
)
98 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
100 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
101 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
105 /* Build linked list of attribute nodes which save all attribute */
106 /* groups specified by the mask. */
109 if (mask
& GL_ACCUM_BUFFER_BIT
) {
110 struct gl_accum_attrib
*attr
;
111 attr
= MALLOC_STRUCT( gl_accum_attrib
);
112 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
113 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
114 newnode
->data
= attr
;
115 newnode
->next
= head
;
119 if (mask
& GL_COLOR_BUFFER_BIT
) {
121 struct gl_colorbuffer_attrib
*attr
;
122 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
123 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
124 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
125 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
126 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
127 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
128 newnode
->data
= attr
;
129 newnode
->next
= head
;
133 if (mask
& GL_CURRENT_BIT
) {
134 struct gl_current_attrib
*attr
;
135 FLUSH_CURRENT( ctx
, 0 );
136 attr
= MALLOC_STRUCT( gl_current_attrib
);
137 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
138 newnode
= new_attrib_node( GL_CURRENT_BIT
);
139 newnode
->data
= attr
;
140 newnode
->next
= head
;
144 if (mask
& GL_DEPTH_BUFFER_BIT
) {
145 struct gl_depthbuffer_attrib
*attr
;
146 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
147 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
148 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
149 newnode
->data
= attr
;
150 newnode
->next
= head
;
154 if (mask
& GL_ENABLE_BIT
) {
155 struct gl_enable_attrib
*attr
;
157 attr
= MALLOC_STRUCT( gl_enable_attrib
);
158 /* Copy enable flags from all other attributes into the enable struct. */
159 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
160 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
161 attr
->Blend
= ctx
->Color
.BlendEnabled
;
162 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
163 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
164 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
165 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
167 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
168 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
169 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
170 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
171 attr
->DepthTest
= ctx
->Depth
.Test
;
172 attr
->Dither
= ctx
->Color
.DitherFlag
;
173 attr
->Fog
= ctx
->Fog
.Enabled
;
174 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
175 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
177 attr
->Lighting
= ctx
->Light
.Enabled
;
178 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
179 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
180 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
181 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
182 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
183 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
184 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
185 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
186 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
187 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
188 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
189 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
190 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
191 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
192 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
193 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
194 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
195 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
196 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
197 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
198 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
199 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
200 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
201 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
202 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
203 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
204 attr
->Normalize
= ctx
->Transform
.Normalize
;
205 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
206 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
207 attr
->PointSprite
= ctx
->Point
.PointSprite
;
208 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
209 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
210 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
211 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
212 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
213 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
214 attr
->Scissor
= ctx
->Scissor
.Enabled
;
215 attr
->Stencil
= ctx
->Stencil
.Enabled
;
216 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
217 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
218 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
219 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
220 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
221 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
222 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
223 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
224 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
225 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
227 /* GL_NV_vertex_program */
228 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
229 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
230 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
231 newnode
= new_attrib_node( GL_ENABLE_BIT
);
232 newnode
->data
= attr
;
233 newnode
->next
= head
;
237 if (mask
& GL_EVAL_BIT
) {
238 struct gl_eval_attrib
*attr
;
239 attr
= MALLOC_STRUCT( gl_eval_attrib
);
240 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
241 newnode
= new_attrib_node( GL_EVAL_BIT
);
242 newnode
->data
= attr
;
243 newnode
->next
= head
;
247 if (mask
& GL_FOG_BIT
) {
248 struct gl_fog_attrib
*attr
;
249 attr
= MALLOC_STRUCT( gl_fog_attrib
);
250 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
251 newnode
= new_attrib_node( GL_FOG_BIT
);
252 newnode
->data
= attr
;
253 newnode
->next
= head
;
257 if (mask
& GL_HINT_BIT
) {
258 struct gl_hint_attrib
*attr
;
259 attr
= MALLOC_STRUCT( gl_hint_attrib
);
260 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
261 newnode
= new_attrib_node( GL_HINT_BIT
);
262 newnode
->data
= attr
;
263 newnode
->next
= head
;
267 if (mask
& GL_LIGHTING_BIT
) {
268 struct gl_light_attrib
*attr
;
269 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
270 attr
= MALLOC_STRUCT( gl_light_attrib
);
271 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
272 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
273 newnode
->data
= attr
;
274 newnode
->next
= head
;
278 if (mask
& GL_LINE_BIT
) {
279 struct gl_line_attrib
*attr
;
280 attr
= MALLOC_STRUCT( gl_line_attrib
);
281 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
282 newnode
= new_attrib_node( GL_LINE_BIT
);
283 newnode
->data
= attr
;
284 newnode
->next
= head
;
288 if (mask
& GL_LIST_BIT
) {
289 struct gl_list_attrib
*attr
;
290 attr
= MALLOC_STRUCT( gl_list_attrib
);
291 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
292 newnode
= new_attrib_node( GL_LIST_BIT
);
293 newnode
->data
= attr
;
294 newnode
->next
= head
;
298 if (mask
& GL_PIXEL_MODE_BIT
) {
299 struct gl_pixel_attrib
*attr
;
300 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
301 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
302 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
303 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
304 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
305 newnode
->data
= attr
;
306 newnode
->next
= head
;
310 if (mask
& GL_POINT_BIT
) {
311 struct gl_point_attrib
*attr
;
312 attr
= MALLOC_STRUCT( gl_point_attrib
);
313 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
314 newnode
= new_attrib_node( GL_POINT_BIT
);
315 newnode
->data
= attr
;
316 newnode
->next
= head
;
320 if (mask
& GL_POLYGON_BIT
) {
321 struct gl_polygon_attrib
*attr
;
322 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
323 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
324 newnode
= new_attrib_node( GL_POLYGON_BIT
);
325 newnode
->data
= attr
;
326 newnode
->next
= head
;
330 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
332 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
333 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
334 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
335 newnode
->data
= stipple
;
336 newnode
->next
= head
;
340 if (mask
& GL_SCISSOR_BIT
) {
341 struct gl_scissor_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
343 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
344 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
345 newnode
->data
= attr
;
346 newnode
->next
= head
;
350 if (mask
& GL_STENCIL_BUFFER_BIT
) {
351 struct gl_stencil_attrib
*attr
;
352 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
353 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
354 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
355 newnode
->data
= attr
;
356 newnode
->next
= head
;
360 if (mask
& GL_TEXTURE_BIT
) {
361 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
365 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
369 _mesa_lock_context_textures(ctx
);
371 /* copy/save the bulk of texture state here */
372 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
374 /* Save references to the currently bound texture objects so they don't
375 * accidentally get deleted while referenced in the attribute stack.
377 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
378 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_INDEX
],
379 ctx
->Texture
.Unit
[u
].Current1D
);
380 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_INDEX
],
381 ctx
->Texture
.Unit
[u
].Current2D
);
382 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_3D_INDEX
],
383 ctx
->Texture
.Unit
[u
].Current3D
);
384 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_CUBE_INDEX
],
385 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
386 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_RECT_INDEX
],
387 ctx
->Texture
.Unit
[u
].CurrentRect
);
388 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_1D_ARRAY_INDEX
],
389 ctx
->Texture
.Unit
[u
].Current1DArray
);
390 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][TEXTURE_2D_ARRAY_INDEX
],
391 ctx
->Texture
.Unit
[u
].Current2DArray
);
394 /* copy state/contents of the currently bound texture objects */
395 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
396 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_INDEX
],
397 ctx
->Texture
.Unit
[u
].Current1D
);
398 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_INDEX
],
399 ctx
->Texture
.Unit
[u
].Current2D
);
400 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_3D_INDEX
],
401 ctx
->Texture
.Unit
[u
].Current3D
);
402 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_CUBE_INDEX
],
403 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
404 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_RECT_INDEX
],
405 ctx
->Texture
.Unit
[u
].CurrentRect
);
406 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_1D_ARRAY_INDEX
],
407 ctx
->Texture
.Unit
[u
].Current1DArray
);
408 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][TEXTURE_2D_ARRAY_INDEX
],
409 ctx
->Texture
.Unit
[u
].Current2DArray
);
412 _mesa_unlock_context_textures(ctx
);
414 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
415 newnode
->data
= texstate
;
416 newnode
->next
= head
;
420 if (mask
& GL_TRANSFORM_BIT
) {
421 struct gl_transform_attrib
*attr
;
422 attr
= MALLOC_STRUCT( gl_transform_attrib
);
423 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
424 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
425 newnode
->data
= attr
;
426 newnode
->next
= head
;
430 if (mask
& GL_VIEWPORT_BIT
) {
431 struct gl_viewport_attrib
*attr
;
432 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
433 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
434 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
435 newnode
->data
= attr
;
436 newnode
->next
= head
;
440 /* GL_ARB_multisample */
441 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
442 struct gl_multisample_attrib
*attr
;
443 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
444 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
445 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
446 newnode
->data
= attr
;
447 newnode
->next
= head
;
452 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
453 ctx
->AttribStackDepth
++;
459 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
463 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
464 if ((VALUE) != (NEWVALUE)) { \
465 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
468 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
469 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
471 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
472 const GLuint mask
= 1 << i
;
473 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
474 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
475 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
478 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
480 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
481 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
483 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
484 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
485 GL_POST_CONVOLUTION_COLOR_TABLE
);
486 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
487 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
488 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
489 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
490 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
491 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
492 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
494 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
496 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
498 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
499 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
500 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
501 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
503 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
505 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
508 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
509 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
511 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
512 GL_MAP1_TEXTURE_COORD_1
);
513 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
514 GL_MAP1_TEXTURE_COORD_2
);
515 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
516 GL_MAP1_TEXTURE_COORD_3
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
518 GL_MAP1_TEXTURE_COORD_4
);
519 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
521 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
523 for (i
= 0; i
< 16; i
++) {
524 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
525 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
528 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
532 GL_MAP2_TEXTURE_COORD_1
);
533 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
534 GL_MAP2_TEXTURE_COORD_2
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
536 GL_MAP2_TEXTURE_COORD_3
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
538 GL_MAP2_TEXTURE_COORD_4
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
541 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
543 for (i
= 0; i
< 16; i
++) {
544 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
545 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
548 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
549 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
550 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
551 GL_RESCALE_NORMAL_EXT
);
552 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
553 enable
->RasterPositionUnclipped
,
554 GL_RASTER_POSITION_UNCLIPPED_IBM
);
555 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
557 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
558 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
561 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
562 GL_POLYGON_OFFSET_POINT
);
563 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
564 GL_POLYGON_OFFSET_LINE
);
565 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
566 GL_POLYGON_OFFSET_FILL
);
567 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
569 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
571 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
572 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
573 if (ctx
->Extensions
.EXT_stencil_two_side
) {
574 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
576 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
578 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
579 enable
->SampleAlphaToCoverage
,
580 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
581 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
582 enable
->SampleAlphaToOne
,
583 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
584 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
585 enable
->SampleCoverage
,
586 GL_SAMPLE_COVERAGE_ARB
);
587 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
588 enable
->SampleCoverageInvert
,
589 GL_SAMPLE_COVERAGE_INVERT_ARB
);
590 /* GL_ARB_vertex_program, GL_NV_vertex_program */
591 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
592 enable
->VertexProgram
,
593 GL_VERTEX_PROGRAM_ARB
);
594 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
595 enable
->VertexProgramPointSize
,
596 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
597 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
598 enable
->VertexProgramTwoSide
,
599 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
601 #undef TEST_AND_UPDATE
603 /* texture unit enables */
604 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
605 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
606 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
607 if (ctx
->Driver
.Enable
) {
608 if (ctx
->Driver
.ActiveTexture
) {
609 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
611 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
612 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
613 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
614 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
615 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
616 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
617 if (ctx
->Extensions
.ARB_texture_cube_map
)
618 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
619 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
620 if (ctx
->Extensions
.NV_texture_rectangle
)
621 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
622 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
626 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
627 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
628 if (ctx
->Driver
.Enable
) {
629 if (ctx
->Driver
.ActiveTexture
) {
630 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
632 if (enable
->TexGen
[i
] & S_BIT
)
633 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
635 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
636 if (enable
->TexGen
[i
] & T_BIT
)
637 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
639 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
640 if (enable
->TexGen
[i
] & R_BIT
)
641 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
643 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
644 if (enable
->TexGen
[i
] & Q_BIT
)
645 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
647 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
651 /* GL_SGI_texture_color_table */
652 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
655 if (ctx
->Driver
.ActiveTexture
) {
656 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
662 * Pop/restore texture attribute/group state.
665 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
669 _mesa_lock_context_textures(ctx
);
671 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
672 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
675 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
676 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
677 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
678 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
679 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
680 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
681 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
682 if (ctx
->Extensions
.ARB_texture_cube_map
) {
683 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
684 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
686 if (ctx
->Extensions
.NV_texture_rectangle
) {
687 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
688 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
690 if (ctx
->Extensions
.SGI_texture_color_table
) {
691 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
692 unit
->ColorTableEnabled
);
694 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
695 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
696 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
697 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
698 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
699 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
700 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
701 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
702 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
703 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
704 /* Eye plane done differently to avoid re-transformation */
706 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
707 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
708 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
709 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
710 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
711 if (ctx
->Driver
.TexGen
) {
712 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
713 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
714 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
715 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
718 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
719 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
720 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
721 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
722 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
723 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
724 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
725 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
726 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
727 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
728 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
730 if (ctx
->Extensions
.EXT_texture_env_combine
||
731 ctx
->Extensions
.ARB_texture_env_combine
) {
732 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
733 unit
->Combine
.ModeRGB
);
734 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
735 unit
->Combine
.ModeA
);
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
737 unit
->Combine
.SourceRGB
[0]);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
739 unit
->Combine
.SourceRGB
[1]);
740 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
741 unit
->Combine
.SourceRGB
[2]);
742 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
743 unit
->Combine
.SourceA
[0]);
744 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
745 unit
->Combine
.SourceA
[1]);
746 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
747 unit
->Combine
.SourceA
[2]);
748 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
749 unit
->Combine
.OperandRGB
[0]);
750 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
751 unit
->Combine
.OperandRGB
[1]);
752 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
753 unit
->Combine
.OperandRGB
[2]);
754 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
755 unit
->Combine
.OperandA
[0]);
756 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
757 unit
->Combine
.OperandA
[1]);
758 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
759 unit
->Combine
.OperandA
[2]);
760 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
761 1 << unit
->Combine
.ScaleShiftRGB
);
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
763 1 << unit
->Combine
.ScaleShiftA
);
766 /* Restore texture object state for each target */
767 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
768 const struct gl_texture_object
*obj
= NULL
;
769 GLfloat bordColor
[4];
772 obj
= &texstate
->SavedObj
[u
][tgt
];
774 /* don't restore state for unsupported targets to prevent
777 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
778 !ctx
->Extensions
.ARB_texture_cube_map
) {
781 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
782 !ctx
->Extensions
.NV_texture_rectangle
) {
785 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
786 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
787 !ctx
->Extensions
.MESA_texture_array
) {
791 target
= obj
->Target
;
793 _mesa_BindTexture(target
, obj
->Name
);
795 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
796 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
797 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
798 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
800 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
801 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
802 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
803 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
804 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
805 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
806 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
807 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
808 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
809 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
810 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
811 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
812 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
813 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
814 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
817 if (ctx
->Extensions
.SGIX_shadow
) {
818 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
820 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
821 obj
->CompareOperator
);
823 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
824 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
829 /* remove saved references to the texture objects */
830 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
831 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
835 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
837 _mesa_unlock_context_textures(ctx
);
842 * This function is kind of long just because we have to call a lot
843 * of device driver functions to update device driver state.
845 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
846 * in order to restore GL state. This isn't terribly efficient but it
847 * ensures that dirty flags and any derived state gets updated correctly.
848 * We could at least check if the value to restore equals the current value
849 * and then skip the Mesa call.
852 _mesa_PopAttrib(void)
854 struct gl_attrib_node
*attr
, *next
;
855 GET_CURRENT_CONTEXT(ctx
);
856 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
858 if (ctx
->AttribStackDepth
== 0) {
859 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
863 ctx
->AttribStackDepth
--;
864 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
868 if (MESA_VERBOSE
& VERBOSE_API
) {
869 _mesa_debug(ctx
, "glPopAttrib %s\n",
870 _mesa_lookup_enum_by_nr(attr
->kind
));
873 switch (attr
->kind
) {
874 case GL_ACCUM_BUFFER_BIT
:
876 const struct gl_accum_attrib
*accum
;
877 accum
= (const struct gl_accum_attrib
*) attr
->data
;
878 _mesa_ClearAccum(accum
->ClearColor
[0],
879 accum
->ClearColor
[1],
880 accum
->ClearColor
[2],
881 accum
->ClearColor
[3]);
884 case GL_COLOR_BUFFER_BIT
:
886 const struct gl_colorbuffer_attrib
*color
;
887 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
888 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
889 _mesa_ClearColor(color
->ClearColor
[0],
890 color
->ClearColor
[1],
891 color
->ClearColor
[2],
892 color
->ClearColor
[3]);
893 _mesa_IndexMask(color
->IndexMask
);
894 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
895 (GLboolean
) (color
->ColorMask
[1] != 0),
896 (GLboolean
) (color
->ColorMask
[2] != 0),
897 (GLboolean
) (color
->ColorMask
[3] != 0));
899 /* Need to determine if more than one color output is
900 * specified. If so, call glDrawBuffersARB, else call
901 * glDrawBuffer(). This is a subtle, but essential point
902 * since GL_FRONT (for example) is illegal for the former
903 * function, but legal for the later.
905 GLboolean multipleBuffers
= GL_FALSE
;
906 if (ctx
->Extensions
.ARB_draw_buffers
) {
908 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
909 if (color
->DrawBuffer
[i
] != GL_NONE
) {
910 multipleBuffers
= GL_TRUE
;
915 /* Call the API_level functions, not _mesa_drawbuffers()
916 * since we need to do error checking on the pop'd
918 * Ex: if GL_FRONT were pushed, but we're popping with a
919 * user FBO bound, GL_FRONT will be illegal and we'll need
920 * to record that error. Per OpenGL ARB decision.
923 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
926 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
928 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
929 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
930 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
931 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
935 /* This special case is because glBlendEquationSeparateEXT
936 * cannot take GL_LOGIC_OP as a parameter.
938 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
939 _mesa_BlendEquation(color
->BlendEquationRGB
);
942 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
943 color
->BlendEquationA
);
945 _mesa_BlendColor(color
->BlendColor
[0],
946 color
->BlendColor
[1],
947 color
->BlendColor
[2],
948 color
->BlendColor
[3]);
949 _mesa_LogicOp(color
->LogicOp
);
950 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
951 color
->ColorLogicOpEnabled
);
952 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
953 color
->IndexLogicOpEnabled
);
954 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
958 FLUSH_CURRENT( ctx
, 0 );
959 MEMCPY( &ctx
->Current
, attr
->data
,
960 sizeof(struct gl_current_attrib
) );
962 case GL_DEPTH_BUFFER_BIT
:
964 const struct gl_depthbuffer_attrib
*depth
;
965 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
966 _mesa_DepthFunc(depth
->Func
);
967 _mesa_ClearDepth(depth
->Clear
);
968 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
969 _mesa_DepthMask(depth
->Mask
);
974 const struct gl_enable_attrib
*enable
;
975 enable
= (const struct gl_enable_attrib
*) attr
->data
;
976 pop_enable_group(ctx
, enable
);
977 ctx
->NewState
|= _NEW_ALL
;
981 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
982 ctx
->NewState
|= _NEW_EVAL
;
986 const struct gl_fog_attrib
*fog
;
987 fog
= (const struct gl_fog_attrib
*) attr
->data
;
988 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
989 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
990 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
991 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
992 _mesa_Fogf(GL_FOG_END
, fog
->End
);
993 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
994 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
999 const struct gl_hint_attrib
*hint
;
1000 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1001 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1002 hint
->PerspectiveCorrection
);
1003 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1004 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1005 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1006 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1007 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1008 hint
->ClipVolumeClipping
);
1009 if (ctx
->Extensions
.ARB_texture_compression
)
1010 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1011 hint
->TextureCompression
);
1014 case GL_LIGHTING_BIT
:
1017 const struct gl_light_attrib
*light
;
1018 light
= (const struct gl_light_attrib
*) attr
->data
;
1019 /* lighting enable */
1020 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1021 /* per-light state */
1022 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1023 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1025 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1026 const struct gl_light
*l
= &light
->Light
[i
];
1027 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1028 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1029 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1030 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1031 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1032 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
1033 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1034 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1035 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1036 &l
->ConstantAttenuation
);
1037 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1038 &l
->LinearAttenuation
);
1039 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1040 &l
->QuadraticAttenuation
);
1043 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1044 light
->Model
.Ambient
);
1045 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1046 (GLfloat
) light
->Model
.LocalViewer
);
1047 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1048 (GLfloat
) light
->Model
.TwoSide
);
1049 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1050 (GLfloat
) light
->Model
.ColorControl
);
1052 _mesa_ShadeModel(light
->ShadeModel
);
1053 /* color material */
1054 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1055 light
->ColorMaterialMode
);
1056 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1057 light
->ColorMaterialEnabled
);
1059 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1060 sizeof(struct gl_material
));
1065 const struct gl_line_attrib
*line
;
1066 line
= (const struct gl_line_attrib
*) attr
->data
;
1067 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1068 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1069 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1070 _mesa_LineWidth(line
->Width
);
1074 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1076 case GL_PIXEL_MODE_BIT
:
1077 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1078 /* XXX what other pixel state needs to be set by function calls? */
1079 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1080 ctx
->NewState
|= _NEW_PIXEL
;
1084 const struct gl_point_attrib
*point
;
1085 point
= (const struct gl_point_attrib
*) attr
->data
;
1086 _mesa_PointSize(point
->Size
);
1087 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1088 if (ctx
->Extensions
.EXT_point_parameters
) {
1089 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1091 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1093 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1095 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1098 if (ctx
->Extensions
.NV_point_sprite
1099 || ctx
->Extensions
.ARB_point_sprite
) {
1101 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1102 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1103 (GLint
) point
->CoordReplace
[u
]);
1105 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1106 if (ctx
->Extensions
.NV_point_sprite
)
1107 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1108 ctx
->Point
.SpriteRMode
);
1109 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1110 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1114 case GL_POLYGON_BIT
:
1116 const struct gl_polygon_attrib
*polygon
;
1117 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1118 _mesa_CullFace(polygon
->CullFaceMode
);
1119 _mesa_FrontFace(polygon
->FrontFace
);
1120 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1121 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1122 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1123 polygon
->OffsetUnits
);
1124 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1125 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1126 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1127 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1128 polygon
->OffsetPoint
);
1129 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1130 polygon
->OffsetLine
);
1131 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1132 polygon
->OffsetFill
);
1135 case GL_POLYGON_STIPPLE_BIT
:
1136 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1137 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1138 if (ctx
->Driver
.PolygonStipple
)
1139 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1141 case GL_SCISSOR_BIT
:
1143 const struct gl_scissor_attrib
*scissor
;
1144 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1145 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1146 scissor
->Width
, scissor
->Height
);
1147 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1150 case GL_STENCIL_BUFFER_BIT
:
1152 const struct gl_stencil_attrib
*stencil
;
1153 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1154 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1155 _mesa_ClearStencil(stencil
->Clear
);
1156 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1157 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1158 stencil
->TestTwoSide
);
1159 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1160 ? GL_BACK
: GL_FRONT
);
1163 _mesa_StencilFuncSeparate(GL_FRONT
,
1164 stencil
->Function
[0],
1166 stencil
->ValueMask
[0]);
1167 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1168 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1169 stencil
->ZFailFunc
[0],
1170 stencil
->ZPassFunc
[0]);
1172 _mesa_StencilFuncSeparate(GL_BACK
,
1173 stencil
->Function
[1],
1175 stencil
->ValueMask
[1]);
1176 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1177 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1178 stencil
->ZFailFunc
[1],
1179 stencil
->ZPassFunc
[1]);
1182 case GL_TRANSFORM_BIT
:
1185 const struct gl_transform_attrib
*xform
;
1186 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1187 _mesa_MatrixMode(xform
->MatrixMode
);
1188 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1189 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1191 /* restore clip planes */
1192 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1193 const GLuint mask
= 1 << 1;
1194 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1195 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1196 if (xform
->ClipPlanesEnabled
& mask
) {
1197 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1200 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1202 if (ctx
->Driver
.ClipPlane
)
1203 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1206 /* normalize/rescale */
1207 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1208 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1209 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1210 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1211 ctx
->Transform
.RescaleNormals
);
1214 case GL_TEXTURE_BIT
:
1215 /* Take care of texture object reference counters */
1217 struct texture_state
*texstate
1218 = (struct texture_state
*) attr
->data
;
1219 pop_texture_group(ctx
, texstate
);
1220 ctx
->NewState
|= _NEW_TEXTURE
;
1223 case GL_VIEWPORT_BIT
:
1225 const struct gl_viewport_attrib
*vp
;
1226 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1227 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1228 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1231 case GL_MULTISAMPLE_BIT_ARB
:
1233 const struct gl_multisample_attrib
*ms
;
1234 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1235 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1236 ms
->SampleCoverageInvert
);
1241 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1254 * Helper for incrementing/decrementing vertex buffer object reference
1255 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1258 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1261 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1262 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1263 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1264 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1265 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1266 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1267 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1268 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1269 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1270 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1271 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1273 array
->ArrayBufferObj
->RefCount
+= step
;
1274 array
->ElementArrayBufferObj
->RefCount
+= step
;
1279 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1283 copy_pixelstore(GLcontext
*ctx
,
1284 struct gl_pixelstore_attrib
*dst
,
1285 const struct gl_pixelstore_attrib
*src
)
1287 dst
->Alignment
= src
->Alignment
;
1288 dst
->RowLength
= src
->RowLength
;
1289 dst
->SkipPixels
= src
->SkipPixels
;
1290 dst
->SkipRows
= src
->SkipRows
;
1291 dst
->ImageHeight
= src
->ImageHeight
;
1292 dst
->SkipImages
= src
->SkipImages
;
1293 dst
->SwapBytes
= src
->SwapBytes
;
1294 dst
->LsbFirst
= src
->LsbFirst
;
1295 dst
->ClientStorage
= src
->ClientStorage
;
1296 dst
->Invert
= src
->Invert
;
1297 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1301 #define GL_CLIENT_PACK_BIT (1<<20)
1302 #define GL_CLIENT_UNPACK_BIT (1<<21)
1306 _mesa_PushClientAttrib(GLbitfield mask
)
1308 struct gl_attrib_node
*newnode
;
1309 struct gl_attrib_node
*head
;
1311 GET_CURRENT_CONTEXT(ctx
);
1312 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1314 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1315 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1319 /* Build linked list of attribute nodes which save all attribute
1320 * groups specified by the mask.
1324 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1325 struct gl_pixelstore_attrib
*attr
;
1326 /* packing attribs */
1327 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1328 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1329 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1330 newnode
->data
= attr
;
1331 newnode
->next
= head
;
1333 /* unpacking attribs */
1334 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1335 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1336 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1337 newnode
->data
= attr
;
1338 newnode
->next
= head
;
1342 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1343 struct gl_array_attrib
*attr
;
1344 struct gl_array_object
*obj
;
1346 attr
= MALLOC_STRUCT( gl_array_attrib
);
1347 obj
= MALLOC_STRUCT( gl_array_object
);
1349 #if FEATURE_ARB_vertex_buffer_object
1350 /* increment ref counts since we're copying pointers to these objects */
1351 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1352 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1355 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1356 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1358 attr
->ArrayObj
= obj
;
1360 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1361 newnode
->data
= attr
;
1362 newnode
->next
= head
;
1364 /* bump reference counts on buffer objects */
1365 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1368 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1369 ctx
->ClientAttribStackDepth
++;
1376 _mesa_PopClientAttrib(void)
1378 struct gl_attrib_node
*node
, *next
;
1380 GET_CURRENT_CONTEXT(ctx
);
1381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1383 if (ctx
->ClientAttribStackDepth
== 0) {
1384 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1388 ctx
->ClientAttribStackDepth
--;
1389 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1392 switch (node
->kind
) {
1393 case GL_CLIENT_PACK_BIT
:
1395 struct gl_pixelstore_attrib
*store
=
1396 (struct gl_pixelstore_attrib
*) node
->data
;
1397 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1398 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1400 ctx
->NewState
|= _NEW_PACKUNPACK
;
1402 case GL_CLIENT_UNPACK_BIT
:
1404 struct gl_pixelstore_attrib
*store
=
1405 (struct gl_pixelstore_attrib
*) node
->data
;
1406 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1407 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1409 ctx
->NewState
|= _NEW_PACKUNPACK
;
1411 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1412 struct gl_array_attrib
* data
=
1413 (struct gl_array_attrib
*) node
->data
;
1415 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1417 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1418 if (data
->LockCount
!= 0)
1419 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1420 else if (ctx
->Array
.LockCount
)
1421 _mesa_UnlockArraysEXT();
1423 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1425 #if FEATURE_ARB_vertex_buffer_object
1426 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1427 data
->ArrayBufferObj
->Name
);
1428 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1429 data
->ElementArrayBufferObj
->Name
);
1432 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1433 sizeof( struct gl_array_object
) );
1435 FREE( data
->ArrayObj
);
1437 /* FIXME: Should some bits in ctx->Array->NewState also be set
1438 * FIXME: here? It seems like it should be set to inclusive-or
1439 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1442 ctx
->NewState
|= _NEW_ARRAY
;
1446 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1459 * Free any attribute state data that might be attached to the context.
1462 _mesa_free_attrib_data(GLcontext
*ctx
)
1464 while (ctx
->AttribStackDepth
> 0) {
1465 struct gl_attrib_node
*attr
, *next
;
1467 ctx
->AttribStackDepth
--;
1468 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1471 if (attr
->kind
== GL_TEXTURE_BIT
) {
1472 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1474 /* clear references to the saved texture objects */
1475 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1476 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1477 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1482 /* any other chunks of state that requires special handling? */
1486 _mesa_free(attr
->data
);
1494 void _mesa_init_attrib( GLcontext
*ctx
)
1496 /* Renderer and client attribute stacks */
1497 ctx
->AttribStackDepth
= 0;
1498 ctx
->ClientAttribStackDepth
= 0;