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"
66 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
68 struct gl_enable_attrib
73 GLbitfield ClipPlanes
;
74 GLboolean ColorMaterial
;
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 /* GL_ARB_vertex_program / GL_NV_vertex_program */
131 GLboolean VertexProgram
;
132 GLboolean VertexProgramPointSize
;
133 GLboolean VertexProgramTwoSide
;
135 /* GL_ARB_point_sprite / GL_NV_point_sprite */
136 GLboolean PointSprite
;
137 GLboolean FragmentShaderATI
;
142 * Node for the attribute stack.
144 struct gl_attrib_node
148 struct gl_attrib_node
*next
;
154 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
158 struct gl_texture_attrib Texture
; /**< The usual context state */
160 /** to save per texture object state (wrap modes, filters, etc): */
161 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
164 * To save references to texture objects (so they don't get accidentally
165 * deleted while saved in the attribute stack).
167 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
171 #if FEATURE_attrib_stack
175 * Allocate new attribute node of given type/kind. Attach payload data.
176 * Insert it into the linked list named by 'head'.
179 save_attrib_data(struct gl_attrib_node
**head
,
180 GLbitfield kind
, void *payload
)
182 struct gl_attrib_node
*n
= MALLOC_STRUCT(gl_attrib_node
);
197 _mesa_PushAttrib(GLbitfield mask
)
199 struct gl_attrib_node
*head
;
201 GET_CURRENT_CONTEXT(ctx
);
202 ASSERT_OUTSIDE_BEGIN_END(ctx
);
204 if (MESA_VERBOSE
& VERBOSE_API
)
205 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
207 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
208 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
212 /* Build linked list of attribute nodes which save all attribute */
213 /* groups specified by the mask. */
216 if (mask
& GL_ACCUM_BUFFER_BIT
) {
217 struct gl_accum_attrib
*attr
;
218 attr
= MALLOC_STRUCT( gl_accum_attrib
);
219 memcpy( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
220 save_attrib_data(&head
, GL_ACCUM_BUFFER_BIT
, attr
);
223 if (mask
& GL_COLOR_BUFFER_BIT
) {
225 struct gl_colorbuffer_attrib
*attr
;
226 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
227 memcpy( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
228 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
229 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
230 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
231 save_attrib_data(&head
, GL_COLOR_BUFFER_BIT
, attr
);
234 if (mask
& GL_CURRENT_BIT
) {
235 struct gl_current_attrib
*attr
;
236 FLUSH_CURRENT( ctx
, 0 );
237 attr
= MALLOC_STRUCT( gl_current_attrib
);
238 memcpy( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
239 save_attrib_data(&head
, GL_CURRENT_BIT
, attr
);
242 if (mask
& GL_DEPTH_BUFFER_BIT
) {
243 struct gl_depthbuffer_attrib
*attr
;
244 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
245 memcpy( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
246 save_attrib_data(&head
, GL_DEPTH_BUFFER_BIT
, attr
);
249 if (mask
& GL_ENABLE_BIT
) {
250 struct gl_enable_attrib
*attr
;
252 attr
= MALLOC_STRUCT( gl_enable_attrib
);
253 /* Copy enable flags from all other attributes into the enable struct. */
254 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
255 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
256 attr
->Blend
= ctx
->Color
.BlendEnabled
;
257 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
258 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
259 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
260 attr
->DepthClamp
= ctx
->Transform
.DepthClamp
;
261 attr
->DepthTest
= ctx
->Depth
.Test
;
262 attr
->Dither
= ctx
->Color
.DitherFlag
;
263 attr
->Fog
= ctx
->Fog
.Enabled
;
264 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
265 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
267 attr
->Lighting
= ctx
->Light
.Enabled
;
268 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
269 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
270 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
271 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
272 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
273 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
274 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
275 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
276 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
277 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
278 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
279 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
280 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
281 memcpy(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
282 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
283 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
284 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
285 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
286 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
287 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
288 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
289 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
290 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
291 memcpy(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
292 attr
->Normalize
= ctx
->Transform
.Normalize
;
293 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
294 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
295 attr
->PointSprite
= ctx
->Point
.PointSprite
;
296 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
297 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
298 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
299 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
300 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
301 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
302 attr
->Scissor
= ctx
->Scissor
.Enabled
;
303 attr
->Stencil
= ctx
->Stencil
.Enabled
;
304 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
305 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
306 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
307 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
308 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
309 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
310 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
311 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
312 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
314 /* GL_NV_vertex_program */
315 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
316 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
317 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
318 save_attrib_data(&head
, GL_ENABLE_BIT
, attr
);
321 if (mask
& GL_EVAL_BIT
) {
322 struct gl_eval_attrib
*attr
;
323 attr
= MALLOC_STRUCT( gl_eval_attrib
);
324 memcpy( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
325 save_attrib_data(&head
, GL_EVAL_BIT
, attr
);
328 if (mask
& GL_FOG_BIT
) {
329 struct gl_fog_attrib
*attr
;
330 attr
= MALLOC_STRUCT( gl_fog_attrib
);
331 memcpy( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
332 save_attrib_data(&head
, GL_FOG_BIT
, attr
);
335 if (mask
& GL_HINT_BIT
) {
336 struct gl_hint_attrib
*attr
;
337 attr
= MALLOC_STRUCT( gl_hint_attrib
);
338 memcpy( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
339 save_attrib_data(&head
, GL_HINT_BIT
, attr
);
342 if (mask
& GL_LIGHTING_BIT
) {
343 struct gl_light_attrib
*attr
;
344 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
345 attr
= MALLOC_STRUCT( gl_light_attrib
);
346 memcpy( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
347 save_attrib_data(&head
, GL_LIGHTING_BIT
, attr
);
350 if (mask
& GL_LINE_BIT
) {
351 struct gl_line_attrib
*attr
;
352 attr
= MALLOC_STRUCT( gl_line_attrib
);
353 memcpy( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
354 save_attrib_data(&head
, GL_LINE_BIT
, attr
);
357 if (mask
& GL_LIST_BIT
) {
358 struct gl_list_attrib
*attr
;
359 attr
= MALLOC_STRUCT( gl_list_attrib
);
360 memcpy( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
361 save_attrib_data(&head
, GL_LIST_BIT
, attr
);
364 if (mask
& GL_PIXEL_MODE_BIT
) {
365 struct gl_pixel_attrib
*attr
;
366 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
367 memcpy( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
368 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
369 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
370 save_attrib_data(&head
, GL_PIXEL_MODE_BIT
, attr
);
373 if (mask
& GL_POINT_BIT
) {
374 struct gl_point_attrib
*attr
;
375 attr
= MALLOC_STRUCT( gl_point_attrib
);
376 memcpy( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
377 save_attrib_data(&head
, GL_POINT_BIT
, attr
);
380 if (mask
& GL_POLYGON_BIT
) {
381 struct gl_polygon_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
383 memcpy( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
384 save_attrib_data(&head
, GL_POLYGON_BIT
, attr
);
387 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
389 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
390 memcpy( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
391 save_attrib_data(&head
, GL_POLYGON_STIPPLE_BIT
, stipple
);
394 if (mask
& GL_SCISSOR_BIT
) {
395 struct gl_scissor_attrib
*attr
;
396 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
397 memcpy( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
398 save_attrib_data(&head
, GL_SCISSOR_BIT
, attr
);
401 if (mask
& GL_STENCIL_BUFFER_BIT
) {
402 struct gl_stencil_attrib
*attr
;
403 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
404 memcpy( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
405 save_attrib_data(&head
, GL_STENCIL_BUFFER_BIT
, attr
);
408 if (mask
& GL_TEXTURE_BIT
) {
409 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
417 _mesa_lock_context_textures(ctx
);
419 /* copy/save the bulk of texture state here */
420 memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
422 /* Save references to the currently bound texture objects so they don't
423 * accidentally get deleted while referenced in the attribute stack.
425 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
426 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
427 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
428 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
432 /* copy state/contents of the currently bound texture objects */
433 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
434 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
435 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
436 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
440 _mesa_unlock_context_textures(ctx
);
442 save_attrib_data(&head
, GL_TEXTURE_BIT
, texstate
);
445 if (mask
& GL_TRANSFORM_BIT
) {
446 struct gl_transform_attrib
*attr
;
447 attr
= MALLOC_STRUCT( gl_transform_attrib
);
448 memcpy( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
449 save_attrib_data(&head
, GL_TRANSFORM_BIT
, attr
);
452 if (mask
& GL_VIEWPORT_BIT
) {
453 struct gl_viewport_attrib
*attr
;
454 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
455 memcpy( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
456 save_attrib_data(&head
, GL_VIEWPORT_BIT
, attr
);
459 /* GL_ARB_multisample */
460 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
461 struct gl_multisample_attrib
*attr
;
462 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
463 memcpy( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
464 save_attrib_data(&head
, GL_MULTISAMPLE_BIT_ARB
, attr
);
468 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
469 ctx
->AttribStackDepth
++;
475 pop_enable_group(struct gl_context
*ctx
, const struct gl_enable_attrib
*enable
)
477 const GLuint curTexUnitSave
= ctx
->Texture
.CurrentUnit
;
480 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
481 if ((VALUE) != (NEWVALUE)) { \
482 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
485 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
486 if (ctx
->Color
.BlendEnabled
!= enable
->Blend
) {
487 if (ctx
->Extensions
.EXT_draw_buffers2
) {
489 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
490 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (enable
->Blend
>> i
) & 1);
494 _mesa_set_enable(ctx
, GL_BLEND
, (enable
->Blend
& 1));
498 for (i
=0;i
<ctx
->Const
.MaxClipPlanes
;i
++) {
499 const GLuint mask
= 1 << i
;
500 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
501 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
502 !!(enable
->ClipPlanes
& mask
));
505 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
507 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
508 TEST_AND_UPDATE(ctx
->Transform
.DepthClamp
, enable
->DepthClamp
,
510 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
511 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
512 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
513 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
514 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
515 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
517 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
519 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
522 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
524 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
525 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
526 GL_MAP1_TEXTURE_COORD_1
);
527 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
528 GL_MAP1_TEXTURE_COORD_2
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
530 GL_MAP1_TEXTURE_COORD_3
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
532 GL_MAP1_TEXTURE_COORD_4
);
533 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
535 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
537 for (i
= 0; i
< 16; i
++) {
538 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
539 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
542 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
543 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
544 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
545 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
546 GL_MAP2_TEXTURE_COORD_1
);
547 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
548 GL_MAP2_TEXTURE_COORD_2
);
549 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
550 GL_MAP2_TEXTURE_COORD_3
);
551 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
552 GL_MAP2_TEXTURE_COORD_4
);
553 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
555 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
557 for (i
= 0; i
< 16; i
++) {
558 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
559 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
562 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
563 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
564 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
565 GL_RESCALE_NORMAL_EXT
);
566 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
567 enable
->RasterPositionUnclipped
,
568 GL_RASTER_POSITION_UNCLIPPED_IBM
);
569 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
571 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
572 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
575 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
576 GL_POLYGON_OFFSET_POINT
);
577 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
578 GL_POLYGON_OFFSET_LINE
);
579 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
580 GL_POLYGON_OFFSET_FILL
);
581 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
583 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
585 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
586 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
587 if (ctx
->Extensions
.EXT_stencil_two_side
) {
588 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
590 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
592 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
593 enable
->SampleAlphaToCoverage
,
594 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
595 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
596 enable
->SampleAlphaToOne
,
597 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
598 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
599 enable
->SampleCoverage
,
600 GL_SAMPLE_COVERAGE_ARB
);
601 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
602 enable
->SampleCoverageInvert
,
603 GL_SAMPLE_COVERAGE_INVERT_ARB
);
604 /* GL_ARB_vertex_program, GL_NV_vertex_program */
605 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
606 enable
->VertexProgram
,
607 GL_VERTEX_PROGRAM_ARB
);
608 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
609 enable
->VertexProgramPointSize
,
610 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
611 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
612 enable
->VertexProgramTwoSide
,
613 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
615 #undef TEST_AND_UPDATE
617 /* texture unit enables */
618 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
619 const GLbitfield enabled
= enable
->Texture
[i
];
620 const GLbitfield genEnabled
= enable
->TexGen
[i
];
622 if (ctx
->Texture
.Unit
[i
].Enabled
!= enabled
) {
623 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
625 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(enabled
& TEXTURE_1D_BIT
));
626 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(enabled
& TEXTURE_2D_BIT
));
627 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(enabled
& TEXTURE_3D_BIT
));
628 if (ctx
->Extensions
.NV_texture_rectangle
) {
629 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_ARB
,
630 !!(enabled
& TEXTURE_RECT_BIT
));
632 if (ctx
->Extensions
.ARB_texture_cube_map
) {
633 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
,
634 !!(enabled
& TEXTURE_CUBE_BIT
));
636 if (ctx
->Extensions
.MESA_texture_array
) {
637 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
638 !!(enabled
& TEXTURE_1D_ARRAY_BIT
));
639 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
640 !!(enabled
& TEXTURE_2D_ARRAY_BIT
));
644 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= genEnabled
) {
645 _mesa_ActiveTextureARB(GL_TEXTURE0
+ i
);
646 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(genEnabled
& S_BIT
));
647 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(genEnabled
& T_BIT
));
648 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(genEnabled
& R_BIT
));
649 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(genEnabled
& Q_BIT
));
653 _mesa_ActiveTextureARB(GL_TEXTURE0
+ curTexUnitSave
);
658 * Pop/restore texture attribute/group state.
661 pop_texture_group(struct gl_context
*ctx
, struct texture_state
*texstate
)
665 _mesa_lock_context_textures(ctx
);
667 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
668 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
671 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
672 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, !!(unit
->Enabled
& TEXTURE_1D_BIT
));
673 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, !!(unit
->Enabled
& TEXTURE_2D_BIT
));
674 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, !!(unit
->Enabled
& TEXTURE_3D_BIT
));
675 if (ctx
->Extensions
.ARB_texture_cube_map
) {
676 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
677 !!(unit
->Enabled
& TEXTURE_CUBE_BIT
));
679 if (ctx
->Extensions
.NV_texture_rectangle
) {
680 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
681 !!(unit
->Enabled
& TEXTURE_RECT_BIT
));
683 if (ctx
->Extensions
.MESA_texture_array
) {
684 _mesa_set_enable(ctx
, GL_TEXTURE_1D_ARRAY_EXT
,
685 !!(unit
->Enabled
& TEXTURE_1D_ARRAY_BIT
));
686 _mesa_set_enable(ctx
, GL_TEXTURE_2D_ARRAY_EXT
,
687 !!(unit
->Enabled
& TEXTURE_2D_ARRAY_BIT
));
690 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
691 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
692 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
693 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
694 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
695 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
696 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
697 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
698 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
699 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
700 /* Eye plane done differently to avoid re-transformation */
702 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
703 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
704 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
705 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
706 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
707 if (ctx
->Driver
.TexGen
) {
708 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
709 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
710 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
711 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
714 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, !!(unit
->TexGenEnabled
& S_BIT
));
715 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, !!(unit
->TexGenEnabled
& T_BIT
));
716 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, !!(unit
->TexGenEnabled
& R_BIT
));
717 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, !!(unit
->TexGenEnabled
& Q_BIT
));
718 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL
, GL_TEXTURE_LOD_BIAS
,
720 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
721 unit
->Combine
.ModeRGB
);
722 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
723 unit
->Combine
.ModeA
);
725 const GLuint n
= ctx
->Extensions
.NV_texture_env_combine4
? 4 : 3;
727 for (i
= 0; i
< n
; i
++) {
728 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
+ i
,
729 unit
->Combine
.SourceRGB
[i
]);
730 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
+ i
,
731 unit
->Combine
.SourceA
[i
]);
732 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
+ i
,
733 unit
->Combine
.OperandRGB
[i
]);
734 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
+ i
,
735 unit
->Combine
.OperandA
[i
]);
738 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
739 1 << unit
->Combine
.ScaleShiftRGB
);
740 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
741 1 << unit
->Combine
.ScaleShiftA
);
743 /* Restore texture object state for each target */
744 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
745 const struct gl_texture_object
*obj
= NULL
;
746 const struct gl_sampler_object
*samp
;
749 obj
= &texstate
->SavedObj
[u
][tgt
];
751 /* don't restore state for unsupported targets to prevent
754 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
755 !ctx
->Extensions
.ARB_texture_cube_map
) {
758 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
759 !ctx
->Extensions
.NV_texture_rectangle
) {
762 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
763 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
764 !ctx
->Extensions
.MESA_texture_array
) {
767 else if (obj
->Target
== GL_TEXTURE_BUFFER
)
769 else if (obj
->Target
== GL_TEXTURE_EXTERNAL_OES
)
772 target
= obj
->Target
;
774 _mesa_BindTexture(target
, obj
->Name
);
776 samp
= &obj
->Sampler
;
778 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, samp
->BorderColor
.f
);
779 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, samp
->WrapS
);
780 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, samp
->WrapT
);
781 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, samp
->WrapR
);
782 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, samp
->MinFilter
);
783 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, samp
->MagFilter
);
784 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, samp
->MinLod
);
785 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, samp
->MaxLod
);
786 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, samp
->LodBias
);
787 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
788 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
789 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
790 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
791 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
792 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
793 samp
->MaxAnisotropy
);
795 if (ctx
->Extensions
.ARB_shadow_ambient
) {
796 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
797 samp
->CompareFailValue
);
801 /* remove saved references to the texture objects */
802 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
803 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
807 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
809 _mesa_unlock_context_textures(ctx
);
814 * This function is kind of long just because we have to call a lot
815 * of device driver functions to update device driver state.
817 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
818 * in order to restore GL state. This isn't terribly efficient but it
819 * ensures that dirty flags and any derived state gets updated correctly.
820 * We could at least check if the value to restore equals the current value
821 * and then skip the Mesa call.
824 _mesa_PopAttrib(void)
826 struct gl_attrib_node
*attr
, *next
;
827 GET_CURRENT_CONTEXT(ctx
);
828 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
830 if (ctx
->AttribStackDepth
== 0) {
831 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
835 ctx
->AttribStackDepth
--;
836 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
840 if (MESA_VERBOSE
& VERBOSE_API
) {
841 _mesa_debug(ctx
, "glPopAttrib %s\n",
842 _mesa_lookup_enum_by_nr(attr
->kind
));
845 switch (attr
->kind
) {
846 case GL_ACCUM_BUFFER_BIT
:
848 const struct gl_accum_attrib
*accum
;
849 accum
= (const struct gl_accum_attrib
*) attr
->data
;
850 _mesa_ClearAccum(accum
->ClearColor
[0],
851 accum
->ClearColor
[1],
852 accum
->ClearColor
[2],
853 accum
->ClearColor
[3]);
856 case GL_COLOR_BUFFER_BIT
:
858 const struct gl_colorbuffer_attrib
*color
;
860 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
861 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
862 _mesa_ClearColor(color
->ClearColor
.f
[0],
863 color
->ClearColor
.f
[1],
864 color
->ClearColor
.f
[2],
865 color
->ClearColor
.f
[3]);
866 _mesa_IndexMask(color
->IndexMask
);
867 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
868 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0][0] != 0),
869 (GLboolean
) (color
->ColorMask
[0][1] != 0),
870 (GLboolean
) (color
->ColorMask
[0][2] != 0),
871 (GLboolean
) (color
->ColorMask
[0][3] != 0));
875 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
876 _mesa_ColorMaskIndexed(i
,
877 (GLboolean
) (color
->ColorMask
[i
][0] != 0),
878 (GLboolean
) (color
->ColorMask
[i
][1] != 0),
879 (GLboolean
) (color
->ColorMask
[i
][2] != 0),
880 (GLboolean
) (color
->ColorMask
[i
][3] != 0));
884 /* Need to determine if more than one color output is
885 * specified. If so, call glDrawBuffersARB, else call
886 * glDrawBuffer(). This is a subtle, but essential point
887 * since GL_FRONT (for example) is illegal for the former
888 * function, but legal for the later.
890 GLboolean multipleBuffers
= GL_FALSE
;
893 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
894 if (color
->DrawBuffer
[i
] != GL_NONE
) {
895 multipleBuffers
= GL_TRUE
;
899 /* Call the API_level functions, not _mesa_drawbuffers()
900 * since we need to do error checking on the pop'd
902 * Ex: if GL_FRONT were pushed, but we're popping with a
903 * user FBO bound, GL_FRONT will be illegal and we'll need
904 * to record that error. Per OpenGL ARB decision.
907 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
910 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
912 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
913 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRefUnclamped
);
914 if (ctx
->Color
.BlendEnabled
!= color
->BlendEnabled
) {
915 if (ctx
->Extensions
.EXT_draw_buffers2
) {
917 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
918 _mesa_set_enablei(ctx
, GL_BLEND
, i
,
919 (color
->BlendEnabled
>> i
) & 1);
923 _mesa_set_enable(ctx
, GL_BLEND
, (color
->BlendEnabled
& 1));
926 if (ctx
->Color
._BlendFuncPerBuffer
||
927 ctx
->Color
._BlendEquationPerBuffer
) {
928 /* set blend per buffer */
930 for (buf
= 0; buf
< ctx
->Const
.MaxDrawBuffers
; buf
++) {
931 _mesa_BlendFuncSeparatei(buf
, color
->Blend
[buf
].SrcRGB
,
932 color
->Blend
[buf
].DstRGB
,
933 color
->Blend
[buf
].SrcA
,
934 color
->Blend
[buf
].DstA
);
935 _mesa_BlendEquationSeparatei(buf
,
936 color
->Blend
[buf
].EquationRGB
,
937 color
->Blend
[buf
].EquationA
);
941 /* set same blend modes for all buffers */
942 _mesa_BlendFuncSeparateEXT(color
->Blend
[0].SrcRGB
,
943 color
->Blend
[0].DstRGB
,
944 color
->Blend
[0].SrcA
,
945 color
->Blend
[0].DstA
);
946 /* This special case is because glBlendEquationSeparateEXT
947 * cannot take GL_LOGIC_OP as a parameter.
949 if (color
->Blend
[0].EquationRGB
==
950 color
->Blend
[0].EquationA
) {
951 _mesa_BlendEquation(color
->Blend
[0].EquationRGB
);
954 _mesa_BlendEquationSeparateEXT(
955 color
->Blend
[0].EquationRGB
,
956 color
->Blend
[0].EquationA
);
959 _mesa_BlendColor(color
->BlendColorUnclamped
[0],
960 color
->BlendColorUnclamped
[1],
961 color
->BlendColorUnclamped
[2],
962 color
->BlendColorUnclamped
[3]);
963 _mesa_LogicOp(color
->LogicOp
);
964 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
965 color
->ColorLogicOpEnabled
);
966 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
967 color
->IndexLogicOpEnabled
);
968 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
969 _mesa_ClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB
, color
->ClampFragmentColor
);
970 _mesa_ClampColorARB(GL_CLAMP_READ_COLOR_ARB
, color
->ClampReadColor
);
974 FLUSH_CURRENT( ctx
, 0 );
975 memcpy( &ctx
->Current
, attr
->data
,
976 sizeof(struct gl_current_attrib
) );
978 case GL_DEPTH_BUFFER_BIT
:
980 const struct gl_depthbuffer_attrib
*depth
;
981 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
982 _mesa_DepthFunc(depth
->Func
);
983 _mesa_ClearDepth(depth
->Clear
);
984 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
985 _mesa_DepthMask(depth
->Mask
);
990 const struct gl_enable_attrib
*enable
;
991 enable
= (const struct gl_enable_attrib
*) attr
->data
;
992 pop_enable_group(ctx
, enable
);
993 ctx
->NewState
|= _NEW_ALL
;
997 memcpy( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
998 ctx
->NewState
|= _NEW_EVAL
;
1002 const struct gl_fog_attrib
*fog
;
1003 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1004 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1005 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1006 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1007 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1008 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1009 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1010 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1015 const struct gl_hint_attrib
*hint
;
1016 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1017 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1018 hint
->PerspectiveCorrection
);
1019 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1020 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1021 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1022 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1023 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1024 hint
->ClipVolumeClipping
);
1025 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1026 hint
->TextureCompression
);
1029 case GL_LIGHTING_BIT
:
1032 const struct gl_light_attrib
*light
;
1033 light
= (const struct gl_light_attrib
*) attr
->data
;
1034 /* lighting enable */
1035 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1036 /* per-light state */
1037 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1038 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1040 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1041 const struct gl_light
*l
= &light
->Light
[i
];
1042 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1043 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1044 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1045 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1046 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1047 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1049 GLfloat p
[4] = { 0 };
1050 p
[0] = l
->SpotExponent
;
1051 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, p
);
1054 GLfloat p
[4] = { 0 };
1055 p
[0] = l
->SpotCutoff
;
1056 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, p
);
1059 GLfloat p
[4] = { 0 };
1060 p
[0] = l
->ConstantAttenuation
;
1061 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
, p
);
1064 GLfloat p
[4] = { 0 };
1065 p
[0] = l
->LinearAttenuation
;
1066 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
, p
);
1069 GLfloat p
[4] = { 0 };
1070 p
[0] = l
->QuadraticAttenuation
;
1071 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
, p
);
1075 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1076 light
->Model
.Ambient
);
1077 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1078 (GLfloat
) light
->Model
.LocalViewer
);
1079 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1080 (GLfloat
) light
->Model
.TwoSide
);
1081 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1082 (GLfloat
) light
->Model
.ColorControl
);
1084 _mesa_ShadeModel(light
->ShadeModel
);
1085 /* color material */
1086 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1087 light
->ColorMaterialMode
);
1088 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1089 light
->ColorMaterialEnabled
);
1091 memcpy(&ctx
->Light
.Material
, &light
->Material
,
1092 sizeof(struct gl_material
));
1093 _mesa_ClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB
, light
->ClampVertexColor
);
1098 const struct gl_line_attrib
*line
;
1099 line
= (const struct gl_line_attrib
*) attr
->data
;
1100 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1101 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1102 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1103 _mesa_LineWidth(line
->Width
);
1107 memcpy( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1109 case GL_PIXEL_MODE_BIT
:
1110 memcpy( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1111 /* XXX what other pixel state needs to be set by function calls? */
1112 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1113 ctx
->NewState
|= _NEW_PIXEL
;
1117 const struct gl_point_attrib
*point
;
1118 point
= (const struct gl_point_attrib
*) attr
->data
;
1119 _mesa_PointSize(point
->Size
);
1120 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1121 if (ctx
->Extensions
.EXT_point_parameters
) {
1122 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1124 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1126 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1128 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1131 if (ctx
->Extensions
.NV_point_sprite
1132 || ctx
->Extensions
.ARB_point_sprite
) {
1134 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1135 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1136 (GLint
) point
->CoordReplace
[u
]);
1138 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1139 if (ctx
->Extensions
.NV_point_sprite
)
1140 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1141 ctx
->Point
.SpriteRMode
);
1142 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1143 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1147 case GL_POLYGON_BIT
:
1149 const struct gl_polygon_attrib
*polygon
;
1150 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1151 _mesa_CullFace(polygon
->CullFaceMode
);
1152 _mesa_FrontFace(polygon
->FrontFace
);
1153 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1154 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1155 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1156 polygon
->OffsetUnits
);
1157 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1158 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1159 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1160 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1161 polygon
->OffsetPoint
);
1162 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1163 polygon
->OffsetLine
);
1164 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1165 polygon
->OffsetFill
);
1168 case GL_POLYGON_STIPPLE_BIT
:
1169 memcpy( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1170 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1171 if (ctx
->Driver
.PolygonStipple
)
1172 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1174 case GL_SCISSOR_BIT
:
1176 const struct gl_scissor_attrib
*scissor
;
1177 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1178 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1179 scissor
->Width
, scissor
->Height
);
1180 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1183 case GL_STENCIL_BUFFER_BIT
:
1185 const struct gl_stencil_attrib
*stencil
;
1186 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1187 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1188 _mesa_ClearStencil(stencil
->Clear
);
1189 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1190 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1191 stencil
->TestTwoSide
);
1192 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1193 ? GL_BACK
: GL_FRONT
);
1196 _mesa_StencilFuncSeparate(GL_FRONT
,
1197 stencil
->Function
[0],
1199 stencil
->ValueMask
[0]);
1200 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1201 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1202 stencil
->ZFailFunc
[0],
1203 stencil
->ZPassFunc
[0]);
1205 _mesa_StencilFuncSeparate(GL_BACK
,
1206 stencil
->Function
[1],
1208 stencil
->ValueMask
[1]);
1209 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1210 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1211 stencil
->ZFailFunc
[1],
1212 stencil
->ZPassFunc
[1]);
1215 case GL_TRANSFORM_BIT
:
1218 const struct gl_transform_attrib
*xform
;
1219 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1220 _mesa_MatrixMode(xform
->MatrixMode
);
1221 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1222 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1224 /* restore clip planes */
1225 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1226 const GLuint mask
= 1 << i
;
1227 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1228 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1229 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
,
1230 !!(xform
->ClipPlanesEnabled
& mask
));
1231 if (ctx
->Driver
.ClipPlane
)
1232 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1235 /* normalize/rescale */
1236 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1237 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1238 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1239 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1240 ctx
->Transform
.RescaleNormals
);
1241 if (xform
->DepthClamp
!= ctx
->Transform
.DepthClamp
)
1242 _mesa_set_enable(ctx
, GL_DEPTH_CLAMP
,
1243 ctx
->Transform
.DepthClamp
);
1246 case GL_TEXTURE_BIT
:
1247 /* Take care of texture object reference counters */
1249 struct texture_state
*texstate
1250 = (struct texture_state
*) attr
->data
;
1251 pop_texture_group(ctx
, texstate
);
1252 ctx
->NewState
|= _NEW_TEXTURE
;
1255 case GL_VIEWPORT_BIT
:
1257 const struct gl_viewport_attrib
*vp
;
1258 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1259 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1260 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1263 case GL_MULTISAMPLE_BIT_ARB
:
1265 const struct gl_multisample_attrib
*ms
;
1266 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1267 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1268 ms
->SampleCoverageInvert
);
1273 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1286 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1290 copy_pixelstore(struct gl_context
*ctx
,
1291 struct gl_pixelstore_attrib
*dst
,
1292 const struct gl_pixelstore_attrib
*src
)
1294 dst
->Alignment
= src
->Alignment
;
1295 dst
->RowLength
= src
->RowLength
;
1296 dst
->SkipPixels
= src
->SkipPixels
;
1297 dst
->SkipRows
= src
->SkipRows
;
1298 dst
->ImageHeight
= src
->ImageHeight
;
1299 dst
->SkipImages
= src
->SkipImages
;
1300 dst
->SwapBytes
= src
->SwapBytes
;
1301 dst
->LsbFirst
= src
->LsbFirst
;
1302 dst
->Invert
= src
->Invert
;
1303 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1307 #define GL_CLIENT_PACK_BIT (1<<20)
1308 #define GL_CLIENT_UNPACK_BIT (1<<21)
1311 * Copy gl_array_object from src to dest.
1312 * 'dest' must be in an initialized state.
1315 copy_array_object(struct gl_context
*ctx
,
1316 struct gl_array_object
*dest
,
1317 struct gl_array_object
*src
)
1324 /* In theory must be the same anyway, but on recreate make sure it matches */
1325 dest
->ARBsemantics
= src
->ARBsemantics
;
1327 for (i
= 0; i
< Elements(src
->VertexAttrib
); i
++)
1328 _mesa_copy_client_array(ctx
, &dest
->VertexAttrib
[i
], &src
->VertexAttrib
[i
]);
1330 /* _Enabled must be the same than on push */
1331 dest
->_Enabled
= src
->_Enabled
;
1332 dest
->_MaxElement
= src
->_MaxElement
;
1336 * Copy gl_array_attrib from src to dest.
1337 * 'dest' must be in an initialized state.
1340 copy_array_attrib(struct gl_context
*ctx
,
1341 struct gl_array_attrib
*dest
,
1342 struct gl_array_attrib
*src
,
1346 /* skip DefaultArrayObj, Objects */
1347 dest
->ActiveTexture
= src
->ActiveTexture
;
1348 dest
->LockFirst
= src
->LockFirst
;
1349 dest
->LockCount
= src
->LockCount
;
1350 dest
->PrimitiveRestart
= src
->PrimitiveRestart
;
1351 dest
->RestartIndex
= src
->RestartIndex
;
1353 /* skip RebindArrays */
1356 copy_array_object(ctx
, dest
->ArrayObj
, src
->ArrayObj
);
1358 /* skip ArrayBufferObj */
1359 /* skip ElementArrayBufferObj */
1363 * Save the content of src to dest.
1366 save_array_attrib(struct gl_context
*ctx
,
1367 struct gl_array_attrib
*dest
,
1368 struct gl_array_attrib
*src
)
1370 /* Set the Name, needed for restore, but do never overwrite.
1371 * Needs to match value in the object hash. */
1372 dest
->ArrayObj
->Name
= src
->ArrayObj
->Name
;
1373 /* And copy all of the rest. */
1374 copy_array_attrib(ctx
, dest
, src
, false);
1376 /* Just reference them here */
1377 _mesa_reference_buffer_object(ctx
, &dest
->ArrayBufferObj
,
1378 src
->ArrayBufferObj
);
1379 _mesa_reference_buffer_object(ctx
, &dest
->ArrayObj
->ElementArrayBufferObj
,
1380 src
->ArrayObj
->ElementArrayBufferObj
);
1384 * Restore the content of src to dest.
1387 restore_array_attrib(struct gl_context
*ctx
,
1388 struct gl_array_attrib
*dest
,
1389 struct gl_array_attrib
*src
)
1391 /* The ARB_vertex_array_object spec says:
1393 * "BindVertexArray fails and an INVALID_OPERATION error is generated
1394 * if array is not a name returned from a previous call to
1395 * GenVertexArrays, or if such a name has since been deleted with
1396 * DeleteVertexArrays."
1398 * Therefore popping a deleted VAO cannot magically recreate it.
1400 * The semantics of objects created using APPLE_vertex_array_objects behave
1401 * differently. These objects expect to be recreated by pop. Alas.
1403 const bool arb_vao
= (src
->ArrayObj
->Name
!= 0
1404 && src
->ArrayObj
->ARBsemantics
);
1406 if (arb_vao
&& !_mesa_IsVertexArrayAPPLE(src
->ArrayObj
->Name
))
1409 _mesa_BindVertexArrayAPPLE(src
->ArrayObj
->Name
);
1411 /* Restore or recreate the buffer objects by the names ... */
1413 || src
->ArrayBufferObj
->Name
== 0
1414 || _mesa_IsBufferARB(src
->ArrayBufferObj
->Name
)) {
1415 /* ... and restore its content */
1416 copy_array_attrib(ctx
, dest
, src
, false);
1418 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1419 src
->ArrayBufferObj
->Name
);
1421 copy_array_attrib(ctx
, dest
, src
, true);
1425 || src
->ArrayObj
->ElementArrayBufferObj
->Name
== 0
1426 || _mesa_IsBufferARB(src
->ArrayObj
->ElementArrayBufferObj
->Name
))
1427 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1428 src
->ArrayObj
->ElementArrayBufferObj
->Name
);
1430 /* Better safe than sorry?! */
1431 dest
->RebindArrays
= GL_TRUE
;
1433 /* FIXME: Should some bits in ctx->Array->NewState also be set
1434 * FIXME: here? It seems like it should be set to inclusive-or
1435 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1438 dest
->NewState
|= src
->ArrayObj
->_Enabled
| dest
->ArrayObj
->_Enabled
;
1442 * init/alloc the fields of 'attrib'.
1443 * Needs to the init part matching free_array_attrib_data below.
1446 init_array_attrib_data(struct gl_context
*ctx
,
1447 struct gl_array_attrib
*attrib
)
1449 /* Get a non driver gl_array_object. */
1450 attrib
->ArrayObj
= CALLOC_STRUCT( gl_array_object
);
1451 _mesa_initialize_array_object(ctx
, attrib
->ArrayObj
, 0);
1455 * Free/unreference the fields of 'attrib' but don't delete it (that's
1456 * done later in the calling code).
1457 * Needs to the cleanup part matching init_array_attrib_data above.
1460 free_array_attrib_data(struct gl_context
*ctx
,
1461 struct gl_array_attrib
*attrib
)
1463 /* We use a non driver array object, so don't just unref since we would
1464 * end up using the drivers DeleteArrayObject function for deletion. */
1465 _mesa_delete_array_object(ctx
, attrib
->ArrayObj
);
1466 attrib
->ArrayObj
= 0;
1467 _mesa_reference_buffer_object(ctx
, &attrib
->ArrayBufferObj
, NULL
);
1472 _mesa_PushClientAttrib(GLbitfield mask
)
1474 struct gl_attrib_node
*head
;
1476 GET_CURRENT_CONTEXT(ctx
);
1477 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1479 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1480 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1484 /* Build linked list of attribute nodes which save all attribute
1485 * groups specified by the mask.
1489 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1490 struct gl_pixelstore_attrib
*attr
;
1491 /* packing attribs */
1492 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1493 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1494 save_attrib_data(&head
, GL_CLIENT_PACK_BIT
, attr
);
1495 /* unpacking attribs */
1496 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1497 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1498 save_attrib_data(&head
, GL_CLIENT_UNPACK_BIT
, attr
);
1501 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1502 struct gl_array_attrib
*attr
;
1503 attr
= CALLOC_STRUCT( gl_array_attrib
);
1504 init_array_attrib_data(ctx
, attr
);
1505 save_array_attrib(ctx
, attr
, &ctx
->Array
);
1506 save_attrib_data(&head
, GL_CLIENT_VERTEX_ARRAY_BIT
, attr
);
1509 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1510 ctx
->ClientAttribStackDepth
++;
1517 _mesa_PopClientAttrib(void)
1519 struct gl_attrib_node
*node
, *next
;
1521 GET_CURRENT_CONTEXT(ctx
);
1522 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1524 if (ctx
->ClientAttribStackDepth
== 0) {
1525 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1529 ctx
->ClientAttribStackDepth
--;
1530 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1533 switch (node
->kind
) {
1534 case GL_CLIENT_PACK_BIT
:
1536 struct gl_pixelstore_attrib
*store
=
1537 (struct gl_pixelstore_attrib
*) node
->data
;
1538 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1539 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1541 ctx
->NewState
|= _NEW_PACKUNPACK
;
1543 case GL_CLIENT_UNPACK_BIT
:
1545 struct gl_pixelstore_attrib
*store
=
1546 (struct gl_pixelstore_attrib
*) node
->data
;
1547 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1548 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1550 ctx
->NewState
|= _NEW_PACKUNPACK
;
1552 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1553 struct gl_array_attrib
* attr
=
1554 (struct gl_array_attrib
*) node
->data
;
1555 restore_array_attrib(ctx
, &ctx
->Array
, attr
);
1556 free_array_attrib_data(ctx
, attr
);
1557 ctx
->NewState
|= _NEW_ARRAY
;
1561 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1574 _mesa_init_attrib_dispatch(struct _glapi_table
*disp
)
1576 SET_PopAttrib(disp
, _mesa_PopAttrib
);
1577 SET_PushAttrib(disp
, _mesa_PushAttrib
);
1578 SET_PopClientAttrib(disp
, _mesa_PopClientAttrib
);
1579 SET_PushClientAttrib(disp
, _mesa_PushClientAttrib
);
1583 #endif /* FEATURE_attrib_stack */
1587 * Free any attribute state data that might be attached to the context.
1590 _mesa_free_attrib_data(struct gl_context
*ctx
)
1592 while (ctx
->AttribStackDepth
> 0) {
1593 struct gl_attrib_node
*attr
, *next
;
1595 ctx
->AttribStackDepth
--;
1596 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1599 if (attr
->kind
== GL_TEXTURE_BIT
) {
1600 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1602 /* clear references to the saved texture objects */
1603 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1604 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1605 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1610 /* any other chunks of state that requires special handling? */
1622 void _mesa_init_attrib( struct gl_context
*ctx
)
1624 /* Renderer and client attribute stacks */
1625 ctx
->AttribStackDepth
= 0;
1626 ctx
->ClientAttribStackDepth
= 0;