1 /* $Id: attrib.c,v 1.20 2000/03/19 01:10:11 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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
*
51 new_attrib_node( GLbitfield kind
)
53 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
63 * Copy texture object state from one texture object to another.
66 copy_texobj_state( struct gl_texture_object
*dest
,
67 const struct gl_texture_object
*src
)
70 dest->Name = src->Name;
71 dest->Dimensions = src->Dimensions;
73 dest
->Priority
= src
->Priority
;
74 dest
->BorderColor
[0] = src
->BorderColor
[0];
75 dest
->BorderColor
[1] = src
->BorderColor
[1];
76 dest
->BorderColor
[2] = src
->BorderColor
[2];
77 dest
->BorderColor
[3] = src
->BorderColor
[3];
78 dest
->WrapS
= src
->WrapS
;
79 dest
->WrapT
= src
->WrapT
;
80 dest
->WrapR
= src
->WrapR
;
81 dest
->MinFilter
= src
->MinFilter
;
82 dest
->MagFilter
= src
->MagFilter
;
83 dest
->MinLod
= src
->MinLod
;
84 dest
->MaxLod
= src
->MaxLod
;
85 dest
->BaseLevel
= src
->BaseLevel
;
86 dest
->MaxLevel
= src
->MaxLevel
;
89 dest
->MinMagThresh
= src
->MinMagThresh
;
90 dest
->Palette
= src
->Palette
;
91 dest
->Complete
= src
->Complete
;
92 dest
->SampleFunc
= src
->SampleFunc
;
98 _mesa_PushAttrib(GLbitfield mask
)
100 struct gl_attrib_node
*newnode
;
101 struct gl_attrib_node
*head
;
103 GET_CURRENT_CONTEXT(ctx
);
104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushAttrib");
106 if (MESA_VERBOSE
&VERBOSE_API
)
107 fprintf(stderr
, "glPushAttrib %x\n", (int)mask
);
109 if (ctx
->AttribStackDepth
>=MAX_ATTRIB_STACK_DEPTH
) {
110 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
114 /* Build linked list of attribute nodes which save all attribute */
115 /* groups specified by the mask. */
118 if (mask
& GL_ACCUM_BUFFER_BIT
) {
119 struct gl_accum_attrib
*attr
;
120 attr
= MALLOC_STRUCT( gl_accum_attrib
);
121 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
122 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
123 newnode
->data
= attr
;
124 newnode
->next
= head
;
128 if (mask
& GL_COLOR_BUFFER_BIT
) {
129 struct gl_colorbuffer_attrib
*attr
;
130 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
131 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
132 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
133 newnode
->data
= attr
;
134 newnode
->next
= head
;
138 if (mask
& GL_CURRENT_BIT
) {
139 struct gl_current_attrib
*attr
;
140 attr
= MALLOC_STRUCT( gl_current_attrib
);
141 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
142 newnode
= new_attrib_node( GL_CURRENT_BIT
);
143 newnode
->data
= attr
;
144 newnode
->next
= head
;
148 if (mask
& GL_DEPTH_BUFFER_BIT
) {
149 struct gl_depthbuffer_attrib
*attr
;
150 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
151 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
152 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
153 newnode
->data
= attr
;
154 newnode
->next
= head
;
158 if (mask
& GL_ENABLE_BIT
) {
159 struct gl_enable_attrib
*attr
;
161 attr
= MALLOC_STRUCT( gl_enable_attrib
);
162 /* Copy enable flags from all other attributes into the enable struct. */
163 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
164 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
165 attr
->Blend
= ctx
->Color
.BlendEnabled
;
166 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
167 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
169 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
170 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
171 attr
->DepthTest
= ctx
->Depth
.Test
;
172 attr
->Dither
= ctx
->Color
.DitherFlag
;
173 attr
->Fog
= ctx
->Fog
.Enabled
;
174 for (i
=0;i
<MAX_LIGHTS
;i
++) {
175 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
177 attr
->Lighting
= ctx
->Light
.Enabled
;
178 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
179 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
180 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
181 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
182 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
183 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
184 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
185 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
186 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
187 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
188 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
189 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
190 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
191 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
192 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
193 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
194 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
195 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
196 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
197 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
198 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
199 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
200 attr
->Normalize
= ctx
->Transform
.Normalize
;
201 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
202 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
203 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
204 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
205 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
206 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
207 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
208 attr
->Scissor
= ctx
->Scissor
.Enabled
;
209 attr
->Stencil
= ctx
->Stencil
.Enabled
;
210 attr
->Texture
= ctx
->Texture
.Enabled
;
211 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
212 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
214 newnode
= new_attrib_node( GL_ENABLE_BIT
);
215 newnode
->data
= attr
;
216 newnode
->next
= head
;
220 if (mask
& GL_EVAL_BIT
) {
221 struct gl_eval_attrib
*attr
;
222 attr
= MALLOC_STRUCT( gl_eval_attrib
);
223 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
224 newnode
= new_attrib_node( GL_EVAL_BIT
);
225 newnode
->data
= attr
;
226 newnode
->next
= head
;
230 if (mask
& GL_FOG_BIT
) {
231 struct gl_fog_attrib
*attr
;
232 attr
= MALLOC_STRUCT( gl_fog_attrib
);
233 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
234 newnode
= new_attrib_node( GL_FOG_BIT
);
235 newnode
->data
= attr
;
236 newnode
->next
= head
;
240 if (mask
& GL_HINT_BIT
) {
241 struct gl_hint_attrib
*attr
;
242 attr
= MALLOC_STRUCT( gl_hint_attrib
);
243 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
244 newnode
= new_attrib_node( GL_HINT_BIT
);
245 newnode
->data
= attr
;
246 newnode
->next
= head
;
250 if (mask
& GL_LIGHTING_BIT
) {
251 struct gl_light_attrib
*attr
;
252 attr
= MALLOC_STRUCT( gl_light_attrib
);
253 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
254 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
255 newnode
->data
= attr
;
256 newnode
->next
= head
;
260 if (mask
& GL_LINE_BIT
) {
261 struct gl_line_attrib
*attr
;
262 attr
= MALLOC_STRUCT( gl_line_attrib
);
263 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
264 newnode
= new_attrib_node( GL_LINE_BIT
);
265 newnode
->data
= attr
;
266 newnode
->next
= head
;
270 if (mask
& GL_LIST_BIT
) {
271 struct gl_list_attrib
*attr
;
272 attr
= MALLOC_STRUCT( gl_list_attrib
);
273 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
274 newnode
= new_attrib_node( GL_LIST_BIT
);
275 newnode
->data
= attr
;
276 newnode
->next
= head
;
280 if (mask
& GL_PIXEL_MODE_BIT
) {
281 struct gl_pixel_attrib
*attr
;
282 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
283 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
284 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
285 newnode
->data
= attr
;
286 newnode
->next
= head
;
290 if (mask
& GL_POINT_BIT
) {
291 struct gl_point_attrib
*attr
;
292 attr
= MALLOC_STRUCT( gl_point_attrib
);
293 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
294 newnode
= new_attrib_node( GL_POINT_BIT
);
295 newnode
->data
= attr
;
296 newnode
->next
= head
;
300 if (mask
& GL_POLYGON_BIT
) {
301 struct gl_polygon_attrib
*attr
;
302 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
303 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
304 newnode
= new_attrib_node( GL_POLYGON_BIT
);
305 newnode
->data
= attr
;
306 newnode
->next
= head
;
310 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
312 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
313 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
314 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
315 newnode
->data
= stipple
;
316 newnode
->next
= head
;
320 if (mask
& GL_SCISSOR_BIT
) {
321 struct gl_scissor_attrib
*attr
;
322 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
323 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
324 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
325 newnode
->data
= attr
;
326 newnode
->next
= head
;
330 if (mask
& GL_STENCIL_BUFFER_BIT
) {
331 struct gl_stencil_attrib
*attr
;
332 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
333 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
334 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
335 newnode
->data
= attr
;
336 newnode
->next
= head
;
340 if (mask
& GL_TEXTURE_BIT
) {
341 struct gl_texture_attrib
*attr
;
343 /* Take care of texture object reference counters */
344 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
345 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
++;
346 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
++;
347 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
++;
349 attr
= MALLOC_STRUCT( gl_texture_attrib
);
350 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
351 /* copy state of the currently bound texture objects */
352 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
353 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].CurrentD
[1]);
354 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].CurrentD
[2]);
355 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].CurrentD
[3]);
357 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
358 newnode
->data
= attr
;
359 newnode
->next
= head
;
363 if (mask
& GL_TRANSFORM_BIT
) {
364 struct gl_transform_attrib
*attr
;
365 attr
= MALLOC_STRUCT( gl_transform_attrib
);
366 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
367 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
368 newnode
->data
= attr
;
369 newnode
->next
= head
;
373 if (mask
& GL_VIEWPORT_BIT
) {
374 struct gl_viewport_attrib
*attr
;
375 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
376 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
377 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
378 newnode
->data
= attr
;
379 newnode
->next
= head
;
383 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
384 ctx
->AttribStackDepth
++;
390 * This function is kind of long just because we have to call a lot
391 * of device driver functions to update device driver state.
394 _mesa_PopAttrib(void)
396 struct gl_attrib_node
*attr
, *next
;
397 GET_CURRENT_CONTEXT(ctx
);
399 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopAttrib");
402 if (ctx
->AttribStackDepth
==0) {
403 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
407 ctx
->AttribStackDepth
--;
408 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
412 if (MESA_VERBOSE
&VERBOSE_API
)
413 fprintf(stderr
, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr
->kind
));
415 switch (attr
->kind
) {
416 case GL_ACCUM_BUFFER_BIT
:
417 MEMCPY( &ctx
->Accum
, attr
->data
, sizeof(struct gl_accum_attrib
) );
419 case GL_COLOR_BUFFER_BIT
:
421 GLenum oldDrawBuffer
= ctx
->Color
.DrawBuffer
;
422 GLenum oldAlphaFunc
= ctx
->Color
.AlphaFunc
;
423 GLubyte oldAlphaRef
= ctx
->Color
.AlphaRef
;
424 GLenum oldBlendSrc
= ctx
->Color
.BlendSrcRGB
;
425 GLenum oldBlendDst
= ctx
->Color
.BlendDstRGB
;
426 GLenum oldLogicOp
= ctx
->Color
.LogicOp
;
427 MEMCPY( &ctx
->Color
, attr
->data
,
428 sizeof(struct gl_colorbuffer_attrib
) );
429 if (ctx
->Color
.DrawBuffer
!= oldDrawBuffer
) {
430 _mesa_DrawBuffer( ctx
->Color
.DrawBuffer
);
432 if ((ctx
->Color
.BlendSrcRGB
!= oldBlendSrc
||
433 ctx
->Color
.BlendDstRGB
!= oldBlendDst
) &&
434 ctx
->Driver
.BlendFunc
)
435 (*ctx
->Driver
.BlendFunc
)( ctx
, ctx
->Color
.BlendSrcRGB
,
436 ctx
->Color
.BlendDstRGB
);
437 if (ctx
->Color
.LogicOp
!= oldLogicOp
&&
438 ctx
->Driver
.LogicOpcode
) {
439 ctx
->Driver
.LogicOpcode( ctx
, ctx
->Color
.LogicOp
);
441 if (ctx
->Visual
->RGBAflag
) {
442 GLubyte r
= (GLint
) (ctx
->Color
.ClearColor
[0] * 255.0F
);
443 GLubyte g
= (GLint
) (ctx
->Color
.ClearColor
[1] * 255.0F
);
444 GLubyte b
= (GLint
) (ctx
->Color
.ClearColor
[2] * 255.0F
);
445 GLubyte a
= (GLint
) (ctx
->Color
.ClearColor
[3] * 255.0F
);
446 (*ctx
->Driver
.ClearColor
)( ctx
, r
, g
, b
, a
);
447 if ((ctx
->Color
.AlphaFunc
!= oldAlphaFunc
||
448 ctx
->Color
.AlphaRef
!= oldAlphaRef
) &&
449 ctx
->Driver
.AlphaFunc
)
450 (*ctx
->Driver
.AlphaFunc
)( ctx
, ctx
->Color
.AlphaFunc
,
451 ctx
->Color
.AlphaRef
/ 255.0F
);
452 if (ctx
->Driver
.ColorMask
) {
453 (*ctx
->Driver
.ColorMask
)(ctx
,
454 ctx
->Color
.ColorMask
[0],
455 ctx
->Color
.ColorMask
[1],
456 ctx
->Color
.ColorMask
[2],
457 ctx
->Color
.ColorMask
[3]);
461 (*ctx
->Driver
.ClearIndex
)( ctx
, ctx
->Color
.ClearIndex
);
466 MEMCPY( &ctx
->Current
, attr
->data
,
467 sizeof(struct gl_current_attrib
) );
469 case GL_DEPTH_BUFFER_BIT
:
471 GLenum oldDepthFunc
= ctx
->Depth
.Func
;
472 GLboolean oldDepthMask
= ctx
->Depth
.Mask
;
473 GLfloat oldDepthClear
= ctx
->Depth
.Clear
;
474 MEMCPY( &ctx
->Depth
, attr
->data
,
475 sizeof(struct gl_depthbuffer_attrib
) );
476 if (ctx
->Depth
.Func
!= oldDepthFunc
&& ctx
->Driver
.DepthFunc
)
477 (*ctx
->Driver
.DepthFunc
)( ctx
, ctx
->Depth
.Func
);
478 if (ctx
->Depth
.Mask
!= oldDepthMask
&& ctx
->Driver
.DepthMask
)
479 (*ctx
->Driver
.DepthMask
)( ctx
, ctx
->Depth
.Mask
);
480 if (ctx
->Depth
.Clear
!= oldDepthClear
&& ctx
->Driver
.ClearDepth
)
481 (*ctx
->Driver
.ClearDepth
)( ctx
, ctx
->Depth
.Clear
);
486 const struct gl_enable_attrib
*enable
;
487 enable
= (const struct gl_enable_attrib
*) attr
->data
;
489 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
490 if ((VALUE) != (NEWVALUE)) { \
491 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
494 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
495 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->AutoNormal
, GL_NORMALIZE
);
496 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
499 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
500 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
501 _mesa_set_enable( ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
), enable
->ClipPlane
[i
] );
504 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
, GL_COLOR_MATERIAL
);
505 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
506 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
507 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
508 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
509 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
510 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
511 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
, GL_LINE_STIPPLE
);
512 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
, GL_INDEX_LOGIC_OP
);
513 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
, GL_COLOR_LOGIC_OP
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
515 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
, GL_MAP1_TEXTURE_COORD_1
);
518 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
, GL_MAP1_TEXTURE_COORD_2
);
519 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
, GL_MAP1_TEXTURE_COORD_3
);
520 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
, GL_MAP1_TEXTURE_COORD_4
);
521 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
, GL_MAP1_VERTEX_3
);
522 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
, GL_MAP1_VERTEX_4
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
524 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
525 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
526 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
, GL_MAP2_TEXTURE_COORD_1
);
527 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
, GL_MAP2_TEXTURE_COORD_2
);
528 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
, GL_MAP2_TEXTURE_COORD_3
);
529 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
, GL_MAP2_TEXTURE_COORD_4
);
530 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
, GL_MAP2_VERTEX_3
);
531 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
, GL_MAP2_VERTEX_4
);
532 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
533 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
, GL_RESCALE_NORMAL_EXT
);
534 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
, GL_POINT_SMOOTH
);
535 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
, GL_POLYGON_OFFSET_POINT
);
536 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
, GL_POLYGON_OFFSET_LINE
);
537 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
, GL_POLYGON_OFFSET_FILL
);
538 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
, GL_POLYGON_SMOOTH
);
539 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
, GL_POLYGON_STIPPLE
);
540 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
541 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
542 if (ctx
->Texture
.Enabled
!= enable
->Texture
) {
543 ctx
->Texture
.Enabled
= enable
->Texture
;
544 if (ctx
->Driver
.Enable
) {
545 if (ctx
->Driver
.ActiveTexture
)
546 (*ctx
->Driver
.ActiveTexture
)( ctx
, 0 );
547 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE0_1D
) );
548 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE0_2D
) );
549 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE0_3D
) );
550 if (ctx
->Driver
.ActiveTexture
)
551 (*ctx
->Driver
.ActiveTexture
)( ctx
, 1 );
552 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE1_1D
) );
553 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE1_2D
) );
554 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE1_3D
) );
555 if (ctx
->Driver
.ActiveTexture
)
556 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
559 #undef TEST_AND_UPDATE
562 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
563 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
564 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
566 /* ctx->Enabled recalculated in state change
569 if (ctx
->Driver
.Enable
) {
570 if (ctx
->Driver
.ActiveTexture
)
571 (*ctx
->Driver
.ActiveTexture
)( ctx
, i
);
572 if (enable
->TexGen
[i
] & S_BIT
)
573 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
575 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
576 if (enable
->TexGen
[i
] & T_BIT
)
577 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
579 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
580 if (enable
->TexGen
[i
] & R_BIT
)
581 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
583 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
584 if (enable
->TexGen
[i
] & Q_BIT
)
585 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
587 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
591 if (ctx
->Driver
.ActiveTexture
)
592 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
597 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
601 GLboolean anyChange
= (GLboolean
) (memcmp( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) ) != 0);
602 MEMCPY( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) );
603 if (anyChange
&& ctx
->Driver
.Fogfv
) {
604 const GLfloat mode
= (GLfloat
) ctx
->Fog
.Mode
;
605 const GLfloat density
= ctx
->Fog
.Density
;
606 const GLfloat start
= ctx
->Fog
.Start
;
607 const GLfloat end
= ctx
->Fog
.End
;
608 const GLfloat index
= ctx
->Fog
.Index
;
609 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_MODE
, &mode
);
610 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_DENSITY
, &density
);
611 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_START
, &start
);
612 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_END
, &end
);
613 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_INDEX
, &index
);
614 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
616 ctx
->Enabled
&= ~ENABLE_FOG
;
617 if (ctx
->Fog
.Enabled
) ctx
->Enabled
|= ENABLE_FOG
;
621 MEMCPY( &ctx
->Hint
, attr
->data
, sizeof(struct gl_hint_attrib
) );
622 if (ctx
->Driver
.Hint
) {
623 (*ctx
->Driver
.Hint
)( ctx
, GL_PERSPECTIVE_CORRECTION_HINT
,
624 ctx
->Hint
.PerspectiveCorrection
);
625 (*ctx
->Driver
.Hint
)( ctx
, GL_POINT_SMOOTH_HINT
,
626 ctx
->Hint
.PointSmooth
);
627 (*ctx
->Driver
.Hint
)( ctx
, GL_LINE_SMOOTH_HINT
,
628 ctx
->Hint
.LineSmooth
);
629 (*ctx
->Driver
.Hint
)( ctx
, GL_POLYGON_SMOOTH_HINT
,
630 ctx
->Hint
.PolygonSmooth
);
631 (*ctx
->Driver
.Hint
)( ctx
, GL_FOG_HINT
, ctx
->Hint
.Fog
);
634 case GL_LIGHTING_BIT
:
635 MEMCPY( &ctx
->Light
, attr
->data
, sizeof(struct gl_light_attrib
) );
636 if (ctx
->Driver
.Enable
) {
638 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
639 GLenum light
= (GLenum
) (GL_LIGHT0
+ i
);
640 (*ctx
->Driver
.Enable
)( ctx
, light
, ctx
->Light
.Light
[i
].Enabled
);
642 (*ctx
->Driver
.Enable
)( ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
644 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
645 ctx
->TriangleCaps
|= DD_FLATSHADE
;
647 ctx
->TriangleCaps
&= ~DD_FLATSHADE
;
648 if (ctx
->Driver
.ShadeModel
)
649 (*ctx
->Driver
.ShadeModel
)(ctx
, ctx
->Light
.ShadeModel
);
650 ctx
->Enabled
&= ~ENABLE_LIGHT
;
651 if (ctx
->Light
.Enabled
&& !is_empty_list(&ctx
->Light
.EnabledList
))
652 ctx
->Enabled
|= ENABLE_LIGHT
;
655 MEMCPY( &ctx
->Line
, attr
->data
, sizeof(struct gl_line_attrib
) );
656 if (ctx
->Driver
.Enable
) {
657 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
658 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
660 if (ctx
->Driver
.LineStipple
)
661 (*ctx
->Driver
.LineStipple
)(ctx
, ctx
->Line
.StippleFactor
,
662 ctx
->Line
.StipplePattern
);
663 if (ctx
->Driver
.LineWidth
)
664 (*ctx
->Driver
.LineWidth
)(ctx
, ctx
->Line
.Width
);
667 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
669 case GL_PIXEL_MODE_BIT
:
670 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
673 MEMCPY( &ctx
->Point
, attr
->data
, sizeof(struct gl_point_attrib
) );
674 if (ctx
->Driver
.Enable
)
675 (*ctx
->Driver
.Enable
)( ctx
, GL_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
679 GLenum oldFrontMode
= ctx
->Polygon
.FrontMode
;
680 GLenum oldBackMode
= ctx
->Polygon
.BackMode
;
681 MEMCPY( &ctx
->Polygon
, attr
->data
,
682 sizeof(struct gl_polygon_attrib
) );
683 if ((ctx
->Polygon
.FrontMode
!= oldFrontMode
||
684 ctx
->Polygon
.BackMode
!= oldBackMode
) &&
685 ctx
->Driver
.PolygonMode
) {
686 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
687 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
689 if (ctx
->Driver
.CullFace
)
690 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
692 if (ctx
->Driver
.FrontFace
)
693 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
695 if (ctx
->Driver
.Enable
)
696 (*ctx
->Driver
.Enable
)( ctx
, GL_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
699 case GL_POLYGON_STIPPLE_BIT
:
700 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
701 if (ctx
->Driver
.PolygonStipple
)
702 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) attr
->data
);
705 MEMCPY( &ctx
->Scissor
, attr
->data
,
706 sizeof(struct gl_scissor_attrib
) );
707 if (ctx
->Driver
.Enable
)
708 (*ctx
->Driver
.Enable
)( ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
709 if (ctx
->Driver
.Scissor
)
710 ctx
->Driver
.Scissor( ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
711 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
713 case GL_STENCIL_BUFFER_BIT
:
714 MEMCPY( &ctx
->Stencil
, attr
->data
,
715 sizeof(struct gl_stencil_attrib
) );
716 if (ctx
->Driver
.StencilFunc
)
717 (*ctx
->Driver
.StencilFunc
)( ctx
, ctx
->Stencil
.Function
,
718 ctx
->Stencil
.Ref
, ctx
->Stencil
.ValueMask
);
719 if (ctx
->Driver
.StencilMask
)
720 (*ctx
->Driver
.StencilMask
)( ctx
, ctx
->Stencil
.WriteMask
);
721 if (ctx
->Driver
.StencilOp
)
722 (*ctx
->Driver
.StencilOp
)( ctx
, ctx
->Stencil
.FailFunc
,
723 ctx
->Stencil
.ZFailFunc
, ctx
->Stencil
.ZPassFunc
);
724 if (ctx
->Driver
.ClearStencil
)
725 (*ctx
->Driver
.ClearStencil
)( ctx
, ctx
->Stencil
.Clear
);
726 if (ctx
->Driver
.Enable
)
727 (*ctx
->Driver
.Enable
)( ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
728 ctx
->TriangleCaps
&= ~DD_STENCIL
;
729 if (ctx
->Stencil
.Enabled
)
730 ctx
->TriangleCaps
|= DD_STENCIL
;
733 case GL_TRANSFORM_BIT
:
734 MEMCPY( &ctx
->Transform
, attr
->data
,
735 sizeof(struct gl_transform_attrib
) );
736 if (ctx
->Driver
.Enable
) {
737 (*ctx
->Driver
.Enable
)( ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
738 (*ctx
->Driver
.Enable
)( ctx
, GL_RESCALE_NORMAL_EXT
, ctx
->Transform
.RescaleNormals
);
740 ctx
->Enabled
&= ~(ENABLE_NORMALIZE
|ENABLE_RESCALE
);
741 if (ctx
->Transform
.Normalize
) ctx
->Enabled
|= ENABLE_NORMALIZE
;
742 if (ctx
->Transform
.RescaleNormals
) ctx
->Enabled
|= ENABLE_RESCALE
;
745 /* Take care of texture object reference counters */
748 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
749 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
--;
750 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
--;
751 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
--;
753 MEMCPY( &ctx
->Texture
, attr
->data
,
754 sizeof(struct gl_texture_attrib
) );
755 /* restore state of the currently bound texture objects */
756 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
757 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[1],
758 &(ctx
->Texture
.Unit
[u
].Saved1D
) );
759 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[2],
760 &(ctx
->Texture
.Unit
[u
].Saved2D
) );
761 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[3],
762 &(ctx
->Texture
.Unit
[u
].Saved3D
) );
763 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[1] );
764 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[2] );
765 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[3] );
770 case GL_VIEWPORT_BIT
:
772 struct gl_viewport_attrib
*v
=
773 (struct gl_viewport_attrib
*)attr
->data
;
775 _mesa_Viewport( v
->X
, v
->Y
, v
->Width
, v
->Height
);
776 _mesa_DepthRange( v
->Near
, v
->Far
);
780 gl_problem( ctx
, "Bad attrib flag in PopAttrib");
790 ctx
->NewState
= NEW_ALL
;
794 #define GL_CLIENT_PACK_BIT (1<<20)
795 #define GL_CLIENT_UNPACK_BIT (1<<21)
799 _mesa_PushClientAttrib(GLbitfield mask
)
801 struct gl_attrib_node
*newnode
;
802 struct gl_attrib_node
*head
;
804 GET_CURRENT_CONTEXT(ctx
);
805 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushClientAttrib");
807 if (ctx
->ClientAttribStackDepth
>=MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
808 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
812 /* Build linked list of attribute nodes which save all attribute */
813 /* groups specified by the mask. */
816 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
817 struct gl_pixelstore_attrib
*attr
;
818 /* packing attribs */
819 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
820 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
821 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
822 newnode
->data
= attr
;
823 newnode
->next
= head
;
825 /* unpacking attribs */
826 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
827 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
828 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
829 newnode
->data
= attr
;
830 newnode
->next
= head
;
833 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
834 struct gl_array_attrib
*attr
;
835 attr
= MALLOC_STRUCT( gl_array_attrib
);
836 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
837 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
838 newnode
->data
= attr
;
839 newnode
->next
= head
;
843 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
844 ctx
->ClientAttribStackDepth
++;
851 _mesa_PopClientAttrib(void)
853 struct gl_attrib_node
*attr
, *next
;
855 GET_CURRENT_CONTEXT(ctx
);
856 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopClientAttrib");
858 if (ctx
->ClientAttribStackDepth
==0) {
859 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
863 ctx
->ClientAttribStackDepth
--;
864 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
867 switch (attr
->kind
) {
868 case GL_CLIENT_PACK_BIT
:
869 MEMCPY( &ctx
->Pack
, attr
->data
,
870 sizeof(struct gl_pixelstore_attrib
) );
872 case GL_CLIENT_UNPACK_BIT
:
873 MEMCPY( &ctx
->Unpack
, attr
->data
,
874 sizeof(struct gl_pixelstore_attrib
) );
876 case GL_CLIENT_VERTEX_ARRAY_BIT
:
877 MEMCPY( &ctx
->Array
, attr
->data
,
878 sizeof(struct gl_array_attrib
) );
881 gl_problem( ctx
, "Bad attrib flag in PopClientAttrib");
891 ctx
->NewState
= NEW_ALL
;