2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
46 #include "multisample.h"
50 #include "simple_list.h"
63 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
65 struct gl_enable_attrib
70 GLbitfield ClipPlanes
;
71 GLboolean ColorMaterial
;
72 GLboolean ColorTable
[COLORTABLE_MAX
];
73 GLboolean Convolution1D
;
74 GLboolean Convolution2D
;
75 GLboolean Separable2D
;
81 GLboolean Light
[MAX_LIGHTS
];
84 GLboolean LineStipple
;
85 GLboolean IndexLogicOp
;
86 GLboolean ColorLogicOp
;
91 GLboolean Map1TextureCoord1
;
92 GLboolean Map1TextureCoord2
;
93 GLboolean Map1TextureCoord3
;
94 GLboolean Map1TextureCoord4
;
95 GLboolean Map1Vertex3
;
96 GLboolean Map1Vertex4
;
97 GLboolean Map1Attrib
[16]; /* GL_NV_vertex_program */
100 GLboolean Map2Normal
;
101 GLboolean Map2TextureCoord1
;
102 GLboolean Map2TextureCoord2
;
103 GLboolean Map2TextureCoord3
;
104 GLboolean Map2TextureCoord4
;
105 GLboolean Map2Vertex3
;
106 GLboolean Map2Vertex4
;
107 GLboolean Map2Attrib
[16]; /* GL_NV_vertex_program */
111 GLboolean PixelTexture
;
112 GLboolean PointSmooth
;
113 GLboolean PolygonOffsetPoint
;
114 GLboolean PolygonOffsetLine
;
115 GLboolean PolygonOffsetFill
;
116 GLboolean PolygonSmooth
;
117 GLboolean PolygonStipple
;
118 GLboolean RescaleNormals
;
121 GLboolean StencilTwoSide
; /* GL_EXT_stencil_two_side */
122 GLboolean MultisampleEnabled
; /* GL_ARB_multisample */
123 GLboolean SampleAlphaToCoverage
; /* GL_ARB_multisample */
124 GLboolean SampleAlphaToOne
; /* GL_ARB_multisample */
125 GLboolean SampleCoverage
; /* GL_ARB_multisample */
126 GLboolean SampleCoverageInvert
; /* GL_ARB_multisample */
127 GLboolean RasterPositionUnclipped
; /* GL_IBM_rasterpos_clip */
129 GLbitfield Texture
[MAX_TEXTURE_UNITS
];
130 GLbitfield TexGen
[MAX_TEXTURE_UNITS
];
132 /* SGI_texture_color_table */
133 GLboolean TextureColorTable
[MAX_TEXTURE_UNITS
];
135 /* GL_ARB_vertex_program / GL_NV_vertex_program */
136 GLboolean VertexProgram
;
137 GLboolean VertexProgramPointSize
;
138 GLboolean VertexProgramTwoSide
;
140 /* GL_ARB_point_sprite / GL_NV_point_sprite */
141 GLboolean PointSprite
;
142 GLboolean FragmentShaderATI
;
147 * Node for the attribute stack.
149 struct gl_attrib_node
153 struct gl_attrib_node
*next
;
159 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
163 struct gl_texture_attrib Texture
; /**< The usual context state */
165 /** to save per texture object state (wrap modes, filters, etc): */
166 struct gl_texture_object SavedObj
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
169 * To save references to texture objects (so they don't get accidentally
170 * deleted while saved in the attribute stack).
172 struct gl_texture_object
*SavedTexRef
[MAX_TEXTURE_UNITS
][NUM_TEXTURE_TARGETS
];
177 * Allocate a new attribute state node. These nodes have a
178 * "kind" value and a pointer to a struct of state data.
180 static struct gl_attrib_node
*
181 new_attrib_node( GLbitfield kind
)
183 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
192 _mesa_PushAttrib(GLbitfield mask
)
194 struct gl_attrib_node
*newnode
;
195 struct gl_attrib_node
*head
;
197 GET_CURRENT_CONTEXT(ctx
);
198 ASSERT_OUTSIDE_BEGIN_END(ctx
);
200 if (MESA_VERBOSE
& VERBOSE_API
)
201 _mesa_debug(ctx
, "glPushAttrib %x\n", (int) mask
);
203 if (ctx
->AttribStackDepth
>= MAX_ATTRIB_STACK_DEPTH
) {
204 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
208 /* Build linked list of attribute nodes which save all attribute */
209 /* groups specified by the mask. */
212 if (mask
& GL_ACCUM_BUFFER_BIT
) {
213 struct gl_accum_attrib
*attr
;
214 attr
= MALLOC_STRUCT( gl_accum_attrib
);
215 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
216 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
217 newnode
->data
= attr
;
218 newnode
->next
= head
;
222 if (mask
& GL_COLOR_BUFFER_BIT
) {
224 struct gl_colorbuffer_attrib
*attr
;
225 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
226 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
227 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
228 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++)
229 attr
->DrawBuffer
[i
] = ctx
->DrawBuffer
->ColorDrawBuffer
[i
];
230 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
231 newnode
->data
= attr
;
232 newnode
->next
= head
;
236 if (mask
& GL_CURRENT_BIT
) {
237 struct gl_current_attrib
*attr
;
238 FLUSH_CURRENT( ctx
, 0 );
239 attr
= MALLOC_STRUCT( gl_current_attrib
);
240 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
241 newnode
= new_attrib_node( GL_CURRENT_BIT
);
242 newnode
->data
= attr
;
243 newnode
->next
= head
;
247 if (mask
& GL_DEPTH_BUFFER_BIT
) {
248 struct gl_depthbuffer_attrib
*attr
;
249 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
250 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
251 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
252 newnode
->data
= attr
;
253 newnode
->next
= head
;
257 if (mask
& GL_ENABLE_BIT
) {
258 struct gl_enable_attrib
*attr
;
260 attr
= MALLOC_STRUCT( gl_enable_attrib
);
261 /* Copy enable flags from all other attributes into the enable struct. */
262 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
263 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
264 attr
->Blend
= ctx
->Color
.BlendEnabled
;
265 attr
->ClipPlanes
= ctx
->Transform
.ClipPlanesEnabled
;
266 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
267 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
268 attr
->ColorTable
[i
] = ctx
->Pixel
.ColorTableEnabled
[i
];
270 attr
->Convolution1D
= ctx
->Pixel
.Convolution1DEnabled
;
271 attr
->Convolution2D
= ctx
->Pixel
.Convolution2DEnabled
;
272 attr
->Separable2D
= ctx
->Pixel
.Separable2DEnabled
;
273 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
274 attr
->DepthTest
= ctx
->Depth
.Test
;
275 attr
->Dither
= ctx
->Color
.DitherFlag
;
276 attr
->Fog
= ctx
->Fog
.Enabled
;
277 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
278 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
280 attr
->Lighting
= ctx
->Light
.Enabled
;
281 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
282 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
283 attr
->Histogram
= ctx
->Pixel
.HistogramEnabled
;
284 attr
->MinMax
= ctx
->Pixel
.MinMaxEnabled
;
285 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
286 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
287 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
288 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
289 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
290 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
291 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
292 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
293 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
294 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
295 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
296 MEMCPY(attr
->Map1Attrib
, ctx
->Eval
.Map1Attrib
, sizeof(ctx
->Eval
.Map1Attrib
));
297 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
298 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
299 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
300 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
301 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
302 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
303 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
304 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
305 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
306 MEMCPY(attr
->Map2Attrib
, ctx
->Eval
.Map2Attrib
, sizeof(ctx
->Eval
.Map2Attrib
));
307 attr
->Normalize
= ctx
->Transform
.Normalize
;
308 attr
->RasterPositionUnclipped
= ctx
->Transform
.RasterPositionUnclipped
;
309 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
310 attr
->PointSprite
= ctx
->Point
.PointSprite
;
311 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
312 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
313 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
314 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
315 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
316 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
317 attr
->Scissor
= ctx
->Scissor
.Enabled
;
318 attr
->Stencil
= ctx
->Stencil
.Enabled
;
319 attr
->StencilTwoSide
= ctx
->Stencil
.TestTwoSide
;
320 attr
->MultisampleEnabled
= ctx
->Multisample
.Enabled
;
321 attr
->SampleAlphaToCoverage
= ctx
->Multisample
.SampleAlphaToCoverage
;
322 attr
->SampleAlphaToOne
= ctx
->Multisample
.SampleAlphaToOne
;
323 attr
->SampleCoverage
= ctx
->Multisample
.SampleCoverage
;
324 attr
->SampleCoverageInvert
= ctx
->Multisample
.SampleCoverageInvert
;
325 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
326 attr
->Texture
[i
] = ctx
->Texture
.Unit
[i
].Enabled
;
327 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
328 attr
->TextureColorTable
[i
] = ctx
->Texture
.Unit
[i
].ColorTableEnabled
;
330 /* GL_NV_vertex_program */
331 attr
->VertexProgram
= ctx
->VertexProgram
.Enabled
;
332 attr
->VertexProgramPointSize
= ctx
->VertexProgram
.PointSizeEnabled
;
333 attr
->VertexProgramTwoSide
= ctx
->VertexProgram
.TwoSideEnabled
;
334 newnode
= new_attrib_node( GL_ENABLE_BIT
);
335 newnode
->data
= attr
;
336 newnode
->next
= head
;
340 if (mask
& GL_EVAL_BIT
) {
341 struct gl_eval_attrib
*attr
;
342 attr
= MALLOC_STRUCT( gl_eval_attrib
);
343 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
344 newnode
= new_attrib_node( GL_EVAL_BIT
);
345 newnode
->data
= attr
;
346 newnode
->next
= head
;
350 if (mask
& GL_FOG_BIT
) {
351 struct gl_fog_attrib
*attr
;
352 attr
= MALLOC_STRUCT( gl_fog_attrib
);
353 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
354 newnode
= new_attrib_node( GL_FOG_BIT
);
355 newnode
->data
= attr
;
356 newnode
->next
= head
;
360 if (mask
& GL_HINT_BIT
) {
361 struct gl_hint_attrib
*attr
;
362 attr
= MALLOC_STRUCT( gl_hint_attrib
);
363 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
364 newnode
= new_attrib_node( GL_HINT_BIT
);
365 newnode
->data
= attr
;
366 newnode
->next
= head
;
370 if (mask
& GL_LIGHTING_BIT
) {
371 struct gl_light_attrib
*attr
;
372 FLUSH_CURRENT(ctx
, 0); /* flush material changes */
373 attr
= MALLOC_STRUCT( gl_light_attrib
);
374 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
375 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
376 newnode
->data
= attr
;
377 newnode
->next
= head
;
381 if (mask
& GL_LINE_BIT
) {
382 struct gl_line_attrib
*attr
;
383 attr
= MALLOC_STRUCT( gl_line_attrib
);
384 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
385 newnode
= new_attrib_node( GL_LINE_BIT
);
386 newnode
->data
= attr
;
387 newnode
->next
= head
;
391 if (mask
& GL_LIST_BIT
) {
392 struct gl_list_attrib
*attr
;
393 attr
= MALLOC_STRUCT( gl_list_attrib
);
394 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
395 newnode
= new_attrib_node( GL_LIST_BIT
);
396 newnode
->data
= attr
;
397 newnode
->next
= head
;
401 if (mask
& GL_PIXEL_MODE_BIT
) {
402 struct gl_pixel_attrib
*attr
;
403 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
404 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
405 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
406 attr
->ReadBuffer
= ctx
->ReadBuffer
->ColorReadBuffer
;
407 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
408 newnode
->data
= attr
;
409 newnode
->next
= head
;
413 if (mask
& GL_POINT_BIT
) {
414 struct gl_point_attrib
*attr
;
415 attr
= MALLOC_STRUCT( gl_point_attrib
);
416 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
417 newnode
= new_attrib_node( GL_POINT_BIT
);
418 newnode
->data
= attr
;
419 newnode
->next
= head
;
423 if (mask
& GL_POLYGON_BIT
) {
424 struct gl_polygon_attrib
*attr
;
425 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
426 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
427 newnode
= new_attrib_node( GL_POLYGON_BIT
);
428 newnode
->data
= attr
;
429 newnode
->next
= head
;
433 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
435 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
436 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
437 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
438 newnode
->data
= stipple
;
439 newnode
->next
= head
;
443 if (mask
& GL_SCISSOR_BIT
) {
444 struct gl_scissor_attrib
*attr
;
445 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
446 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
447 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
448 newnode
->data
= attr
;
449 newnode
->next
= head
;
453 if (mask
& GL_STENCIL_BUFFER_BIT
) {
454 struct gl_stencil_attrib
*attr
;
455 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
456 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
457 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
458 newnode
->data
= attr
;
459 newnode
->next
= head
;
463 if (mask
& GL_TEXTURE_BIT
) {
464 struct texture_state
*texstate
= CALLOC_STRUCT(texture_state
);
468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glPushAttrib(GL_TEXTURE_BIT)");
472 _mesa_lock_context_textures(ctx
);
474 /* copy/save the bulk of texture state here */
475 _mesa_memcpy(&texstate
->Texture
, &ctx
->Texture
, sizeof(ctx
->Texture
));
477 /* Save references to the currently bound texture objects so they don't
478 * accidentally get deleted while referenced in the attribute stack.
480 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
481 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
482 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tex
],
483 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
487 /* copy state/contents of the currently bound texture objects */
488 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
489 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
490 _mesa_copy_texture_object(&texstate
->SavedObj
[u
][tex
],
491 ctx
->Texture
.Unit
[u
].CurrentTex
[tex
]);
495 _mesa_unlock_context_textures(ctx
);
497 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
498 newnode
->data
= texstate
;
499 newnode
->next
= head
;
503 if (mask
& GL_TRANSFORM_BIT
) {
504 struct gl_transform_attrib
*attr
;
505 attr
= MALLOC_STRUCT( gl_transform_attrib
);
506 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
507 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
508 newnode
->data
= attr
;
509 newnode
->next
= head
;
513 if (mask
& GL_VIEWPORT_BIT
) {
514 struct gl_viewport_attrib
*attr
;
515 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
516 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
517 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
518 newnode
->data
= attr
;
519 newnode
->next
= head
;
523 /* GL_ARB_multisample */
524 if (mask
& GL_MULTISAMPLE_BIT_ARB
) {
525 struct gl_multisample_attrib
*attr
;
526 attr
= MALLOC_STRUCT( gl_multisample_attrib
);
527 MEMCPY( attr
, &ctx
->Multisample
, sizeof(struct gl_multisample_attrib
) );
528 newnode
= new_attrib_node( GL_MULTISAMPLE_BIT_ARB
);
529 newnode
->data
= attr
;
530 newnode
->next
= head
;
535 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
536 ctx
->AttribStackDepth
++;
542 pop_enable_group(GLcontext
*ctx
, const struct gl_enable_attrib
*enable
)
546 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
547 if ((VALUE) != (NEWVALUE)) { \
548 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
551 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
552 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
554 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
555 const GLuint mask
= 1 << i
;
556 if ((ctx
->Transform
.ClipPlanesEnabled
& mask
) != (enable
->ClipPlanes
& mask
))
557 _mesa_set_enable(ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
),
558 (GLboolean
) ((enable
->ClipPlanes
& mask
) ? GL_TRUE
: GL_FALSE
));
561 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
,
563 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_PRECONVOLUTION
],
564 enable
->ColorTable
[COLORTABLE_PRECONVOLUTION
],
566 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCONVOLUTION
],
567 enable
->ColorTable
[COLORTABLE_POSTCONVOLUTION
],
568 GL_POST_CONVOLUTION_COLOR_TABLE
);
569 TEST_AND_UPDATE(ctx
->Pixel
.ColorTableEnabled
[COLORTABLE_POSTCOLORMATRIX
],
570 enable
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
],
571 GL_POST_COLOR_MATRIX_COLOR_TABLE
);
572 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
573 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
574 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
575 TEST_AND_UPDATE(ctx
->Pixel
.Convolution1DEnabled
, enable
->Convolution1D
,
577 TEST_AND_UPDATE(ctx
->Pixel
.Convolution2DEnabled
, enable
->Convolution2D
,
579 TEST_AND_UPDATE(ctx
->Pixel
.Separable2DEnabled
, enable
->Separable2D
,
581 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
582 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
583 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
584 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
,
586 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
,
588 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
,
591 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
592 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
593 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
594 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
,
595 GL_MAP1_TEXTURE_COORD_1
);
596 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
,
597 GL_MAP1_TEXTURE_COORD_2
);
598 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
,
599 GL_MAP1_TEXTURE_COORD_3
);
600 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
,
601 GL_MAP1_TEXTURE_COORD_4
);
602 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
,
604 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
,
606 for (i
= 0; i
< 16; i
++) {
607 TEST_AND_UPDATE(ctx
->Eval
.Map1Attrib
[i
], enable
->Map1Attrib
[i
],
608 GL_MAP1_VERTEX_ATTRIB0_4_NV
+ i
);
611 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
612 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
613 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
614 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
,
615 GL_MAP2_TEXTURE_COORD_1
);
616 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
,
617 GL_MAP2_TEXTURE_COORD_2
);
618 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
,
619 GL_MAP2_TEXTURE_COORD_3
);
620 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
,
621 GL_MAP2_TEXTURE_COORD_4
);
622 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
,
624 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
,
626 for (i
= 0; i
< 16; i
++) {
627 TEST_AND_UPDATE(ctx
->Eval
.Map2Attrib
[i
], enable
->Map2Attrib
[i
],
628 GL_MAP2_VERTEX_ATTRIB0_4_NV
+ i
);
631 TEST_AND_UPDATE(ctx
->Eval
.AutoNormal
, enable
->AutoNormal
, GL_AUTO_NORMAL
);
632 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
633 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
,
634 GL_RESCALE_NORMAL_EXT
);
635 TEST_AND_UPDATE(ctx
->Transform
.RasterPositionUnclipped
,
636 enable
->RasterPositionUnclipped
,
637 GL_RASTER_POSITION_UNCLIPPED_IBM
);
638 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
,
640 if (ctx
->Extensions
.NV_point_sprite
|| ctx
->Extensions
.ARB_point_sprite
) {
641 TEST_AND_UPDATE(ctx
->Point
.PointSprite
, enable
->PointSprite
,
644 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
,
645 GL_POLYGON_OFFSET_POINT
);
646 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
,
647 GL_POLYGON_OFFSET_LINE
);
648 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
,
649 GL_POLYGON_OFFSET_FILL
);
650 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
,
652 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
,
654 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
655 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
656 if (ctx
->Extensions
.EXT_stencil_two_side
) {
657 TEST_AND_UPDATE(ctx
->Stencil
.TestTwoSide
, enable
->StencilTwoSide
, GL_STENCIL_TEST_TWO_SIDE_EXT
);
659 TEST_AND_UPDATE(ctx
->Multisample
.Enabled
, enable
->MultisampleEnabled
,
661 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToCoverage
,
662 enable
->SampleAlphaToCoverage
,
663 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
);
664 TEST_AND_UPDATE(ctx
->Multisample
.SampleAlphaToOne
,
665 enable
->SampleAlphaToOne
,
666 GL_SAMPLE_ALPHA_TO_ONE_ARB
);
667 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverage
,
668 enable
->SampleCoverage
,
669 GL_SAMPLE_COVERAGE_ARB
);
670 TEST_AND_UPDATE(ctx
->Multisample
.SampleCoverageInvert
,
671 enable
->SampleCoverageInvert
,
672 GL_SAMPLE_COVERAGE_INVERT_ARB
);
673 /* GL_ARB_vertex_program, GL_NV_vertex_program */
674 TEST_AND_UPDATE(ctx
->VertexProgram
.Enabled
,
675 enable
->VertexProgram
,
676 GL_VERTEX_PROGRAM_ARB
);
677 TEST_AND_UPDATE(ctx
->VertexProgram
.PointSizeEnabled
,
678 enable
->VertexProgramPointSize
,
679 GL_VERTEX_PROGRAM_POINT_SIZE_ARB
);
680 TEST_AND_UPDATE(ctx
->VertexProgram
.TwoSideEnabled
,
681 enable
->VertexProgramTwoSide
,
682 GL_VERTEX_PROGRAM_TWO_SIDE_ARB
);
684 #undef TEST_AND_UPDATE
686 /* texture unit enables */
687 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
688 if (ctx
->Texture
.Unit
[i
].Enabled
!= enable
->Texture
[i
]) {
689 ctx
->Texture
.Unit
[i
].Enabled
= enable
->Texture
[i
];
690 if (ctx
->Driver
.Enable
) {
691 if (ctx
->Driver
.ActiveTexture
) {
692 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
694 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
,
695 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_1D_BIT
) );
696 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
,
697 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_2D_BIT
) );
698 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
,
699 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_3D_BIT
) );
700 if (ctx
->Extensions
.ARB_texture_cube_map
)
701 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
702 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_CUBE_BIT
) );
703 if (ctx
->Extensions
.NV_texture_rectangle
)
704 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_RECTANGLE_NV
,
705 (GLboolean
) (enable
->Texture
[i
] & TEXTURE_RECT_BIT
) );
709 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
710 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
711 if (ctx
->Driver
.Enable
) {
712 if (ctx
->Driver
.ActiveTexture
) {
713 (*ctx
->Driver
.ActiveTexture
)(ctx
, i
);
715 if (enable
->TexGen
[i
] & S_BIT
)
716 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
718 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
719 if (enable
->TexGen
[i
] & T_BIT
)
720 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
722 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
723 if (enable
->TexGen
[i
] & R_BIT
)
724 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
726 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
727 if (enable
->TexGen
[i
] & Q_BIT
)
728 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
730 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
734 /* GL_SGI_texture_color_table */
735 ctx
->Texture
.Unit
[i
].ColorTableEnabled
= enable
->TextureColorTable
[i
];
738 if (ctx
->Driver
.ActiveTexture
) {
739 (*ctx
->Driver
.ActiveTexture
)(ctx
, ctx
->Texture
.CurrentUnit
);
745 * Pop/restore texture attribute/group state.
748 pop_texture_group(GLcontext
*ctx
, struct texture_state
*texstate
)
752 _mesa_lock_context_textures(ctx
);
754 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
755 const struct gl_texture_unit
*unit
= &texstate
->Texture
.Unit
[u
];
758 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ u
);
759 _mesa_set_enable(ctx
, GL_TEXTURE_1D
,
760 (unit
->Enabled
& TEXTURE_1D_BIT
) ? GL_TRUE
: GL_FALSE
);
761 _mesa_set_enable(ctx
, GL_TEXTURE_2D
,
762 (unit
->Enabled
& TEXTURE_2D_BIT
) ? GL_TRUE
: GL_FALSE
);
763 _mesa_set_enable(ctx
, GL_TEXTURE_3D
,
764 (unit
->Enabled
& TEXTURE_3D_BIT
) ? GL_TRUE
: GL_FALSE
);
765 if (ctx
->Extensions
.ARB_texture_cube_map
) {
766 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP_ARB
,
767 (unit
->Enabled
& TEXTURE_CUBE_BIT
) ? GL_TRUE
: GL_FALSE
);
769 if (ctx
->Extensions
.NV_texture_rectangle
) {
770 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE_NV
,
771 (unit
->Enabled
& TEXTURE_RECT_BIT
) ? GL_TRUE
: GL_FALSE
);
773 if (ctx
->Extensions
.SGI_texture_color_table
) {
774 _mesa_set_enable(ctx
, GL_TEXTURE_COLOR_TABLE_SGI
,
775 unit
->ColorTableEnabled
);
777 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, unit
->EnvMode
);
778 _mesa_TexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, unit
->EnvColor
);
779 _mesa_TexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, unit
->GenS
.Mode
);
780 _mesa_TexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, unit
->GenT
.Mode
);
781 _mesa_TexGeni(GL_R
, GL_TEXTURE_GEN_MODE
, unit
->GenR
.Mode
);
782 _mesa_TexGeni(GL_Q
, GL_TEXTURE_GEN_MODE
, unit
->GenQ
.Mode
);
783 _mesa_TexGenfv(GL_S
, GL_OBJECT_PLANE
, unit
->GenS
.ObjectPlane
);
784 _mesa_TexGenfv(GL_T
, GL_OBJECT_PLANE
, unit
->GenT
.ObjectPlane
);
785 _mesa_TexGenfv(GL_R
, GL_OBJECT_PLANE
, unit
->GenR
.ObjectPlane
);
786 _mesa_TexGenfv(GL_Q
, GL_OBJECT_PLANE
, unit
->GenQ
.ObjectPlane
);
787 /* Eye plane done differently to avoid re-transformation */
789 struct gl_texture_unit
*destUnit
= &ctx
->Texture
.Unit
[u
];
790 COPY_4FV(destUnit
->GenS
.EyePlane
, unit
->GenS
.EyePlane
);
791 COPY_4FV(destUnit
->GenT
.EyePlane
, unit
->GenT
.EyePlane
);
792 COPY_4FV(destUnit
->GenR
.EyePlane
, unit
->GenR
.EyePlane
);
793 COPY_4FV(destUnit
->GenQ
.EyePlane
, unit
->GenQ
.EyePlane
);
794 if (ctx
->Driver
.TexGen
) {
795 ctx
->Driver
.TexGen(ctx
, GL_S
, GL_EYE_PLANE
, unit
->GenS
.EyePlane
);
796 ctx
->Driver
.TexGen(ctx
, GL_T
, GL_EYE_PLANE
, unit
->GenT
.EyePlane
);
797 ctx
->Driver
.TexGen(ctx
, GL_R
, GL_EYE_PLANE
, unit
->GenR
.EyePlane
);
798 ctx
->Driver
.TexGen(ctx
, GL_Q
, GL_EYE_PLANE
, unit
->GenQ
.EyePlane
);
801 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
,
802 ((unit
->TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
));
803 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
,
804 ((unit
->TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
));
805 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
,
806 ((unit
->TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
));
807 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
,
808 ((unit
->TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
));
809 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
810 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
,
811 GL_TEXTURE_LOD_BIAS_EXT
, unit
->LodBias
);
813 if (ctx
->Extensions
.EXT_texture_env_combine
||
814 ctx
->Extensions
.ARB_texture_env_combine
) {
815 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
,
816 unit
->Combine
.ModeRGB
);
817 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
,
818 unit
->Combine
.ModeA
);
819 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
,
820 unit
->Combine
.SourceRGB
[0]);
821 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_RGB
,
822 unit
->Combine
.SourceRGB
[1]);
823 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_RGB
,
824 unit
->Combine
.SourceRGB
[2]);
825 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE0_ALPHA
,
826 unit
->Combine
.SourceA
[0]);
827 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE1_ALPHA
,
828 unit
->Combine
.SourceA
[1]);
829 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_SOURCE2_ALPHA
,
830 unit
->Combine
.SourceA
[2]);
831 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_RGB
,
832 unit
->Combine
.OperandRGB
[0]);
833 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_RGB
,
834 unit
->Combine
.OperandRGB
[1]);
835 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_RGB
,
836 unit
->Combine
.OperandRGB
[2]);
837 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND0_ALPHA
,
838 unit
->Combine
.OperandA
[0]);
839 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND1_ALPHA
,
840 unit
->Combine
.OperandA
[1]);
841 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_OPERAND2_ALPHA
,
842 unit
->Combine
.OperandA
[2]);
843 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_RGB_SCALE
,
844 1 << unit
->Combine
.ScaleShiftRGB
);
845 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_ALPHA_SCALE
,
846 1 << unit
->Combine
.ScaleShiftA
);
849 /* Restore texture object state for each target */
850 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
851 const struct gl_texture_object
*obj
= NULL
;
852 GLfloat bordColor
[4];
855 obj
= &texstate
->SavedObj
[u
][tgt
];
857 /* don't restore state for unsupported targets to prevent
860 if (obj
->Target
== GL_TEXTURE_CUBE_MAP_ARB
&&
861 !ctx
->Extensions
.ARB_texture_cube_map
) {
864 else if (obj
->Target
== GL_TEXTURE_RECTANGLE_NV
&&
865 !ctx
->Extensions
.NV_texture_rectangle
) {
868 else if ((obj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
||
869 obj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) &&
870 !ctx
->Extensions
.MESA_texture_array
) {
874 target
= obj
->Target
;
876 _mesa_BindTexture(target
, obj
->Name
);
878 bordColor
[0] = CHAN_TO_FLOAT(obj
->BorderColor
[0]);
879 bordColor
[1] = CHAN_TO_FLOAT(obj
->BorderColor
[1]);
880 bordColor
[2] = CHAN_TO_FLOAT(obj
->BorderColor
[2]);
881 bordColor
[3] = CHAN_TO_FLOAT(obj
->BorderColor
[3]);
883 _mesa_TexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, bordColor
);
884 _mesa_TexParameterf(target
, GL_TEXTURE_PRIORITY
, obj
->Priority
);
885 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, obj
->WrapS
);
886 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, obj
->WrapT
);
887 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, obj
->WrapR
);
888 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, obj
->MinFilter
);
889 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, obj
->MagFilter
);
890 _mesa_TexParameterf(target
, GL_TEXTURE_MIN_LOD
, obj
->MinLod
);
891 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_LOD
, obj
->MaxLod
);
892 _mesa_TexParameterf(target
, GL_TEXTURE_LOD_BIAS
, obj
->LodBias
);
893 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, obj
->BaseLevel
);
894 if (target
!= GL_TEXTURE_RECTANGLE_ARB
)
895 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, obj
->MaxLevel
);
896 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
897 _mesa_TexParameterf(target
, GL_TEXTURE_MAX_ANISOTROPY_EXT
,
900 if (ctx
->Extensions
.ARB_shadow_ambient
) {
901 _mesa_TexParameterf(target
, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
,
902 obj
->CompareFailValue
);
906 /* remove saved references to the texture objects */
907 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
908 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
912 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
+ texstate
->Texture
.CurrentUnit
);
914 _mesa_unlock_context_textures(ctx
);
919 * This function is kind of long just because we have to call a lot
920 * of device driver functions to update device driver state.
922 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
923 * in order to restore GL state. This isn't terribly efficient but it
924 * ensures that dirty flags and any derived state gets updated correctly.
925 * We could at least check if the value to restore equals the current value
926 * and then skip the Mesa call.
929 _mesa_PopAttrib(void)
931 struct gl_attrib_node
*attr
, *next
;
932 GET_CURRENT_CONTEXT(ctx
);
933 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
935 if (ctx
->AttribStackDepth
== 0) {
936 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
940 ctx
->AttribStackDepth
--;
941 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
945 if (MESA_VERBOSE
& VERBOSE_API
) {
946 _mesa_debug(ctx
, "glPopAttrib %s\n",
947 _mesa_lookup_enum_by_nr(attr
->kind
));
950 switch (attr
->kind
) {
951 case GL_ACCUM_BUFFER_BIT
:
953 const struct gl_accum_attrib
*accum
;
954 accum
= (const struct gl_accum_attrib
*) attr
->data
;
955 _mesa_ClearAccum(accum
->ClearColor
[0],
956 accum
->ClearColor
[1],
957 accum
->ClearColor
[2],
958 accum
->ClearColor
[3]);
961 case GL_COLOR_BUFFER_BIT
:
963 const struct gl_colorbuffer_attrib
*color
;
964 color
= (const struct gl_colorbuffer_attrib
*) attr
->data
;
965 _mesa_ClearIndex((GLfloat
) color
->ClearIndex
);
966 _mesa_ClearColor(color
->ClearColor
[0],
967 color
->ClearColor
[1],
968 color
->ClearColor
[2],
969 color
->ClearColor
[3]);
970 _mesa_IndexMask(color
->IndexMask
);
971 _mesa_ColorMask((GLboolean
) (color
->ColorMask
[0] != 0),
972 (GLboolean
) (color
->ColorMask
[1] != 0),
973 (GLboolean
) (color
->ColorMask
[2] != 0),
974 (GLboolean
) (color
->ColorMask
[3] != 0));
976 /* Need to determine if more than one color output is
977 * specified. If so, call glDrawBuffersARB, else call
978 * glDrawBuffer(). This is a subtle, but essential point
979 * since GL_FRONT (for example) is illegal for the former
980 * function, but legal for the later.
982 GLboolean multipleBuffers
= GL_FALSE
;
985 for (i
= 1; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
986 if (color
->DrawBuffer
[i
] != GL_NONE
) {
987 multipleBuffers
= GL_TRUE
;
991 /* Call the API_level functions, not _mesa_drawbuffers()
992 * since we need to do error checking on the pop'd
994 * Ex: if GL_FRONT were pushed, but we're popping with a
995 * user FBO bound, GL_FRONT will be illegal and we'll need
996 * to record that error. Per OpenGL ARB decision.
999 _mesa_DrawBuffersARB(ctx
->Const
.MaxDrawBuffers
,
1002 _mesa_DrawBuffer(color
->DrawBuffer
[0]);
1004 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, color
->AlphaEnabled
);
1005 _mesa_AlphaFunc(color
->AlphaFunc
, color
->AlphaRef
);
1006 _mesa_set_enable(ctx
, GL_BLEND
, color
->BlendEnabled
);
1007 _mesa_BlendFuncSeparateEXT(color
->BlendSrcRGB
,
1011 /* This special case is because glBlendEquationSeparateEXT
1012 * cannot take GL_LOGIC_OP as a parameter.
1014 if ( color
->BlendEquationRGB
== color
->BlendEquationA
) {
1015 _mesa_BlendEquation(color
->BlendEquationRGB
);
1018 _mesa_BlendEquationSeparateEXT(color
->BlendEquationRGB
,
1019 color
->BlendEquationA
);
1021 _mesa_BlendColor(color
->BlendColor
[0],
1022 color
->BlendColor
[1],
1023 color
->BlendColor
[2],
1024 color
->BlendColor
[3]);
1025 _mesa_LogicOp(color
->LogicOp
);
1026 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
,
1027 color
->ColorLogicOpEnabled
);
1028 _mesa_set_enable(ctx
, GL_INDEX_LOGIC_OP
,
1029 color
->IndexLogicOpEnabled
);
1030 _mesa_set_enable(ctx
, GL_DITHER
, color
->DitherFlag
);
1033 case GL_CURRENT_BIT
:
1034 FLUSH_CURRENT( ctx
, 0 );
1035 MEMCPY( &ctx
->Current
, attr
->data
,
1036 sizeof(struct gl_current_attrib
) );
1038 case GL_DEPTH_BUFFER_BIT
:
1040 const struct gl_depthbuffer_attrib
*depth
;
1041 depth
= (const struct gl_depthbuffer_attrib
*) attr
->data
;
1042 _mesa_DepthFunc(depth
->Func
);
1043 _mesa_ClearDepth(depth
->Clear
);
1044 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, depth
->Test
);
1045 _mesa_DepthMask(depth
->Mask
);
1050 const struct gl_enable_attrib
*enable
;
1051 enable
= (const struct gl_enable_attrib
*) attr
->data
;
1052 pop_enable_group(ctx
, enable
);
1053 ctx
->NewState
|= _NEW_ALL
;
1057 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
1058 ctx
->NewState
|= _NEW_EVAL
;
1062 const struct gl_fog_attrib
*fog
;
1063 fog
= (const struct gl_fog_attrib
*) attr
->data
;
1064 _mesa_set_enable(ctx
, GL_FOG
, fog
->Enabled
);
1065 _mesa_Fogfv(GL_FOG_COLOR
, fog
->Color
);
1066 _mesa_Fogf(GL_FOG_DENSITY
, fog
->Density
);
1067 _mesa_Fogf(GL_FOG_START
, fog
->Start
);
1068 _mesa_Fogf(GL_FOG_END
, fog
->End
);
1069 _mesa_Fogf(GL_FOG_INDEX
, fog
->Index
);
1070 _mesa_Fogi(GL_FOG_MODE
, fog
->Mode
);
1075 const struct gl_hint_attrib
*hint
;
1076 hint
= (const struct gl_hint_attrib
*) attr
->data
;
1077 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT
,
1078 hint
->PerspectiveCorrection
);
1079 _mesa_Hint(GL_POINT_SMOOTH_HINT
, hint
->PointSmooth
);
1080 _mesa_Hint(GL_LINE_SMOOTH_HINT
, hint
->LineSmooth
);
1081 _mesa_Hint(GL_POLYGON_SMOOTH_HINT
, hint
->PolygonSmooth
);
1082 _mesa_Hint(GL_FOG_HINT
, hint
->Fog
);
1083 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT
,
1084 hint
->ClipVolumeClipping
);
1085 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB
,
1086 hint
->TextureCompression
);
1089 case GL_LIGHTING_BIT
:
1092 const struct gl_light_attrib
*light
;
1093 light
= (const struct gl_light_attrib
*) attr
->data
;
1094 /* lighting enable */
1095 _mesa_set_enable(ctx
, GL_LIGHTING
, light
->Enabled
);
1096 /* per-light state */
1097 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
))
1098 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
1100 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1101 const struct gl_light
*l
= &light
->Light
[i
];
1102 _mesa_set_enable(ctx
, GL_LIGHT0
+ i
, l
->Enabled
);
1103 _mesa_light(ctx
, i
, GL_AMBIENT
, l
->Ambient
);
1104 _mesa_light(ctx
, i
, GL_DIFFUSE
, l
->Diffuse
);
1105 _mesa_light(ctx
, i
, GL_SPECULAR
, l
->Specular
);
1106 _mesa_light(ctx
, i
, GL_POSITION
, l
->EyePosition
);
1107 _mesa_light(ctx
, i
, GL_SPOT_DIRECTION
, l
->SpotDirection
);
1108 _mesa_light(ctx
, i
, GL_SPOT_EXPONENT
, &l
->SpotExponent
);
1109 _mesa_light(ctx
, i
, GL_SPOT_CUTOFF
, &l
->SpotCutoff
);
1110 _mesa_light(ctx
, i
, GL_CONSTANT_ATTENUATION
,
1111 &l
->ConstantAttenuation
);
1112 _mesa_light(ctx
, i
, GL_LINEAR_ATTENUATION
,
1113 &l
->LinearAttenuation
);
1114 _mesa_light(ctx
, i
, GL_QUADRATIC_ATTENUATION
,
1115 &l
->QuadraticAttenuation
);
1118 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT
,
1119 light
->Model
.Ambient
);
1120 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER
,
1121 (GLfloat
) light
->Model
.LocalViewer
);
1122 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE
,
1123 (GLfloat
) light
->Model
.TwoSide
);
1124 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL
,
1125 (GLfloat
) light
->Model
.ColorControl
);
1127 _mesa_ShadeModel(light
->ShadeModel
);
1128 /* color material */
1129 _mesa_ColorMaterial(light
->ColorMaterialFace
,
1130 light
->ColorMaterialMode
);
1131 _mesa_set_enable(ctx
, GL_COLOR_MATERIAL
,
1132 light
->ColorMaterialEnabled
);
1134 MEMCPY(&ctx
->Light
.Material
, &light
->Material
,
1135 sizeof(struct gl_material
));
1140 const struct gl_line_attrib
*line
;
1141 line
= (const struct gl_line_attrib
*) attr
->data
;
1142 _mesa_set_enable(ctx
, GL_LINE_SMOOTH
, line
->SmoothFlag
);
1143 _mesa_set_enable(ctx
, GL_LINE_STIPPLE
, line
->StippleFlag
);
1144 _mesa_LineStipple(line
->StippleFactor
, line
->StipplePattern
);
1145 _mesa_LineWidth(line
->Width
);
1149 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
1151 case GL_PIXEL_MODE_BIT
:
1152 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
1153 /* XXX what other pixel state needs to be set by function calls? */
1154 _mesa_ReadBuffer(ctx
->Pixel
.ReadBuffer
);
1155 ctx
->NewState
|= _NEW_PIXEL
;
1159 const struct gl_point_attrib
*point
;
1160 point
= (const struct gl_point_attrib
*) attr
->data
;
1161 _mesa_PointSize(point
->Size
);
1162 _mesa_set_enable(ctx
, GL_POINT_SMOOTH
, point
->SmoothFlag
);
1163 if (ctx
->Extensions
.EXT_point_parameters
) {
1164 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT
,
1166 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT
,
1168 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT
,
1170 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT
,
1173 if (ctx
->Extensions
.NV_point_sprite
1174 || ctx
->Extensions
.ARB_point_sprite
) {
1176 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1177 _mesa_TexEnvi(GL_POINT_SPRITE_NV
, GL_COORD_REPLACE_NV
,
1178 (GLint
) point
->CoordReplace
[u
]);
1180 _mesa_set_enable(ctx
, GL_POINT_SPRITE_NV
,point
->PointSprite
);
1181 if (ctx
->Extensions
.NV_point_sprite
)
1182 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV
,
1183 ctx
->Point
.SpriteRMode
);
1184 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN
,
1185 (GLfloat
)ctx
->Point
.SpriteOrigin
);
1189 case GL_POLYGON_BIT
:
1191 const struct gl_polygon_attrib
*polygon
;
1192 polygon
= (const struct gl_polygon_attrib
*) attr
->data
;
1193 _mesa_CullFace(polygon
->CullFaceMode
);
1194 _mesa_FrontFace(polygon
->FrontFace
);
1195 _mesa_PolygonMode(GL_FRONT
, polygon
->FrontMode
);
1196 _mesa_PolygonMode(GL_BACK
, polygon
->BackMode
);
1197 _mesa_PolygonOffset(polygon
->OffsetFactor
,
1198 polygon
->OffsetUnits
);
1199 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, polygon
->SmoothFlag
);
1200 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, polygon
->StippleFlag
);
1201 _mesa_set_enable(ctx
, GL_CULL_FACE
, polygon
->CullFlag
);
1202 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_POINT
,
1203 polygon
->OffsetPoint
);
1204 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_LINE
,
1205 polygon
->OffsetLine
);
1206 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
,
1207 polygon
->OffsetFill
);
1210 case GL_POLYGON_STIPPLE_BIT
:
1211 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
1212 ctx
->NewState
|= _NEW_POLYGONSTIPPLE
;
1213 if (ctx
->Driver
.PolygonStipple
)
1214 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
1216 case GL_SCISSOR_BIT
:
1218 const struct gl_scissor_attrib
*scissor
;
1219 scissor
= (const struct gl_scissor_attrib
*) attr
->data
;
1220 _mesa_Scissor(scissor
->X
, scissor
->Y
,
1221 scissor
->Width
, scissor
->Height
);
1222 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, scissor
->Enabled
);
1225 case GL_STENCIL_BUFFER_BIT
:
1227 const struct gl_stencil_attrib
*stencil
;
1228 stencil
= (const struct gl_stencil_attrib
*) attr
->data
;
1229 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
1230 _mesa_ClearStencil(stencil
->Clear
);
1231 if (ctx
->Extensions
.EXT_stencil_two_side
) {
1232 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
1233 stencil
->TestTwoSide
);
1234 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
1235 ? GL_BACK
: GL_FRONT
);
1238 _mesa_StencilFuncSeparate(GL_FRONT
,
1239 stencil
->Function
[0],
1241 stencil
->ValueMask
[0]);
1242 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
1243 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
1244 stencil
->ZFailFunc
[0],
1245 stencil
->ZPassFunc
[0]);
1247 _mesa_StencilFuncSeparate(GL_BACK
,
1248 stencil
->Function
[1],
1250 stencil
->ValueMask
[1]);
1251 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
1252 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
1253 stencil
->ZFailFunc
[1],
1254 stencil
->ZPassFunc
[1]);
1257 case GL_TRANSFORM_BIT
:
1260 const struct gl_transform_attrib
*xform
;
1261 xform
= (const struct gl_transform_attrib
*) attr
->data
;
1262 _mesa_MatrixMode(xform
->MatrixMode
);
1263 if (_math_matrix_is_dirty(ctx
->ProjectionMatrixStack
.Top
))
1264 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
1266 /* restore clip planes */
1267 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
1268 const GLuint mask
= 1 << i
;
1269 const GLfloat
*eyePlane
= xform
->EyeUserPlane
[i
];
1270 COPY_4V(ctx
->Transform
.EyeUserPlane
[i
], eyePlane
);
1271 if (xform
->ClipPlanesEnabled
& mask
) {
1272 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1275 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
1277 if (ctx
->Driver
.ClipPlane
)
1278 ctx
->Driver
.ClipPlane( ctx
, GL_CLIP_PLANE0
+ i
, eyePlane
);
1281 /* normalize/rescale */
1282 if (xform
->Normalize
!= ctx
->Transform
.Normalize
)
1283 _mesa_set_enable(ctx
, GL_NORMALIZE
,ctx
->Transform
.Normalize
);
1284 if (xform
->RescaleNormals
!= ctx
->Transform
.RescaleNormals
)
1285 _mesa_set_enable(ctx
, GL_RESCALE_NORMAL_EXT
,
1286 ctx
->Transform
.RescaleNormals
);
1289 case GL_TEXTURE_BIT
:
1290 /* Take care of texture object reference counters */
1292 struct texture_state
*texstate
1293 = (struct texture_state
*) attr
->data
;
1294 pop_texture_group(ctx
, texstate
);
1295 ctx
->NewState
|= _NEW_TEXTURE
;
1298 case GL_VIEWPORT_BIT
:
1300 const struct gl_viewport_attrib
*vp
;
1301 vp
= (const struct gl_viewport_attrib
*) attr
->data
;
1302 _mesa_Viewport(vp
->X
, vp
->Y
, vp
->Width
, vp
->Height
);
1303 _mesa_DepthRange(vp
->Near
, vp
->Far
);
1306 case GL_MULTISAMPLE_BIT_ARB
:
1308 const struct gl_multisample_attrib
*ms
;
1309 ms
= (const struct gl_multisample_attrib
*) attr
->data
;
1310 _mesa_SampleCoverageARB(ms
->SampleCoverageValue
,
1311 ms
->SampleCoverageInvert
);
1316 _mesa_problem( ctx
, "Bad attrib flag in PopAttrib");
1329 * Helper for incrementing/decrementing vertex buffer object reference
1330 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1333 adjust_buffer_object_ref_counts(struct gl_array_attrib
*array
, GLint step
)
1336 array
->ArrayObj
->Vertex
.BufferObj
->RefCount
+= step
;
1337 array
->ArrayObj
->Normal
.BufferObj
->RefCount
+= step
;
1338 array
->ArrayObj
->Color
.BufferObj
->RefCount
+= step
;
1339 array
->ArrayObj
->SecondaryColor
.BufferObj
->RefCount
+= step
;
1340 array
->ArrayObj
->FogCoord
.BufferObj
->RefCount
+= step
;
1341 array
->ArrayObj
->Index
.BufferObj
->RefCount
+= step
;
1342 array
->ArrayObj
->EdgeFlag
.BufferObj
->RefCount
+= step
;
1343 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
1344 array
->ArrayObj
->TexCoord
[i
].BufferObj
->RefCount
+= step
;
1345 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1346 array
->ArrayObj
->VertexAttrib
[i
].BufferObj
->RefCount
+= step
;
1351 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1355 copy_pixelstore(GLcontext
*ctx
,
1356 struct gl_pixelstore_attrib
*dst
,
1357 const struct gl_pixelstore_attrib
*src
)
1359 dst
->Alignment
= src
->Alignment
;
1360 dst
->RowLength
= src
->RowLength
;
1361 dst
->SkipPixels
= src
->SkipPixels
;
1362 dst
->SkipRows
= src
->SkipRows
;
1363 dst
->ImageHeight
= src
->ImageHeight
;
1364 dst
->SkipImages
= src
->SkipImages
;
1365 dst
->SwapBytes
= src
->SwapBytes
;
1366 dst
->LsbFirst
= src
->LsbFirst
;
1367 dst
->ClientStorage
= src
->ClientStorage
;
1368 dst
->Invert
= src
->Invert
;
1369 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1373 #define GL_CLIENT_PACK_BIT (1<<20)
1374 #define GL_CLIENT_UNPACK_BIT (1<<21)
1378 _mesa_PushClientAttrib(GLbitfield mask
)
1380 struct gl_attrib_node
*newnode
;
1381 struct gl_attrib_node
*head
;
1383 GET_CURRENT_CONTEXT(ctx
);
1384 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1386 if (ctx
->ClientAttribStackDepth
>= MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
1387 _mesa_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
1391 /* Build linked list of attribute nodes which save all attribute
1392 * groups specified by the mask.
1396 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
1397 struct gl_pixelstore_attrib
*attr
;
1398 /* packing attribs */
1399 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1400 copy_pixelstore(ctx
, attr
, &ctx
->Pack
);
1401 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
1402 newnode
->data
= attr
;
1403 newnode
->next
= head
;
1405 /* unpacking attribs */
1406 attr
= CALLOC_STRUCT( gl_pixelstore_attrib
);
1407 copy_pixelstore(ctx
, attr
, &ctx
->Unpack
);
1408 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
1409 newnode
->data
= attr
;
1410 newnode
->next
= head
;
1414 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
1415 struct gl_array_attrib
*attr
;
1416 struct gl_array_object
*obj
;
1418 attr
= MALLOC_STRUCT( gl_array_attrib
);
1419 obj
= MALLOC_STRUCT( gl_array_object
);
1421 #if FEATURE_ARB_vertex_buffer_object
1422 /* increment ref counts since we're copying pointers to these objects */
1423 ctx
->Array
.ArrayBufferObj
->RefCount
++;
1424 ctx
->Array
.ElementArrayBufferObj
->RefCount
++;
1427 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
1428 MEMCPY( obj
, ctx
->Array
.ArrayObj
, sizeof(struct gl_array_object
) );
1430 attr
->ArrayObj
= obj
;
1432 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
1433 newnode
->data
= attr
;
1434 newnode
->next
= head
;
1436 /* bump reference counts on buffer objects */
1437 adjust_buffer_object_ref_counts(&ctx
->Array
, 1);
1440 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
1441 ctx
->ClientAttribStackDepth
++;
1448 _mesa_PopClientAttrib(void)
1450 struct gl_attrib_node
*node
, *next
;
1452 GET_CURRENT_CONTEXT(ctx
);
1453 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1455 if (ctx
->ClientAttribStackDepth
== 0) {
1456 _mesa_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
1460 ctx
->ClientAttribStackDepth
--;
1461 node
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
1464 switch (node
->kind
) {
1465 case GL_CLIENT_PACK_BIT
:
1467 struct gl_pixelstore_attrib
*store
=
1468 (struct gl_pixelstore_attrib
*) node
->data
;
1469 copy_pixelstore(ctx
, &ctx
->Pack
, store
);
1470 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1472 ctx
->NewState
|= _NEW_PACKUNPACK
;
1474 case GL_CLIENT_UNPACK_BIT
:
1476 struct gl_pixelstore_attrib
*store
=
1477 (struct gl_pixelstore_attrib
*) node
->data
;
1478 copy_pixelstore(ctx
, &ctx
->Unpack
, store
);
1479 _mesa_reference_buffer_object(ctx
, &store
->BufferObj
, NULL
);
1481 ctx
->NewState
|= _NEW_PACKUNPACK
;
1483 case GL_CLIENT_VERTEX_ARRAY_BIT
: {
1484 struct gl_array_attrib
* data
=
1485 (struct gl_array_attrib
*) node
->data
;
1487 adjust_buffer_object_ref_counts(&ctx
->Array
, -1);
1489 ctx
->Array
.ActiveTexture
= data
->ActiveTexture
;
1490 if (data
->LockCount
!= 0)
1491 _mesa_LockArraysEXT(data
->LockFirst
, data
->LockCount
);
1492 else if (ctx
->Array
.LockCount
)
1493 _mesa_UnlockArraysEXT();
1495 _mesa_BindVertexArrayAPPLE( data
->ArrayObj
->Name
);
1497 #if FEATURE_ARB_vertex_buffer_object
1498 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
,
1499 data
->ArrayBufferObj
->Name
);
1500 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
1501 data
->ElementArrayBufferObj
->Name
);
1504 MEMCPY( ctx
->Array
.ArrayObj
, data
->ArrayObj
,
1505 sizeof( struct gl_array_object
) );
1507 FREE( data
->ArrayObj
);
1509 /* FIXME: Should some bits in ctx->Array->NewState also be set
1510 * FIXME: here? It seems like it should be set to inclusive-or
1511 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1514 ctx
->NewState
|= _NEW_ARRAY
;
1518 _mesa_problem( ctx
, "Bad attrib flag in PopClientAttrib");
1531 * Free any attribute state data that might be attached to the context.
1534 _mesa_free_attrib_data(GLcontext
*ctx
)
1536 while (ctx
->AttribStackDepth
> 0) {
1537 struct gl_attrib_node
*attr
, *next
;
1539 ctx
->AttribStackDepth
--;
1540 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
1543 if (attr
->kind
== GL_TEXTURE_BIT
) {
1544 struct texture_state
*texstate
= (struct texture_state
*)attr
->data
;
1546 /* clear references to the saved texture objects */
1547 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1548 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1549 _mesa_reference_texobj(&texstate
->SavedTexRef
[u
][tgt
], NULL
);
1554 /* any other chunks of state that requires special handling? */
1558 _mesa_free(attr
->data
);
1566 void _mesa_init_attrib( GLcontext
*ctx
)
1568 /* Renderer and client attribute stacks */
1569 ctx
->AttribStackDepth
= 0;
1570 ctx
->ClientAttribStackDepth
= 0;