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"
59 #include "main/dispatch.h"
63 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
65 struct gl_enable_attrib
70 GLbitfield ClipPlanes
;
71 GLboolean ColorMaterial
;
72 GLboolean Convolution1D
;
73 GLboolean Convolution2D
;
74 GLboolean Separable2D
;
80 GLboolean Light
[MAX_LIGHTS
];
83 GLboolean LineStipple
;
84 GLboolean IndexLogicOp
;
85 GLboolean ColorLogicOp
;
90 GLboolean Map1TextureCoord1
;
91 GLboolean Map1TextureCoord2
;
92 GLboolean Map1TextureCoord3
;
93 GLboolean Map1TextureCoord4
;
94 GLboolean Map1Vertex3
;
95 GLboolean Map1Vertex4
;
96 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2TextureCoord1
;
101 GLboolean Map2TextureCoord2
;
102 GLboolean Map2TextureCoord3
;
103 GLboolean Map2TextureCoord4
;
104 GLboolean Map2Vertex3
;
105 GLboolean Map2Vertex4
;
106 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
109 GLboolean PixelTexture
;
110 GLboolean PointSmooth
;
111 GLboolean PolygonOffsetPoint
;
112 GLboolean PolygonOffsetLine
;
113 GLboolean PolygonOffsetFill
;
114 GLboolean PolygonSmooth
;
115 GLboolean PolygonStipple
;
116 GLboolean RescaleNormals
;
119 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
120 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
121 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
122 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
123 GLboolean SampleCoverage
; /* GL_ARB_multisample */
124 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
125 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
127 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
128 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
130 /* SGI_texture_color_table */
131 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
133 /* GL_ARB_vertex_program / GL_NV_vertex_program */
134 GLboolean VertexProgram
;
135 GLboolean VertexProgramPointSize
;
136 GLboolean VertexProgramTwoSide
;
138 /* GL_ARB_point_sprite / GL_NV_point_sprite */
139 GLboolean PointSprite
;
140 GLboolean FragmentShaderATI
;
145 * Node for the attribute stack.
147 struct gl_attrib_node
151 struct gl_attrib_node
*next
;
157 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
161 struct gl_texture_attrib Texture
; /**< The usual context state */
163 /** to save per texture object state (wrap modes, filters, etc): */
164 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
167 * To save references to texture objects (so they don't get accidentally
168 * deleted while saved in the attribute stack).
170 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
174 #if FEATURE_attrib_stack
178 * Allocate new attribute node of given type/kind. Attach payload data.
179 * Insert it into the linked list named by 'head'.
182 save_attrib_data(struct gl_attrib_node
**head
,
183 GLbitfield kind
, void *payload
)
185 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
200 _mesa_PushAttrib(GLbitfield mask
)
202 struct gl_attrib_node
*head
;
204 GET_CURRENT_CONTEXT(ctx
);
205 ASSERT_OUTSIDE_BEGIN_END(ctx
);
207 if (MESA_VERBOSE
& VERBOSE_API
)
208 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
210 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
211 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
215 /* Build linked list of attribute nodes which save all attribute */
216 /* groups specified by the mask. */
219 if (mask
& GL_ACCUM_BUFFER_BIT
) {
220 struct gl_accum_attrib
*attr
;
221 attr
= MALLOC_STRUCT( gl_accum_attrib
);
222 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
223 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
226 if (mask
& GL_COLOR_BUFFER_BIT
) {
228 struct gl_colorbuffer_attrib
*attr
;
229 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
230 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
231 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
232 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
233 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
234 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
237 if (mask
& GL_CURRENT_BIT
) {
238 struct gl_current_attrib
*attr
;
239 FLUSH_CURRENT( ctx
, 0 );
240 attr
= MALLOC_STRUCT( gl_current_attrib
);
241 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
242 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
245 if (mask
& GL_DEPTH_BUFFER_BIT
) {
246 struct gl_depthbuffer_attrib
*attr
;
247 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
248 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
249 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
252 if (mask
& GL_ENABLE_BIT
) {
253 struct gl_enable_attrib
*attr
;
255 attr
= MALLOC_STRUCT( gl_enable_attrib
);
256 /* Copy enable flags from all other attributes into the enable struct. */
257 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
258 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
259 attr
->Blend
= ctx
->Color
.BlendEnabled
;
260 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
261 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
262 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
263 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
264 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
265 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
266 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
267 attr
->DepthTest
= ctx
->Depth
.Test
;
268 attr
->Dither
= ctx
->Color
.DitherFlag
;
269 attr
->Fog
= ctx
->Fog
.Enabled
;
270 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
271 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
273 attr
->Lighting
= ctx
->Light
.Enabled
;
274 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
275 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
276 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
277 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
278 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
279 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
280 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
281 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
282 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
283 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
284 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
285 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
286 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
287 memcpy(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
288 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
289 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
290 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
291 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
292 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
293 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
294 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
295 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
296 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
297 memcpy(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
298 attr
->Normalize
= ctx
->Transform
.Normalize
;
299 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
300 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
301 attr
->PointSprite
= ctx
->Point
.PointSprite
;
302 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
303 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
304 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
305 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
306 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
307 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
308 attr
->Scissor
= ctx
->Scissor
.Enabled
;
309 attr
->Stencil
= ctx
->Stencil
.Enabled
;
310 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
311 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
312 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
313 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
314 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
315 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
316 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
317 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
318 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
319 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
321 /* GL_NV_vertex_program */
322 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
323 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
324 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
325 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
328 if (mask
& GL_EVAL_BIT
) {
329 struct gl_eval_attrib
*attr
;
330 attr
= MALLOC_STRUCT( gl_eval_attrib
);
331 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
332 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
335 if (mask
& GL_FOG_BIT
) {
336 struct gl_fog_attrib
*attr
;
337 attr
= MALLOC_STRUCT( gl_fog_attrib
);
338 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
339 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
342 if (mask
& GL_HINT_BIT
) {
343 struct gl_hint_attrib
*attr
;
344 attr
= MALLOC_STRUCT( gl_hint_attrib
);
345 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
346 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
349 if (mask
& GL_LIGHTING_BIT
) {
350 struct gl_light_attrib
*attr
;
351 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
352 attr
= MALLOC_STRUCT( gl_light_attrib
);
353 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
354 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
357 if (mask
& GL_LINE_BIT
) {
358 struct gl_line_attrib
*attr
;
359 attr
= MALLOC_STRUCT( gl_line_attrib
);
360 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
361 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
364 if (mask
& GL_LIST_BIT
) {
365 struct gl_list_attrib
*attr
;
366 attr
= MALLOC_STRUCT( gl_list_attrib
);
367 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
368 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
371 if (mask
& GL_PIXEL_MODE_BIT
) {
372 struct gl_pixel_attrib
*attr
;
373 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
374 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
375 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
376 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
377 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
380 if (mask
& GL_POINT_BIT
) {
381 struct gl_point_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_point_attrib
);
383 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
384 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
387 if (mask
& GL_POLYGON_BIT
) {
388 struct gl_polygon_attrib
*attr
;
389 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
390 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
391 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
394 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
396 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
397 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
398 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
401 if (mask
& GL_SCISSOR_BIT
) {
402 struct gl_scissor_attrib
*attr
;
403 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
404 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
405 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
408 if (mask
& GL_STENCIL_BUFFER_BIT
) {
409 struct gl_stencil_attrib
*attr
;
410 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
411 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
412 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
415 if (mask
& GL_TEXTURE_BIT
) {
416 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
424 _mesa_lock_context_textures(ctx
);
426 /* copy/save the bulk of texture state here */
427 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
429 /* Save references to the currently bound texture objects so they don't
430 * accidentally get deleted while referenced in the attribute stack.
432 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
433 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
434 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
435 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
439 /* copy state/contents of the currently bound texture objects */
440 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
441 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
442 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
443 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
447 _mesa_unlock_context_textures(ctx
);
449 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
452 if (mask
& GL_TRANSFORM_BIT
) {
453 struct gl_transform_attrib
*attr
;
454 attr
= MALLOC_STRUCT( gl_transform_attrib
);
455 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
456 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
459 if (mask
& GL_VIEWPORT_BIT
) {
460 struct gl_viewport_attrib
*attr
;
461 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
462 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
463 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
466 /* GL_ARB_multisample */
467 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
468 struct gl_multisample_attrib
*attr
;
469 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
470 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
471 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
475 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
476 ctx
->AttribStackDepth
++;
482 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
484 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
487 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
488 if ((VALUE) != (NEWVALUE)) { \
489 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
492 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
493 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
494 if (ctx
->Extensions
.EXT_draw_buffers2
) {
496 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
497 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
501 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
505 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
506 const GLuint mask
= 1 << i
;
507 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
508 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
509 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
512 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
514 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
515 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
517 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
518 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
519 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
521 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
523 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
525 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
526 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
527 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
528 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
530 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
532 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
537 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
538 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
539 GL_MAP1_TEXTURE_COORD_1
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
541 GL_MAP1_TEXTURE_COORD_2
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
543 GL_MAP1_TEXTURE_COORD_3
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
545 GL_MAP1_TEXTURE_COORD_4
);
546 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
548 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
550 for (i
= 0; i
< 16; i
++) {
551 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
552 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
555 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
556 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
557 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
558 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
559 GL_MAP2_TEXTURE_COORD_1
);
560 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
561 GL_MAP2_TEXTURE_COORD_2
);
562 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
563 GL_MAP2_TEXTURE_COORD_3
);
564 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
565 GL_MAP2_TEXTURE_COORD_4
);
566 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
568 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
570 for (i
= 0; i
< 16; i
++) {
571 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
572 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
575 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
576 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
577 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
578 GL_RESCALE_NORMAL_EXT
);
579 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
580 enable
->RasterPositionUnclipped
,
581 GL_RASTER_POSITION_UNCLIPPED_IBM
);
582 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
584 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
585 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
588 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
589 GL_POLYGON_OFFSET_POINT
);
590 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
591 GL_POLYGON_OFFSET_LINE
);
592 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
593 GL_POLYGON_OFFSET_FILL
);
594 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
596 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
598 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
599 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
600 if (ctx
->Extensions
.EXT_stencil_two_side
) {
601 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
603 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
605 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
606 enable
->SampleAlphaToCoverage
,
607 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
608 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
609 enable
->SampleAlphaToOne
,
610 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
611 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
612 enable
->SampleCoverage
,
613 GL_SAMPLE_COVERAGE_ARB
);
614 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
615 enable
->SampleCoverageInvert
,
616 GL_SAMPLE_COVERAGE_INVERT_ARB
);
617 /* GL_ARB_vertex_program, GL_NV_vertex_program */
618 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
619 enable
->VertexProgram
,
620 GL_VERTEX_PROGRAM_ARB
);
621 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
622 enable
->VertexProgramPointSize
,
623 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
624 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
625 enable
->VertexProgramTwoSide
,
626 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
628 #undef TEST_AND_UPDATE
630 /* texture unit enables */
631 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
632 const GLbitfield enabled
= enable
->Texture
[i
];
633 const GLbitfield genEnabled
= enable
->TexGen
[i
];
635 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
636 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
638 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
639 (enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
640 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
641 (enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
642 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
643 (enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
644 if (ctx
->Extensions
.NV_texture_rectangle
) {
645 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
646 (enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
648 if (ctx
->Extensions
.ARB_texture_cube_map
) {
649 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
650 (enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
652 if (ctx
->Extensions
.MESA_texture_array
) {
653 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
654 (enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
655 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
656 (enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
660 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
661 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
662 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
663 (genEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
);
664 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
665 (genEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
);
666 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
667 (genEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
);
668 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
669 (genEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
);
672 /* GL_SGI_texture_color_table */
673 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
676 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
681 * Pop/restore texture attribute/group state.
684 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
688 _mesa_lock_context_textures(ctx
);
690 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
691 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
694 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
695 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
696 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
697 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
698 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
699 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
700 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
701 if (ctx
->Extensions
.ARB_texture_cube_map
) {
702 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
703 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
705 if (ctx
->Extensions
.NV_texture_rectangle
) {
706 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
707 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
709 if (ctx
->Extensions
.MESA_texture_array
) {
710 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
711 (unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
713 (unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
) ? GL_TRUE
: GL_FALSE
);
716 if (ctx
->Extensions
.SGI_texture_color_table
) {
717 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
718 unit
->ColorTableEnabled
);
720 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
721 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
722 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
723 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
724 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
725 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
726 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
727 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
728 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
729 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
730 /* Eye plane done differently to avoid re-transformation */
732 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
733 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
734 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
735 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
736 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
737 if (ctx
->Driver
.TexGen
) {
738 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
739 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
740 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
741 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
744 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
745 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
746 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
747 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
748 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
749 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
750 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
751 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
752 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
753 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
754 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
756 if (ctx
->Extensions
.EXT_texture_env_combine
||
757 ctx
->Extensions
.ARB_texture_env_combine
) {
758 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
759 unit
->Combine
.ModeRGB
);
760 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
761 unit
->Combine
.ModeA
);
762 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
763 unit
->Combine
.SourceRGB
[0]);
764 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
765 unit
->Combine
.SourceRGB
[1]);
766 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
767 unit
->Combine
.SourceRGB
[2]);
768 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
769 unit
->Combine
.SourceA
[0]);
770 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
771 unit
->Combine
.SourceA
[1]);
772 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
773 unit
->Combine
.SourceA
[2]);
774 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
775 unit
->Combine
.OperandRGB
[0]);
776 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
777 unit
->Combine
.OperandRGB
[1]);
778 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
779 unit
->Combine
.OperandRGB
[2]);
780 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
781 unit
->Combine
.OperandA
[0]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
783 unit
->Combine
.OperandA
[1]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
785 unit
->Combine
.OperandA
[2]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
787 1 << unit
->Combine
.ScaleShiftRGB
);
788 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
789 1 << unit
->Combine
.ScaleShiftA
);
792 /* Restore texture object state for each target */
793 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
794 const struct gl_texture_object
*obj
= NULL
;
797 obj
= &texstate
->SavedObj
[u
][tgt
];
799 /* don't restore state for unsupported targets to prevent
802 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
803 !ctx
->Extensions
.ARB_texture_cube_map
) {
806 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
807 !ctx
->Extensions
.NV_texture_rectangle
) {
810 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
811 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
812 !ctx
->Extensions
.MESA_texture_array
) {
816 target
= obj
->Target
;
818 _mesa_BindTexture(target
, obj
->Name
);
820 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, obj
->BorderColor
.f
);
821 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
822 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
823 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
824 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
825 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
826 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
827 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
828 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
829 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
830 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
831 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
832 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
833 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
834 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
837 if (ctx
->Extensions
.ARB_shadow_ambient
) {
838 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
839 obj
->CompareFailValue
);
843 /* remove saved references to the texture objects */
844 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
845 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
849 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
851 _mesa_unlock_context_textures(ctx
);
856 * This function is kind of long just because we have to call a lot
857 * of device driver functions to update device driver state.
859 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
860 * in order to restore GL state. This isn't terribly efficient but it
861 * ensures that dirty flags and any derived state gets updated correctly.
862 * We could at least check if the value to restore equals the current value
863 * and then skip the Mesa call.
866 _mesa_PopAttrib(void)
868 struct gl_attrib_node
*attr
, *next
;
869 GET_CURRENT_CONTEXT(ctx
);
870 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
872 if (ctx
->AttribStackDepth
== 0) {
873 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
877 ctx
->AttribStackDepth
--;
878 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
882 if (MESA_VERBOSE
& VERBOSE_API
) {
883 _mesa_debug(ctx
, "glPopAttrib %s\n",
884 _mesa_lookup_enum_by_nr(attr
->kind
));
887 switch (attr
->kind
) {
888 case GL_ACCUM_BUFFER_BIT
:
890 const struct gl_accum_attrib
*accum
;
891 accum
= (const struct gl_accum_attrib
*) attr
->data
;
892 _mesa_ClearAccum(accum
->ClearColor
[0],
893 accum
->ClearColor
[1],
894 accum
->ClearColor
[2],
895 accum
->ClearColor
[3]);
898 case GL_COLOR_BUFFER_BIT
:
900 const struct gl_colorbuffer_attrib
*color
;
902 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
903 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
904 _mesa_ClearColor(color
->ClearColor
[0],
905 color
->ClearColor
[1],
906 color
->ClearColor
[2],
907 color
->ClearColor
[3]);
908 _mesa_IndexMask(color
->IndexMask
);
909 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
910 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
911 (GLboolean
) (color
->ColorMask
[0][1] != 0),
912 (GLboolean
) (color
->ColorMask
[0][2] != 0),
913 (GLboolean
) (color
->ColorMask
[0][3] != 0));
917 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
918 _mesa_ColorMaskIndexed(i
,
919 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
920 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
921 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
922 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
926 /* Need to determine if more than one color output is
927 * specified. If so, call glDrawBuffersARB, else call
928 * glDrawBuffer(). This is a subtle, but essential point
929 * since GL_FRONT (for example) is illegal for the former
930 * function, but legal for the later.
932 GLboolean multipleBuffers
= GL_FALSE
;
935 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
936 if (color
->DrawBuffer
[i
] != GL_NONE
) {
937 multipleBuffers
= GL_TRUE
;
941 /* Call the API_level functions, not _mesa_drawbuffers()
942 * since we need to do error checking on the pop'd
944 * Ex: if GL_FRONT were pushed, but we're popping with a
945 * user FBO bound, GL_FRONT will be illegal and we'll need
946 * to record that error. Per OpenGL ARB decision.
949 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
952 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
954 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
955 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
956 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
957 if (ctx
->Extensions
.EXT_draw_buffers2
) {
959 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
960 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
961 (color
->BlendEnabled
>> i
) & 1);
965 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
968 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
972 /* This special case is because glBlendEquationSeparateEXT
973 * cannot take GL_LOGIC_OP as a parameter.
975 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
976 _mesa_BlendEquation(color
->BlendEquationRGB
);
979 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
980 color
->BlendEquationA
);
982 _mesa_BlendColor(color
->BlendColor
[0],
983 color
->BlendColor
[1],
984 color
->BlendColor
[2],
985 color
->BlendColor
[3]);
986 _mesa_LogicOp(color
->LogicOp
);
987 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
988 color
->ColorLogicOpEnabled
);
989 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
990 color
->IndexLogicOpEnabled
);
991 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
995 FLUSH_CURRENT( ctx
, 0 );
996 memcpy( &ctx
->Current
, attr
->data
,
997 sizeof(struct gl_current_attrib
) );
999 case GL_DEPTH_BUFFER_BIT
:
1001 const struct gl_depthbuffer_attrib
*depth
;
1002 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1003 _mesa_DepthFunc(depth
->Func
);
1004 _mesa_ClearDepth(depth
->Clear
);
1005 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1006 _mesa_DepthMask(depth
->Mask
);
1011 const struct gl_enable_attrib
*enable
;
1012 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1013 pop_enable_group(ctx
, enable
);
1014 ctx
->NewState
|= _NEW_ALL
;
1018 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1019 ctx
->NewState
|= _NEW_EVAL
;
1023 const struct gl_fog_attrib
*fog
;
1024 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1025 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1026 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1027 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1028 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1029 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1030 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1031 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1036 const struct gl_hint_attrib
*hint
;
1037 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1038 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1039 hint
->PerspectiveCorrection
);
1040 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1041 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1042 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1043 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1044 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1045 hint
->ClipVolumeClipping
);
1046 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1047 hint
->TextureCompression
);
1050 case GL_LIGHTING_BIT
:
1053 const struct gl_light_attrib
*light
;
1054 light
= (const struct gl_light_attrib
*) attr
->data
;
1055 /* lighting enable */
1056 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1057 /* per-light state */
1058 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1059 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1061 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1062 const struct gl_light
*l
= &light
->Light
[i
];
1063 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1064 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1065 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1066 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1067 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1068 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1070 GLfloat p
[4] = { 0 };
1071 p
[0] = l
->SpotExponent
;
1072 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1075 GLfloat p
[4] = { 0 };
1076 p
[0] = l
->SpotCutoff
;
1077 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1080 GLfloat p
[4] = { 0 };
1081 p
[0] = l
->ConstantAttenuation
;
1082 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1085 GLfloat p
[4] = { 0 };
1086 p
[0] = l
->LinearAttenuation
;
1087 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1090 GLfloat p
[4] = { 0 };
1091 p
[0] = l
->QuadraticAttenuation
;
1092 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1096 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1097 light
->Model
.Ambient
);
1098 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1099 (GLfloat
) light
->Model
.LocalViewer
);
1100 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1101 (GLfloat
) light
->Model
.TwoSide
);
1102 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1103 (GLfloat
) light
->Model
.ColorControl
);
1105 _mesa_ShadeModel(light
->ShadeModel
);
1106 /* color material */
1107 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1108 light
->ColorMaterialMode
);
1109 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1110 light
->ColorMaterialEnabled
);
1112 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1113 sizeof(struct gl_material
));
1118 const struct gl_line_attrib
*line
;
1119 line
= (const struct gl_line_attrib
*) attr
->data
;
1120 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1121 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1122 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1123 _mesa_LineWidth(line
->Width
);
1127 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1129 case GL_PIXEL_MODE_BIT
:
1130 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1131 /* XXX what other pixel state needs to be set by function calls? */
1132 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1133 ctx
->NewState
|= _NEW_PIXEL
;
1137 const struct gl_point_attrib
*point
;
1138 point
= (const struct gl_point_attrib
*) attr
->data
;
1139 _mesa_PointSize(point
->Size
);
1140 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1141 if (ctx
->Extensions
.EXT_point_parameters
) {
1142 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1144 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1146 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1148 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1151 if (ctx
->Extensions
.NV_point_sprite
1152 || ctx
->Extensions
.ARB_point_sprite
) {
1154 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1155 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1156 (GLint
) point
->CoordReplace
[u
]);
1158 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1159 if (ctx
->Extensions
.NV_point_sprite
)
1160 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1161 ctx
->Point
.SpriteRMode
);
1162 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1163 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1167 case GL_POLYGON_BIT
:
1169 const struct gl_polygon_attrib
*polygon
;
1170 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1171 _mesa_CullFace(polygon
->CullFaceMode
);
1172 _mesa_FrontFace(polygon
->FrontFace
);
1173 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1174 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1175 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1176 polygon
->OffsetUnits
);
1177 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1178 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1179 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1180 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1181 polygon
->OffsetPoint
);
1182 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1183 polygon
->OffsetLine
);
1184 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1185 polygon
->OffsetFill
);
1188 case GL_POLYGON_STIPPLE_BIT
:
1189 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1190 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1191 if (ctx
->Driver
.PolygonStipple
)
1192 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1194 case GL_SCISSOR_BIT
:
1196 const struct gl_scissor_attrib
*scissor
;
1197 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1198 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1199 scissor
->Width
, scissor
->Height
);
1200 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1203 case GL_STENCIL_BUFFER_BIT
:
1205 const struct gl_stencil_attrib
*stencil
;
1206 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1207 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1208 _mesa_ClearStencil(stencil
->Clear
);
1209 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1210 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1211 stencil
->TestTwoSide
);
1212 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1213 ? GL_BACK
: GL_FRONT
);
1216 _mesa_StencilFuncSeparate(GL_FRONT
,
1217 stencil
->Function
[0],
1219 stencil
->ValueMask
[0]);
1220 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1221 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1222 stencil
->ZFailFunc
[0],
1223 stencil
->ZPassFunc
[0]);
1225 _mesa_StencilFuncSeparate(GL_BACK
,
1226 stencil
->Function
[1],
1228 stencil
->ValueMask
[1]);
1229 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1230 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1231 stencil
->ZFailFunc
[1],
1232 stencil
->ZPassFunc
[1]);
1235 case GL_TRANSFORM_BIT
:
1238 const struct gl_transform_attrib
*xform
;
1239 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1240 _mesa_MatrixMode(xform
->MatrixMode
);
1241 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1242 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1244 /* restore clip planes */
1245 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1246 const GLuint mask
= 1 << i
;
1247 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1248 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1249 if (xform
->ClipPlanesEnabled
& mask
) {
1250 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1253 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1255 if (ctx
->Driver
.ClipPlane
)
1256 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1259 /* normalize/rescale */
1260 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1261 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1262 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1263 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1264 ctx
->Transform
.RescaleNormals
);
1265 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1266 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1267 ctx
->Transform
.DepthClamp
);
1270 case GL_TEXTURE_BIT
:
1271 /* Take care of texture object reference counters */
1273 struct texture_state
*texstate
1274 = (struct texture_state
*) attr
->data
;
1275 pop_texture_group(ctx
, texstate
);
1276 ctx
->NewState
|= _NEW_TEXTURE
;
1279 case GL_VIEWPORT_BIT
:
1281 const struct gl_viewport_attrib
*vp
;
1282 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1283 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1284 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1287 case GL_MULTISAMPLE_BIT_ARB
:
1289 const struct gl_multisample_attrib
*ms
;
1290 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1291 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1292 ms
->SampleCoverageInvert
);
1297 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1310 * Helper for incrementing/decrementing vertex buffer object reference
1311 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1314 adjust_buffer_object_ref_counts(struct gl_array_object
*arrayObj
, GLint step
)
1318 arrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1319 arrayObj
->Weight
.BufferObj
->RefCount
+= step
;
1320 arrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1321 arrayObj
->Color
.BufferObj
->RefCount
+= step
;
1322 arrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1323 arrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1324 arrayObj
->Index
.BufferObj
->RefCount
+= step
;
1325 arrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1326 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1327 arrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1328 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1329 arrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1334 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1338 copy_pixelstore(GLcontext
*ctx
,
1339 struct gl_pixelstore_attrib
*dst
,
1340 const struct gl_pixelstore_attrib
*src
)
1342 dst
->Alignment
= src
->Alignment
;
1343 dst
->RowLength
= src
->RowLength
;
1344 dst
->SkipPixels
= src
->SkipPixels
;
1345 dst
->SkipRows
= src
->SkipRows
;
1346 dst
->ImageHeight
= src
->ImageHeight
;
1347 dst
->SkipImages
= src
->SkipImages
;
1348 dst
->SwapBytes
= src
->SwapBytes
;
1349 dst
->LsbFirst
= src
->LsbFirst
;
1350 dst
->ClientStorage
= src
->ClientStorage
;
1351 dst
->Invert
= src
->Invert
;
1352 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1356 #define GL_CLIENT_PACK_BIT (1<<20)
1357 #define GL_CLIENT_UNPACK_BIT (1<<21)
1361 _mesa_PushClientAttrib(GLbitfield mask
)
1363 struct gl_attrib_node
*head
;
1365 GET_CURRENT_CONTEXT(ctx
);
1366 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1368 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1369 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1373 /* Build linked list of attribute nodes which save all attribute
1374 * groups specified by the mask.
1378 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1379 struct gl_pixelstore_attrib
*attr
;
1380 /* packing attribs */
1381 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1382 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1383 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1384 /* unpacking attribs */
1385 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1386 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1387 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1390 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1391 struct gl_array_attrib
*attr
;
1392 struct gl_array_object
*obj
;
1394 attr
= MALLOC_STRUCT( gl_array_attrib
);
1395 obj
= MALLOC_STRUCT( gl_array_object
);
1397 #if FEATURE_ARB_vertex_buffer_object
1398 /* increment ref counts since we're copying pointers to these objects */
1399 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1400 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1403 memcpy( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1404 memcpy( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1406 attr
->ArrayObj
= obj
;
1408 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1410 /* bump reference counts on buffer objects */
1411 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, 1);
1414 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1415 ctx
->ClientAttribStackDepth
++;
1422 _mesa_PopClientAttrib(void)
1424 struct gl_attrib_node
*node
, *next
;
1426 GET_CURRENT_CONTEXT(ctx
);
1427 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1429 if (ctx
->ClientAttribStackDepth
== 0) {
1430 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1434 ctx
->ClientAttribStackDepth
--;
1435 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1438 switch (node
->kind
) {
1439 case GL_CLIENT_PACK_BIT
:
1441 struct gl_pixelstore_attrib
*store
=
1442 (struct gl_pixelstore_attrib
*) node
->data
;
1443 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1444 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1446 ctx
->NewState
|= _NEW_PACKUNPACK
;
1448 case GL_CLIENT_UNPACK_BIT
:
1450 struct gl_pixelstore_attrib
*store
=
1451 (struct gl_pixelstore_attrib
*) node
->data
;
1452 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1453 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1455 ctx
->NewState
|= _NEW_PACKUNPACK
;
1457 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1458 struct gl_array_attrib
* data
=
1459 (struct gl_array_attrib
*) node
->data
;
1461 adjust_buffer_object_ref_counts(ctx
->Array
.ArrayObj
, -1);
1463 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1464 if (data
->LockCount
!= 0)
1465 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1466 else if (ctx
->Array
.LockCount
)
1467 _mesa_UnlockArraysEXT();
1469 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1471 #if FEATURE_ARB_vertex_buffer_object
1472 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1473 data
->ArrayBufferObj
->Name
);
1474 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1475 data
->ElementArrayBufferObj
->Name
);
1478 memcpy( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1479 sizeof( struct gl_array_object
) );
1481 FREE( data
->ArrayObj
);
1483 /* FIXME: Should some bits in ctx->Array->NewState also be set
1484 * FIXME: here? It seems like it should be set to inclusive-or
1485 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1488 ctx
->NewState
|= _NEW_ARRAY
;
1492 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1505 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1507 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1508 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1509 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1510 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1514 #endif /* FEATURE_attrib_stack */
1518 * Free any attribute state data that might be attached to the context.
1521 _mesa_free_attrib_data(GLcontext
*ctx
)
1523 while (ctx
->AttribStackDepth
> 0) {
1524 struct gl_attrib_node
*attr
, *next
;
1526 ctx
->AttribStackDepth
--;
1527 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1530 if (attr
->kind
== GL_TEXTURE_BIT
) {
1531 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1533 /* clear references to the saved texture objects */
1534 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1535 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1536 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1541 /* any other chunks of state that requires special handling? */
1553 void _mesa_init_attrib( GLcontext
*ctx
)
1555 /* Renderer and client attribute stacks */
1556 ctx
->AttribStackDepth
= 0;
1557 ctx
->ClientAttribStackDepth
= 0;