1 /* $Id: attrib.c,v 1.10 1999/11/08 15:28:08 brianp 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.
37 #include "GL/xf86glx.h"
45 #include "simple_list.h"
54 * Allocate a new attribute state node. These nodes have a
55 * "kind" value and a pointer to a struct of state data.
57 static struct gl_attrib_node
*new_attrib_node( GLbitfield kind
)
59 struct gl_attrib_node
*an
= MALLOC_STRUCT(gl_attrib_node
);
69 * Copy texture object state from one texture object to another.
71 static void copy_texobj_state( struct gl_texture_object
*dest
,
72 const struct gl_texture_object
*src
)
75 dest->Name = src->Name;
76 dest->Dimensions = src->Dimensions;
78 dest
->Priority
= src
->Priority
;
79 dest
->BorderColor
[0] = src
->BorderColor
[0];
80 dest
->BorderColor
[1] = src
->BorderColor
[1];
81 dest
->BorderColor
[2] = src
->BorderColor
[2];
82 dest
->BorderColor
[3] = src
->BorderColor
[3];
83 dest
->WrapS
= src
->WrapS
;
84 dest
->WrapT
= src
->WrapT
;
85 dest
->WrapR
= src
->WrapR
;
86 dest
->MinFilter
= src
->MinFilter
;
87 dest
->MagFilter
= src
->MagFilter
;
88 dest
->MinLod
= src
->MinLod
;
89 dest
->MaxLod
= src
->MaxLod
;
90 dest
->BaseLevel
= src
->BaseLevel
;
91 dest
->MaxLevel
= src
->MaxLevel
;
94 dest
->MinMagThresh
= src
->MinMagThresh
;
95 memcpy( dest
->Palette
, src
->Palette
,
96 sizeof(GLubyte
) * MAX_TEXTURE_PALETTE_SIZE
* 4 );
97 dest
->PaletteSize
= src
->PaletteSize
;
98 dest
->PaletteIntFormat
= src
->PaletteIntFormat
;
99 dest
->PaletteFormat
= src
->PaletteFormat
;
100 dest
->Complete
= src
->Complete
;
101 dest
->SampleFunc
= src
->SampleFunc
;
106 void gl_PushAttrib( GLcontext
* ctx
, GLbitfield mask
)
108 struct gl_attrib_node
*newnode
;
109 struct gl_attrib_node
*head
;
111 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushAttrib");
113 if (MESA_VERBOSE
&VERBOSE_API
)
114 fprintf(stderr
, "glPushAttrib %x\n", mask
);
116 if (ctx
->AttribStackDepth
>=MAX_ATTRIB_STACK_DEPTH
) {
117 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
121 /* Build linked list of attribute nodes which save all attribute */
122 /* groups specified by the mask. */
125 if (mask
& GL_ACCUM_BUFFER_BIT
) {
126 struct gl_accum_attrib
*attr
;
127 attr
= MALLOC_STRUCT( gl_accum_attrib
);
128 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
129 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
130 newnode
->data
= attr
;
131 newnode
->next
= head
;
135 if (mask
& GL_COLOR_BUFFER_BIT
) {
136 struct gl_colorbuffer_attrib
*attr
;
137 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
138 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
139 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
140 newnode
->data
= attr
;
141 newnode
->next
= head
;
145 if (mask
& GL_CURRENT_BIT
) {
146 struct gl_current_attrib
*attr
;
147 attr
= MALLOC_STRUCT( gl_current_attrib
);
148 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
149 newnode
= new_attrib_node( GL_CURRENT_BIT
);
150 newnode
->data
= attr
;
151 newnode
->next
= head
;
155 if (mask
& GL_DEPTH_BUFFER_BIT
) {
156 struct gl_depthbuffer_attrib
*attr
;
157 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
158 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
159 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
160 newnode
->data
= attr
;
161 newnode
->next
= head
;
165 if (mask
& GL_ENABLE_BIT
) {
166 struct gl_enable_attrib
*attr
;
168 attr
= MALLOC_STRUCT( gl_enable_attrib
);
169 /* Copy enable flags from all other attributes into the enable struct. */
170 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
171 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
172 attr
->Blend
= ctx
->Color
.BlendEnabled
;
173 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
174 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
176 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
177 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
178 attr
->DepthTest
= ctx
->Depth
.Test
;
179 attr
->Dither
= ctx
->Color
.DitherFlag
;
180 attr
->Fog
= ctx
->Fog
.Enabled
;
181 for (i
=0;i
<MAX_LIGHTS
;i
++) {
182 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
184 attr
->Lighting
= ctx
->Light
.Enabled
;
185 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
186 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
187 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
188 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
189 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
190 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
191 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
192 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
193 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
194 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
195 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
196 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
197 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
198 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
199 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
200 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
201 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
202 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
203 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
204 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
205 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
206 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
207 attr
->Normalize
= ctx
->Transform
.Normalize
;
208 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
209 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
210 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
211 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
212 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
213 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
214 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
215 attr
->Scissor
= ctx
->Scissor
.Enabled
;
216 attr
->Stencil
= ctx
->Stencil
.Enabled
;
217 attr
->Texture
= ctx
->Texture
.Enabled
;
218 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
219 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
221 newnode
= new_attrib_node( GL_ENABLE_BIT
);
222 newnode
->data
= attr
;
223 newnode
->next
= head
;
227 if (mask
& GL_EVAL_BIT
) {
228 struct gl_eval_attrib
*attr
;
229 attr
= MALLOC_STRUCT( gl_eval_attrib
);
230 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
231 newnode
= new_attrib_node( GL_EVAL_BIT
);
232 newnode
->data
= attr
;
233 newnode
->next
= head
;
237 if (mask
& GL_FOG_BIT
) {
238 struct gl_fog_attrib
*attr
;
239 attr
= MALLOC_STRUCT( gl_fog_attrib
);
240 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
241 newnode
= new_attrib_node( GL_FOG_BIT
);
242 newnode
->data
= attr
;
243 newnode
->next
= head
;
247 if (mask
& GL_HINT_BIT
) {
248 struct gl_hint_attrib
*attr
;
249 attr
= MALLOC_STRUCT( gl_hint_attrib
);
250 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
251 newnode
= new_attrib_node( GL_HINT_BIT
);
252 newnode
->data
= attr
;
253 newnode
->next
= head
;
257 if (mask
& GL_LIGHTING_BIT
) {
258 struct gl_light_attrib
*attr
;
259 attr
= MALLOC_STRUCT( gl_light_attrib
);
260 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
261 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
262 newnode
->data
= attr
;
263 newnode
->next
= head
;
267 if (mask
& GL_LINE_BIT
) {
268 struct gl_line_attrib
*attr
;
269 attr
= MALLOC_STRUCT( gl_line_attrib
);
270 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
271 newnode
= new_attrib_node( GL_LINE_BIT
);
272 newnode
->data
= attr
;
273 newnode
->next
= head
;
277 if (mask
& GL_LIST_BIT
) {
278 struct gl_list_attrib
*attr
;
279 attr
= MALLOC_STRUCT( gl_list_attrib
);
280 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
281 newnode
= new_attrib_node( GL_LIST_BIT
);
282 newnode
->data
= attr
;
283 newnode
->next
= head
;
287 if (mask
& GL_PIXEL_MODE_BIT
) {
288 struct gl_pixel_attrib
*attr
;
289 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
290 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
291 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
292 newnode
->data
= attr
;
293 newnode
->next
= head
;
297 if (mask
& GL_POINT_BIT
) {
298 struct gl_point_attrib
*attr
;
299 attr
= MALLOC_STRUCT( gl_point_attrib
);
300 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
301 newnode
= new_attrib_node( GL_POINT_BIT
);
302 newnode
->data
= attr
;
303 newnode
->next
= head
;
307 if (mask
& GL_POLYGON_BIT
) {
308 struct gl_polygon_attrib
*attr
;
309 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
310 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
311 newnode
= new_attrib_node( GL_POLYGON_BIT
);
312 newnode
->data
= attr
;
313 newnode
->next
= head
;
317 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
319 stipple
= (GLuint
*) MALLOC( 32*sizeof(GLuint
) );
320 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
321 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
322 newnode
->data
= stipple
;
323 newnode
->next
= head
;
327 if (mask
& GL_SCISSOR_BIT
) {
328 struct gl_scissor_attrib
*attr
;
329 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
330 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
331 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
332 newnode
->data
= attr
;
333 newnode
->next
= head
;
337 if (mask
& GL_STENCIL_BUFFER_BIT
) {
338 struct gl_stencil_attrib
*attr
;
339 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
340 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
341 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
342 newnode
->data
= attr
;
343 newnode
->next
= head
;
347 if (mask
& GL_TEXTURE_BIT
) {
348 struct gl_texture_attrib
*attr
;
350 /* Take care of texture object reference counters */
351 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
352 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
++;
353 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
++;
354 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
++;
356 attr
= MALLOC_STRUCT( gl_texture_attrib
);
357 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
358 /* copy state of the currently bound texture objects */
359 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
360 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].CurrentD
[1]);
361 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].CurrentD
[2]);
362 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].CurrentD
[3]);
364 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
365 newnode
->data
= attr
;
366 newnode
->next
= head
;
370 if (mask
& GL_TRANSFORM_BIT
) {
371 struct gl_transform_attrib
*attr
;
372 attr
= MALLOC_STRUCT( gl_transform_attrib
);
373 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
374 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
375 newnode
->data
= attr
;
376 newnode
->next
= head
;
380 if (mask
& GL_VIEWPORT_BIT
) {
381 struct gl_viewport_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
383 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
384 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
385 newnode
->data
= attr
;
386 newnode
->next
= head
;
390 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
391 ctx
->AttribStackDepth
++;
397 * This function is kind of long just because we have to call a lot
398 * of device driver functions to update device driver state.
400 void gl_PopAttrib( GLcontext
* ctx
)
402 struct gl_attrib_node
*attr
, *next
;
404 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopAttrib");
407 if (ctx
->AttribStackDepth
==0) {
408 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
412 ctx
->AttribStackDepth
--;
413 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
417 if (MESA_VERBOSE
&VERBOSE_API
)
418 fprintf(stderr
, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr
->kind
));
420 switch (attr
->kind
) {
421 case GL_ACCUM_BUFFER_BIT
:
422 MEMCPY( &ctx
->Accum
, attr
->data
, sizeof(struct gl_accum_attrib
) );
424 case GL_COLOR_BUFFER_BIT
:
426 GLenum oldDrawBuffer
= ctx
->Color
.DrawBuffer
;
427 GLenum oldAlphaFunc
= ctx
->Color
.AlphaFunc
;
428 GLubyte oldAlphaRef
= ctx
->Color
.AlphaRef
;
429 GLenum oldBlendSrc
= ctx
->Color
.BlendSrcRGB
;
430 GLenum oldBlendDst
= ctx
->Color
.BlendDstRGB
;
431 MEMCPY( &ctx
->Color
, attr
->data
,
432 sizeof(struct gl_colorbuffer_attrib
) );
433 if (ctx
->Color
.DrawBuffer
!= oldDrawBuffer
) {
434 gl_DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
);
436 if ((ctx
->Color
.AlphaFunc
!= oldAlphaFunc
||
437 ctx
->Color
.AlphaRef
!= oldAlphaRef
) &&
438 ctx
->Driver
.AlphaFunc
)
439 (*ctx
->Driver
.AlphaFunc
)( ctx
, ctx
->Color
.AlphaFunc
,
440 ctx
->Color
.AlphaRef
/ 255.0F
);
441 if ((ctx
->Color
.BlendSrcRGB
!= oldBlendSrc
||
442 ctx
->Color
.BlendSrcRGB
!= oldBlendDst
) &&
443 ctx
->Driver
.BlendFunc
)
444 (*ctx
->Driver
.BlendFunc
)( ctx
, ctx
->Color
.BlendSrcRGB
,
445 ctx
->Color
.BlendDstRGB
);
449 MEMCPY( &ctx
->Current
, attr
->data
,
450 sizeof(struct gl_current_attrib
) );
452 case GL_DEPTH_BUFFER_BIT
:
454 GLenum oldDepthFunc
= ctx
->Depth
.Func
;
455 GLboolean oldDepthMask
= ctx
->Depth
.Mask
;
456 GLfloat oldDepthClear
= ctx
->Depth
.Clear
;
457 MEMCPY( &ctx
->Depth
, attr
->data
,
458 sizeof(struct gl_depthbuffer_attrib
) );
459 if (ctx
->Depth
.Func
!= oldDepthFunc
&& ctx
->Driver
.DepthFunc
)
460 (*ctx
->Driver
.DepthFunc
)( ctx
, ctx
->Depth
.Func
);
461 if (ctx
->Depth
.Mask
!= oldDepthMask
&& ctx
->Driver
.DepthMask
)
462 (*ctx
->Driver
.DepthMask
)( ctx
, ctx
->Depth
.Mask
);
463 if (ctx
->Depth
.Clear
!= oldDepthClear
&& ctx
->Driver
.ClearDepth
)
464 (*ctx
->Driver
.ClearDepth
)( ctx
, ctx
->Depth
.Clear
);
469 const struct gl_enable_attrib
*enable
;
470 enable
= (const struct gl_enable_attrib
*) attr
->data
;
472 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
473 if ((VALUE) != (NEWVALUE)) { \
474 gl_set_enable( ctx, ENUM, (NEWVALUE) ); \
477 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
478 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->AutoNormal
, GL_NORMALIZE
);
479 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
482 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
483 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
484 gl_set_enable( ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
), enable
->ClipPlane
[i
] );
487 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
, GL_COLOR_MATERIAL
);
488 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
489 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
490 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
491 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
492 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
493 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
494 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
, GL_LINE_STIPPLE
);
495 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
, GL_INDEX_LOGIC_OP
);
496 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
, GL_COLOR_LOGIC_OP
);
497 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
498 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
499 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
500 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
, GL_MAP1_TEXTURE_COORD_1
);
501 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
, GL_MAP1_TEXTURE_COORD_2
);
502 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
, GL_MAP1_TEXTURE_COORD_3
);
503 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
, GL_MAP1_TEXTURE_COORD_4
);
504 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
, GL_MAP1_VERTEX_3
);
505 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
, GL_MAP1_VERTEX_4
);
506 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
507 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
508 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
509 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
, GL_MAP2_TEXTURE_COORD_1
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
, GL_MAP2_TEXTURE_COORD_2
);
511 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
, GL_MAP2_TEXTURE_COORD_3
);
512 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
, GL_MAP2_TEXTURE_COORD_4
);
513 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
, GL_MAP2_VERTEX_3
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
, GL_MAP2_VERTEX_4
);
515 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
516 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
, GL_RESCALE_NORMAL_EXT
);
517 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
, GL_POINT_SMOOTH
);
518 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
, GL_POLYGON_OFFSET_POINT
);
519 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
, GL_POLYGON_OFFSET_LINE
);
520 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
, GL_POLYGON_OFFSET_FILL
);
521 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
, GL_POLYGON_SMOOTH
);
522 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
, GL_POLYGON_STIPPLE
);
523 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
524 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
525 if (ctx
->Texture
.Enabled
!= enable
->Texture
) {
526 ctx
->Texture
.Enabled
= enable
->Texture
;
527 if (ctx
->Driver
.Enable
) {
528 if (ctx
->Driver
.ActiveTexture
)
529 (*ctx
->Driver
.ActiveTexture
)( ctx
, 0 );
530 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE0_1D
) );
531 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE0_2D
) );
532 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE0_3D
) );
533 if (ctx
->Driver
.ActiveTexture
)
534 (*ctx
->Driver
.ActiveTexture
)( ctx
, 1 );
535 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE1_1D
) );
536 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE1_2D
) );
537 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE1_3D
) );
538 if (ctx
->Driver
.ActiveTexture
)
539 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
542 #undef TEST_AND_UPDATE
545 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
546 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
547 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
549 /* ctx->Enabled recalculated in state change
552 if (ctx
->Driver
.Enable
) {
553 if (ctx
->Driver
.ActiveTexture
)
554 (*ctx
->Driver
.ActiveTexture
)( ctx
, i
);
555 if (enable
->TexGen
[i
] & S_BIT
)
556 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
558 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
559 if (enable
->TexGen
[i
] & T_BIT
)
560 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
562 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
563 if (enable
->TexGen
[i
] & R_BIT
)
564 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
566 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
567 if (enable
->TexGen
[i
] & Q_BIT
)
568 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
570 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
574 if (ctx
->Driver
.ActiveTexture
)
575 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
580 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
584 GLboolean anyChange
= (GLboolean
) (memcmp( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) ) != 0);
585 MEMCPY( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) );
586 if (anyChange
&& ctx
->Driver
.Fogfv
) {
587 const GLfloat mode
= (GLfloat
) ctx
->Fog
.Mode
;
588 const GLfloat density
= ctx
->Fog
.Density
;
589 const GLfloat start
= ctx
->Fog
.Start
;
590 const GLfloat end
= ctx
->Fog
.End
;
591 const GLfloat index
= ctx
->Fog
.Index
;
592 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_MODE
, &mode
);
593 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_DENSITY
, &density
);
594 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_START
, &start
);
595 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_END
, &end
);
596 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_INDEX
, &index
);
597 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
599 ctx
->Enabled
&= ENABLE_FOG
;
600 if (ctx
->Fog
.Enabled
) ctx
->Enabled
|= ENABLE_FOG
;
604 MEMCPY( &ctx
->Hint
, attr
->data
, sizeof(struct gl_hint_attrib
) );
605 if (ctx
->Driver
.Hint
) {
606 (*ctx
->Driver
.Hint
)( ctx
, GL_PERSPECTIVE_CORRECTION_HINT
,
607 ctx
->Hint
.PerspectiveCorrection
);
608 (*ctx
->Driver
.Hint
)( ctx
, GL_POINT_SMOOTH_HINT
,
609 ctx
->Hint
.PointSmooth
);
610 (*ctx
->Driver
.Hint
)( ctx
, GL_LINE_SMOOTH_HINT
,
611 ctx
->Hint
.LineSmooth
);
612 (*ctx
->Driver
.Hint
)( ctx
, GL_POLYGON_SMOOTH_HINT
,
613 ctx
->Hint
.PolygonSmooth
);
614 (*ctx
->Driver
.Hint
)( ctx
, GL_FOG_HINT
, ctx
->Hint
.Fog
);
617 case GL_LIGHTING_BIT
:
618 MEMCPY( &ctx
->Light
, attr
->data
, sizeof(struct gl_light_attrib
) );
619 if (ctx
->Driver
.Enable
) {
621 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
622 GLenum light
= (GLenum
) (GL_LIGHT0
+ i
);
623 (*ctx
->Driver
.Enable
)( ctx
, light
, ctx
->Light
.Light
[i
].Enabled
);
625 (*ctx
->Driver
.Enable
)( ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
627 ctx
->Enabled
&= ENABLE_LIGHT
;
628 if (ctx
->Light
.Enabled
&& !is_empty_list(&ctx
->Light
.EnabledList
))
629 ctx
->Enabled
|= ENABLE_LIGHT
;
632 MEMCPY( &ctx
->Line
, attr
->data
, sizeof(struct gl_line_attrib
) );
633 if (ctx
->Driver
.Enable
) {
634 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
635 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
639 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
641 case GL_PIXEL_MODE_BIT
:
642 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
645 MEMCPY( &ctx
->Point
, attr
->data
, sizeof(struct gl_point_attrib
) );
646 if (ctx
->Driver
.Enable
)
647 (*ctx
->Driver
.Enable
)( ctx
, GL_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
651 GLenum oldFrontMode
= ctx
->Polygon
.FrontMode
;
652 GLenum oldBackMode
= ctx
->Polygon
.BackMode
;
653 MEMCPY( &ctx
->Polygon
, attr
->data
,
654 sizeof(struct gl_polygon_attrib
) );
655 if ((ctx
->Polygon
.FrontMode
!= oldFrontMode
||
656 ctx
->Polygon
.BackMode
!= oldBackMode
) &&
657 ctx
->Driver
.PolygonMode
) {
658 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
659 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
661 if (ctx
->Driver
.CullFace
)
662 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
664 if (ctx
->Driver
.FrontFace
)
665 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
667 if (ctx
->Driver
.Enable
)
668 (*ctx
->Driver
.Enable
)( ctx
, GL_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
671 case GL_POLYGON_STIPPLE_BIT
:
672 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
675 MEMCPY( &ctx
->Scissor
, attr
->data
,
676 sizeof(struct gl_scissor_attrib
) );
677 if (ctx
->Driver
.Enable
)
678 (*ctx
->Driver
.Enable
)( ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
679 if (ctx
->Driver
.Scissor
)
680 ctx
->Driver
.Scissor( ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
681 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
683 case GL_STENCIL_BUFFER_BIT
:
684 MEMCPY( &ctx
->Stencil
, attr
->data
,
685 sizeof(struct gl_stencil_attrib
) );
686 if (ctx
->Driver
.StencilFunc
)
687 (*ctx
->Driver
.StencilFunc
)( ctx
, ctx
->Stencil
.Function
,
688 ctx
->Stencil
.Ref
, ctx
->Stencil
.ValueMask
);
689 if (ctx
->Driver
.StencilMask
)
690 (*ctx
->Driver
.StencilMask
)( ctx
, ctx
->Stencil
.WriteMask
);
691 if (ctx
->Driver
.StencilOp
)
692 (*ctx
->Driver
.StencilOp
)( ctx
, ctx
->Stencil
.FailFunc
,
693 ctx
->Stencil
.ZFailFunc
, ctx
->Stencil
.ZPassFunc
);
694 if (ctx
->Driver
.ClearStencil
)
695 (*ctx
->Driver
.ClearStencil
)( ctx
, ctx
->Stencil
.Clear
);
696 if (ctx
->Driver
.Enable
)
697 (*ctx
->Driver
.Enable
)( ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
698 ctx
->TriangleCaps
&= ~DD_STENCIL
;
699 if (ctx
->Stencil
.Enabled
)
700 ctx
->TriangleCaps
|= DD_STENCIL
;
703 case GL_TRANSFORM_BIT
:
704 MEMCPY( &ctx
->Transform
, attr
->data
,
705 sizeof(struct gl_transform_attrib
) );
706 if (ctx
->Driver
.Enable
) {
707 (*ctx
->Driver
.Enable
)( ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
708 (*ctx
->Driver
.Enable
)( ctx
, GL_RESCALE_NORMAL_EXT
, ctx
->Transform
.RescaleNormals
);
710 ctx
->Enabled
&= ~(ENABLE_NORMALIZE
|ENABLE_RESCALE
);
711 if (ctx
->Transform
.Normalize
) ctx
->Enabled
|= ENABLE_NORMALIZE
;
712 if (ctx
->Transform
.RescaleNormals
) ctx
->Enabled
|= ENABLE_RESCALE
;
715 /* Take care of texture object reference counters */
718 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
719 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
--;
720 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
--;
721 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
--;
723 MEMCPY( &ctx
->Texture
, attr
->data
,
724 sizeof(struct gl_texture_attrib
) );
725 /* restore state of the currently bound texture objects */
726 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
727 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[1],
728 &(ctx
->Texture
.Unit
[u
].Saved1D
) );
729 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[2],
730 &(ctx
->Texture
.Unit
[u
].Saved2D
) );
731 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[3],
732 &(ctx
->Texture
.Unit
[u
].Saved3D
) );
733 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[1] );
734 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[2] );
735 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[3] );
740 case GL_VIEWPORT_BIT
:
742 struct gl_viewport_attrib
*v
=
743 (struct gl_viewport_attrib
*)attr
->data
;
745 gl_Viewport( ctx
, v
->X
, v
->Y
, v
->Width
, v
->Height
);
746 gl_DepthRange( ctx
, v
->Near
, v
->Far
);
750 gl_problem( ctx
, "Bad attrib flag in PopAttrib");
760 ctx
->NewState
= NEW_ALL
;
764 #define GL_CLIENT_PACK_BIT (1<<20)
765 #define GL_CLIENT_UNPACK_BIT (1<<21)
768 void gl_PushClientAttrib( GLcontext
*ctx
, GLbitfield mask
)
770 struct gl_attrib_node
*newnode
;
771 struct gl_attrib_node
*head
;
773 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushClientAttrib");
775 if (ctx
->ClientAttribStackDepth
>=MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
776 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
780 /* Build linked list of attribute nodes which save all attribute */
781 /* groups specified by the mask. */
784 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
785 struct gl_pixelstore_attrib
*attr
;
786 /* packing attribs */
787 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
788 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
789 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
790 newnode
->data
= attr
;
791 newnode
->next
= head
;
793 /* unpacking attribs */
794 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
795 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
796 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
797 newnode
->data
= attr
;
798 newnode
->next
= head
;
801 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
802 struct gl_array_attrib
*attr
;
803 attr
= MALLOC_STRUCT( gl_array_attrib
);
804 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
805 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
806 newnode
->data
= attr
;
807 newnode
->next
= head
;
811 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
812 ctx
->ClientAttribStackDepth
++;
818 void gl_PopClientAttrib( GLcontext
*ctx
)
820 struct gl_attrib_node
*attr
, *next
;
822 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopClientAttrib");
824 if (ctx
->ClientAttribStackDepth
==0) {
825 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
829 ctx
->ClientAttribStackDepth
--;
830 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
833 switch (attr
->kind
) {
834 case GL_CLIENT_PACK_BIT
:
835 MEMCPY( &ctx
->Pack
, attr
->data
,
836 sizeof(struct gl_pixelstore_attrib
) );
838 case GL_CLIENT_UNPACK_BIT
:
839 MEMCPY( &ctx
->Unpack
, attr
->data
,
840 sizeof(struct gl_pixelstore_attrib
) );
842 case GL_CLIENT_VERTEX_ARRAY_BIT
:
843 MEMCPY( &ctx
->Array
, attr
->data
,
844 sizeof(struct gl_array_attrib
) );
847 gl_problem( ctx
, "Bad attrib flag in PopClientAttrib");
857 ctx
->NewState
= NEW_ALL
;