1 /* $Id: attrib.c,v 1.13 1999/11/23 21:15:37 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include "simple_list.h"
47 * Allocate a new attribute state node. These nodes have a
48 * "kind" value and a pointer to a struct of state data.
50 static struct gl_attrib_node
*new_attrib_node( GLbitfield kind
)
52 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
62 * Copy texture object state from one texture object to another.
64 static void copy_texobj_state( struct gl_texture_object
*dest
,
65 const struct gl_texture_object
*src
)
68 dest->Name = src->Name;
69 dest->Dimensions = src->Dimensions;
71 dest
->Priority
= src
->Priority
;
72 dest
->BorderColor
[0] = src
->BorderColor
[0];
73 dest
->BorderColor
[1] = src
->BorderColor
[1];
74 dest
->BorderColor
[2] = src
->BorderColor
[2];
75 dest
->BorderColor
[3] = src
->BorderColor
[3];
76 dest
->WrapS
= src
->WrapS
;
77 dest
->WrapT
= src
->WrapT
;
78 dest
->WrapR
= src
->WrapR
;
79 dest
->MinFilter
= src
->MinFilter
;
80 dest
->MagFilter
= src
->MagFilter
;
81 dest
->MinLod
= src
->MinLod
;
82 dest
->MaxLod
= src
->MaxLod
;
83 dest
->BaseLevel
= src
->BaseLevel
;
84 dest
->MaxLevel
= src
->MaxLevel
;
87 dest
->MinMagThresh
= src
->MinMagThresh
;
88 dest
->Palette
= src
->Palette
;
89 dest
->Complete
= src
->Complete
;
90 dest
->SampleFunc
= src
->SampleFunc
;
95 void gl_PushAttrib( GLcontext
* ctx
, GLbitfield mask
)
97 struct gl_attrib_node
*newnode
;
98 struct gl_attrib_node
*head
;
100 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushAttrib");
102 if (MESA_VERBOSE
&VERBOSE_API
)
103 fprintf(stderr
, "glPushAttrib %x\n", mask
);
105 if (ctx
->AttribStackDepth
>=MAX_ATTRIB_STACK_DEPTH
) {
106 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
110 /* Build linked list of attribute nodes which save all attribute */
111 /* groups specified by the mask. */
114 if (mask
& GL_ACCUM_BUFFER_BIT
) {
115 struct gl_accum_attrib
*attr
;
116 attr
= MALLOC_STRUCT( gl_accum_attrib
);
117 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
118 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
119 newnode
->data
= attr
;
120 newnode
->next
= head
;
124 if (mask
& GL_COLOR_BUFFER_BIT
) {
125 struct gl_colorbuffer_attrib
*attr
;
126 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
127 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
128 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
129 newnode
->data
= attr
;
130 newnode
->next
= head
;
134 if (mask
& GL_CURRENT_BIT
) {
135 struct gl_current_attrib
*attr
;
136 attr
= MALLOC_STRUCT( gl_current_attrib
);
137 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
138 newnode
= new_attrib_node( GL_CURRENT_BIT
);
139 newnode
->data
= attr
;
140 newnode
->next
= head
;
144 if (mask
& GL_DEPTH_BUFFER_BIT
) {
145 struct gl_depthbuffer_attrib
*attr
;
146 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
147 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
148 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
149 newnode
->data
= attr
;
150 newnode
->next
= head
;
154 if (mask
& GL_ENABLE_BIT
) {
155 struct gl_enable_attrib
*attr
;
157 attr
= MALLOC_STRUCT( gl_enable_attrib
);
158 /* Copy enable flags from all other attributes into the enable struct. */
159 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
160 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
161 attr
->Blend
= ctx
->Color
.BlendEnabled
;
162 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
163 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
165 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
166 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
167 attr
->DepthTest
= ctx
->Depth
.Test
;
168 attr
->Dither
= ctx
->Color
.DitherFlag
;
169 attr
->Fog
= ctx
->Fog
.Enabled
;
170 for (i
=0;i
<MAX_LIGHTS
;i
++) {
171 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
173 attr
->Lighting
= ctx
->Light
.Enabled
;
174 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
175 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
176 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
177 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
178 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
179 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
180 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
181 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
182 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
183 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
184 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
185 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
186 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
187 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
188 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
189 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
190 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
191 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
192 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
193 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
194 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
195 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
196 attr
->Normalize
= ctx
->Transform
.Normalize
;
197 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
198 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
199 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
200 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
201 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
202 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
203 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
204 attr
->Scissor
= ctx
->Scissor
.Enabled
;
205 attr
->Stencil
= ctx
->Stencil
.Enabled
;
206 attr
->Texture
= ctx
->Texture
.Enabled
;
207 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
208 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
210 newnode
= new_attrib_node( GL_ENABLE_BIT
);
211 newnode
->data
= attr
;
212 newnode
->next
= head
;
216 if (mask
& GL_EVAL_BIT
) {
217 struct gl_eval_attrib
*attr
;
218 attr
= MALLOC_STRUCT( gl_eval_attrib
);
219 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
220 newnode
= new_attrib_node( GL_EVAL_BIT
);
221 newnode
->data
= attr
;
222 newnode
->next
= head
;
226 if (mask
& GL_FOG_BIT
) {
227 struct gl_fog_attrib
*attr
;
228 attr
= MALLOC_STRUCT( gl_fog_attrib
);
229 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
230 newnode
= new_attrib_node( GL_FOG_BIT
);
231 newnode
->data
= attr
;
232 newnode
->next
= head
;
236 if (mask
& GL_HINT_BIT
) {
237 struct gl_hint_attrib
*attr
;
238 attr
= MALLOC_STRUCT( gl_hint_attrib
);
239 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
240 newnode
= new_attrib_node( GL_HINT_BIT
);
241 newnode
->data
= attr
;
242 newnode
->next
= head
;
246 if (mask
& GL_LIGHTING_BIT
) {
247 struct gl_light_attrib
*attr
;
248 attr
= MALLOC_STRUCT( gl_light_attrib
);
249 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
250 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
251 newnode
->data
= attr
;
252 newnode
->next
= head
;
256 if (mask
& GL_LINE_BIT
) {
257 struct gl_line_attrib
*attr
;
258 attr
= MALLOC_STRUCT( gl_line_attrib
);
259 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
260 newnode
= new_attrib_node( GL_LINE_BIT
);
261 newnode
->data
= attr
;
262 newnode
->next
= head
;
266 if (mask
& GL_LIST_BIT
) {
267 struct gl_list_attrib
*attr
;
268 attr
= MALLOC_STRUCT( gl_list_attrib
);
269 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
270 newnode
= new_attrib_node( GL_LIST_BIT
);
271 newnode
->data
= attr
;
272 newnode
->next
= head
;
276 if (mask
& GL_PIXEL_MODE_BIT
) {
277 struct gl_pixel_attrib
*attr
;
278 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
279 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
280 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
281 newnode
->data
= attr
;
282 newnode
->next
= head
;
286 if (mask
& GL_POINT_BIT
) {
287 struct gl_point_attrib
*attr
;
288 attr
= MALLOC_STRUCT( gl_point_attrib
);
289 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
290 newnode
= new_attrib_node( GL_POINT_BIT
);
291 newnode
->data
= attr
;
292 newnode
->next
= head
;
296 if (mask
& GL_POLYGON_BIT
) {
297 struct gl_polygon_attrib
*attr
;
298 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
299 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
300 newnode
= new_attrib_node( GL_POLYGON_BIT
);
301 newnode
->data
= attr
;
302 newnode
->next
= head
;
306 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
308 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
309 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
310 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
311 newnode
->data
= stipple
;
312 newnode
->next
= head
;
316 if (mask
& GL_SCISSOR_BIT
) {
317 struct gl_scissor_attrib
*attr
;
318 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
319 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
320 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
321 newnode
->data
= attr
;
322 newnode
->next
= head
;
326 if (mask
& GL_STENCIL_BUFFER_BIT
) {
327 struct gl_stencil_attrib
*attr
;
328 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
329 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
330 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
331 newnode
->data
= attr
;
332 newnode
->next
= head
;
336 if (mask
& GL_TEXTURE_BIT
) {
337 struct gl_texture_attrib
*attr
;
339 /* Take care of texture object reference counters */
340 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
341 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
++;
342 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
++;
343 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
++;
345 attr
= MALLOC_STRUCT( gl_texture_attrib
);
346 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
347 /* copy state of the currently bound texture objects */
348 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
349 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].CurrentD
[1]);
350 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].CurrentD
[2]);
351 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].CurrentD
[3]);
353 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
354 newnode
->data
= attr
;
355 newnode
->next
= head
;
359 if (mask
& GL_TRANSFORM_BIT
) {
360 struct gl_transform_attrib
*attr
;
361 attr
= MALLOC_STRUCT( gl_transform_attrib
);
362 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
363 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
364 newnode
->data
= attr
;
365 newnode
->next
= head
;
369 if (mask
& GL_VIEWPORT_BIT
) {
370 struct gl_viewport_attrib
*attr
;
371 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
372 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
373 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
374 newnode
->data
= attr
;
375 newnode
->next
= head
;
379 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
380 ctx
->AttribStackDepth
++;
386 * This function is kind of long just because we have to call a lot
387 * of device driver functions to update device driver state.
389 void gl_PopAttrib( GLcontext
* ctx
)
391 struct gl_attrib_node
*attr
, *next
;
393 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopAttrib");
396 if (ctx
->AttribStackDepth
==0) {
397 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
401 ctx
->AttribStackDepth
--;
402 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
406 if (MESA_VERBOSE
&VERBOSE_API
)
407 fprintf(stderr
, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr
->kind
));
409 switch (attr
->kind
) {
410 case GL_ACCUM_BUFFER_BIT
:
411 MEMCPY( &ctx
->Accum
, attr
->data
, sizeof(struct gl_accum_attrib
) );
413 case GL_COLOR_BUFFER_BIT
:
415 GLenum oldDrawBuffer
= ctx
->Color
.DrawBuffer
;
416 GLenum oldAlphaFunc
= ctx
->Color
.AlphaFunc
;
417 GLubyte oldAlphaRef
= ctx
->Color
.AlphaRef
;
418 GLenum oldBlendSrc
= ctx
->Color
.BlendSrcRGB
;
419 GLenum oldBlendDst
= ctx
->Color
.BlendDstRGB
;
420 MEMCPY( &ctx
->Color
, attr
->data
,
421 sizeof(struct gl_colorbuffer_attrib
) );
422 if (ctx
->Color
.DrawBuffer
!= oldDrawBuffer
) {
423 _mesa_DrawBuffer( ctx
->Color
.DrawBuffer
);
425 if ((ctx
->Color
.AlphaFunc
!= oldAlphaFunc
||
426 ctx
->Color
.AlphaRef
!= oldAlphaRef
) &&
427 ctx
->Driver
.AlphaFunc
)
428 (*ctx
->Driver
.AlphaFunc
)( ctx
, ctx
->Color
.AlphaFunc
,
429 ctx
->Color
.AlphaRef
/ 255.0F
);
430 if ((ctx
->Color
.BlendSrcRGB
!= oldBlendSrc
||
431 ctx
->Color
.BlendSrcRGB
!= oldBlendDst
) &&
432 ctx
->Driver
.BlendFunc
)
433 (*ctx
->Driver
.BlendFunc
)( ctx
, ctx
->Color
.BlendSrcRGB
,
434 ctx
->Color
.BlendDstRGB
);
438 MEMCPY( &ctx
->Current
, attr
->data
,
439 sizeof(struct gl_current_attrib
) );
441 case GL_DEPTH_BUFFER_BIT
:
443 GLenum oldDepthFunc
= ctx
->Depth
.Func
;
444 GLboolean oldDepthMask
= ctx
->Depth
.Mask
;
445 GLfloat oldDepthClear
= ctx
->Depth
.Clear
;
446 MEMCPY( &ctx
->Depth
, attr
->data
,
447 sizeof(struct gl_depthbuffer_attrib
) );
448 if (ctx
->Depth
.Func
!= oldDepthFunc
&& ctx
->Driver
.DepthFunc
)
449 (*ctx
->Driver
.DepthFunc
)( ctx
, ctx
->Depth
.Func
);
450 if (ctx
->Depth
.Mask
!= oldDepthMask
&& ctx
->Driver
.DepthMask
)
451 (*ctx
->Driver
.DepthMask
)( ctx
, ctx
->Depth
.Mask
);
452 if (ctx
->Depth
.Clear
!= oldDepthClear
&& ctx
->Driver
.ClearDepth
)
453 (*ctx
->Driver
.ClearDepth
)( ctx
, ctx
->Depth
.Clear
);
458 const struct gl_enable_attrib
*enable
;
459 enable
= (const struct gl_enable_attrib
*) attr
->data
;
461 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
462 if ((VALUE) != (NEWVALUE)) { \
463 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
466 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
467 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->AutoNormal
, GL_NORMALIZE
);
468 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
471 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
472 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
473 _mesa_set_enable( ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
), enable
->ClipPlane
[i
] );
476 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
, GL_COLOR_MATERIAL
);
477 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
478 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
479 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
480 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
481 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
482 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
483 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
, GL_LINE_STIPPLE
);
484 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
, GL_INDEX_LOGIC_OP
);
485 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
, GL_COLOR_LOGIC_OP
);
486 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
487 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
488 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
489 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
, GL_MAP1_TEXTURE_COORD_1
);
490 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
, GL_MAP1_TEXTURE_COORD_2
);
491 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
, GL_MAP1_TEXTURE_COORD_3
);
492 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
, GL_MAP1_TEXTURE_COORD_4
);
493 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
, GL_MAP1_VERTEX_3
);
494 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
, GL_MAP1_VERTEX_4
);
495 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
496 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
497 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
498 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
, GL_MAP2_TEXTURE_COORD_1
);
499 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
, GL_MAP2_TEXTURE_COORD_2
);
500 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
, GL_MAP2_TEXTURE_COORD_3
);
501 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
, GL_MAP2_TEXTURE_COORD_4
);
502 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
, GL_MAP2_VERTEX_3
);
503 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
, GL_MAP2_VERTEX_4
);
504 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
505 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
, GL_RESCALE_NORMAL_EXT
);
506 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
, GL_POINT_SMOOTH
);
507 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
, GL_POLYGON_OFFSET_POINT
);
508 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
, GL_POLYGON_OFFSET_LINE
);
509 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
, GL_POLYGON_OFFSET_FILL
);
510 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
, GL_POLYGON_SMOOTH
);
511 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
, GL_POLYGON_STIPPLE
);
512 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
513 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
514 if (ctx
->Texture
.Enabled
!= enable
->Texture
) {
515 ctx
->Texture
.Enabled
= enable
->Texture
;
516 if (ctx
->Driver
.Enable
) {
517 if (ctx
->Driver
.ActiveTexture
)
518 (*ctx
->Driver
.ActiveTexture
)( ctx
, 0 );
519 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE0_1D
) );
520 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE0_2D
) );
521 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE0_3D
) );
522 if (ctx
->Driver
.ActiveTexture
)
523 (*ctx
->Driver
.ActiveTexture
)( ctx
, 1 );
524 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE1_1D
) );
525 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE1_2D
) );
526 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE1_3D
) );
527 if (ctx
->Driver
.ActiveTexture
)
528 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
531 #undef TEST_AND_UPDATE
534 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
535 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
536 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
538 /* ctx->Enabled recalculated in state change
541 if (ctx
->Driver
.Enable
) {
542 if (ctx
->Driver
.ActiveTexture
)
543 (*ctx
->Driver
.ActiveTexture
)( ctx
, i
);
544 if (enable
->TexGen
[i
] & S_BIT
)
545 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
547 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
548 if (enable
->TexGen
[i
] & T_BIT
)
549 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
551 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
552 if (enable
->TexGen
[i
] & R_BIT
)
553 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
555 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
556 if (enable
->TexGen
[i
] & Q_BIT
)
557 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
559 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
563 if (ctx
->Driver
.ActiveTexture
)
564 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
569 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
573 GLboolean anyChange
= (GLboolean
) (memcmp( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) ) != 0);
574 MEMCPY( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) );
575 if (anyChange
&& ctx
->Driver
.Fogfv
) {
576 const GLfloat mode
= (GLfloat
) ctx
->Fog
.Mode
;
577 const GLfloat density
= ctx
->Fog
.Density
;
578 const GLfloat start
= ctx
->Fog
.Start
;
579 const GLfloat end
= ctx
->Fog
.End
;
580 const GLfloat index
= ctx
->Fog
.Index
;
581 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_MODE
, &mode
);
582 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_DENSITY
, &density
);
583 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_START
, &start
);
584 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_END
, &end
);
585 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_INDEX
, &index
);
586 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
588 ctx
->Enabled
&= ~ENABLE_FOG
;
589 if (ctx
->Fog
.Enabled
) ctx
->Enabled
|= ENABLE_FOG
;
593 MEMCPY( &ctx
->Hint
, attr
->data
, sizeof(struct gl_hint_attrib
) );
594 if (ctx
->Driver
.Hint
) {
595 (*ctx
->Driver
.Hint
)( ctx
, GL_PERSPECTIVE_CORRECTION_HINT
,
596 ctx
->Hint
.PerspectiveCorrection
);
597 (*ctx
->Driver
.Hint
)( ctx
, GL_POINT_SMOOTH_HINT
,
598 ctx
->Hint
.PointSmooth
);
599 (*ctx
->Driver
.Hint
)( ctx
, GL_LINE_SMOOTH_HINT
,
600 ctx
->Hint
.LineSmooth
);
601 (*ctx
->Driver
.Hint
)( ctx
, GL_POLYGON_SMOOTH_HINT
,
602 ctx
->Hint
.PolygonSmooth
);
603 (*ctx
->Driver
.Hint
)( ctx
, GL_FOG_HINT
, ctx
->Hint
.Fog
);
606 case GL_LIGHTING_BIT
:
607 MEMCPY( &ctx
->Light
, attr
->data
, sizeof(struct gl_light_attrib
) );
608 if (ctx
->Driver
.Enable
) {
610 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
611 GLenum light
= (GLenum
) (GL_LIGHT0
+ i
);
612 (*ctx
->Driver
.Enable
)( ctx
, light
, ctx
->Light
.Light
[i
].Enabled
);
614 (*ctx
->Driver
.Enable
)( ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
616 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
617 ctx
->TriangleCaps
|= DD_FLATSHADE
;
619 ctx
->TriangleCaps
&= ~DD_FLATSHADE
;
620 if (ctx
->Driver
.ShadeModel
)
621 (*ctx
->Driver
.ShadeModel
)(ctx
, ctx
->Light
.ShadeModel
);
622 ctx
->Enabled
&= ~ENABLE_LIGHT
;
623 if (ctx
->Light
.Enabled
&& !is_empty_list(&ctx
->Light
.EnabledList
))
624 ctx
->Enabled
|= ENABLE_LIGHT
;
627 MEMCPY( &ctx
->Line
, attr
->data
, sizeof(struct gl_line_attrib
) );
628 if (ctx
->Driver
.Enable
) {
629 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
630 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
634 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
636 case GL_PIXEL_MODE_BIT
:
637 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
640 MEMCPY( &ctx
->Point
, attr
->data
, sizeof(struct gl_point_attrib
) );
641 if (ctx
->Driver
.Enable
)
642 (*ctx
->Driver
.Enable
)( ctx
, GL_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
646 GLenum oldFrontMode
= ctx
->Polygon
.FrontMode
;
647 GLenum oldBackMode
= ctx
->Polygon
.BackMode
;
648 MEMCPY( &ctx
->Polygon
, attr
->data
,
649 sizeof(struct gl_polygon_attrib
) );
650 if ((ctx
->Polygon
.FrontMode
!= oldFrontMode
||
651 ctx
->Polygon
.BackMode
!= oldBackMode
) &&
652 ctx
->Driver
.PolygonMode
) {
653 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
654 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
656 if (ctx
->Driver
.CullFace
)
657 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
659 if (ctx
->Driver
.FrontFace
)
660 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
662 if (ctx
->Driver
.Enable
)
663 (*ctx
->Driver
.Enable
)( ctx
, GL_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
666 case GL_POLYGON_STIPPLE_BIT
:
667 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
670 MEMCPY( &ctx
->Scissor
, attr
->data
,
671 sizeof(struct gl_scissor_attrib
) );
672 if (ctx
->Driver
.Enable
)
673 (*ctx
->Driver
.Enable
)( ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
674 if (ctx
->Driver
.Scissor
)
675 ctx
->Driver
.Scissor( ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
676 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
678 case GL_STENCIL_BUFFER_BIT
:
679 MEMCPY( &ctx
->Stencil
, attr
->data
,
680 sizeof(struct gl_stencil_attrib
) );
681 if (ctx
->Driver
.StencilFunc
)
682 (*ctx
->Driver
.StencilFunc
)( ctx
, ctx
->Stencil
.Function
,
683 ctx
->Stencil
.Ref
, ctx
->Stencil
.ValueMask
);
684 if (ctx
->Driver
.StencilMask
)
685 (*ctx
->Driver
.StencilMask
)( ctx
, ctx
->Stencil
.WriteMask
);
686 if (ctx
->Driver
.StencilOp
)
687 (*ctx
->Driver
.StencilOp
)( ctx
, ctx
->Stencil
.FailFunc
,
688 ctx
->Stencil
.ZFailFunc
, ctx
->Stencil
.ZPassFunc
);
689 if (ctx
->Driver
.ClearStencil
)
690 (*ctx
->Driver
.ClearStencil
)( ctx
, ctx
->Stencil
.Clear
);
691 if (ctx
->Driver
.Enable
)
692 (*ctx
->Driver
.Enable
)( ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
693 ctx
->TriangleCaps
&= ~DD_STENCIL
;
694 if (ctx
->Stencil
.Enabled
)
695 ctx
->TriangleCaps
|= DD_STENCIL
;
698 case GL_TRANSFORM_BIT
:
699 MEMCPY( &ctx
->Transform
, attr
->data
,
700 sizeof(struct gl_transform_attrib
) );
701 if (ctx
->Driver
.Enable
) {
702 (*ctx
->Driver
.Enable
)( ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
703 (*ctx
->Driver
.Enable
)( ctx
, GL_RESCALE_NORMAL_EXT
, ctx
->Transform
.RescaleNormals
);
705 ctx
->Enabled
&= ~(ENABLE_NORMALIZE
|ENABLE_RESCALE
);
706 if (ctx
->Transform
.Normalize
) ctx
->Enabled
|= ENABLE_NORMALIZE
;
707 if (ctx
->Transform
.RescaleNormals
) ctx
->Enabled
|= ENABLE_RESCALE
;
710 /* Take care of texture object reference counters */
713 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
714 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
--;
715 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
--;
716 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
--;
718 MEMCPY( &ctx
->Texture
, attr
->data
,
719 sizeof(struct gl_texture_attrib
) );
720 /* restore state of the currently bound texture objects */
721 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
722 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[1],
723 &(ctx
->Texture
.Unit
[u
].Saved1D
) );
724 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[2],
725 &(ctx
->Texture
.Unit
[u
].Saved2D
) );
726 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[3],
727 &(ctx
->Texture
.Unit
[u
].Saved3D
) );
728 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[1] );
729 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[2] );
730 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[3] );
735 case GL_VIEWPORT_BIT
:
737 struct gl_viewport_attrib
*v
=
738 (struct gl_viewport_attrib
*)attr
->data
;
740 _mesa_Viewport( v
->X
, v
->Y
, v
->Width
, v
->Height
);
741 _mesa_DepthRange( v
->Near
, v
->Far
);
745 gl_problem( ctx
, "Bad attrib flag in PopAttrib");
755 ctx
->NewState
= NEW_ALL
;
759 #define GL_CLIENT_PACK_BIT (1<<20)
760 #define GL_CLIENT_UNPACK_BIT (1<<21)
763 void gl_PushClientAttrib( GLcontext
*ctx
, GLbitfield mask
)
765 struct gl_attrib_node
*newnode
;
766 struct gl_attrib_node
*head
;
768 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushClientAttrib");
770 if (ctx
->ClientAttribStackDepth
>=MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
771 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
775 /* Build linked list of attribute nodes which save all attribute */
776 /* groups specified by the mask. */
779 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
780 struct gl_pixelstore_attrib
*attr
;
781 /* packing attribs */
782 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
783 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
784 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
785 newnode
->data
= attr
;
786 newnode
->next
= head
;
788 /* unpacking attribs */
789 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
790 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
791 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
792 newnode
->data
= attr
;
793 newnode
->next
= head
;
796 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
797 struct gl_array_attrib
*attr
;
798 attr
= MALLOC_STRUCT( gl_array_attrib
);
799 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
800 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
801 newnode
->data
= attr
;
802 newnode
->next
= head
;
806 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
807 ctx
->ClientAttribStackDepth
++;
813 void gl_PopClientAttrib( GLcontext
*ctx
)
815 struct gl_attrib_node
*attr
, *next
;
817 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopClientAttrib");
819 if (ctx
->ClientAttribStackDepth
==0) {
820 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
824 ctx
->ClientAttribStackDepth
--;
825 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
828 switch (attr
->kind
) {
829 case GL_CLIENT_PACK_BIT
:
830 MEMCPY( &ctx
->Pack
, attr
->data
,
831 sizeof(struct gl_pixelstore_attrib
) );
833 case GL_CLIENT_UNPACK_BIT
:
834 MEMCPY( &ctx
->Unpack
, attr
->data
,
835 sizeof(struct gl_pixelstore_attrib
) );
837 case GL_CLIENT_VERTEX_ARRAY_BIT
:
838 MEMCPY( &ctx
->Array
, attr
->data
,
839 sizeof(struct gl_array_attrib
) );
842 gl_problem( ctx
, "Bad attrib flag in PopClientAttrib");
852 ctx
->NewState
= NEW_ALL
;
858 _mesa_PushAttrib( GLbitfield mask
)
860 GET_CURRENT_CONTEXT(ctx
);
861 gl_PushAttrib(ctx
, mask
);
866 _mesa_PopAttrib( void )
868 GET_CURRENT_CONTEXT(ctx
);
874 _mesa_PushClientAttrib( GLbitfield mask
)
876 GET_CURRENT_CONTEXT(ctx
);
877 gl_PushClientAttrib(ctx
, mask
);
882 _mesa_PopClientAttrib( void )
884 GET_CURRENT_CONTEXT(ctx
);
885 gl_PopClientAttrib(ctx
);