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"
45 #include "multisample.h"
49 #include "simple_list.h"
59 #include "glapi/dispatch.h"
63 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
65 struct gl_enable_attrib
70 GLbitfield ClipPlanes
;
71 GLboolean ColorMaterial
;
72 GLboolean ColorTable
[COLORTABLE_MAX
];
73 GLboolean Convolution1D
;
74 GLboolean Convolution2D
;
75 GLboolean Separable2D
;
82 GLboolean Light
[MAX_LIGHTS
];
85 GLboolean LineStipple
;
86 GLboolean IndexLogicOp
;
87 GLboolean ColorLogicOp
;
92 GLboolean Map1TextureCoord1
;
93 GLboolean Map1TextureCoord2
;
94 GLboolean Map1TextureCoord3
;
95 GLboolean Map1TextureCoord4
;
96 GLboolean Map1Vertex3
;
97 GLboolean Map1Vertex4
;
98 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
101 GLboolean Map2Normal
;
102 GLboolean Map2TextureCoord1
;
103 GLboolean Map2TextureCoord2
;
104 GLboolean Map2TextureCoord3
;
105 GLboolean Map2TextureCoord4
;
106 GLboolean Map2Vertex3
;
107 GLboolean Map2Vertex4
;
108 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
112 GLboolean PixelTexture
;
113 GLboolean PointSmooth
;
114 GLboolean PolygonOffsetPoint
;
115 GLboolean PolygonOffsetLine
;
116 GLboolean PolygonOffsetFill
;
117 GLboolean PolygonSmooth
;
118 GLboolean PolygonStipple
;
119 GLboolean RescaleNormals
;
122 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
123 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
124 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
125 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
126 GLboolean SampleCoverage
; /* GL_ARB_multisample */
127 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
128 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
130 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
131 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
133 /* SGI_texture_color_table */
134 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
136 /* GL_ARB_vertex_program / GL_NV_vertex_program */
137 GLboolean VertexProgram
;
138 GLboolean VertexProgramPointSize
;
139 GLboolean VertexProgramTwoSide
;
141 /* GL_ARB_point_sprite / GL_NV_point_sprite */
142 GLboolean PointSprite
;
143 GLboolean FragmentShaderATI
;
148 * Node for the attribute stack.
150 struct gl_attrib_node
154 struct gl_attrib_node
*next
;
160 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
164 struct gl_texture_attrib Texture
; /**< The usual context state */
166 /** to save per texture object state (wrap modes, filters, etc): */
167 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
170 * To save references to texture objects (so they don't get accidentally
171 * deleted while saved in the attribute stack).
173 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
177 #if FEATURE_attrib_stack
181 * Allocate new attribute node of given type/kind. Attach payload data.
182 * Insert it into the linked list named by 'head'.
185 save_attrib_data(struct gl_attrib_node
**head
,
186 GLbitfield kind
, void *payload
)
188 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
203 _mesa_PushAttrib(GLbitfield mask
)
205 struct gl_attrib_node
*head
;
207 GET_CURRENT_CONTEXT(ctx
);
208 ASSERT_OUTSIDE_BEGIN_END(ctx
);
210 if (MESA_VERBOSE
& VERBOSE_API
)
211 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
213 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
214 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
218 /* Build linked list of attribute nodes which save all attribute */
219 /* groups specified by the mask. */
222 if (mask
& GL_ACCUM_BUFFER_BIT
) {
223 struct gl_accum_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_accum_attrib
);
225 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
226 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
229 if (mask
& GL_COLOR_BUFFER_BIT
) {
231 struct gl_colorbuffer_attrib
*attr
;
232 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
233 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
234 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
235 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
236 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
237 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
240 if (mask
& GL_CURRENT_BIT
) {
241 struct gl_current_attrib
*attr
;
242 FLUSH_CURRENT( ctx
, 0 );
243 attr
= MALLOC_STRUCT( gl_current_attrib
);
244 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
245 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
248 if (mask
& GL_DEPTH_BUFFER_BIT
) {
249 struct gl_depthbuffer_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
251 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
252 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
255 if (mask
& GL_ENABLE_BIT
) {
256 struct gl_enable_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_enable_attrib
);
259 /* Copy enable flags from all other attributes into the enable struct. */
260 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
261 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
262 attr
->Blend
= ctx
->Color
.BlendEnabled
;
263 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
264 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
265 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
266 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
268 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
269 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
270 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
271 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
272 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
273 attr
->DepthTest
= ctx
->Depth
.Test
;
274 attr
->Dither
= ctx
->Color
.DitherFlag
;
275 attr
->Fog
= ctx
->Fog
.Enabled
;
276 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
277 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
279 attr
->Lighting
= ctx
->Light
.Enabled
;
280 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
281 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
282 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
283 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
284 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
285 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
286 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
287 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
288 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
289 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
290 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
291 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
292 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
293 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
294 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
295 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
296 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
297 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
298 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
299 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
300 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
301 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
302 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
303 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
304 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
305 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
306 attr
->Normalize
= ctx
->Transform
.Normalize
;
307 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
308 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
309 attr
->PointSprite
= ctx
->Point
.PointSprite
;
310 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
311 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
312 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
313 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
314 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
315 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
316 attr
->Scissor
= ctx
->Scissor
.Enabled
;
317 attr
->Stencil
= ctx
->Stencil
.Enabled
;
318 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
319 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
320 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
321 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
322 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
323 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
324 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
325 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
326 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
327 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
329 /* GL_NV_vertex_program */
330 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
331 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
332 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
333 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
336 if (mask
& GL_EVAL_BIT
) {
337 struct gl_eval_attrib
*attr
;
338 attr
= MALLOC_STRUCT( gl_eval_attrib
);
339 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
340 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
343 if (mask
& GL_FOG_BIT
) {
344 struct gl_fog_attrib
*attr
;
345 attr
= MALLOC_STRUCT( gl_fog_attrib
);
346 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
347 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
350 if (mask
& GL_HINT_BIT
) {
351 struct gl_hint_attrib
*attr
;
352 attr
= MALLOC_STRUCT( gl_hint_attrib
);
353 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
354 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
357 if (mask
& GL_LIGHTING_BIT
) {
358 struct gl_light_attrib
*attr
;
359 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
360 attr
= MALLOC_STRUCT( gl_light_attrib
);
361 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
362 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
365 if (mask
& GL_LINE_BIT
) {
366 struct gl_line_attrib
*attr
;
367 attr
= MALLOC_STRUCT( gl_line_attrib
);
368 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
369 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
372 if (mask
& GL_LIST_BIT
) {
373 struct gl_list_attrib
*attr
;
374 attr
= MALLOC_STRUCT( gl_list_attrib
);
375 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
376 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
379 if (mask
& GL_PIXEL_MODE_BIT
) {
380 struct gl_pixel_attrib
*attr
;
381 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
382 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
383 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
384 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
385 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
388 if (mask
& GL_POINT_BIT
) {
389 struct gl_point_attrib
*attr
;
390 attr
= MALLOC_STRUCT( gl_point_attrib
);
391 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
392 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
395 if (mask
& GL_POLYGON_BIT
) {
396 struct gl_polygon_attrib
*attr
;
397 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
398 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
399 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
402 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
404 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
405 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
406 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
409 if (mask
& GL_SCISSOR_BIT
) {
410 struct gl_scissor_attrib
*attr
;
411 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
412 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
413 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
416 if (mask
& GL_STENCIL_BUFFER_BIT
) {
417 struct gl_stencil_attrib
*attr
;
418 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
419 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
420 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
423 if (mask
& GL_TEXTURE_BIT
) {
424 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
428 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
432 _mesa_lock_context_textures(ctx
);
434 /* copy/save the bulk of texture state here */
435 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
437 /* Save references to the currently bound texture objects so they don't
438 * accidentally get deleted while referenced in the attribute stack.
440 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
441 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
442 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
443 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
447 /* copy state/contents of the currently bound texture objects */
448 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
449 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
450 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
451 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
455 _mesa_unlock_context_textures(ctx
);
457 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
460 if (mask
& GL_TRANSFORM_BIT
) {
461 struct gl_transform_attrib
*attr
;
462 attr
= MALLOC_STRUCT( gl_transform_attrib
);
463 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
464 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
467 if (mask
& GL_VIEWPORT_BIT
) {
468 struct gl_viewport_attrib
*attr
;
469 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
470 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
471 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
474 /* GL_ARB_multisample */
475 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
476 struct gl_multisample_attrib
*attr
;
477 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
478 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
479 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
483 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
484 ctx
->AttribStackDepth
++;
490 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
492 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
495 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
496 if ((VALUE) != (NEWVALUE)) { \
497 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
500 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
501 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
502 if (ctx
->Extensions
.EXT_draw_buffers2
) {
504 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
505 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
509 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
513 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
514 const GLuint mask
= 1 << i
;
515 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
516 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
517 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
520 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
522 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
523 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
525 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
526 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
527 GL_POST_CONVOLUTION_COLOR_TABLE
);
528 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
529 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
530 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
531 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
532 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
534 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
535 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
536 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
538 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
540 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
542 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
543 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
544 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
545 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
547 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
549 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
552 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
554 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
556 GL_MAP1_TEXTURE_COORD_1
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
558 GL_MAP1_TEXTURE_COORD_2
);
559 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
560 GL_MAP1_TEXTURE_COORD_3
);
561 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
562 GL_MAP1_TEXTURE_COORD_4
);
563 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
565 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
567 for (i
= 0; i
< 16; i
++) {
568 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
569 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
572 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
573 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
574 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
575 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
576 GL_MAP2_TEXTURE_COORD_1
);
577 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
578 GL_MAP2_TEXTURE_COORD_2
);
579 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
580 GL_MAP2_TEXTURE_COORD_3
);
581 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
582 GL_MAP2_TEXTURE_COORD_4
);
583 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
585 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
587 for (i
= 0; i
< 16; i
++) {
588 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
589 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
592 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
593 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
594 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
595 GL_RESCALE_NORMAL_EXT
);
596 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
597 enable
->RasterPositionUnclipped
,
598 GL_RASTER_POSITION_UNCLIPPED_IBM
);
599 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
601 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
602 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
605 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
606 GL_POLYGON_OFFSET_POINT
);
607 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
608 GL_POLYGON_OFFSET_LINE
);
609 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
610 GL_POLYGON_OFFSET_FILL
);
611 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
613 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
615 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
616 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
617 if (ctx
->Extensions
.EXT_stencil_two_side
) {
618 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
620 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
622 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
623 enable
->SampleAlphaToCoverage
,
624 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
625 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
626 enable
->SampleAlphaToOne
,
627 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
628 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
629 enable
->SampleCoverage
,
630 GL_SAMPLE_COVERAGE_ARB
);
631 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
632 enable
->SampleCoverageInvert
,
633 GL_SAMPLE_COVERAGE_INVERT_ARB
);
634 /* GL_ARB_vertex_program, GL_NV_vertex_program */
635 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
636 enable
->VertexProgram
,
637 GL_VERTEX_PROGRAM_ARB
);
638 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
639 enable
->VertexProgramPointSize
,
640 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
641 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
642 enable
->VertexProgramTwoSide
,
643 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
645 #undef TEST_AND_UPDATE
647 /* texture unit enables */
648 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
649 const GLbitfield enabled
= enable
->Texture
[i
];
650 const GLbitfield genEnabled
= enable
->TexGen
[i
];
652 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
653 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
655 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
656 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
657 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
658 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
659 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
660 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
661 if (ctx
->Extensions
.NV_texture_rectangle
) {
662 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
663 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
665 if (ctx
->Extensions
.ARB_texture_cube_map
) {
666 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
667 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
669 if (ctx
->Extensions
.MESA_texture_array
) {
670 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
671 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
672 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
673 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
677 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
678 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
679 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
680 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
681 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
682 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
683 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
684 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
685 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
686 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
689 /* GL_SGI_texture_color_table */
690 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
693 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
698 * Pop/restore texture attribute/group state.
701 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
705 _mesa_lock_context_textures(ctx
);
707 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
708 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
711 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
713 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
714 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
715 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
716 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
717 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
718 if (ctx
->Extensions
.ARB_texture_cube_map
) {
719 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
720 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
722 if (ctx
->Extensions
.NV_texture_rectangle
) {
723 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
724 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
726 if (ctx
->Extensions
.MESA_texture_array
) {
727 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
728 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
729 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
730 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
733 if (ctx
->Extensions
.SGI_texture_color_table
) {
734 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
735 unit
->ColorTableEnabled
);
737 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
738 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
739 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
740 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
741 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
742 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
743 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
744 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
745 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
746 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
747 /* Eye plane done differently to avoid re-transformation */
749 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
750 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
751 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
752 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
753 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
754 if (ctx
->Driver
.TexGen
) {
755 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
756 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
757 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
758 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
761 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
762 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
763 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
764 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
765 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
766 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
767 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
768 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
769 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
770 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
771 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
773 if (ctx
->Extensions
.EXT_texture_env_combine
||
774 ctx
->Extensions
.ARB_texture_env_combine
) {
775 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
776 unit
->Combine
.ModeRGB
);
777 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
778 unit
->Combine
.ModeA
);
779 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
780 unit
->Combine
.SourceRGB
[0]);
781 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
782 unit
->Combine
.SourceRGB
[1]);
783 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
784 unit
->Combine
.SourceRGB
[2]);
785 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
786 unit
->Combine
.SourceA
[0]);
787 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
788 unit
->Combine
.SourceA
[1]);
789 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
790 unit
->Combine
.SourceA
[2]);
791 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
792 unit
->Combine
.OperandRGB
[0]);
793 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
794 unit
->Combine
.OperandRGB
[1]);
795 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
796 unit
->Combine
.OperandRGB
[2]);
797 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
798 unit
->Combine
.OperandA
[0]);
799 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
800 unit
->Combine
.OperandA
[1]);
801 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
802 unit
->Combine
.OperandA
[2]);
803 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
804 1 << unit
->Combine
.ScaleShiftRGB
);
805 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
806 1 << unit
->Combine
.ScaleShiftA
);
809 /* Restore texture object state for each target */
810 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
811 const struct gl_texture_object
*obj
= NULL
;
814 obj
= &texstate
->SavedObj
[u
][tgt
];
816 /* don't restore state for unsupported targets to prevent
819 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
820 !ctx
->Extensions
.ARB_texture_cube_map
) {
823 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
824 !ctx
->Extensions
.NV_texture_rectangle
) {
827 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
828 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
829 !ctx
->Extensions
.MESA_texture_array
) {
833 target
= obj
->Target
;
835 _mesa_BindTexture(target
, obj
->Name
);
837 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
.f
);
838 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
839 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
840 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
841 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
842 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
843 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
844 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
845 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
846 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
847 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
848 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
849 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
850 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
851 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
854 if (ctx
->Extensions
.ARB_shadow_ambient
) {
855 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
856 obj
->CompareFailValue
);
860 /* remove saved references to the texture objects */
861 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
862 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], 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
;
919 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
920 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
921 _mesa_ClearColor(color
->ClearColor
[0],
922 color
->ClearColor
[1],
923 color
->ClearColor
[2],
924 color
->ClearColor
[3]);
925 _mesa_IndexMask(color
->IndexMask
);
926 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
927 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
928 (GLboolean
) (color
->ColorMask
[0][1] != 0),
929 (GLboolean
) (color
->ColorMask
[0][2] != 0),
930 (GLboolean
) (color
->ColorMask
[0][3] != 0));
934 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
935 _mesa_ColorMaskIndexed(i
,
936 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
937 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
938 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
939 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
943 /* Need to determine if more than one color output is
944 * specified. If so, call glDrawBuffersARB, else call
945 * glDrawBuffer(). This is a subtle, but essential point
946 * since GL_FRONT (for example) is illegal for the former
947 * function, but legal for the later.
949 GLboolean multipleBuffers
= GL_FALSE
;
952 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
953 if (color
->DrawBuffer
[i
] != GL_NONE
) {
954 multipleBuffers
= GL_TRUE
;
958 /* Call the API_level functions, not _mesa_drawbuffers()
959 * since we need to do error checking on the pop'd
961 * Ex: if GL_FRONT were pushed, but we're popping with a
962 * user FBO bound, GL_FRONT will be illegal and we'll need
963 * to record that error. Per OpenGL ARB decision.
966 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
969 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
971 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
972 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
973 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
974 if (ctx
->Extensions
.EXT_draw_buffers2
) {
976 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
977 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
978 (color
->BlendEnabled
>> i
) & 1);
982 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
985 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
989 /* This special case is because glBlendEquationSeparateEXT
990 * cannot take GL_LOGIC_OP as a parameter.
992 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
993 _mesa_BlendEquation(color
->BlendEquationRGB
);
996 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
997 color
->BlendEquationA
);
999 _mesa_BlendColor(color
->BlendColor
[0],
1000 color
->BlendColor
[1],
1001 color
->BlendColor
[2],
1002 color
->BlendColor
[3]);
1003 _mesa_LogicOp(color
->LogicOp
);
1004 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1005 color
->ColorLogicOpEnabled
);
1006 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1007 color
->IndexLogicOpEnabled
);
1008 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1011 case GL_CURRENT_BIT
:
1012 FLUSH_CURRENT( ctx
, 0 );
1013 MEMCPY( &ctx
->Current
, attr
->data
,
1014 sizeof(struct gl_current_attrib
) );
1016 case GL_DEPTH_BUFFER_BIT
:
1018 const struct gl_depthbuffer_attrib
*depth
;
1019 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1020 _mesa_DepthFunc(depth
->Func
);
1021 _mesa_ClearDepth(depth
->Clear
);
1022 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1023 _mesa_DepthMask(depth
->Mask
);
1028 const struct gl_enable_attrib
*enable
;
1029 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1030 pop_enable_group(ctx
, enable
);
1031 ctx
->NewState
|= _NEW_ALL
;
1035 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1036 ctx
->NewState
|= _NEW_EVAL
;
1040 const struct gl_fog_attrib
*fog
;
1041 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1042 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1043 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1044 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1045 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1046 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1047 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1048 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1053 const struct gl_hint_attrib
*hint
;
1054 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1055 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1056 hint
->PerspectiveCorrection
);
1057 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1058 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1059 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1060 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1061 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1062 hint
->ClipVolumeClipping
);
1063 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1064 hint
->TextureCompression
);
1067 case GL_LIGHTING_BIT
:
1070 const struct gl_light_attrib
*light
;
1071 light
= (const struct gl_light_attrib
*) attr
->data
;
1072 /* lighting enable */
1073 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1074 /* per-light state */
1075 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1076 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1078 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1079 const struct gl_light
*l
= &light
->Light
[i
];
1080 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1081 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1082 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1083 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1084 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1085 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1087 GLfloat p
[4] = { 0 };
1088 p
[0] = l
->SpotExponent
;
1089 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1092 GLfloat p
[4] = { 0 };
1093 p
[0] = l
->SpotCutoff
;
1094 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1097 GLfloat p
[4] = { 0 };
1098 p
[0] = l
->ConstantAttenuation
;
1099 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1102 GLfloat p
[4] = { 0 };
1103 p
[0] = l
->LinearAttenuation
;
1104 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1107 GLfloat p
[4] = { 0 };
1108 p
[0] = l
->QuadraticAttenuation
;
1109 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1113 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1114 light
->Model
.Ambient
);
1115 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1116 (GLfloat
) light
->Model
.LocalViewer
);
1117 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1118 (GLfloat
) light
->Model
.TwoSide
);
1119 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1120 (GLfloat
) light
->Model
.ColorControl
);
1122 _mesa_ShadeModel(light
->ShadeModel
);
1123 /* color material */
1124 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1125 light
->ColorMaterialMode
);
1126 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1127 light
->ColorMaterialEnabled
);
1129 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1130 sizeof(struct gl_material
));
1135 const struct gl_line_attrib
*line
;
1136 line
= (const struct gl_line_attrib
*) attr
->data
;
1137 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1138 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1139 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1140 _mesa_LineWidth(line
->Width
);
1144 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1146 case GL_PIXEL_MODE_BIT
:
1147 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1148 /* XXX what other pixel state needs to be set by function calls? */
1149 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1150 ctx
->NewState
|= _NEW_PIXEL
;
1154 const struct gl_point_attrib
*point
;
1155 point
= (const struct gl_point_attrib
*) attr
->data
;
1156 _mesa_PointSize(point
->Size
);
1157 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1158 if (ctx
->Extensions
.EXT_point_parameters
) {
1159 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1161 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1163 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1165 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1168 if (ctx
->Extensions
.NV_point_sprite
1169 || ctx
->Extensions
.ARB_point_sprite
) {
1171 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1172 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1173 (GLint
) point
->CoordReplace
[u
]);
1175 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1176 if (ctx
->Extensions
.NV_point_sprite
)
1177 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1178 ctx
->Point
.SpriteRMode
);
1179 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1180 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1184 case GL_POLYGON_BIT
:
1186 const struct gl_polygon_attrib
*polygon
;
1187 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1188 _mesa_CullFace(polygon
->CullFaceMode
);
1189 _mesa_FrontFace(polygon
->FrontFace
);
1190 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1191 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1192 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1193 polygon
->OffsetUnits
);
1194 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1195 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1196 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1197 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1198 polygon
->OffsetPoint
);
1199 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1200 polygon
->OffsetLine
);
1201 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1202 polygon
->OffsetFill
);
1205 case GL_POLYGON_STIPPLE_BIT
:
1206 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1207 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1208 if (ctx
->Driver
.PolygonStipple
)
1209 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1211 case GL_SCISSOR_BIT
:
1213 const struct gl_scissor_attrib
*scissor
;
1214 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1215 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1216 scissor
->Width
, scissor
->Height
);
1217 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1220 case GL_STENCIL_BUFFER_BIT
:
1222 const struct gl_stencil_attrib
*stencil
;
1223 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1224 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1225 _mesa_ClearStencil(stencil
->Clear
);
1226 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1227 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1228 stencil
->TestTwoSide
);
1229 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1230 ? GL_BACK
: GL_FRONT
);
1233 _mesa_StencilFuncSeparate(GL_FRONT
,
1234 stencil
->Function
[0],
1236 stencil
->ValueMask
[0]);
1237 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1238 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1239 stencil
->ZFailFunc
[0],
1240 stencil
->ZPassFunc
[0]);
1242 _mesa_StencilFuncSeparate(GL_BACK
,
1243 stencil
->Function
[1],
1245 stencil
->ValueMask
[1]);
1246 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1247 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1248 stencil
->ZFailFunc
[1],
1249 stencil
->ZPassFunc
[1]);
1252 case GL_TRANSFORM_BIT
:
1255 const struct gl_transform_attrib
*xform
;
1256 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1257 _mesa_MatrixMode(xform
->MatrixMode
);
1258 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1259 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1261 /* restore clip planes */
1262 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1263 const GLuint mask
= 1 << i
;
1264 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1265 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1266 if (xform
->ClipPlanesEnabled
& mask
) {
1267 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1270 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1272 if (ctx
->Driver
.ClipPlane
)
1273 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1276 /* normalize/rescale */
1277 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1278 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1279 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1280 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1281 ctx
->Transform
.RescaleNormals
);
1282 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1283 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1284 ctx
->Transform
.DepthClamp
);
1287 case GL_TEXTURE_BIT
:
1288 /* Take care of texture object reference counters */
1290 struct texture_state
*texstate
1291 = (struct texture_state
*) attr
->data
;
1292 pop_texture_group(ctx
, texstate
);
1293 ctx
->NewState
|= _NEW_TEXTURE
;
1296 case GL_VIEWPORT_BIT
:
1298 const struct gl_viewport_attrib
*vp
;
1299 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1300 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1301 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1304 case GL_MULTISAMPLE_BIT_ARB
:
1306 const struct gl_multisample_attrib
*ms
;
1307 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1308 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1309 ms
->SampleCoverageInvert
);
1314 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1327 * Helper for incrementing/decrementing vertex buffer object reference
1328 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1331 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1335 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1336 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1337 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1338 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1339 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1340 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1341 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1342 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1343 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1344 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1345 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1346 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1351 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1355 copy_pixelstore(GLcontext
*ctx
,
1356 struct gl_pixelstore_attrib
*dst
,
1357 const struct gl_pixelstore_attrib
*src
)
1359 dst
->Alignment
= src
->Alignment
;
1360 dst
->RowLength
= src
->RowLength
;
1361 dst
->SkipPixels
= src
->SkipPixels
;
1362 dst
->SkipRows
= src
->SkipRows
;
1363 dst
->ImageHeight
= src
->ImageHeight
;
1364 dst
->SkipImages
= src
->SkipImages
;
1365 dst
->SwapBytes
= src
->SwapBytes
;
1366 dst
->LsbFirst
= src
->LsbFirst
;
1367 dst
->ClientStorage
= src
->ClientStorage
;
1368 dst
->Invert
= src
->Invert
;
1369 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1373 #define GL_CLIENT_PACK_BIT (1<<20)
1374 #define GL_CLIENT_UNPACK_BIT (1<<21)
1378 _mesa_PushClientAttrib(GLbitfield mask
)
1380 struct gl_attrib_node
*head
;
1382 GET_CURRENT_CONTEXT(ctx
);
1383 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1385 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1386 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1390 /* Build linked list of attribute nodes which save all attribute
1391 * groups specified by the mask.
1395 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1396 struct gl_pixelstore_attrib
*attr
;
1397 /* packing attribs */
1398 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1399 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1400 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1401 /* unpacking attribs */
1402 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1403 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1404 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1407 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1408 struct gl_array_attrib
*attr
;
1409 struct gl_array_object
*obj
;
1411 attr
= MALLOC_STRUCT( gl_array_attrib
);
1412 obj
= MALLOC_STRUCT( gl_array_object
);
1414 #if FEATURE_ARB_vertex_buffer_object
1415 /* increment ref counts since we're copying pointers to these objects */
1416 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1417 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1420 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1421 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1423 attr
->ArrayObj
= obj
;
1425 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1427 /* bump reference counts on buffer objects */
1428 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1431 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1432 ctx
->ClientAttribStackDepth
++;
1439 _mesa_PopClientAttrib(void)
1441 struct gl_attrib_node
*node
, *next
;
1443 GET_CURRENT_CONTEXT(ctx
);
1444 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1446 if (ctx
->ClientAttribStackDepth
== 0) {
1447 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1451 ctx
->ClientAttribStackDepth
--;
1452 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1455 switch (node
->kind
) {
1456 case GL_CLIENT_PACK_BIT
:
1458 struct gl_pixelstore_attrib
*store
=
1459 (struct gl_pixelstore_attrib
*) node
->data
;
1460 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1461 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1463 ctx
->NewState
|= _NEW_PACKUNPACK
;
1465 case GL_CLIENT_UNPACK_BIT
:
1467 struct gl_pixelstore_attrib
*store
=
1468 (struct gl_pixelstore_attrib
*) node
->data
;
1469 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1470 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1472 ctx
->NewState
|= _NEW_PACKUNPACK
;
1474 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1475 struct gl_array_attrib
* data
=
1476 (struct gl_array_attrib
*) node
->data
;
1478 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1480 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1481 if (data
->LockCount
!= 0)
1482 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1483 else if (ctx
->Array
.LockCount
)
1484 _mesa_UnlockArraysEXT();
1486 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1488 #if FEATURE_ARB_vertex_buffer_object
1489 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1490 data
->ArrayBufferObj
->Name
);
1491 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1492 data
->ElementArrayBufferObj
->Name
);
1495 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1496 sizeof( struct gl_array_object
) );
1498 FREE( data
->ArrayObj
);
1500 /* FIXME: Should some bits in ctx->Array->NewState also be set
1501 * FIXME: here? It seems like it should be set to inclusive-or
1502 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1505 ctx
->NewState
|= _NEW_ARRAY
;
1509 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1522 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1524 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1525 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1526 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1527 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1531 #endif /* FEATURE_attrib_stack */
1535 * Free any attribute state data that might be attached to the context.
1538 _mesa_free_attrib_data(GLcontext
*ctx
)
1540 while (ctx
->AttribStackDepth
> 0) {
1541 struct gl_attrib_node
*attr
, *next
;
1543 ctx
->AttribStackDepth
--;
1544 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1547 if (attr
->kind
== GL_TEXTURE_BIT
) {
1548 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1550 /* clear references to the saved texture objects */
1551 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1552 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1553 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1558 /* any other chunks of state that requires special handling? */
1562 _mesa_free(attr
->data
);
1570 void _mesa_init_attrib( GLcontext
*ctx
)
1572 /* Renderer and client attribute stacks */
1573 ctx
->AttribStackDepth
= 0;
1574 ctx
->ClientAttribStackDepth
= 0;