2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
46 #include "multisample.h"
50 #include "simple_list.h"
60 #include "glapi/dispatch.h"
64 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
66 struct gl_enable_attrib
71 GLbitfield ClipPlanes
;
72 GLboolean ColorMaterial
;
73 GLboolean ColorTable
[COLORTABLE_MAX
];
74 GLboolean Convolution1D
;
75 GLboolean Convolution2D
;
76 GLboolean Separable2D
;
83 GLboolean Light
[MAX_LIGHTS
];
86 GLboolean LineStipple
;
87 GLboolean IndexLogicOp
;
88 GLboolean ColorLogicOp
;
93 GLboolean Map1TextureCoord1
;
94 GLboolean Map1TextureCoord2
;
95 GLboolean Map1TextureCoord3
;
96 GLboolean Map1TextureCoord4
;
97 GLboolean Map1Vertex3
;
98 GLboolean Map1Vertex4
;
99 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2Color4
;
102 GLboolean Map2Normal
;
103 GLboolean Map2TextureCoord1
;
104 GLboolean Map2TextureCoord2
;
105 GLboolean Map2TextureCoord3
;
106 GLboolean Map2TextureCoord4
;
107 GLboolean Map2Vertex3
;
108 GLboolean Map2Vertex4
;
109 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
113 GLboolean PixelTexture
;
114 GLboolean PointSmooth
;
115 GLboolean PolygonOffsetPoint
;
116 GLboolean PolygonOffsetLine
;
117 GLboolean PolygonOffsetFill
;
118 GLboolean PolygonSmooth
;
119 GLboolean PolygonStipple
;
120 GLboolean RescaleNormals
;
123 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
124 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
125 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
126 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
127 GLboolean SampleCoverage
; /* GL_ARB_multisample */
128 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
129 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
131 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
132 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
134 /* SGI_texture_color_table */
135 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
137 /* GL_ARB_vertex_program / GL_NV_vertex_program */
138 GLboolean VertexProgram
;
139 GLboolean VertexProgramPointSize
;
140 GLboolean VertexProgramTwoSide
;
142 /* GL_ARB_point_sprite / GL_NV_point_sprite */
143 GLboolean PointSprite
;
144 GLboolean FragmentShaderATI
;
149 * Node for the attribute stack.
151 struct gl_attrib_node
155 struct gl_attrib_node
*next
;
161 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
165 struct gl_texture_attrib Texture
; /**< The usual context state */
167 /** to save per texture object state (wrap modes, filters, etc): */
168 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
171 * To save references to texture objects (so they don't get accidentally
172 * deleted while saved in the attribute stack).
174 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
178 #if FEATURE_attrib_stack
182 * Allocate new attribute node of given type/kind. Attach payload data.
183 * Insert it into the linked list named by 'head'.
186 save_attrib_data(struct gl_attrib_node
**head
,
187 GLbitfield kind
, void *payload
)
189 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
204 _mesa_PushAttrib(GLbitfield mask
)
206 struct gl_attrib_node
*head
;
208 GET_CURRENT_CONTEXT(ctx
);
209 ASSERT_OUTSIDE_BEGIN_END(ctx
);
211 if (MESA_VERBOSE
& VERBOSE_API
)
212 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
214 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
215 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
219 /* Build linked list of attribute nodes which save all attribute */
220 /* groups specified by the mask. */
223 if (mask
& GL_ACCUM_BUFFER_BIT
) {
224 struct gl_accum_attrib
*attr
;
225 attr
= MALLOC_STRUCT( gl_accum_attrib
);
226 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
227 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
230 if (mask
& GL_COLOR_BUFFER_BIT
) {
232 struct gl_colorbuffer_attrib
*attr
;
233 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
234 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
235 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
236 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
237 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
238 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
241 if (mask
& GL_CURRENT_BIT
) {
242 struct gl_current_attrib
*attr
;
243 FLUSH_CURRENT( ctx
, 0 );
244 attr
= MALLOC_STRUCT( gl_current_attrib
);
245 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
246 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
249 if (mask
& GL_DEPTH_BUFFER_BIT
) {
250 struct gl_depthbuffer_attrib
*attr
;
251 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
252 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
253 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
256 if (mask
& GL_ENABLE_BIT
) {
257 struct gl_enable_attrib
*attr
;
259 attr
= MALLOC_STRUCT( gl_enable_attrib
);
260 /* Copy enable flags from all other attributes into the enable struct. */
261 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
262 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
263 attr
->Blend
= ctx
->Color
.BlendEnabled
;
264 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
265 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
266 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
267 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
269 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
270 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
271 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
272 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
273 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
274 attr
->DepthTest
= ctx
->Depth
.Test
;
275 attr
->Dither
= ctx
->Color
.DitherFlag
;
276 attr
->Fog
= ctx
->Fog
.Enabled
;
277 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
278 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
280 attr
->Lighting
= ctx
->Light
.Enabled
;
281 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
282 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
283 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
284 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
285 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
286 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
287 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
288 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
289 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
290 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
291 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
292 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
293 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
294 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
295 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
296 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
297 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
298 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
299 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
300 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
301 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
302 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
303 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
304 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
305 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
306 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
307 attr
->Normalize
= ctx
->Transform
.Normalize
;
308 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
309 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
310 attr
->PointSprite
= ctx
->Point
.PointSprite
;
311 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
312 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
313 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
314 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
315 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
316 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
317 attr
->Scissor
= ctx
->Scissor
.Enabled
;
318 attr
->Stencil
= ctx
->Stencil
.Enabled
;
319 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
320 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
321 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
322 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
323 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
324 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
325 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
326 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
327 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
328 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
330 /* GL_NV_vertex_program */
331 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
332 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
333 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
334 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
337 if (mask
& GL_EVAL_BIT
) {
338 struct gl_eval_attrib
*attr
;
339 attr
= MALLOC_STRUCT( gl_eval_attrib
);
340 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
341 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
344 if (mask
& GL_FOG_BIT
) {
345 struct gl_fog_attrib
*attr
;
346 attr
= MALLOC_STRUCT( gl_fog_attrib
);
347 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
348 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
351 if (mask
& GL_HINT_BIT
) {
352 struct gl_hint_attrib
*attr
;
353 attr
= MALLOC_STRUCT( gl_hint_attrib
);
354 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
355 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
358 if (mask
& GL_LIGHTING_BIT
) {
359 struct gl_light_attrib
*attr
;
360 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
361 attr
= MALLOC_STRUCT( gl_light_attrib
);
362 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
363 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
366 if (mask
& GL_LINE_BIT
) {
367 struct gl_line_attrib
*attr
;
368 attr
= MALLOC_STRUCT( gl_line_attrib
);
369 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
370 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
373 if (mask
& GL_LIST_BIT
) {
374 struct gl_list_attrib
*attr
;
375 attr
= MALLOC_STRUCT( gl_list_attrib
);
376 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
377 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
380 if (mask
& GL_PIXEL_MODE_BIT
) {
381 struct gl_pixel_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
383 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
384 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
385 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
386 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
389 if (mask
& GL_POINT_BIT
) {
390 struct gl_point_attrib
*attr
;
391 attr
= MALLOC_STRUCT( gl_point_attrib
);
392 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
393 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
396 if (mask
& GL_POLYGON_BIT
) {
397 struct gl_polygon_attrib
*attr
;
398 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
399 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
400 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
403 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
405 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
406 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
407 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
410 if (mask
& GL_SCISSOR_BIT
) {
411 struct gl_scissor_attrib
*attr
;
412 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
413 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
414 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
417 if (mask
& GL_STENCIL_BUFFER_BIT
) {
418 struct gl_stencil_attrib
*attr
;
419 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
420 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
421 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
424 if (mask
& GL_TEXTURE_BIT
) {
425 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
429 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
433 _mesa_lock_context_textures(ctx
);
435 /* copy/save the bulk of texture state here */
436 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
438 /* Save references to the currently bound texture objects so they don't
439 * accidentally get deleted while referenced in the attribute stack.
441 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
442 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
443 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
444 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
448 /* copy state/contents of the currently bound texture objects */
449 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
450 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
451 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
452 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
456 _mesa_unlock_context_textures(ctx
);
458 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
461 if (mask
& GL_TRANSFORM_BIT
) {
462 struct gl_transform_attrib
*attr
;
463 attr
= MALLOC_STRUCT( gl_transform_attrib
);
464 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
465 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
468 if (mask
& GL_VIEWPORT_BIT
) {
469 struct gl_viewport_attrib
*attr
;
470 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
471 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
472 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
475 /* GL_ARB_multisample */
476 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
477 struct gl_multisample_attrib
*attr
;
478 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
479 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
480 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
484 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
485 ctx
->AttribStackDepth
++;
491 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
493 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
496 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
497 if ((VALUE) != (NEWVALUE)) { \
498 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
501 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
502 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
503 if (ctx
->Extensions
.EXT_draw_buffers2
) {
505 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
506 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
510 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
514 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
515 const GLuint mask
= 1 << i
;
516 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
517 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
518 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
521 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
523 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
524 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
526 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
527 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
528 GL_POST_CONVOLUTION_COLOR_TABLE
);
529 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
530 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
531 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
532 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
533 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
535 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
536 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
537 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
539 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
541 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
543 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
544 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
545 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
546 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
548 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
550 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
553 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
557 GL_MAP1_TEXTURE_COORD_1
);
558 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
559 GL_MAP1_TEXTURE_COORD_2
);
560 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
561 GL_MAP1_TEXTURE_COORD_3
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
563 GL_MAP1_TEXTURE_COORD_4
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
566 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
568 for (i
= 0; i
< 16; i
++) {
569 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
570 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
573 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
574 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
575 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
576 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
577 GL_MAP2_TEXTURE_COORD_1
);
578 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
579 GL_MAP2_TEXTURE_COORD_2
);
580 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
581 GL_MAP2_TEXTURE_COORD_3
);
582 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
583 GL_MAP2_TEXTURE_COORD_4
);
584 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
586 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
588 for (i
= 0; i
< 16; i
++) {
589 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
590 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
593 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
594 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
595 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
596 GL_RESCALE_NORMAL_EXT
);
597 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
598 enable
->RasterPositionUnclipped
,
599 GL_RASTER_POSITION_UNCLIPPED_IBM
);
600 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
602 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
603 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
606 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
607 GL_POLYGON_OFFSET_POINT
);
608 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
609 GL_POLYGON_OFFSET_LINE
);
610 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
611 GL_POLYGON_OFFSET_FILL
);
612 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
614 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
616 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
617 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
618 if (ctx
->Extensions
.EXT_stencil_two_side
) {
619 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
621 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
623 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
624 enable
->SampleAlphaToCoverage
,
625 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
626 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
627 enable
->SampleAlphaToOne
,
628 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
629 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
630 enable
->SampleCoverage
,
631 GL_SAMPLE_COVERAGE_ARB
);
632 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
633 enable
->SampleCoverageInvert
,
634 GL_SAMPLE_COVERAGE_INVERT_ARB
);
635 /* GL_ARB_vertex_program, GL_NV_vertex_program */
636 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
637 enable
->VertexProgram
,
638 GL_VERTEX_PROGRAM_ARB
);
639 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
640 enable
->VertexProgramPointSize
,
641 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
642 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
643 enable
->VertexProgramTwoSide
,
644 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
646 #undef TEST_AND_UPDATE
648 /* texture unit enables */
649 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
650 const GLbitfield enabled
= enable
->Texture
[i
];
651 const GLbitfield genEnabled
= enable
->TexGen
[i
];
653 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
654 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
656 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
657 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
658 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
659 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
660 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
661 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
662 if (ctx
->Extensions
.NV_texture_rectangle
) {
663 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
664 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
666 if (ctx
->Extensions
.ARB_texture_cube_map
) {
667 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
668 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
670 if (ctx
->Extensions
.MESA_texture_array
) {
671 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
672 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
673 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
674 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
678 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
679 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
680 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
681 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
682 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
683 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
684 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
685 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
686 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
687 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
690 /* GL_SGI_texture_color_table */
691 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
694 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
699 * Pop/restore texture attribute/group state.
702 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
706 _mesa_lock_context_textures(ctx
);
708 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
709 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
712 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
713 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
714 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
715 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
716 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
717 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
718 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
719 if (ctx
->Extensions
.ARB_texture_cube_map
) {
720 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
721 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
723 if (ctx
->Extensions
.NV_texture_rectangle
) {
724 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
725 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
727 if (ctx
->Extensions
.MESA_texture_array
) {
728 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
729 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
730 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
731 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
734 if (ctx
->Extensions
.SGI_texture_color_table
) {
735 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
736 unit
->ColorTableEnabled
);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
739 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
740 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
741 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
742 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
743 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
744 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
745 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
746 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
747 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
748 /* Eye plane done differently to avoid re-transformation */
750 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
751 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
752 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
753 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
754 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
755 if (ctx
->Driver
.TexGen
) {
756 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
757 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
758 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
759 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
762 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
763 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
764 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
765 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
766 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
767 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
768 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
769 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
770 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
771 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
772 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
774 if (ctx
->Extensions
.EXT_texture_env_combine
||
775 ctx
->Extensions
.ARB_texture_env_combine
) {
776 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
777 unit
->Combine
.ModeRGB
);
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
779 unit
->Combine
.ModeA
);
780 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
781 unit
->Combine
.SourceRGB
[0]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
783 unit
->Combine
.SourceRGB
[1]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
785 unit
->Combine
.SourceRGB
[2]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
787 unit
->Combine
.SourceA
[0]);
788 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
789 unit
->Combine
.SourceA
[1]);
790 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
791 unit
->Combine
.SourceA
[2]);
792 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
793 unit
->Combine
.OperandRGB
[0]);
794 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
795 unit
->Combine
.OperandRGB
[1]);
796 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
797 unit
->Combine
.OperandRGB
[2]);
798 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
799 unit
->Combine
.OperandA
[0]);
800 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
801 unit
->Combine
.OperandA
[1]);
802 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
803 unit
->Combine
.OperandA
[2]);
804 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
805 1 << unit
->Combine
.ScaleShiftRGB
);
806 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
807 1 << unit
->Combine
.ScaleShiftA
);
810 /* Restore texture object state for each target */
811 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
812 const struct gl_texture_object
*obj
= NULL
;
815 obj
= &texstate
->SavedObj
[u
][tgt
];
817 /* don't restore state for unsupported targets to prevent
820 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
821 !ctx
->Extensions
.ARB_texture_cube_map
) {
824 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
825 !ctx
->Extensions
.NV_texture_rectangle
) {
828 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
829 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
830 !ctx
->Extensions
.MESA_texture_array
) {
834 target
= obj
->Target
;
836 _mesa_BindTexture(target
, obj
->Name
);
838 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
.f
);
839 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
840 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
841 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
842 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
843 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
844 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
845 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
846 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
847 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
848 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
849 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
850 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
851 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
852 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
855 if (ctx
->Extensions
.ARB_shadow_ambient
) {
856 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
857 obj
->CompareFailValue
);
861 /* remove saved references to the texture objects */
862 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
863 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
867 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
869 _mesa_unlock_context_textures(ctx
);
874 * This function is kind of long just because we have to call a lot
875 * of device driver functions to update device driver state.
877 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
878 * in order to restore GL state. This isn't terribly efficient but it
879 * ensures that dirty flags and any derived state gets updated correctly.
880 * We could at least check if the value to restore equals the current value
881 * and then skip the Mesa call.
884 _mesa_PopAttrib(void)
886 struct gl_attrib_node
*attr
, *next
;
887 GET_CURRENT_CONTEXT(ctx
);
888 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
890 if (ctx
->AttribStackDepth
== 0) {
891 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
895 ctx
->AttribStackDepth
--;
896 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
900 if (MESA_VERBOSE
& VERBOSE_API
) {
901 _mesa_debug(ctx
, "glPopAttrib %s\n",
902 _mesa_lookup_enum_by_nr(attr
->kind
));
905 switch (attr
->kind
) {
906 case GL_ACCUM_BUFFER_BIT
:
908 const struct gl_accum_attrib
*accum
;
909 accum
= (const struct gl_accum_attrib
*) attr
->data
;
910 _mesa_ClearAccum(accum
->ClearColor
[0],
911 accum
->ClearColor
[1],
912 accum
->ClearColor
[2],
913 accum
->ClearColor
[3]);
916 case GL_COLOR_BUFFER_BIT
:
918 const struct gl_colorbuffer_attrib
*color
;
920 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
921 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
922 _mesa_ClearColor(color
->ClearColor
[0],
923 color
->ClearColor
[1],
924 color
->ClearColor
[2],
925 color
->ClearColor
[3]);
926 _mesa_IndexMask(color
->IndexMask
);
927 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
928 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
929 (GLboolean
) (color
->ColorMask
[0][1] != 0),
930 (GLboolean
) (color
->ColorMask
[0][2] != 0),
931 (GLboolean
) (color
->ColorMask
[0][3] != 0));
935 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
936 _mesa_ColorMaskIndexed(i
,
937 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
938 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
939 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
940 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
944 /* Need to determine if more than one color output is
945 * specified. If so, call glDrawBuffersARB, else call
946 * glDrawBuffer(). This is a subtle, but essential point
947 * since GL_FRONT (for example) is illegal for the former
948 * function, but legal for the later.
950 GLboolean multipleBuffers
= GL_FALSE
;
953 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
954 if (color
->DrawBuffer
[i
] != GL_NONE
) {
955 multipleBuffers
= GL_TRUE
;
959 /* Call the API_level functions, not _mesa_drawbuffers()
960 * since we need to do error checking on the pop'd
962 * Ex: if GL_FRONT were pushed, but we're popping with a
963 * user FBO bound, GL_FRONT will be illegal and we'll need
964 * to record that error. Per OpenGL ARB decision.
967 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
970 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
972 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
973 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
974 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
975 if (ctx
->Extensions
.EXT_draw_buffers2
) {
977 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
978 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
979 (color
->BlendEnabled
>> i
) & 1);
983 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
986 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
990 /* This special case is because glBlendEquationSeparateEXT
991 * cannot take GL_LOGIC_OP as a parameter.
993 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
994 _mesa_BlendEquation(color
->BlendEquationRGB
);
997 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
998 color
->BlendEquationA
);
1000 _mesa_BlendColor(color
->BlendColor
[0],
1001 color
->BlendColor
[1],
1002 color
->BlendColor
[2],
1003 color
->BlendColor
[3]);
1004 _mesa_LogicOp(color
->LogicOp
);
1005 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1006 color
->ColorLogicOpEnabled
);
1007 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1008 color
->IndexLogicOpEnabled
);
1009 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1012 case GL_CURRENT_BIT
:
1013 FLUSH_CURRENT( ctx
, 0 );
1014 MEMCPY( &ctx
->Current
, attr
->data
,
1015 sizeof(struct gl_current_attrib
) );
1017 case GL_DEPTH_BUFFER_BIT
:
1019 const struct gl_depthbuffer_attrib
*depth
;
1020 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1021 _mesa_DepthFunc(depth
->Func
);
1022 _mesa_ClearDepth(depth
->Clear
);
1023 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1024 _mesa_DepthMask(depth
->Mask
);
1029 const struct gl_enable_attrib
*enable
;
1030 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1031 pop_enable_group(ctx
, enable
);
1032 ctx
->NewState
|= _NEW_ALL
;
1036 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1037 ctx
->NewState
|= _NEW_EVAL
;
1041 const struct gl_fog_attrib
*fog
;
1042 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1043 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1044 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1045 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1046 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1047 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1048 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1049 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1054 const struct gl_hint_attrib
*hint
;
1055 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1056 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1057 hint
->PerspectiveCorrection
);
1058 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1059 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1060 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1061 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1062 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1063 hint
->ClipVolumeClipping
);
1064 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1065 hint
->TextureCompression
);
1068 case GL_LIGHTING_BIT
:
1071 const struct gl_light_attrib
*light
;
1072 light
= (const struct gl_light_attrib
*) attr
->data
;
1073 /* lighting enable */
1074 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1075 /* per-light state */
1076 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1077 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1079 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1080 const struct gl_light
*l
= &light
->Light
[i
];
1081 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1082 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1083 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1084 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1085 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1086 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1088 GLfloat p
[4] = { 0 };
1089 p
[0] = l
->SpotExponent
;
1090 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1093 GLfloat p
[4] = { 0 };
1094 p
[0] = l
->SpotCutoff
;
1095 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1098 GLfloat p
[4] = { 0 };
1099 p
[0] = l
->ConstantAttenuation
;
1100 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1103 GLfloat p
[4] = { 0 };
1104 p
[0] = l
->LinearAttenuation
;
1105 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1108 GLfloat p
[4] = { 0 };
1109 p
[0] = l
->QuadraticAttenuation
;
1110 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1114 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1115 light
->Model
.Ambient
);
1116 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1117 (GLfloat
) light
->Model
.LocalViewer
);
1118 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1119 (GLfloat
) light
->Model
.TwoSide
);
1120 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1121 (GLfloat
) light
->Model
.ColorControl
);
1123 _mesa_ShadeModel(light
->ShadeModel
);
1124 /* color material */
1125 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1126 light
->ColorMaterialMode
);
1127 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1128 light
->ColorMaterialEnabled
);
1130 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1131 sizeof(struct gl_material
));
1136 const struct gl_line_attrib
*line
;
1137 line
= (const struct gl_line_attrib
*) attr
->data
;
1138 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1139 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1140 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1141 _mesa_LineWidth(line
->Width
);
1145 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1147 case GL_PIXEL_MODE_BIT
:
1148 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1149 /* XXX what other pixel state needs to be set by function calls? */
1150 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1151 ctx
->NewState
|= _NEW_PIXEL
;
1155 const struct gl_point_attrib
*point
;
1156 point
= (const struct gl_point_attrib
*) attr
->data
;
1157 _mesa_PointSize(point
->Size
);
1158 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1159 if (ctx
->Extensions
.EXT_point_parameters
) {
1160 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1162 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1164 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1166 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1169 if (ctx
->Extensions
.NV_point_sprite
1170 || ctx
->Extensions
.ARB_point_sprite
) {
1172 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1173 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1174 (GLint
) point
->CoordReplace
[u
]);
1176 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1177 if (ctx
->Extensions
.NV_point_sprite
)
1178 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1179 ctx
->Point
.SpriteRMode
);
1180 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1181 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1185 case GL_POLYGON_BIT
:
1187 const struct gl_polygon_attrib
*polygon
;
1188 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1189 _mesa_CullFace(polygon
->CullFaceMode
);
1190 _mesa_FrontFace(polygon
->FrontFace
);
1191 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1192 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1193 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1194 polygon
->OffsetUnits
);
1195 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1196 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1197 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1198 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1199 polygon
->OffsetPoint
);
1200 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1201 polygon
->OffsetLine
);
1202 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1203 polygon
->OffsetFill
);
1206 case GL_POLYGON_STIPPLE_BIT
:
1207 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1208 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1209 if (ctx
->Driver
.PolygonStipple
)
1210 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1212 case GL_SCISSOR_BIT
:
1214 const struct gl_scissor_attrib
*scissor
;
1215 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1216 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1217 scissor
->Width
, scissor
->Height
);
1218 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1221 case GL_STENCIL_BUFFER_BIT
:
1223 const struct gl_stencil_attrib
*stencil
;
1224 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1225 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1226 _mesa_ClearStencil(stencil
->Clear
);
1227 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1228 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1229 stencil
->TestTwoSide
);
1230 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1231 ? GL_BACK
: GL_FRONT
);
1234 _mesa_StencilFuncSeparate(GL_FRONT
,
1235 stencil
->Function
[0],
1237 stencil
->ValueMask
[0]);
1238 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1239 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1240 stencil
->ZFailFunc
[0],
1241 stencil
->ZPassFunc
[0]);
1243 _mesa_StencilFuncSeparate(GL_BACK
,
1244 stencil
->Function
[1],
1246 stencil
->ValueMask
[1]);
1247 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1248 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1249 stencil
->ZFailFunc
[1],
1250 stencil
->ZPassFunc
[1]);
1253 case GL_TRANSFORM_BIT
:
1256 const struct gl_transform_attrib
*xform
;
1257 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1258 _mesa_MatrixMode(xform
->MatrixMode
);
1259 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1260 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1262 /* restore clip planes */
1263 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1264 const GLuint mask
= 1 << i
;
1265 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1266 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1267 if (xform
->ClipPlanesEnabled
& mask
) {
1268 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1271 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1273 if (ctx
->Driver
.ClipPlane
)
1274 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1277 /* normalize/rescale */
1278 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1279 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1280 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1281 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1282 ctx
->Transform
.RescaleNormals
);
1283 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1284 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1285 ctx
->Transform
.DepthClamp
);
1288 case GL_TEXTURE_BIT
:
1289 /* Take care of texture object reference counters */
1291 struct texture_state
*texstate
1292 = (struct texture_state
*) attr
->data
;
1293 pop_texture_group(ctx
, texstate
);
1294 ctx
->NewState
|= _NEW_TEXTURE
;
1297 case GL_VIEWPORT_BIT
:
1299 const struct gl_viewport_attrib
*vp
;
1300 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1301 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1302 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1305 case GL_MULTISAMPLE_BIT_ARB
:
1307 const struct gl_multisample_attrib
*ms
;
1308 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1309 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1310 ms
->SampleCoverageInvert
);
1315 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1328 * Helper for incrementing/decrementing vertex buffer object reference
1329 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1332 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1336 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1337 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1338 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1339 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1340 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1341 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1342 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1343 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1344 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1345 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1346 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1347 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1352 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1356 copy_pixelstore(GLcontext
*ctx
,
1357 struct gl_pixelstore_attrib
*dst
,
1358 const struct gl_pixelstore_attrib
*src
)
1360 dst
->Alignment
= src
->Alignment
;
1361 dst
->RowLength
= src
->RowLength
;
1362 dst
->SkipPixels
= src
->SkipPixels
;
1363 dst
->SkipRows
= src
->SkipRows
;
1364 dst
->ImageHeight
= src
->ImageHeight
;
1365 dst
->SkipImages
= src
->SkipImages
;
1366 dst
->SwapBytes
= src
->SwapBytes
;
1367 dst
->LsbFirst
= src
->LsbFirst
;
1368 dst
->ClientStorage
= src
->ClientStorage
;
1369 dst
->Invert
= src
->Invert
;
1370 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1374 #define GL_CLIENT_PACK_BIT (1<<20)
1375 #define GL_CLIENT_UNPACK_BIT (1<<21)
1379 _mesa_PushClientAttrib(GLbitfield mask
)
1381 struct gl_attrib_node
*head
;
1383 GET_CURRENT_CONTEXT(ctx
);
1384 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1386 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1387 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1391 /* Build linked list of attribute nodes which save all attribute
1392 * groups specified by the mask.
1396 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1397 struct gl_pixelstore_attrib
*attr
;
1398 /* packing attribs */
1399 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1400 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1401 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1402 /* unpacking attribs */
1403 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1404 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1405 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1408 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1409 struct gl_array_attrib
*attr
;
1410 struct gl_array_object
*obj
;
1412 attr
= MALLOC_STRUCT( gl_array_attrib
);
1413 obj
= MALLOC_STRUCT( gl_array_object
);
1415 #if FEATURE_ARB_vertex_buffer_object
1416 /* increment ref counts since we're copying pointers to these objects */
1417 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1418 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1421 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1422 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1424 attr
->ArrayObj
= obj
;
1426 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1428 /* bump reference counts on buffer objects */
1429 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1432 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1433 ctx
->ClientAttribStackDepth
++;
1440 _mesa_PopClientAttrib(void)
1442 struct gl_attrib_node
*node
, *next
;
1444 GET_CURRENT_CONTEXT(ctx
);
1445 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1447 if (ctx
->ClientAttribStackDepth
== 0) {
1448 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1452 ctx
->ClientAttribStackDepth
--;
1453 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1456 switch (node
->kind
) {
1457 case GL_CLIENT_PACK_BIT
:
1459 struct gl_pixelstore_attrib
*store
=
1460 (struct gl_pixelstore_attrib
*) node
->data
;
1461 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1462 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1464 ctx
->NewState
|= _NEW_PACKUNPACK
;
1466 case GL_CLIENT_UNPACK_BIT
:
1468 struct gl_pixelstore_attrib
*store
=
1469 (struct gl_pixelstore_attrib
*) node
->data
;
1470 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1471 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1473 ctx
->NewState
|= _NEW_PACKUNPACK
;
1475 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1476 struct gl_array_attrib
* data
=
1477 (struct gl_array_attrib
*) node
->data
;
1479 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1481 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1482 if (data
->LockCount
!= 0)
1483 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1484 else if (ctx
->Array
.LockCount
)
1485 _mesa_UnlockArraysEXT();
1487 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1489 #if FEATURE_ARB_vertex_buffer_object
1490 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1491 data
->ArrayBufferObj
->Name
);
1492 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1493 data
->ElementArrayBufferObj
->Name
);
1496 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1497 sizeof( struct gl_array_object
) );
1499 FREE( data
->ArrayObj
);
1501 /* FIXME: Should some bits in ctx->Array->NewState also be set
1502 * FIXME: here? It seems like it should be set to inclusive-or
1503 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1506 ctx
->NewState
|= _NEW_ARRAY
;
1510 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1523 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1525 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1526 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1527 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1528 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1532 #endif /* FEATURE_attrib_stack */
1536 * Free any attribute state data that might be attached to the context.
1539 _mesa_free_attrib_data(GLcontext
*ctx
)
1541 while (ctx
->AttribStackDepth
> 0) {
1542 struct gl_attrib_node
*attr
, *next
;
1544 ctx
->AttribStackDepth
--;
1545 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1548 if (attr
->kind
== GL_TEXTURE_BIT
) {
1549 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1551 /* clear references to the saved texture objects */
1552 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1553 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1554 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1559 /* any other chunks of state that requires special handling? */
1563 _mesa_free(attr
->data
);
1571 void _mesa_init_attrib( GLcontext
*ctx
)
1573 /* Renderer and client attribute stacks */
1574 ctx
->AttribStackDepth
= 0;
1575 ctx
->ClientAttribStackDepth
= 0;