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 "mfeatures.h"
47 #include "multisample.h"
60 #include "main/dispatch.h"
64 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
66 struct gl_enable_attrib
71 GLbitfield ClipPlanes
;
72 GLboolean ColorMaterial
;
78 GLboolean Light
[MAX_LIGHTS
];
81 GLboolean LineStipple
;
82 GLboolean IndexLogicOp
;
83 GLboolean ColorLogicOp
;
88 GLboolean Map1TextureCoord1
;
89 GLboolean Map1TextureCoord2
;
90 GLboolean Map1TextureCoord3
;
91 GLboolean Map1TextureCoord4
;
92 GLboolean Map1Vertex3
;
93 GLboolean Map1Vertex4
;
94 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
98 GLboolean Map2TextureCoord1
;
99 GLboolean Map2TextureCoord2
;
100 GLboolean Map2TextureCoord3
;
101 GLboolean Map2TextureCoord4
;
102 GLboolean Map2Vertex3
;
103 GLboolean Map2Vertex4
;
104 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
107 GLboolean PixelTexture
;
108 GLboolean PointSmooth
;
109 GLboolean PolygonOffsetPoint
;
110 GLboolean PolygonOffsetLine
;
111 GLboolean PolygonOffsetFill
;
112 GLboolean PolygonSmooth
;
113 GLboolean PolygonStipple
;
114 GLboolean RescaleNormals
;
117 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
118 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
119 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
120 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
121 GLboolean SampleCoverage
; /* GL_ARB_multisample */
122 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
123 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
125 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
126 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
128 /* GL_ARB_vertex_program / GL_NV_vertex_program */
129 GLboolean VertexProgram
;
130 GLboolean VertexProgramPointSize
;
131 GLboolean VertexProgramTwoSide
;
133 /* GL_ARB_point_sprite / GL_NV_point_sprite */
134 GLboolean PointSprite
;
135 GLboolean FragmentShaderATI
;
140 * Node for the attribute stack.
142 struct gl_attrib_node
146 struct gl_attrib_node
*next
;
152 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
156 struct gl_texture_attrib Texture
; /**< The usual context state */
158 /** to save per texture object state (wrap modes, filters, etc): */
159 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
162 * To save references to texture objects (so they don't get accidentally
163 * deleted while saved in the attribute stack).
165 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
169 #if FEATURE_attrib_stack
173 * Allocate new attribute node of given type/kind. Attach payload data.
174 * Insert it into the linked list named by 'head'.
177 save_attrib_data(struct gl_attrib_node
**head
,
178 GLbitfield kind
, void *payload
)
180 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
195 _mesa_PushAttrib(GLbitfield mask
)
197 struct gl_attrib_node
*head
;
199 GET_CURRENT_CONTEXT(ctx
);
200 ASSERT_OUTSIDE_BEGIN_END(ctx
);
202 if (MESA_VERBOSE
& VERBOSE_API
)
203 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
205 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
206 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
210 /* Build linked list of attribute nodes which save all attribute */
211 /* groups specified by the mask. */
214 if (mask
& GL_ACCUM_BUFFER_BIT
) {
215 struct gl_accum_attrib
*attr
;
216 attr
= MALLOC_STRUCT( gl_accum_attrib
);
217 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
218 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
221 if (mask
& GL_COLOR_BUFFER_BIT
) {
223 struct gl_colorbuffer_attrib
*attr
;
224 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
225 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
226 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
227 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
228 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
229 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
232 if (mask
& GL_CURRENT_BIT
) {
233 struct gl_current_attrib
*attr
;
234 FLUSH_CURRENT( ctx
, 0 );
235 attr
= MALLOC_STRUCT( gl_current_attrib
);
236 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
237 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
240 if (mask
& GL_DEPTH_BUFFER_BIT
) {
241 struct gl_depthbuffer_attrib
*attr
;
242 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
243 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
244 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
247 if (mask
& GL_ENABLE_BIT
) {
248 struct gl_enable_attrib
*attr
;
250 attr
= MALLOC_STRUCT( gl_enable_attrib
);
251 /* Copy enable flags from all other attributes into the enable struct. */
252 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
253 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
254 attr
->Blend
= ctx
->Color
.BlendEnabled
;
255 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
256 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
257 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
258 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
259 attr
->DepthTest
= ctx
->Depth
.Test
;
260 attr
->Dither
= ctx
->Color
.DitherFlag
;
261 attr
->Fog
= ctx
->Fog
.Enabled
;
262 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
263 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
265 attr
->Lighting
= ctx
->Light
.Enabled
;
266 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
267 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
268 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
269 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
270 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
271 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
272 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
273 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
274 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
275 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
276 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
277 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
278 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
279 memcpy(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
280 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
281 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
282 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
283 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
284 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
285 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
286 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
287 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
288 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
289 memcpy(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
290 attr
->Normalize
= ctx
->Transform
.Normalize
;
291 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
292 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
293 attr
->PointSprite
= ctx
->Point
.PointSprite
;
294 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
295 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
296 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
297 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
298 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
299 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
300 attr
->Scissor
= ctx
->Scissor
.Enabled
;
301 attr
->Stencil
= ctx
->Stencil
.Enabled
;
302 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
303 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
304 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
305 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
306 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
307 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
308 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
309 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
310 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
312 /* GL_NV_vertex_program */
313 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
314 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
315 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
316 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
319 if (mask
& GL_EVAL_BIT
) {
320 struct gl_eval_attrib
*attr
;
321 attr
= MALLOC_STRUCT( gl_eval_attrib
);
322 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
323 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
326 if (mask
& GL_FOG_BIT
) {
327 struct gl_fog_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_fog_attrib
);
329 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
330 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
333 if (mask
& GL_HINT_BIT
) {
334 struct gl_hint_attrib
*attr
;
335 attr
= MALLOC_STRUCT( gl_hint_attrib
);
336 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
337 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
340 if (mask
& GL_LIGHTING_BIT
) {
341 struct gl_light_attrib
*attr
;
342 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
343 attr
= MALLOC_STRUCT( gl_light_attrib
);
344 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
345 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
348 if (mask
& GL_LINE_BIT
) {
349 struct gl_line_attrib
*attr
;
350 attr
= MALLOC_STRUCT( gl_line_attrib
);
351 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
352 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
355 if (mask
& GL_LIST_BIT
) {
356 struct gl_list_attrib
*attr
;
357 attr
= MALLOC_STRUCT( gl_list_attrib
);
358 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
359 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
362 if (mask
& GL_PIXEL_MODE_BIT
) {
363 struct gl_pixel_attrib
*attr
;
364 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
365 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
366 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
367 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
368 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
371 if (mask
& GL_POINT_BIT
) {
372 struct gl_point_attrib
*attr
;
373 attr
= MALLOC_STRUCT( gl_point_attrib
);
374 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
375 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
378 if (mask
& GL_POLYGON_BIT
) {
379 struct gl_polygon_attrib
*attr
;
380 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
381 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
382 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
385 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
387 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
388 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
389 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
392 if (mask
& GL_SCISSOR_BIT
) {
393 struct gl_scissor_attrib
*attr
;
394 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
395 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
396 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
399 if (mask
& GL_STENCIL_BUFFER_BIT
) {
400 struct gl_stencil_attrib
*attr
;
401 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
402 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
403 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
406 if (mask
& GL_TEXTURE_BIT
) {
407 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
411 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
415 _mesa_lock_context_textures(ctx
);
417 /* copy/save the bulk of texture state here */
418 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
420 /* Save references to the currently bound texture objects so they don't
421 * accidentally get deleted while referenced in the attribute stack.
423 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
424 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
425 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
426 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
430 /* copy state/contents of the currently bound texture objects */
431 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
432 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
433 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
434 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
438 _mesa_unlock_context_textures(ctx
);
440 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
443 if (mask
& GL_TRANSFORM_BIT
) {
444 struct gl_transform_attrib
*attr
;
445 attr
= MALLOC_STRUCT( gl_transform_attrib
);
446 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
447 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
450 if (mask
& GL_VIEWPORT_BIT
) {
451 struct gl_viewport_attrib
*attr
;
452 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
453 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
454 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
457 /* GL_ARB_multisample */
458 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
459 struct gl_multisample_attrib
*attr
;
460 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
461 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
462 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
466 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
467 ctx
->AttribStackDepth
++;
473 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
475 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
478 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
479 if ((VALUE) != (NEWVALUE)) { \
480 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
483 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
484 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
485 if (ctx
->Extensions
.EXT_draw_buffers2
) {
487 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
488 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
492 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
496 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
497 const GLuint mask
= 1 << i
;
498 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
499 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
500 !!(enable
->ClipPlanes
& mask
));
503 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
505 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
506 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
508 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
509 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
510 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
511 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
512 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
513 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
515 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
517 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
520 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
521 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
522 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
524 GL_MAP1_TEXTURE_COORD_1
);
525 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
526 GL_MAP1_TEXTURE_COORD_2
);
527 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
528 GL_MAP1_TEXTURE_COORD_3
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
530 GL_MAP1_TEXTURE_COORD_4
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
533 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
535 for (i
= 0; i
< 16; i
++) {
536 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
537 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
540 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
541 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
544 GL_MAP2_TEXTURE_COORD_1
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
546 GL_MAP2_TEXTURE_COORD_2
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
548 GL_MAP2_TEXTURE_COORD_3
);
549 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
550 GL_MAP2_TEXTURE_COORD_4
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
553 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
555 for (i
= 0; i
< 16; i
++) {
556 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
557 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
560 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
561 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
562 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
563 GL_RESCALE_NORMAL_EXT
);
564 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
565 enable
->RasterPositionUnclipped
,
566 GL_RASTER_POSITION_UNCLIPPED_IBM
);
567 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
569 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
570 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
573 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
574 GL_POLYGON_OFFSET_POINT
);
575 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
576 GL_POLYGON_OFFSET_LINE
);
577 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
578 GL_POLYGON_OFFSET_FILL
);
579 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
581 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
583 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
584 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
585 if (ctx
->Extensions
.EXT_stencil_two_side
) {
586 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
588 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
590 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
591 enable
->SampleAlphaToCoverage
,
592 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
593 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
594 enable
->SampleAlphaToOne
,
595 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
596 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
597 enable
->SampleCoverage
,
598 GL_SAMPLE_COVERAGE_ARB
);
599 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
600 enable
->SampleCoverageInvert
,
601 GL_SAMPLE_COVERAGE_INVERT_ARB
);
602 /* GL_ARB_vertex_program, GL_NV_vertex_program */
603 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
604 enable
->VertexProgram
,
605 GL_VERTEX_PROGRAM_ARB
);
606 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
607 enable
->VertexProgramPointSize
,
608 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
609 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
610 enable
->VertexProgramTwoSide
,
611 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
613 #undef TEST_AND_UPDATE
615 /* texture unit enables */
616 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
617 const GLbitfield enabled
= enable
->Texture
[i
];
618 const GLbitfield genEnabled
= enable
->TexGen
[i
];
620 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
621 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
623 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
624 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
625 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
626 if (ctx
->Extensions
.NV_texture_rectangle
) {
627 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
628 !!(enabled
& TEXTURE_RECT_BIT
));
630 if (ctx
->Extensions
.ARB_texture_cube_map
) {
631 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
632 !!(enabled
& TEXTURE_CUBE_BIT
));
634 if (ctx
->Extensions
.MESA_texture_array
) {
635 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
636 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
637 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
638 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
642 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
643 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
644 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
645 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
646 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
647 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
651 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
656 * Pop/restore texture attribute/group state.
659 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
663 _mesa_lock_context_textures(ctx
);
665 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
666 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
669 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
670 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
671 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
672 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
673 if (ctx
->Extensions
.ARB_texture_cube_map
) {
674 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
675 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
677 if (ctx
->Extensions
.NV_texture_rectangle
) {
678 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
679 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
681 if (ctx
->Extensions
.MESA_texture_array
) {
682 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
683 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
684 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
685 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
688 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
689 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
690 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
691 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
692 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
693 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
694 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
695 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
696 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
697 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
698 /* Eye plane done differently to avoid re-transformation */
700 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
701 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
702 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
703 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
704 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
705 if (ctx
->Driver
.TexGen
) {
706 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
707 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
708 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
709 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
712 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
713 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
714 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
715 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
716 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
718 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
719 unit
->Combine
.ModeRGB
);
720 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
721 unit
->Combine
.ModeA
);
723 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
725 for (i
= 0; i
< n
; i
++) {
726 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
727 unit
->Combine
.SourceRGB
[i
]);
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
729 unit
->Combine
.SourceA
[i
]);
730 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
731 unit
->Combine
.OperandRGB
[i
]);
732 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
733 unit
->Combine
.OperandA
[i
]);
736 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
737 1 << unit
->Combine
.ScaleShiftRGB
);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
739 1 << unit
->Combine
.ScaleShiftA
);
741 /* Restore texture object state for each target */
742 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
743 const struct gl_texture_object
*obj
= NULL
;
744 const struct gl_sampler_object
*samp
;
747 obj
= &texstate
->SavedObj
[u
][tgt
];
749 /* don't restore state for unsupported targets to prevent
752 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
753 !ctx
->Extensions
.ARB_texture_cube_map
) {
756 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
757 !ctx
->Extensions
.NV_texture_rectangle
) {
760 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
761 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
762 !ctx
->Extensions
.MESA_texture_array
) {
765 else if (obj
->Target
== GL_TEXTURE_BUFFER
)
767 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
770 target
= obj
->Target
;
772 _mesa_BindTexture(target
, obj
->Name
);
774 samp
= &obj
->Sampler
;
776 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
777 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
778 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
779 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
780 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
781 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
782 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
783 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
784 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
785 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
786 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
787 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
788 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
789 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
790 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
791 samp
->MaxAnisotropy
);
793 if (ctx
->Extensions
.ARB_shadow_ambient
) {
794 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
795 samp
->CompareFailValue
);
799 /* remove saved references to the texture objects */
800 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
801 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
805 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
807 _mesa_unlock_context_textures(ctx
);
812 * This function is kind of long just because we have to call a lot
813 * of device driver functions to update device driver state.
815 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
816 * in order to restore GL state. This isn't terribly efficient but it
817 * ensures that dirty flags and any derived state gets updated correctly.
818 * We could at least check if the value to restore equals the current value
819 * and then skip the Mesa call.
822 _mesa_PopAttrib(void)
824 struct gl_attrib_node
*attr
, *next
;
825 GET_CURRENT_CONTEXT(ctx
);
826 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
828 if (ctx
->AttribStackDepth
== 0) {
829 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
833 ctx
->AttribStackDepth
--;
834 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
838 if (MESA_VERBOSE
& VERBOSE_API
) {
839 _mesa_debug(ctx
, "glPopAttrib %s\n",
840 _mesa_lookup_enum_by_nr(attr
->kind
));
843 switch (attr
->kind
) {
844 case GL_ACCUM_BUFFER_BIT
:
846 const struct gl_accum_attrib
*accum
;
847 accum
= (const struct gl_accum_attrib
*) attr
->data
;
848 _mesa_ClearAccum(accum
->ClearColor
[0],
849 accum
->ClearColor
[1],
850 accum
->ClearColor
[2],
851 accum
->ClearColor
[3]);
854 case GL_COLOR_BUFFER_BIT
:
856 const struct gl_colorbuffer_attrib
*color
;
858 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
859 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
860 _mesa_ClearColor(color
->ClearColor
.f
[0],
861 color
->ClearColor
.f
[1],
862 color
->ClearColor
.f
[2],
863 color
->ClearColor
.f
[3]);
864 _mesa_IndexMask(color
->IndexMask
);
865 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
866 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
867 (GLboolean
) (color
->ColorMask
[0][1] != 0),
868 (GLboolean
) (color
->ColorMask
[0][2] != 0),
869 (GLboolean
) (color
->ColorMask
[0][3] != 0));
873 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
874 _mesa_ColorMaskIndexed(i
,
875 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
876 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
877 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
878 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
882 /* Need to determine if more than one color output is
883 * specified. If so, call glDrawBuffersARB, else call
884 * glDrawBuffer(). This is a subtle, but essential point
885 * since GL_FRONT (for example) is illegal for the former
886 * function, but legal for the later.
888 GLboolean multipleBuffers
= GL_FALSE
;
891 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
892 if (color
->DrawBuffer
[i
] != GL_NONE
) {
893 multipleBuffers
= GL_TRUE
;
897 /* Call the API_level functions, not _mesa_drawbuffers()
898 * since we need to do error checking on the pop'd
900 * Ex: if GL_FRONT were pushed, but we're popping with a
901 * user FBO bound, GL_FRONT will be illegal and we'll need
902 * to record that error. Per OpenGL ARB decision.
905 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
908 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
910 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
911 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
912 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
913 if (ctx
->Extensions
.EXT_draw_buffers2
) {
915 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
916 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
917 (color
->BlendEnabled
>> i
) & 1);
921 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
924 if (ctx
->Color
._BlendFuncPerBuffer
||
925 ctx
->Color
._BlendEquationPerBuffer
) {
926 /* set blend per buffer */
928 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
929 _mesa_BlendFuncSeparatei(buf
, color
->Blend
[buf
].SrcRGB
,
930 color
->Blend
[buf
].DstRGB
,
931 color
->Blend
[buf
].SrcA
,
932 color
->Blend
[buf
].DstA
);
933 _mesa_BlendEquationSeparatei(buf
,
934 color
->Blend
[buf
].EquationRGB
,
935 color
->Blend
[buf
].EquationA
);
939 /* set same blend modes for all buffers */
940 _mesa_BlendFuncSeparateEXT(color
->Blend
[0].SrcRGB
,
941 color
->Blend
[0].DstRGB
,
942 color
->Blend
[0].SrcA
,
943 color
->Blend
[0].DstA
);
944 /* This special case is because glBlendEquationSeparateEXT
945 * cannot take GL_LOGIC_OP as a parameter.
947 if (color
->Blend
[0].EquationRGB
==
948 color
->Blend
[0].EquationA
) {
949 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
952 _mesa_BlendEquationSeparateEXT(
953 color
->Blend
[0].EquationRGB
,
954 color
->Blend
[0].EquationA
);
957 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
958 color
->BlendColorUnclamped
[1],
959 color
->BlendColorUnclamped
[2],
960 color
->BlendColorUnclamped
[3]);
961 _mesa_LogicOp(color
->LogicOp
);
962 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
963 color
->ColorLogicOpEnabled
);
964 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
965 color
->IndexLogicOpEnabled
);
966 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
967 _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
968 _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
972 FLUSH_CURRENT( ctx
, 0 );
973 memcpy( &ctx
->Current
, attr
->data
,
974 sizeof(struct gl_current_attrib
) );
976 case GL_DEPTH_BUFFER_BIT
:
978 const struct gl_depthbuffer_attrib
*depth
;
979 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
980 _mesa_DepthFunc(depth
->Func
);
981 _mesa_ClearDepth(depth
->Clear
);
982 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
983 _mesa_DepthMask(depth
->Mask
);
988 const struct gl_enable_attrib
*enable
;
989 enable
= (const struct gl_enable_attrib
*) attr
->data
;
990 pop_enable_group(ctx
, enable
);
991 ctx
->NewState
|= _NEW_ALL
;
995 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
996 ctx
->NewState
|= _NEW_EVAL
;
1000 const struct gl_fog_attrib
*fog
;
1001 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1002 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1003 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1004 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1005 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1006 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1007 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1008 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1013 const struct gl_hint_attrib
*hint
;
1014 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1015 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1016 hint
->PerspectiveCorrection
);
1017 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1018 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1019 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1020 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1021 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1022 hint
->ClipVolumeClipping
);
1023 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1024 hint
->TextureCompression
);
1027 case GL_LIGHTING_BIT
:
1030 const struct gl_light_attrib
*light
;
1031 light
= (const struct gl_light_attrib
*) attr
->data
;
1032 /* lighting enable */
1033 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1034 /* per-light state */
1035 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1036 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1038 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1039 const struct gl_light
*l
= &light
->Light
[i
];
1040 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1041 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1042 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1043 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1044 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1045 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1047 GLfloat p
[4] = { 0 };
1048 p
[0] = l
->SpotExponent
;
1049 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1052 GLfloat p
[4] = { 0 };
1053 p
[0] = l
->SpotCutoff
;
1054 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1057 GLfloat p
[4] = { 0 };
1058 p
[0] = l
->ConstantAttenuation
;
1059 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1062 GLfloat p
[4] = { 0 };
1063 p
[0] = l
->LinearAttenuation
;
1064 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1067 GLfloat p
[4] = { 0 };
1068 p
[0] = l
->QuadraticAttenuation
;
1069 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1073 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1074 light
->Model
.Ambient
);
1075 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1076 (GLfloat
) light
->Model
.LocalViewer
);
1077 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1078 (GLfloat
) light
->Model
.TwoSide
);
1079 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1080 (GLfloat
) light
->Model
.ColorControl
);
1082 _mesa_ShadeModel(light
->ShadeModel
);
1083 /* color material */
1084 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1085 light
->ColorMaterialMode
);
1086 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1087 light
->ColorMaterialEnabled
);
1089 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1090 sizeof(struct gl_material
));
1091 _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1096 const struct gl_line_attrib
*line
;
1097 line
= (const struct gl_line_attrib
*) attr
->data
;
1098 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1099 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1100 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1101 _mesa_LineWidth(line
->Width
);
1105 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1107 case GL_PIXEL_MODE_BIT
:
1108 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1109 /* XXX what other pixel state needs to be set by function calls? */
1110 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1111 ctx
->NewState
|= _NEW_PIXEL
;
1115 const struct gl_point_attrib
*point
;
1116 point
= (const struct gl_point_attrib
*) attr
->data
;
1117 _mesa_PointSize(point
->Size
);
1118 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1119 if (ctx
->Extensions
.EXT_point_parameters
) {
1120 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1122 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1124 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1126 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1129 if (ctx
->Extensions
.NV_point_sprite
1130 || ctx
->Extensions
.ARB_point_sprite
) {
1132 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1133 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1134 (GLint
) point
->CoordReplace
[u
]);
1136 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1137 if (ctx
->Extensions
.NV_point_sprite
)
1138 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1139 ctx
->Point
.SpriteRMode
);
1140 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1141 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1145 case GL_POLYGON_BIT
:
1147 const struct gl_polygon_attrib
*polygon
;
1148 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1149 _mesa_CullFace(polygon
->CullFaceMode
);
1150 _mesa_FrontFace(polygon
->FrontFace
);
1151 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1152 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1153 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1154 polygon
->OffsetUnits
);
1155 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1156 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1157 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1158 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1159 polygon
->OffsetPoint
);
1160 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1161 polygon
->OffsetLine
);
1162 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1163 polygon
->OffsetFill
);
1166 case GL_POLYGON_STIPPLE_BIT
:
1167 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1168 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1169 if (ctx
->Driver
.PolygonStipple
)
1170 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1172 case GL_SCISSOR_BIT
:
1174 const struct gl_scissor_attrib
*scissor
;
1175 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1176 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1177 scissor
->Width
, scissor
->Height
);
1178 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1181 case GL_STENCIL_BUFFER_BIT
:
1183 const struct gl_stencil_attrib
*stencil
;
1184 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1185 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1186 _mesa_ClearStencil(stencil
->Clear
);
1187 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1188 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1189 stencil
->TestTwoSide
);
1190 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1191 ? GL_BACK
: GL_FRONT
);
1194 _mesa_StencilFuncSeparate(GL_FRONT
,
1195 stencil
->Function
[0],
1197 stencil
->ValueMask
[0]);
1198 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1199 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1200 stencil
->ZFailFunc
[0],
1201 stencil
->ZPassFunc
[0]);
1203 _mesa_StencilFuncSeparate(GL_BACK
,
1204 stencil
->Function
[1],
1206 stencil
->ValueMask
[1]);
1207 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1208 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1209 stencil
->ZFailFunc
[1],
1210 stencil
->ZPassFunc
[1]);
1213 case GL_TRANSFORM_BIT
:
1216 const struct gl_transform_attrib
*xform
;
1217 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1218 _mesa_MatrixMode(xform
->MatrixMode
);
1219 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1220 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1222 /* restore clip planes */
1223 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1224 const GLuint mask
= 1 << i
;
1225 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1226 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1227 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1228 !!(xform
->ClipPlanesEnabled
& mask
));
1229 if (ctx
->Driver
.ClipPlane
)
1230 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1233 /* normalize/rescale */
1234 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1235 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1236 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1237 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1238 ctx
->Transform
.RescaleNormals
);
1239 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1240 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1241 ctx
->Transform
.DepthClamp
);
1244 case GL_TEXTURE_BIT
:
1245 /* Take care of texture object reference counters */
1247 struct texture_state
*texstate
1248 = (struct texture_state
*) attr
->data
;
1249 pop_texture_group(ctx
, texstate
);
1250 ctx
->NewState
|= _NEW_TEXTURE
;
1253 case GL_VIEWPORT_BIT
:
1255 const struct gl_viewport_attrib
*vp
;
1256 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1257 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1258 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1261 case GL_MULTISAMPLE_BIT_ARB
:
1263 const struct gl_multisample_attrib
*ms
;
1264 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1265 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1266 ms
->SampleCoverageInvert
);
1271 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1284 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1288 copy_pixelstore(struct gl_context
*ctx
,
1289 struct gl_pixelstore_attrib
*dst
,
1290 const struct gl_pixelstore_attrib
*src
)
1292 dst
->Alignment
= src
->Alignment
;
1293 dst
->RowLength
= src
->RowLength
;
1294 dst
->SkipPixels
= src
->SkipPixels
;
1295 dst
->SkipRows
= src
->SkipRows
;
1296 dst
->ImageHeight
= src
->ImageHeight
;
1297 dst
->SkipImages
= src
->SkipImages
;
1298 dst
->SwapBytes
= src
->SwapBytes
;
1299 dst
->LsbFirst
= src
->LsbFirst
;
1300 dst
->Invert
= src
->Invert
;
1301 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1305 #define GL_CLIENT_PACK_BIT (1<<20)
1306 #define GL_CLIENT_UNPACK_BIT (1<<21)
1309 * Copy gl_array_object from src to dest.
1310 * 'dest' must be in an initialized state.
1313 copy_array_object(struct gl_context
*ctx
,
1314 struct gl_array_object
*dest
,
1315 struct gl_array_object
*src
)
1322 /* In theory must be the same anyway, but on recreate make sure it matches */
1323 dest
->VBOonly
= src
->VBOonly
;
1325 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1326 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1328 /* _Enabled must be the same than on push */
1329 dest
->_Enabled
= src
->_Enabled
;
1330 dest
->_MaxElement
= src
->_MaxElement
;
1334 * Copy gl_array_attrib from src to dest.
1335 * 'dest' must be in an initialized state.
1338 copy_array_attrib(struct gl_context
*ctx
,
1339 struct gl_array_attrib
*dest
,
1340 struct gl_array_attrib
*src
)
1343 /* skip DefaultArrayObj, Objects */
1344 dest
->ActiveTexture
= src
->ActiveTexture
;
1345 dest
->LockFirst
= src
->LockFirst
;
1346 dest
->LockCount
= src
->LockCount
;
1347 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1348 dest
->RestartIndex
= src
->RestartIndex
;
1350 /* skip RebindArrays */
1352 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1354 /* skip ArrayBufferObj */
1355 /* skip ElementArrayBufferObj */
1359 * Save the content of src to dest.
1362 save_array_attrib(struct gl_context
*ctx
,
1363 struct gl_array_attrib
*dest
,
1364 struct gl_array_attrib
*src
)
1366 /* Set the Name, needed for restore, but do never overwrite.
1367 * Needs to match value in the object hash. */
1368 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1369 /* And copy all of the rest. */
1370 copy_array_attrib(ctx
, dest
, src
);
1372 /* Just reference them here */
1373 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1374 src
->ArrayBufferObj
);
1375 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1376 src
->ArrayObj
->ElementArrayBufferObj
);
1380 * Restore the content of src to dest.
1383 restore_array_attrib(struct gl_context
*ctx
,
1384 struct gl_array_attrib
*dest
,
1385 struct gl_array_attrib
*src
)
1387 /* Restore or recreate the array object by its name ... */
1388 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1390 /* ... and restore its content */
1391 copy_array_attrib(ctx
, dest
, src
);
1393 /* Restore or recreate the buffer objects by the names ... */
1394 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1395 src
->ArrayBufferObj
->Name
);
1396 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1397 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1399 /* Better safe than sorry?! */
1400 dest
->RebindArrays
= GL_TRUE
;
1402 /* FIXME: Should some bits in ctx->Array->NewState also be set
1403 * FIXME: here? It seems like it should be set to inclusive-or
1404 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1407 dest
->NewState
|= src
->ArrayObj
->_Enabled
| dest
->ArrayObj
->_Enabled
;
1411 * init/alloc the fields of 'attrib'.
1412 * Needs to the init part matching free_array_attrib_data below.
1415 init_array_attrib_data(struct gl_context
*ctx
,
1416 struct gl_array_attrib
*attrib
)
1418 /* Get a non driver gl_array_object. */
1419 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1420 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1424 * Free/unreference the fields of 'attrib' but don't delete it (that's
1425 * done later in the calling code).
1426 * Needs to the cleanup part matching init_array_attrib_data above.
1429 free_array_attrib_data(struct gl_context
*ctx
,
1430 struct gl_array_attrib
*attrib
)
1432 /* We use a non driver array object, so don't just unref since we would
1433 * end up using the drivers DeleteArrayObject function for deletion. */
1434 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1435 attrib
->ArrayObj
= 0;
1436 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1441 _mesa_PushClientAttrib(GLbitfield mask
)
1443 struct gl_attrib_node
*head
;
1445 GET_CURRENT_CONTEXT(ctx
);
1446 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1448 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1449 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1453 /* Build linked list of attribute nodes which save all attribute
1454 * groups specified by the mask.
1458 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1459 struct gl_pixelstore_attrib
*attr
;
1460 /* packing attribs */
1461 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1462 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1463 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1464 /* unpacking attribs */
1465 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1466 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1467 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1470 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1471 struct gl_array_attrib
*attr
;
1472 attr
= CALLOC_STRUCT( gl_array_attrib
);
1473 init_array_attrib_data(ctx
, attr
);
1474 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1475 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1478 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1479 ctx
->ClientAttribStackDepth
++;
1486 _mesa_PopClientAttrib(void)
1488 struct gl_attrib_node
*node
, *next
;
1490 GET_CURRENT_CONTEXT(ctx
);
1491 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1493 if (ctx
->ClientAttribStackDepth
== 0) {
1494 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1498 ctx
->ClientAttribStackDepth
--;
1499 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1502 switch (node
->kind
) {
1503 case GL_CLIENT_PACK_BIT
:
1505 struct gl_pixelstore_attrib
*store
=
1506 (struct gl_pixelstore_attrib
*) node
->data
;
1507 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1508 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1510 ctx
->NewState
|= _NEW_PACKUNPACK
;
1512 case GL_CLIENT_UNPACK_BIT
:
1514 struct gl_pixelstore_attrib
*store
=
1515 (struct gl_pixelstore_attrib
*) node
->data
;
1516 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1517 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1519 ctx
->NewState
|= _NEW_PACKUNPACK
;
1521 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1522 struct gl_array_attrib
* attr
=
1523 (struct gl_array_attrib
*) node
->data
;
1524 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1525 free_array_attrib_data(ctx
, attr
);
1526 ctx
->NewState
|= _NEW_ARRAY
;
1530 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1543 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1545 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1546 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1547 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1548 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1552 #endif /* FEATURE_attrib_stack */
1556 * Free any attribute state data that might be attached to the context.
1559 _mesa_free_attrib_data(struct gl_context
*ctx
)
1561 while (ctx
->AttribStackDepth
> 0) {
1562 struct gl_attrib_node
*attr
, *next
;
1564 ctx
->AttribStackDepth
--;
1565 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1568 if (attr
->kind
== GL_TEXTURE_BIT
) {
1569 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1571 /* clear references to the saved texture objects */
1572 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1573 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1574 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1579 /* any other chunks of state that requires special handling? */
1591 void _mesa_init_attrib( struct gl_context
*ctx
)
1593 /* Renderer and client attribute stacks */
1594 ctx
->AttribStackDepth
= 0;
1595 ctx
->ClientAttribStackDepth
= 0;