2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "bufferobj.h"
46 #include "simple_list.h"
51 #include "math/m_xform.h"
55 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
59 struct gl_texture_attrib Texture
; /**< The usual context state */
61 /** to save per texture object state (wrap modes, filters, etc): */
62 struct gl_texture_object Saved1D
[MAX_TEXTURE_UNITS
];
63 struct gl_texture_object Saved2D
[MAX_TEXTURE_UNITS
];
64 struct gl_texture_object Saved3D
[MAX_TEXTURE_UNITS
];
65 struct gl_texture_object SavedCube
[MAX_TEXTURE_UNITS
];
66 struct gl_texture_object SavedRect
[MAX_TEXTURE_UNITS
];
67 struct gl_texture_object Saved1DArray
[MAX_TEXTURE_UNITS
];
68 struct gl_texture_object Saved2DArray
[MAX_TEXTURE_UNITS
];
71 * To save references to texture objects (so they don't get accidentally
72 * deleted while saved in the attribute stack).
74 struct gl_texture_object
*SavedRef1D
[MAX_TEXTURE_UNITS
];
75 struct gl_texture_object
*SavedRef2D
[MAX_TEXTURE_UNITS
];
76 struct gl_texture_object
*SavedRef3D
[MAX_TEXTURE_UNITS
];
77 struct gl_texture_object
*SavedRefCube
[MAX_TEXTURE_UNITS
];
78 struct gl_texture_object
*SavedRefRect
[MAX_TEXTURE_UNITS
];
79 struct gl_texture_object
*SavedRef1DArray
[MAX_TEXTURE_UNITS
];
80 struct gl_texture_object
*SavedRef2DArray
[MAX_TEXTURE_UNITS
];
85 * Allocate a new attribute state node. These nodes have a
86 * "kind" value and a pointer to a struct of state data.
88 static struct gl_attrib_node
*
89 new_attrib_node( GLbitfield kind
)
91 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
100 _mesa_PushAttrib(GLbitfield mask
)
102 struct gl_attrib_node
*newnode
;
103 struct gl_attrib_node
*head
;
105 GET_CURRENT_CONTEXT(ctx
);
106 ASSERT_OUTSIDE_BEGIN_END(ctx
);
108 if (MESA_VERBOSE
& VERBOSE_API
)
109 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
111 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
112 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
116 /* Build linked list of attribute nodes which save all attribute */
117 /* groups specified by the mask. */
120 if (mask
& GL_ACCUM_BUFFER_BIT
) {
121 struct gl_accum_attrib
*attr
;
122 attr
= MALLOC_STRUCT( gl_accum_attrib
);
123 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
124 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
125 newnode
->data
= attr
;
126 newnode
->next
= head
;
130 if (mask
& GL_COLOR_BUFFER_BIT
) {
132 struct gl_colorbuffer_attrib
*attr
;
133 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
134 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
135 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
136 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
137 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
138 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
139 newnode
->data
= attr
;
140 newnode
->next
= head
;
144 if (mask
& GL_CURRENT_BIT
) {
145 struct gl_current_attrib
*attr
;
146 FLUSH_CURRENT( ctx
, 0 );
147 attr
= MALLOC_STRUCT( gl_current_attrib
);
148 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
149 newnode
= new_attrib_node( GL_CURRENT_BIT
);
150 newnode
->data
= attr
;
151 newnode
->next
= head
;
155 if (mask
& GL_DEPTH_BUFFER_BIT
) {
156 struct gl_depthbuffer_attrib
*attr
;
157 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
158 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
159 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
160 newnode
->data
= attr
;
161 newnode
->next
= head
;
165 if (mask
& GL_ENABLE_BIT
) {
166 struct gl_enable_attrib
*attr
;
168 attr
= MALLOC_STRUCT( gl_enable_attrib
);
169 /* Copy enable flags from all other attributes into the enable struct. */
170 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
171 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
172 attr
->Blend
= ctx
->Color
.BlendEnabled
;
173 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
174 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
175 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
176 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
178 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
179 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
180 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
181 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
182 attr
->DepthTest
= ctx
->Depth
.Test
;
183 attr
->Dither
= ctx
->Color
.DitherFlag
;
184 attr
->Fog
= ctx
->Fog
.Enabled
;
185 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
186 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
188 attr
->Lighting
= ctx
->Light
.Enabled
;
189 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
190 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
191 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
192 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
193 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
194 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
195 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
196 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
197 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
198 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
199 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
200 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
201 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
202 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
203 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
204 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
205 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
206 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
207 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
208 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
209 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
210 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
211 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
212 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
213 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
214 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
215 attr
->Normalize
= ctx
->Transform
.Normalize
;
216 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
217 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
218 attr
->PointSprite
= ctx
->Point
.PointSprite
;
219 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
220 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
221 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
222 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
223 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
224 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
225 attr
->Scissor
= ctx
->Scissor
.Enabled
;
226 attr
->Stencil
= ctx
->Stencil
.Enabled
;
227 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
228 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
229 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
230 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
231 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
232 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
233 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
234 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
235 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
236 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
238 /* GL_NV_vertex_program */
239 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
240 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
241 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
242 newnode
= new_attrib_node( GL_ENABLE_BIT
);
243 newnode
->data
= attr
;
244 newnode
->next
= head
;
248 if (mask
& GL_EVAL_BIT
) {
249 struct gl_eval_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_eval_attrib
);
251 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
252 newnode
= new_attrib_node( GL_EVAL_BIT
);
253 newnode
->data
= attr
;
254 newnode
->next
= head
;
258 if (mask
& GL_FOG_BIT
) {
259 struct gl_fog_attrib
*attr
;
260 attr
= MALLOC_STRUCT( gl_fog_attrib
);
261 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
262 newnode
= new_attrib_node( GL_FOG_BIT
);
263 newnode
->data
= attr
;
264 newnode
->next
= head
;
268 if (mask
& GL_HINT_BIT
) {
269 struct gl_hint_attrib
*attr
;
270 attr
= MALLOC_STRUCT( gl_hint_attrib
);
271 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
272 newnode
= new_attrib_node( GL_HINT_BIT
);
273 newnode
->data
= attr
;
274 newnode
->next
= head
;
278 if (mask
& GL_LIGHTING_BIT
) {
279 struct gl_light_attrib
*attr
;
280 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
281 attr
= MALLOC_STRUCT( gl_light_attrib
);
282 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
283 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
284 newnode
->data
= attr
;
285 newnode
->next
= head
;
289 if (mask
& GL_LINE_BIT
) {
290 struct gl_line_attrib
*attr
;
291 attr
= MALLOC_STRUCT( gl_line_attrib
);
292 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
293 newnode
= new_attrib_node( GL_LINE_BIT
);
294 newnode
->data
= attr
;
295 newnode
->next
= head
;
299 if (mask
& GL_LIST_BIT
) {
300 struct gl_list_attrib
*attr
;
301 attr
= MALLOC_STRUCT( gl_list_attrib
);
302 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
303 newnode
= new_attrib_node( GL_LIST_BIT
);
304 newnode
->data
= attr
;
305 newnode
->next
= head
;
309 if (mask
& GL_PIXEL_MODE_BIT
) {
310 struct gl_pixel_attrib
*attr
;
311 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
312 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
313 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
314 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
315 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
316 newnode
->data
= attr
;
317 newnode
->next
= head
;
321 if (mask
& GL_POINT_BIT
) {
322 struct gl_point_attrib
*attr
;
323 attr
= MALLOC_STRUCT( gl_point_attrib
);
324 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
325 newnode
= new_attrib_node( GL_POINT_BIT
);
326 newnode
->data
= attr
;
327 newnode
->next
= head
;
331 if (mask
& GL_POLYGON_BIT
) {
332 struct gl_polygon_attrib
*attr
;
333 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
334 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
335 newnode
= new_attrib_node( GL_POLYGON_BIT
);
336 newnode
->data
= attr
;
337 newnode
->next
= head
;
341 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
343 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
344 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
345 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
346 newnode
->data
= stipple
;
347 newnode
->next
= head
;
351 if (mask
& GL_SCISSOR_BIT
) {
352 struct gl_scissor_attrib
*attr
;
353 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
354 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
355 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
356 newnode
->data
= attr
;
357 newnode
->next
= head
;
361 if (mask
& GL_STENCIL_BUFFER_BIT
) {
362 struct gl_stencil_attrib
*attr
;
363 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
364 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
365 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
366 newnode
->data
= attr
;
367 newnode
->next
= head
;
371 if (mask
& GL_TEXTURE_BIT
) {
372 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
376 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
380 _mesa_lock_context_textures(ctx
);
382 /* copy/save the bulk of texture state here */
383 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
385 /* Save references to the currently bound texture objects so they don't
386 * accidentally get deleted while referenced in the attribute stack.
388 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
389 _mesa_reference_texobj(&texstate
->SavedRef1D
[u
], ctx
->Texture
.Unit
[u
].Current1D
);
390 _mesa_reference_texobj(&texstate
->SavedRef2D
[u
], ctx
->Texture
.Unit
[u
].Current2D
);
391 _mesa_reference_texobj(&texstate
->SavedRef3D
[u
], ctx
->Texture
.Unit
[u
].Current3D
);
392 _mesa_reference_texobj(&texstate
->SavedRefCube
[u
], ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
393 _mesa_reference_texobj(&texstate
->SavedRefRect
[u
], ctx
->Texture
.Unit
[u
].CurrentRect
);
394 _mesa_reference_texobj(&texstate
->SavedRef1DArray
[u
], ctx
->Texture
.Unit
[u
].Current1DArray
);
395 _mesa_reference_texobj(&texstate
->SavedRef2DArray
[u
], ctx
->Texture
.Unit
[u
].Current2DArray
);
398 /* copy state/contents of the currently bound texture objects */
399 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
400 _mesa_copy_texture_object(&texstate
->Saved1D
[u
],
401 ctx
->Texture
.Unit
[u
].Current1D
);
402 _mesa_copy_texture_object(&texstate
->Saved2D
[u
],
403 ctx
->Texture
.Unit
[u
].Current2D
);
404 _mesa_copy_texture_object(&texstate
->Saved3D
[u
],
405 ctx
->Texture
.Unit
[u
].Current3D
);
406 _mesa_copy_texture_object(&texstate
->SavedCube
[u
],
407 ctx
->Texture
.Unit
[u
].CurrentCubeMap
);
408 _mesa_copy_texture_object(&texstate
->SavedRect
[u
],
409 ctx
->Texture
.Unit
[u
].CurrentRect
);
410 _mesa_copy_texture_object(&texstate
->Saved1DArray
[u
],
411 ctx
->Texture
.Unit
[u
].Current1DArray
);
412 _mesa_copy_texture_object(&texstate
->Saved2DArray
[u
],
413 ctx
->Texture
.Unit
[u
].Current2DArray
);
416 _mesa_unlock_context_textures(ctx
);
418 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
419 newnode
->data
= texstate
;
420 newnode
->next
= head
;
424 if (mask
& GL_TRANSFORM_BIT
) {
425 struct gl_transform_attrib
*attr
;
426 attr
= MALLOC_STRUCT( gl_transform_attrib
);
427 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
428 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
429 newnode
->data
= attr
;
430 newnode
->next
= head
;
434 if (mask
& GL_VIEWPORT_BIT
) {
435 struct gl_viewport_attrib
*attr
;
436 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
437 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
438 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
439 newnode
->data
= attr
;
440 newnode
->next
= head
;
444 /* GL_ARB_multisample */
445 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
446 struct gl_multisample_attrib
*attr
;
447 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
448 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
449 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
450 newnode
->data
= attr
;
451 newnode
->next
= head
;
456 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
457 ctx
->AttribStackDepth
++;
463 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
467 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
468 if ((VALUE) != (NEWVALUE)) { \
469 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
472 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
473 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
475 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
476 const GLuint mask
= 1 << i
;
477 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
478 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
479 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
482 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
484 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
485 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
487 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
488 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
489 GL_POST_CONVOLUTION_COLOR_TABLE
);
490 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
491 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
492 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
493 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
494 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
495 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
496 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
498 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
500 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
502 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
503 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
504 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
505 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
507 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
509 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
512 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
513 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
515 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
516 GL_MAP1_TEXTURE_COORD_1
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
518 GL_MAP1_TEXTURE_COORD_2
);
519 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
520 GL_MAP1_TEXTURE_COORD_3
);
521 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
522 GL_MAP1_TEXTURE_COORD_4
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
525 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
527 for (i
= 0; i
< 16; i
++) {
528 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
529 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
532 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
533 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
534 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
535 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
536 GL_MAP2_TEXTURE_COORD_1
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
538 GL_MAP2_TEXTURE_COORD_2
);
539 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
540 GL_MAP2_TEXTURE_COORD_3
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
542 GL_MAP2_TEXTURE_COORD_4
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
545 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
547 for (i
= 0; i
< 16; i
++) {
548 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
549 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
552 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
553 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
554 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
555 GL_RESCALE_NORMAL_EXT
);
556 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
557 enable
->RasterPositionUnclipped
,
558 GL_RASTER_POSITION_UNCLIPPED_IBM
);
559 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
561 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
562 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
565 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
566 GL_POLYGON_OFFSET_POINT
);
567 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
568 GL_POLYGON_OFFSET_LINE
);
569 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
570 GL_POLYGON_OFFSET_FILL
);
571 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
573 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
575 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
576 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
577 if (ctx
->Extensions
.EXT_stencil_two_side
) {
578 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
580 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
582 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
583 enable
->SampleAlphaToCoverage
,
584 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
585 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
586 enable
->SampleAlphaToOne
,
587 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
588 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
589 enable
->SampleCoverage
,
590 GL_SAMPLE_COVERAGE_ARB
);
591 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
592 enable
->SampleCoverageInvert
,
593 GL_SAMPLE_COVERAGE_INVERT_ARB
);
594 /* GL_ARB_vertex_program, GL_NV_vertex_program */
595 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
596 enable
->VertexProgram
,
597 GL_VERTEX_PROGRAM_ARB
);
598 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
599 enable
->VertexProgramPointSize
,
600 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
601 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
602 enable
->VertexProgramTwoSide
,
603 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
605 #undef TEST_AND_UPDATE
607 /* texture unit enables */
608 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
609 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
610 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
611 if (ctx
->Driver
.Enable
) {
612 if (ctx
->Driver
.ActiveTexture
) {
613 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
615 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
616 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
617 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
618 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
619 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
620 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
621 if (ctx
->Extensions
.ARB_texture_cube_map
)
622 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
623 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
624 if (ctx
->Extensions
.NV_texture_rectangle
)
625 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
626 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
630 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
631 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
632 if (ctx
->Driver
.Enable
) {
633 if (ctx
->Driver
.ActiveTexture
) {
634 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
636 if (enable
->TexGen
[i
] & S_BIT
)
637 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
639 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
640 if (enable
->TexGen
[i
] & T_BIT
)
641 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
643 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
644 if (enable
->TexGen
[i
] & R_BIT
)
645 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
647 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
648 if (enable
->TexGen
[i
] & Q_BIT
)
649 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
651 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
655 /* GL_SGI_texture_color_table */
656 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
659 if (ctx
->Driver
.ActiveTexture
) {
660 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
666 * Pop/restore texture attribute/group state.
669 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
673 _mesa_lock_context_textures(ctx
);
675 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
676 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
679 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
680 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
681 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
682 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
683 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
684 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
685 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
686 if (ctx
->Extensions
.ARB_texture_cube_map
) {
687 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
688 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
690 if (ctx
->Extensions
.NV_texture_rectangle
) {
691 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
692 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
694 if (ctx
->Extensions
.SGI_texture_color_table
) {
695 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
696 unit
->ColorTableEnabled
);
698 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
699 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
700 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenModeS
);
701 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenModeT
);
702 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenModeR
);
703 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenModeQ
);
704 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->ObjectPlaneS
);
705 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->ObjectPlaneT
);
706 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->ObjectPlaneR
);
707 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->ObjectPlaneQ
);
708 /* Eye plane done differently to avoid re-transformation */
710 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
711 COPY_4FV(destUnit
->EyePlaneS
, unit
->EyePlaneS
);
712 COPY_4FV(destUnit
->EyePlaneT
, unit
->EyePlaneT
);
713 COPY_4FV(destUnit
->EyePlaneR
, unit
->EyePlaneR
);
714 COPY_4FV(destUnit
->EyePlaneQ
, unit
->EyePlaneQ
);
715 if (ctx
->Driver
.TexGen
) {
716 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->EyePlaneS
);
717 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->EyePlaneT
);
718 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->EyePlaneR
);
719 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->EyePlaneQ
);
722 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
723 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
724 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
725 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
726 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
727 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
728 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
729 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
730 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
731 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
732 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
734 if (ctx
->Extensions
.EXT_texture_env_combine
||
735 ctx
->Extensions
.ARB_texture_env_combine
) {
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
737 unit
->Combine
.ModeRGB
);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
739 unit
->Combine
.ModeA
);
740 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
741 unit
->Combine
.SourceRGB
[0]);
742 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
743 unit
->Combine
.SourceRGB
[1]);
744 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
745 unit
->Combine
.SourceRGB
[2]);
746 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
747 unit
->Combine
.SourceA
[0]);
748 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
749 unit
->Combine
.SourceA
[1]);
750 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
751 unit
->Combine
.SourceA
[2]);
752 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
753 unit
->Combine
.OperandRGB
[0]);
754 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
755 unit
->Combine
.OperandRGB
[1]);
756 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
757 unit
->Combine
.OperandRGB
[2]);
758 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
759 unit
->Combine
.OperandA
[0]);
760 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
761 unit
->Combine
.OperandA
[1]);
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
763 unit
->Combine
.OperandA
[2]);
764 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
765 1 << unit
->Combine
.ScaleShiftRGB
);
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
767 1 << unit
->Combine
.ScaleShiftA
);
770 /* Restore texture object state for each target */
771 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
772 const struct gl_texture_object
*obj
= NULL
;
773 GLfloat bordColor
[4];
777 case TEXTURE_1D_INDEX
:
778 obj
= &texstate
->Saved1D
[u
];
779 ASSERT(obj
->Target
== GL_TEXTURE_1D
);
781 case TEXTURE_2D_INDEX
:
782 obj
= &texstate
->Saved2D
[u
];
783 ASSERT(obj
->Target
== GL_TEXTURE_2D
);
785 case TEXTURE_3D_INDEX
:
786 obj
= &texstate
->Saved3D
[u
];
787 ASSERT(obj
->Target
== GL_TEXTURE_3D
);
789 case TEXTURE_CUBE_INDEX
:
790 if (!ctx
->Extensions
.ARB_texture_cube_map
)
792 obj
= &texstate
->SavedCube
[u
];
793 ASSERT(obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
);
795 case TEXTURE_RECT_INDEX
:
796 if (!ctx
->Extensions
.NV_texture_rectangle
)
798 obj
= &texstate
->SavedRect
[u
];
799 ASSERT(obj
->Target
== GL_TEXTURE_RECTANGLE_NV
);
801 case TEXTURE_1D_ARRAY_INDEX
:
802 if (!ctx
->Extensions
.MESA_texture_array
)
804 obj
= &texstate
->Saved1DArray
[u
];
805 ASSERT(obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
);
807 case TEXTURE_2D_ARRAY_INDEX
:
808 if (!ctx
->Extensions
.MESA_texture_array
)
810 obj
= &texstate
->Saved2DArray
[u
];
811 ASSERT(obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
);
814 _mesa_problem(ctx
, "bad texture index in pop_texture_group");
818 target
= obj
->Target
;
820 _mesa_BindTexture(target
, obj
->Name
);
822 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
823 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
824 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
825 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
827 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
828 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
829 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
831 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
832 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
833 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
834 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
835 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
836 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
837 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
838 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
839 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
840 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
841 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
844 if (ctx
->Extensions
.SGIX_shadow
) {
845 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_SGIX
,
847 _mesa_TexParameteri(target
, GL_TEXTURE_COMPARE_OPERATOR_SGIX
,
848 obj
->CompareOperator
);
850 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
851 _mesa_TexParameterf(target
, GL_SHADOW_AMBIENT_SGIX
,
856 /* remove saved references to the texture objects */
857 _mesa_reference_texobj(&texstate
->SavedRef1D
[u
], NULL
);
858 _mesa_reference_texobj(&texstate
->SavedRef2D
[u
], NULL
);
859 _mesa_reference_texobj(&texstate
->SavedRef3D
[u
], NULL
);
860 _mesa_reference_texobj(&texstate
->SavedRefCube
[u
], NULL
);
861 _mesa_reference_texobj(&texstate
->SavedRefRect
[u
], NULL
);
862 _mesa_reference_texobj(&texstate
->SavedRef1DArray
[u
], NULL
);
863 _mesa_reference_texobj(&texstate
->SavedRef2DArray
[u
], NULL
);
866 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
868 _mesa_unlock_context_textures(ctx
);
873 * This function is kind of long just because we have to call a lot
874 * of device driver functions to update device driver state.
876 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
877 * in order to restore GL state. This isn't terribly efficient but it
878 * ensures that dirty flags and any derived state gets updated correctly.
879 * We could at least check if the value to restore equals the current value
880 * and then skip the Mesa call.
883 _mesa_PopAttrib(void)
885 struct gl_attrib_node
*attr
, *next
;
886 GET_CURRENT_CONTEXT(ctx
);
887 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
889 if (ctx
->AttribStackDepth
== 0) {
890 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
894 ctx
->AttribStackDepth
--;
895 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
899 if (MESA_VERBOSE
& VERBOSE_API
) {
900 _mesa_debug(ctx
, "glPopAttrib %s\n",
901 _mesa_lookup_enum_by_nr(attr
->kind
));
904 switch (attr
->kind
) {
905 case GL_ACCUM_BUFFER_BIT
:
907 const struct gl_accum_attrib
*accum
;
908 accum
= (const struct gl_accum_attrib
*) attr
->data
;
909 _mesa_ClearAccum(accum
->ClearColor
[0],
910 accum
->ClearColor
[1],
911 accum
->ClearColor
[2],
912 accum
->ClearColor
[3]);
915 case GL_COLOR_BUFFER_BIT
:
917 const struct gl_colorbuffer_attrib
*color
;
918 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
919 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
920 _mesa_ClearColor(color
->ClearColor
[0],
921 color
->ClearColor
[1],
922 color
->ClearColor
[2],
923 color
->ClearColor
[3]);
924 _mesa_IndexMask(color
->IndexMask
);
925 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
926 (GLboolean
) (color
->ColorMask
[1] != 0),
927 (GLboolean
) (color
->ColorMask
[2] != 0),
928 (GLboolean
) (color
->ColorMask
[3] != 0));
930 /* Need to determine if more than one color output is
931 * specified. If so, call glDrawBuffersARB, else call
932 * glDrawBuffer(). This is a subtle, but essential point
933 * since GL_FRONT (for example) is illegal for the former
934 * function, but legal for the later.
936 GLboolean multipleBuffers
= GL_FALSE
;
937 if (ctx
->Extensions
.ARB_draw_buffers
) {
939 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
940 if (color
->DrawBuffer
[i
] != GL_NONE
) {
941 multipleBuffers
= GL_TRUE
;
946 /* Call the API_level functions, not _mesa_drawbuffers()
947 * since we need to do error checking on the pop'd
949 * Ex: if GL_FRONT were pushed, but we're popping with a
950 * user FBO bound, GL_FRONT will be illegal and we'll need
951 * to record that error. Per OpenGL ARB decision.
954 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
957 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
959 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
960 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
961 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
962 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
966 /* This special case is because glBlendEquationSeparateEXT
967 * cannot take GL_LOGIC_OP as a parameter.
969 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
970 _mesa_BlendEquation(color
->BlendEquationRGB
);
973 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
974 color
->BlendEquationA
);
976 _mesa_BlendColor(color
->BlendColor
[0],
977 color
->BlendColor
[1],
978 color
->BlendColor
[2],
979 color
->BlendColor
[3]);
980 _mesa_LogicOp(color
->LogicOp
);
981 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
982 color
->ColorLogicOpEnabled
);
983 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
984 color
->IndexLogicOpEnabled
);
985 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
989 FLUSH_CURRENT( ctx
, 0 );
990 MEMCPY( &ctx
->Current
, attr
->data
,
991 sizeof(struct gl_current_attrib
) );
993 case GL_DEPTH_BUFFER_BIT
:
995 const struct gl_depthbuffer_attrib
*depth
;
996 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
997 _mesa_DepthFunc(depth
->Func
);
998 _mesa_ClearDepth(depth
->Clear
);
999 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1000 _mesa_DepthMask(depth
->Mask
);
1005 const struct gl_enable_attrib
*enable
;
1006 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1007 pop_enable_group(ctx
, enable
);
1008 ctx
->NewState
|= _NEW_ALL
;
1012 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1013 ctx
->NewState
|= _NEW_EVAL
;
1017 const struct gl_fog_attrib
*fog
;
1018 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1019 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1020 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1021 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1022 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1023 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1024 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1025 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1030 const struct gl_hint_attrib
*hint
;
1031 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1032 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1033 hint
->PerspectiveCorrection
);
1034 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1035 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1036 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1037 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1038 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1039 hint
->ClipVolumeClipping
);
1040 if (ctx
->Extensions
.ARB_texture_compression
)
1041 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1042 hint
->TextureCompression
);
1045 case GL_LIGHTING_BIT
:
1048 const struct gl_light_attrib
*light
;
1049 light
= (const struct gl_light_attrib
*) attr
->data
;
1050 /* lighting enable */
1051 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1052 /* per-light state */
1053 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1054 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1056 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1057 const struct gl_light
*l
= &light
->Light
[i
];
1058 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1059 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1060 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1061 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1062 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1063 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->EyeDirection
);
1064 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1065 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1066 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1067 &l
->ConstantAttenuation
);
1068 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1069 &l
->LinearAttenuation
);
1070 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1071 &l
->QuadraticAttenuation
);
1074 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1075 light
->Model
.Ambient
);
1076 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1077 (GLfloat
) light
->Model
.LocalViewer
);
1078 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1079 (GLfloat
) light
->Model
.TwoSide
);
1080 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1081 (GLfloat
) light
->Model
.ColorControl
);
1083 _mesa_ShadeModel(light
->ShadeModel
);
1084 /* color material */
1085 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1086 light
->ColorMaterialMode
);
1087 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1088 light
->ColorMaterialEnabled
);
1090 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1091 sizeof(struct gl_material
));
1096 const struct gl_line_attrib
*line
;
1097 line
= (const struct gl_line_attrib
*) attr
->data
;
1098 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1099 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1100 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1101 _mesa_LineWidth(line
->Width
);
1105 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1107 case GL_PIXEL_MODE_BIT
:
1108 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1109 /* XXX what other pixel state needs to be set by function calls? */
1110 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1111 ctx
->NewState
|= _NEW_PIXEL
;
1115 const struct gl_point_attrib
*point
;
1116 point
= (const struct gl_point_attrib
*) attr
->data
;
1117 _mesa_PointSize(point
->Size
);
1118 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1119 if (ctx
->Extensions
.EXT_point_parameters
) {
1120 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT
,
1122 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT
,
1124 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT
,
1126 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1129 if (ctx
->Extensions
.NV_point_sprite
1130 || ctx
->Extensions
.ARB_point_sprite
) {
1132 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1133 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1134 (GLint
) point
->CoordReplace
[u
]);
1136 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1137 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV
,
1138 ctx
->Point
.SpriteRMode
);
1139 _mesa_PointParameterfEXT(GL_POINT_SPRITE_COORD_ORIGIN
,
1140 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1144 case GL_POLYGON_BIT
:
1146 const struct gl_polygon_attrib
*polygon
;
1147 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1148 _mesa_CullFace(polygon
->CullFaceMode
);
1149 _mesa_FrontFace(polygon
->FrontFace
);
1150 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1151 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1152 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1153 polygon
->OffsetUnits
);
1154 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1155 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1156 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1157 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1158 polygon
->OffsetPoint
);
1159 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1160 polygon
->OffsetLine
);
1161 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1162 polygon
->OffsetFill
);
1165 case GL_POLYGON_STIPPLE_BIT
:
1166 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1167 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1168 if (ctx
->Driver
.PolygonStipple
)
1169 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1171 case GL_SCISSOR_BIT
:
1173 const struct gl_scissor_attrib
*scissor
;
1174 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1175 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1176 scissor
->Width
, scissor
->Height
);
1177 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1180 case GL_STENCIL_BUFFER_BIT
:
1182 const struct gl_stencil_attrib
*stencil
;
1183 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1184 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1185 _mesa_ClearStencil(stencil
->Clear
);
1186 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1187 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1188 stencil
->TestTwoSide
);
1189 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1190 ? GL_BACK
: GL_FRONT
);
1193 _mesa_StencilFuncSeparate(GL_FRONT
,
1194 stencil
->Function
[0],
1196 stencil
->ValueMask
[0]);
1197 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1198 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1199 stencil
->ZFailFunc
[0],
1200 stencil
->ZPassFunc
[0]);
1202 _mesa_StencilFuncSeparate(GL_BACK
,
1203 stencil
->Function
[1],
1205 stencil
->ValueMask
[1]);
1206 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1207 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1208 stencil
->ZFailFunc
[1],
1209 stencil
->ZPassFunc
[1]);
1212 case GL_TRANSFORM_BIT
:
1215 const struct gl_transform_attrib
*xform
;
1216 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1217 _mesa_MatrixMode(xform
->MatrixMode
);
1218 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1219 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1221 /* restore clip planes */
1222 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1223 const GLuint mask
= 1 << 1;
1224 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1225 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1226 if (xform
->ClipPlanesEnabled
& mask
) {
1227 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1230 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1232 if (ctx
->Driver
.ClipPlane
)
1233 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1236 /* normalize/rescale */
1237 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1238 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1239 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1240 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1241 ctx
->Transform
.RescaleNormals
);
1244 case GL_TEXTURE_BIT
:
1245 /* Take care of texture object reference counters */
1247 struct texture_state
*texstate
1248 = (struct texture_state
*) attr
->data
;
1249 pop_texture_group(ctx
, texstate
);
1250 ctx
->NewState
|= _NEW_TEXTURE
;
1253 case GL_VIEWPORT_BIT
:
1255 const struct gl_viewport_attrib
*vp
;
1256 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1257 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1258 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1261 case GL_MULTISAMPLE_BIT_ARB
:
1263 const struct gl_multisample_attrib
*ms
;
1264 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1265 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1266 ms
->SampleCoverageInvert
);
1271 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1284 * Helper for incrementing/decrementing vertex buffer object reference
1285 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1288 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1291 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1292 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1293 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1294 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1295 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1296 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1297 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1298 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1299 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1300 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1301 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1303 array
->ArrayBufferObj
->RefCount
+= step
;
1304 array
->ElementArrayBufferObj
->RefCount
+= step
;
1308 #define GL_CLIENT_PACK_BIT (1<<20)
1309 #define GL_CLIENT_UNPACK_BIT (1<<21)
1313 _mesa_PushClientAttrib(GLbitfield mask
)
1315 struct gl_attrib_node
*newnode
;
1316 struct gl_attrib_node
*head
;
1318 GET_CURRENT_CONTEXT(ctx
);
1319 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1321 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1322 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1326 /* Build linked list of attribute nodes which save all attribute */
1327 /* groups specified by the mask. */
1330 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1331 struct gl_pixelstore_attrib
*attr
;
1332 #if FEATURE_EXT_pixel_buffer_object
1333 ctx
->Pack
.BufferObj
->RefCount
++;
1334 ctx
->Unpack
.BufferObj
->RefCount
++;
1336 /* packing attribs */
1337 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1338 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
1339 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1340 newnode
->data
= attr
;
1341 newnode
->next
= head
;
1343 /* unpacking attribs */
1344 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
1345 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
1346 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1347 newnode
->data
= attr
;
1348 newnode
->next
= head
;
1351 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1352 struct gl_array_attrib
*attr
;
1353 struct gl_array_object
*obj
;
1355 attr
= MALLOC_STRUCT( gl_array_attrib
);
1356 obj
= MALLOC_STRUCT( gl_array_object
);
1358 #if FEATURE_ARB_vertex_buffer_object
1359 /* increment ref counts since we're copying pointers to these objects */
1360 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1361 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1364 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1365 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1367 attr
->ArrayObj
= obj
;
1369 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1370 newnode
->data
= attr
;
1371 newnode
->next
= head
;
1373 /* bump reference counts on buffer objects */
1374 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1377 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1378 ctx
->ClientAttribStackDepth
++;
1385 _mesa_PopClientAttrib(void)
1387 struct gl_attrib_node
*attr
, *next
;
1389 GET_CURRENT_CONTEXT(ctx
);
1390 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1392 if (ctx
->ClientAttribStackDepth
== 0) {
1393 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1397 ctx
->ClientAttribStackDepth
--;
1398 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1401 switch (attr
->kind
) {
1402 case GL_CLIENT_PACK_BIT
:
1403 #if FEATURE_EXT_pixel_buffer_object
1404 ctx
->Pack
.BufferObj
->RefCount
--;
1405 if (ctx
->Pack
.BufferObj
->RefCount
<= 0) {
1406 _mesa_remove_buffer_object( ctx
, ctx
->Pack
.BufferObj
);
1407 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Pack
.BufferObj
);
1410 MEMCPY( &ctx
->Pack
, attr
->data
,
1411 sizeof(struct gl_pixelstore_attrib
) );
1412 ctx
->NewState
|= _NEW_PACKUNPACK
;
1414 case GL_CLIENT_UNPACK_BIT
:
1415 #if FEATURE_EXT_pixel_buffer_object
1416 ctx
->Unpack
.BufferObj
->RefCount
--;
1417 if (ctx
->Unpack
.BufferObj
->RefCount
<= 0) {
1418 _mesa_remove_buffer_object( ctx
, ctx
->Unpack
.BufferObj
);
1419 (*ctx
->Driver
.DeleteBuffer
)( ctx
, ctx
->Unpack
.BufferObj
);
1422 MEMCPY( &ctx
->Unpack
, attr
->data
,
1423 sizeof(struct gl_pixelstore_attrib
) );
1424 ctx
->NewState
|= _NEW_PACKUNPACK
;
1426 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1427 struct gl_array_attrib
* data
=
1428 (struct gl_array_attrib
*) attr
->data
;
1430 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1432 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1433 ctx
->Array
.LockFirst
= data
->LockFirst
;
1434 ctx
->Array
.LockCount
= data
->LockCount
;
1436 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1438 #if FEATURE_ARB_vertex_buffer_object
1439 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1440 data
->ArrayBufferObj
->Name
);
1441 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1442 data
->ElementArrayBufferObj
->Name
);
1445 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1446 sizeof( struct gl_array_object
) );
1448 FREE( data
->ArrayObj
);
1450 /* FIXME: Should some bits in ctx->Array->NewState also be set
1451 * FIXME: here? It seems like it should be set to inclusive-or
1452 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1455 ctx
->NewState
|= _NEW_ARRAY
;
1459 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1472 * Free any attribute state data that might be attached to the context.
1475 _mesa_free_attrib_data(GLcontext
*ctx
)
1477 while (ctx
->AttribStackDepth
> 0) {
1478 struct gl_attrib_node
*attr
, *next
;
1480 ctx
->AttribStackDepth
--;
1481 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1484 if (attr
->kind
== GL_TEXTURE_BIT
) {
1485 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1487 /* clear references to the saved texture objects */
1488 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1489 _mesa_reference_texobj(&texstate
->SavedRef1D
[u
], NULL
);
1490 _mesa_reference_texobj(&texstate
->SavedRef2D
[u
], NULL
);
1491 _mesa_reference_texobj(&texstate
->SavedRef3D
[u
], NULL
);
1492 _mesa_reference_texobj(&texstate
->SavedRefCube
[u
], NULL
);
1493 _mesa_reference_texobj(&texstate
->SavedRefRect
[u
], NULL
);
1494 _mesa_reference_texobj(&texstate
->SavedRef1DArray
[u
], NULL
);
1495 _mesa_reference_texobj(&texstate
->SavedRef2DArray
[u
], NULL
);
1499 /* any other chunks of state that requires special handling? */
1503 _mesa_free(attr
->data
);
1511 void _mesa_init_attrib( GLcontext
*ctx
)
1513 /* Renderer and client attribute stacks */
1514 ctx
->AttribStackDepth
= 0;
1515 ctx
->ClientAttribStackDepth
= 0;