1 /* $Id: attrib.c,v 1.5 1999/10/08 09:27:10 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.
39 #include "GL/xf86glx.h"
47 #include "simple_list.h"
52 #include "GL/xf86glx.h"
57 #define MALLOC_STRUCT(T) (struct T *) malloc( sizeof(struct T) )
62 * Allocate a new attribute state node. These nodes have a
63 * "kind" value and a pointer to a struct of state data.
65 static struct gl_attrib_node
*new_attrib_node( GLbitfield kind
)
67 struct gl_attrib_node
*an
;
69 an
= (struct gl_attrib_node
*) malloc( sizeof(struct gl_attrib_node
) );
79 * Copy texture object state from one texture object to another.
81 static void copy_texobj_state( struct gl_texture_object
*dest
,
82 const struct gl_texture_object
*src
)
85 dest->Name = src->Name;
86 dest->Dimensions = src->Dimensions;
88 dest
->Priority
= src
->Priority
;
89 dest
->BorderColor
[0] = src
->BorderColor
[0];
90 dest
->BorderColor
[1] = src
->BorderColor
[1];
91 dest
->BorderColor
[2] = src
->BorderColor
[2];
92 dest
->BorderColor
[3] = src
->BorderColor
[3];
93 dest
->WrapS
= src
->WrapS
;
94 dest
->WrapT
= src
->WrapT
;
95 dest
->WrapR
= src
->WrapR
;
96 dest
->MinFilter
= src
->MinFilter
;
97 dest
->MagFilter
= src
->MagFilter
;
98 dest
->MinLod
= src
->MinLod
;
99 dest
->MaxLod
= src
->MaxLod
;
100 dest
->BaseLevel
= src
->BaseLevel
;
101 dest
->MaxLevel
= src
->MaxLevel
;
104 dest
->MinMagThresh
= src
->MinMagThresh
;
105 memcpy( dest
->Palette
, src
->Palette
,
106 sizeof(GLubyte
) * MAX_TEXTURE_PALETTE_SIZE
* 4 );
107 dest
->PaletteSize
= src
->PaletteSize
;
108 dest
->PaletteIntFormat
= src
->PaletteIntFormat
;
109 dest
->PaletteFormat
= src
->PaletteFormat
;
110 dest
->Complete
= src
->Complete
;
111 dest
->SampleFunc
= src
->SampleFunc
;
116 void gl_PushAttrib( GLcontext
* ctx
, GLbitfield mask
)
118 struct gl_attrib_node
*newnode
;
119 struct gl_attrib_node
*head
;
121 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushAttrib");
123 if (MESA_VERBOSE
&VERBOSE_API
)
124 fprintf(stderr
, "glPushAttrib %x\n", mask
);
126 if (ctx
->AttribStackDepth
>=MAX_ATTRIB_STACK_DEPTH
) {
127 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushAttrib" );
131 /* Build linked list of attribute nodes which save all attribute */
132 /* groups specified by the mask. */
135 if (mask
& GL_ACCUM_BUFFER_BIT
) {
136 struct gl_accum_attrib
*attr
;
137 attr
= MALLOC_STRUCT( gl_accum_attrib
);
138 MEMCPY( attr
, &ctx
->Accum
, sizeof(struct gl_accum_attrib
) );
139 newnode
= new_attrib_node( GL_ACCUM_BUFFER_BIT
);
140 newnode
->data
= attr
;
141 newnode
->next
= head
;
145 if (mask
& GL_COLOR_BUFFER_BIT
) {
146 struct gl_colorbuffer_attrib
*attr
;
147 attr
= MALLOC_STRUCT( gl_colorbuffer_attrib
);
148 MEMCPY( attr
, &ctx
->Color
, sizeof(struct gl_colorbuffer_attrib
) );
149 newnode
= new_attrib_node( GL_COLOR_BUFFER_BIT
);
150 newnode
->data
= attr
;
151 newnode
->next
= head
;
155 if (mask
& GL_CURRENT_BIT
) {
156 struct gl_current_attrib
*attr
;
157 attr
= MALLOC_STRUCT( gl_current_attrib
);
158 MEMCPY( attr
, &ctx
->Current
, sizeof(struct gl_current_attrib
) );
159 newnode
= new_attrib_node( GL_CURRENT_BIT
);
160 newnode
->data
= attr
;
161 newnode
->next
= head
;
165 if (mask
& GL_DEPTH_BUFFER_BIT
) {
166 struct gl_depthbuffer_attrib
*attr
;
167 attr
= MALLOC_STRUCT( gl_depthbuffer_attrib
);
168 MEMCPY( attr
, &ctx
->Depth
, sizeof(struct gl_depthbuffer_attrib
) );
169 newnode
= new_attrib_node( GL_DEPTH_BUFFER_BIT
);
170 newnode
->data
= attr
;
171 newnode
->next
= head
;
175 if (mask
& GL_ENABLE_BIT
) {
176 struct gl_enable_attrib
*attr
;
178 attr
= MALLOC_STRUCT( gl_enable_attrib
);
179 /* Copy enable flags from all other attributes into the enable struct. */
180 attr
->AlphaTest
= ctx
->Color
.AlphaEnabled
;
181 attr
->AutoNormal
= ctx
->Eval
.AutoNormal
;
182 attr
->Blend
= ctx
->Color
.BlendEnabled
;
183 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
184 attr
->ClipPlane
[i
] = ctx
->Transform
.ClipEnabled
[i
];
186 attr
->ColorMaterial
= ctx
->Light
.ColorMaterialEnabled
;
187 attr
->CullFace
= ctx
->Polygon
.CullFlag
;
188 attr
->DepthTest
= ctx
->Depth
.Test
;
189 attr
->Dither
= ctx
->Color
.DitherFlag
;
190 attr
->Fog
= ctx
->Fog
.Enabled
;
191 for (i
=0;i
<MAX_LIGHTS
;i
++) {
192 attr
->Light
[i
] = ctx
->Light
.Light
[i
].Enabled
;
194 attr
->Lighting
= ctx
->Light
.Enabled
;
195 attr
->LineSmooth
= ctx
->Line
.SmoothFlag
;
196 attr
->LineStipple
= ctx
->Line
.StippleFlag
;
197 attr
->IndexLogicOp
= ctx
->Color
.IndexLogicOpEnabled
;
198 attr
->ColorLogicOp
= ctx
->Color
.ColorLogicOpEnabled
;
199 attr
->Map1Color4
= ctx
->Eval
.Map1Color4
;
200 attr
->Map1Index
= ctx
->Eval
.Map1Index
;
201 attr
->Map1Normal
= ctx
->Eval
.Map1Normal
;
202 attr
->Map1TextureCoord1
= ctx
->Eval
.Map1TextureCoord1
;
203 attr
->Map1TextureCoord2
= ctx
->Eval
.Map1TextureCoord2
;
204 attr
->Map1TextureCoord3
= ctx
->Eval
.Map1TextureCoord3
;
205 attr
->Map1TextureCoord4
= ctx
->Eval
.Map1TextureCoord4
;
206 attr
->Map1Vertex3
= ctx
->Eval
.Map1Vertex3
;
207 attr
->Map1Vertex4
= ctx
->Eval
.Map1Vertex4
;
208 attr
->Map2Color4
= ctx
->Eval
.Map2Color4
;
209 attr
->Map2Index
= ctx
->Eval
.Map2Index
;
210 attr
->Map2Normal
= ctx
->Eval
.Map2Normal
;
211 attr
->Map2TextureCoord1
= ctx
->Eval
.Map2TextureCoord1
;
212 attr
->Map2TextureCoord2
= ctx
->Eval
.Map2TextureCoord2
;
213 attr
->Map2TextureCoord3
= ctx
->Eval
.Map2TextureCoord3
;
214 attr
->Map2TextureCoord4
= ctx
->Eval
.Map2TextureCoord4
;
215 attr
->Map2Vertex3
= ctx
->Eval
.Map2Vertex3
;
216 attr
->Map2Vertex4
= ctx
->Eval
.Map2Vertex4
;
217 attr
->Normalize
= ctx
->Transform
.Normalize
;
218 attr
->PointSmooth
= ctx
->Point
.SmoothFlag
;
219 attr
->PolygonOffsetPoint
= ctx
->Polygon
.OffsetPoint
;
220 attr
->PolygonOffsetLine
= ctx
->Polygon
.OffsetLine
;
221 attr
->PolygonOffsetFill
= ctx
->Polygon
.OffsetFill
;
222 attr
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
223 attr
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
224 attr
->RescaleNormals
= ctx
->Transform
.RescaleNormals
;
225 attr
->Scissor
= ctx
->Scissor
.Enabled
;
226 attr
->Stencil
= ctx
->Stencil
.Enabled
;
227 attr
->Texture
= ctx
->Texture
.Enabled
;
228 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
229 attr
->TexGen
[i
] = ctx
->Texture
.Unit
[i
].TexGenEnabled
;
231 newnode
= new_attrib_node( GL_ENABLE_BIT
);
232 newnode
->data
= attr
;
233 newnode
->next
= head
;
237 if (mask
& GL_EVAL_BIT
) {
238 struct gl_eval_attrib
*attr
;
239 attr
= MALLOC_STRUCT( gl_eval_attrib
);
240 MEMCPY( attr
, &ctx
->Eval
, sizeof(struct gl_eval_attrib
) );
241 newnode
= new_attrib_node( GL_EVAL_BIT
);
242 newnode
->data
= attr
;
243 newnode
->next
= head
;
247 if (mask
& GL_FOG_BIT
) {
248 struct gl_fog_attrib
*attr
;
249 attr
= MALLOC_STRUCT( gl_fog_attrib
);
250 MEMCPY( attr
, &ctx
->Fog
, sizeof(struct gl_fog_attrib
) );
251 newnode
= new_attrib_node( GL_FOG_BIT
);
252 newnode
->data
= attr
;
253 newnode
->next
= head
;
257 if (mask
& GL_HINT_BIT
) {
258 struct gl_hint_attrib
*attr
;
259 attr
= MALLOC_STRUCT( gl_hint_attrib
);
260 MEMCPY( attr
, &ctx
->Hint
, sizeof(struct gl_hint_attrib
) );
261 newnode
= new_attrib_node( GL_HINT_BIT
);
262 newnode
->data
= attr
;
263 newnode
->next
= head
;
267 if (mask
& GL_LIGHTING_BIT
) {
268 struct gl_light_attrib
*attr
;
269 attr
= MALLOC_STRUCT( gl_light_attrib
);
270 MEMCPY( attr
, &ctx
->Light
, sizeof(struct gl_light_attrib
) );
271 newnode
= new_attrib_node( GL_LIGHTING_BIT
);
272 newnode
->data
= attr
;
273 newnode
->next
= head
;
277 if (mask
& GL_LINE_BIT
) {
278 struct gl_line_attrib
*attr
;
279 attr
= MALLOC_STRUCT( gl_line_attrib
);
280 MEMCPY( attr
, &ctx
->Line
, sizeof(struct gl_line_attrib
) );
281 newnode
= new_attrib_node( GL_LINE_BIT
);
282 newnode
->data
= attr
;
283 newnode
->next
= head
;
287 if (mask
& GL_LIST_BIT
) {
288 struct gl_list_attrib
*attr
;
289 attr
= MALLOC_STRUCT( gl_list_attrib
);
290 MEMCPY( attr
, &ctx
->List
, sizeof(struct gl_list_attrib
) );
291 newnode
= new_attrib_node( GL_LIST_BIT
);
292 newnode
->data
= attr
;
293 newnode
->next
= head
;
297 if (mask
& GL_PIXEL_MODE_BIT
) {
298 struct gl_pixel_attrib
*attr
;
299 attr
= MALLOC_STRUCT( gl_pixel_attrib
);
300 MEMCPY( attr
, &ctx
->Pixel
, sizeof(struct gl_pixel_attrib
) );
301 newnode
= new_attrib_node( GL_PIXEL_MODE_BIT
);
302 newnode
->data
= attr
;
303 newnode
->next
= head
;
307 if (mask
& GL_POINT_BIT
) {
308 struct gl_point_attrib
*attr
;
309 attr
= MALLOC_STRUCT( gl_point_attrib
);
310 MEMCPY( attr
, &ctx
->Point
, sizeof(struct gl_point_attrib
) );
311 newnode
= new_attrib_node( GL_POINT_BIT
);
312 newnode
->data
= attr
;
313 newnode
->next
= head
;
317 if (mask
& GL_POLYGON_BIT
) {
318 struct gl_polygon_attrib
*attr
;
319 attr
= MALLOC_STRUCT( gl_polygon_attrib
);
320 MEMCPY( attr
, &ctx
->Polygon
, sizeof(struct gl_polygon_attrib
) );
321 newnode
= new_attrib_node( GL_POLYGON_BIT
);
322 newnode
->data
= attr
;
323 newnode
->next
= head
;
327 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
329 stipple
= (GLuint
*) malloc( 32*sizeof(GLuint
) );
330 MEMCPY( stipple
, ctx
->PolygonStipple
, 32*sizeof(GLuint
) );
331 newnode
= new_attrib_node( GL_POLYGON_STIPPLE_BIT
);
332 newnode
->data
= stipple
;
333 newnode
->next
= head
;
337 if (mask
& GL_SCISSOR_BIT
) {
338 struct gl_scissor_attrib
*attr
;
339 attr
= MALLOC_STRUCT( gl_scissor_attrib
);
340 MEMCPY( attr
, &ctx
->Scissor
, sizeof(struct gl_scissor_attrib
) );
341 newnode
= new_attrib_node( GL_SCISSOR_BIT
);
342 newnode
->data
= attr
;
343 newnode
->next
= head
;
347 if (mask
& GL_STENCIL_BUFFER_BIT
) {
348 struct gl_stencil_attrib
*attr
;
349 attr
= MALLOC_STRUCT( gl_stencil_attrib
);
350 MEMCPY( attr
, &ctx
->Stencil
, sizeof(struct gl_stencil_attrib
) );
351 newnode
= new_attrib_node( GL_STENCIL_BUFFER_BIT
);
352 newnode
->data
= attr
;
353 newnode
->next
= head
;
357 if (mask
& GL_TEXTURE_BIT
) {
358 struct gl_texture_attrib
*attr
;
360 /* Take care of texture object reference counters */
361 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
362 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
++;
363 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
++;
364 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
++;
366 attr
= MALLOC_STRUCT( gl_texture_attrib
);
367 MEMCPY( attr
, &ctx
->Texture
, sizeof(struct gl_texture_attrib
) );
368 /* copy state of the currently bound texture objects */
369 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
370 copy_texobj_state(&attr
->Unit
[u
].Saved1D
, attr
->Unit
[u
].CurrentD
[1]);
371 copy_texobj_state(&attr
->Unit
[u
].Saved2D
, attr
->Unit
[u
].CurrentD
[2]);
372 copy_texobj_state(&attr
->Unit
[u
].Saved3D
, attr
->Unit
[u
].CurrentD
[3]);
374 newnode
= new_attrib_node( GL_TEXTURE_BIT
);
375 newnode
->data
= attr
;
376 newnode
->next
= head
;
380 if (mask
& GL_TRANSFORM_BIT
) {
381 struct gl_transform_attrib
*attr
;
382 attr
= MALLOC_STRUCT( gl_transform_attrib
);
383 MEMCPY( attr
, &ctx
->Transform
, sizeof(struct gl_transform_attrib
) );
384 newnode
= new_attrib_node( GL_TRANSFORM_BIT
);
385 newnode
->data
= attr
;
386 newnode
->next
= head
;
390 if (mask
& GL_VIEWPORT_BIT
) {
391 struct gl_viewport_attrib
*attr
;
392 attr
= MALLOC_STRUCT( gl_viewport_attrib
);
393 MEMCPY( attr
, &ctx
->Viewport
, sizeof(struct gl_viewport_attrib
) );
394 newnode
= new_attrib_node( GL_VIEWPORT_BIT
);
395 newnode
->data
= attr
;
396 newnode
->next
= head
;
400 ctx
->AttribStack
[ctx
->AttribStackDepth
] = head
;
401 ctx
->AttribStackDepth
++;
407 * This function is kind of long just because we have to call a lot
408 * of device driver functions to update device driver state.
410 void gl_PopAttrib( GLcontext
* ctx
)
412 struct gl_attrib_node
*attr
, *next
;
414 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopAttrib");
417 if (ctx
->AttribStackDepth
==0) {
418 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopAttrib" );
422 ctx
->AttribStackDepth
--;
423 attr
= ctx
->AttribStack
[ctx
->AttribStackDepth
];
427 if (MESA_VERBOSE
&VERBOSE_API
)
428 fprintf(stderr
, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr
->kind
));
430 switch (attr
->kind
) {
431 case GL_ACCUM_BUFFER_BIT
:
432 MEMCPY( &ctx
->Accum
, attr
->data
, sizeof(struct gl_accum_attrib
) );
434 case GL_COLOR_BUFFER_BIT
:
436 GLenum oldDrawBuffer
= ctx
->Color
.DrawBuffer
;
437 GLenum oldAlphaFunc
= ctx
->Color
.AlphaFunc
;
438 GLubyte oldAlphaRef
= ctx
->Color
.AlphaRef
;
439 GLenum oldBlendSrc
= ctx
->Color
.BlendSrcRGB
;
440 GLenum oldBlendDst
= ctx
->Color
.BlendDstRGB
;
441 MEMCPY( &ctx
->Color
, attr
->data
,
442 sizeof(struct gl_colorbuffer_attrib
) );
443 if (ctx
->Color
.DrawBuffer
!= oldDrawBuffer
) {
444 gl_DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
);
446 if ((ctx
->Color
.AlphaFunc
!= oldAlphaFunc
||
447 ctx
->Color
.AlphaRef
!= oldAlphaRef
) &&
448 ctx
->Driver
.AlphaFunc
)
449 (*ctx
->Driver
.AlphaFunc
)( ctx
, ctx
->Color
.AlphaFunc
,
450 ctx
->Color
.AlphaRef
/ 255.0F
);
451 if ((ctx
->Color
.BlendSrcRGB
!= oldBlendSrc
||
452 ctx
->Color
.BlendSrcRGB
!= oldBlendDst
) &&
453 ctx
->Driver
.BlendFunc
)
454 (*ctx
->Driver
.BlendFunc
)( ctx
, ctx
->Color
.BlendSrcRGB
,
455 ctx
->Color
.BlendDstRGB
);
459 MEMCPY( &ctx
->Current
, attr
->data
,
460 sizeof(struct gl_current_attrib
) );
462 case GL_DEPTH_BUFFER_BIT
:
464 GLenum oldDepthFunc
= ctx
->Depth
.Func
;
465 GLboolean oldDepthMask
= ctx
->Depth
.Mask
;
466 GLfloat oldDepthClear
= ctx
->Depth
.Clear
;
467 MEMCPY( &ctx
->Depth
, attr
->data
,
468 sizeof(struct gl_depthbuffer_attrib
) );
469 if (ctx
->Depth
.Func
!= oldDepthFunc
&& ctx
->Driver
.DepthFunc
)
470 (*ctx
->Driver
.DepthFunc
)( ctx
, ctx
->Depth
.Func
);
471 if (ctx
->Depth
.Mask
!= oldDepthMask
&& ctx
->Driver
.DepthMask
)
472 (*ctx
->Driver
.DepthMask
)( ctx
, ctx
->Depth
.Mask
);
473 if (ctx
->Depth
.Clear
!= oldDepthClear
&& ctx
->Driver
.ClearDepth
)
474 (*ctx
->Driver
.ClearDepth
)( ctx
, ctx
->Depth
.Clear
);
479 const struct gl_enable_attrib
*enable
;
480 enable
= (const struct gl_enable_attrib
*) attr
->data
;
482 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
483 if ((VALUE) != (NEWVALUE)) { \
484 gl_set_enable( ctx, ENUM, (NEWVALUE) ); \
487 TEST_AND_UPDATE(ctx
->Color
.AlphaEnabled
, enable
->AlphaTest
, GL_ALPHA_TEST
);
488 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->AutoNormal
, GL_NORMALIZE
);
489 TEST_AND_UPDATE(ctx
->Color
.BlendEnabled
, enable
->Blend
, GL_BLEND
);
492 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
493 if (ctx
->Transform
.ClipEnabled
[i
] != enable
->ClipPlane
[i
])
494 gl_set_enable( ctx
, (GLenum
) (GL_CLIP_PLANE0
+ i
), enable
->ClipPlane
[i
] );
497 TEST_AND_UPDATE(ctx
->Light
.ColorMaterialEnabled
, enable
->ColorMaterial
, GL_COLOR_MATERIAL
);
498 TEST_AND_UPDATE(ctx
->Polygon
.CullFlag
, enable
->CullFace
, GL_CULL_FACE
);
499 TEST_AND_UPDATE(ctx
->Depth
.Test
, enable
->DepthTest
, GL_DEPTH_TEST
);
500 TEST_AND_UPDATE(ctx
->Color
.DitherFlag
, enable
->Dither
, GL_DITHER
);
501 TEST_AND_UPDATE(ctx
->Fog
.Enabled
, enable
->Fog
, GL_FOG
);
502 TEST_AND_UPDATE(ctx
->Light
.Enabled
, enable
->Lighting
, GL_LIGHTING
);
503 TEST_AND_UPDATE(ctx
->Line
.SmoothFlag
, enable
->LineSmooth
, GL_LINE_SMOOTH
);
504 TEST_AND_UPDATE(ctx
->Line
.StippleFlag
, enable
->LineStipple
, GL_LINE_STIPPLE
);
505 TEST_AND_UPDATE(ctx
->Color
.IndexLogicOpEnabled
, enable
->IndexLogicOp
, GL_INDEX_LOGIC_OP
);
506 TEST_AND_UPDATE(ctx
->Color
.ColorLogicOpEnabled
, enable
->ColorLogicOp
, GL_COLOR_LOGIC_OP
);
507 TEST_AND_UPDATE(ctx
->Eval
.Map1Color4
, enable
->Map1Color4
, GL_MAP1_COLOR_4
);
508 TEST_AND_UPDATE(ctx
->Eval
.Map1Index
, enable
->Map1Index
, GL_MAP1_INDEX
);
509 TEST_AND_UPDATE(ctx
->Eval
.Map1Normal
, enable
->Map1Normal
, GL_MAP1_NORMAL
);
510 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord1
, enable
->Map1TextureCoord1
, GL_MAP1_TEXTURE_COORD_1
);
511 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord2
, enable
->Map1TextureCoord2
, GL_MAP1_TEXTURE_COORD_2
);
512 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord3
, enable
->Map1TextureCoord3
, GL_MAP1_TEXTURE_COORD_3
);
513 TEST_AND_UPDATE(ctx
->Eval
.Map1TextureCoord4
, enable
->Map1TextureCoord4
, GL_MAP1_TEXTURE_COORD_4
);
514 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex3
, enable
->Map1Vertex3
, GL_MAP1_VERTEX_3
);
515 TEST_AND_UPDATE(ctx
->Eval
.Map1Vertex4
, enable
->Map1Vertex4
, GL_MAP1_VERTEX_4
);
516 TEST_AND_UPDATE(ctx
->Eval
.Map2Color4
, enable
->Map2Color4
, GL_MAP2_COLOR_4
);
517 TEST_AND_UPDATE(ctx
->Eval
.Map2Index
, enable
->Map2Index
, GL_MAP2_INDEX
);
518 TEST_AND_UPDATE(ctx
->Eval
.Map2Normal
, enable
->Map2Normal
, GL_MAP2_NORMAL
);
519 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord1
, enable
->Map2TextureCoord1
, GL_MAP2_TEXTURE_COORD_1
);
520 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord2
, enable
->Map2TextureCoord2
, GL_MAP2_TEXTURE_COORD_2
);
521 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord3
, enable
->Map2TextureCoord3
, GL_MAP2_TEXTURE_COORD_3
);
522 TEST_AND_UPDATE(ctx
->Eval
.Map2TextureCoord4
, enable
->Map2TextureCoord4
, GL_MAP2_TEXTURE_COORD_4
);
523 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex3
, enable
->Map2Vertex3
, GL_MAP2_VERTEX_3
);
524 TEST_AND_UPDATE(ctx
->Eval
.Map2Vertex4
, enable
->Map2Vertex4
, GL_MAP2_VERTEX_4
);
525 TEST_AND_UPDATE(ctx
->Transform
.Normalize
, enable
->Normalize
, GL_NORMALIZE
);
526 TEST_AND_UPDATE(ctx
->Transform
.RescaleNormals
, enable
->RescaleNormals
, GL_RESCALE_NORMAL_EXT
);
527 TEST_AND_UPDATE(ctx
->Point
.SmoothFlag
, enable
->PointSmooth
, GL_POINT_SMOOTH
);
528 TEST_AND_UPDATE(ctx
->Polygon
.OffsetPoint
, enable
->PolygonOffsetPoint
, GL_POLYGON_OFFSET_POINT
);
529 TEST_AND_UPDATE(ctx
->Polygon
.OffsetLine
, enable
->PolygonOffsetLine
, GL_POLYGON_OFFSET_LINE
);
530 TEST_AND_UPDATE(ctx
->Polygon
.OffsetFill
, enable
->PolygonOffsetFill
, GL_POLYGON_OFFSET_FILL
);
531 TEST_AND_UPDATE(ctx
->Polygon
.SmoothFlag
, enable
->PolygonSmooth
, GL_POLYGON_SMOOTH
);
532 TEST_AND_UPDATE(ctx
->Polygon
.StippleFlag
, enable
->PolygonStipple
, GL_POLYGON_STIPPLE
);
533 TEST_AND_UPDATE(ctx
->Scissor
.Enabled
, enable
->Scissor
, GL_SCISSOR_TEST
);
534 TEST_AND_UPDATE(ctx
->Stencil
.Enabled
, enable
->Stencil
, GL_STENCIL_TEST
);
535 if (ctx
->Texture
.Enabled
!= enable
->Texture
) {
536 ctx
->Texture
.Enabled
= enable
->Texture
;
537 if (ctx
->Driver
.Enable
) {
538 if (ctx
->Driver
.ActiveTexture
)
539 (*ctx
->Driver
.ActiveTexture
)( ctx
, 0 );
540 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE0_1D
) );
541 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE0_2D
) );
542 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE0_3D
) );
543 if (ctx
->Driver
.ActiveTexture
)
544 (*ctx
->Driver
.ActiveTexture
)( ctx
, 1 );
545 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_1D
, (GLboolean
) (enable
->Texture
& TEXTURE1_1D
) );
546 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_2D
, (GLboolean
) (enable
->Texture
& TEXTURE1_2D
) );
547 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_3D
, (GLboolean
) (enable
->Texture
& TEXTURE1_3D
) );
548 if (ctx
->Driver
.ActiveTexture
)
549 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
552 #undef TEST_AND_UPDATE
555 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++) {
556 if (ctx
->Texture
.Unit
[i
].TexGenEnabled
!= enable
->TexGen
[i
]) {
557 ctx
->Texture
.Unit
[i
].TexGenEnabled
= enable
->TexGen
[i
];
559 /* ctx->Enabled recalculated in state change
562 if (ctx
->Driver
.Enable
) {
563 if (ctx
->Driver
.ActiveTexture
)
564 (*ctx
->Driver
.ActiveTexture
)( ctx
, i
);
565 if (enable
->TexGen
[i
] & S_BIT
)
566 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
568 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
569 if (enable
->TexGen
[i
] & T_BIT
)
570 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
572 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
573 if (enable
->TexGen
[i
] & R_BIT
)
574 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
576 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
577 if (enable
->TexGen
[i
] & Q_BIT
)
578 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
580 (*ctx
->Driver
.Enable
)( ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
584 if (ctx
->Driver
.ActiveTexture
)
585 (*ctx
->Driver
.ActiveTexture
)( ctx
, ctx
->Texture
.CurrentUnit
);
590 MEMCPY( &ctx
->Eval
, attr
->data
, sizeof(struct gl_eval_attrib
) );
594 GLboolean anyChange
= (memcmp( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) ) != 0);
595 MEMCPY( &ctx
->Fog
, attr
->data
, sizeof(struct gl_fog_attrib
) );
596 if (anyChange
&& ctx
->Driver
.Fogfv
) {
597 const GLfloat mode
= ctx
->Fog
.Mode
;
598 const GLfloat density
= ctx
->Fog
.Density
;
599 const GLfloat start
= ctx
->Fog
.Start
;
600 const GLfloat end
= ctx
->Fog
.End
;
601 const GLfloat index
= ctx
->Fog
.Index
;
602 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_MODE
, &mode
);
603 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_DENSITY
, &density
);
604 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_START
, &start
);
605 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_END
, &end
);
606 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_INDEX
, &index
);
607 (*ctx
->Driver
.Fogfv
)( ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
609 ctx
->Enabled
&= ENABLE_FOG
;
610 if (ctx
->Fog
.Enabled
) ctx
->Enabled
|= ENABLE_FOG
;
614 MEMCPY( &ctx
->Hint
, attr
->data
, sizeof(struct gl_hint_attrib
) );
615 if (ctx
->Driver
.Hint
) {
616 (*ctx
->Driver
.Hint
)( ctx
, GL_PERSPECTIVE_CORRECTION_HINT
,
617 ctx
->Hint
.PerspectiveCorrection
);
618 (*ctx
->Driver
.Hint
)( ctx
, GL_POINT_SMOOTH_HINT
,
619 ctx
->Hint
.PointSmooth
);
620 (*ctx
->Driver
.Hint
)( ctx
, GL_LINE_SMOOTH_HINT
,
621 ctx
->Hint
.LineSmooth
);
622 (*ctx
->Driver
.Hint
)( ctx
, GL_POLYGON_SMOOTH_HINT
,
623 ctx
->Hint
.PolygonSmooth
);
624 (*ctx
->Driver
.Hint
)( ctx
, GL_FOG_HINT
, ctx
->Hint
.Fog
);
627 case GL_LIGHTING_BIT
:
628 MEMCPY( &ctx
->Light
, attr
->data
, sizeof(struct gl_light_attrib
) );
629 if (ctx
->Driver
.Enable
) {
631 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
632 GLenum light
= (GLenum
) (GL_LIGHT0
+ i
);
633 (*ctx
->Driver
.Enable
)( ctx
, light
, ctx
->Light
.Light
[i
].Enabled
);
635 (*ctx
->Driver
.Enable
)( ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
637 ctx
->Enabled
&= ENABLE_LIGHT
;
638 if (ctx
->Light
.Enabled
&& !is_empty_list(&ctx
->Light
.EnabledList
))
639 ctx
->Enabled
|= ENABLE_LIGHT
;
642 MEMCPY( &ctx
->Line
, attr
->data
, sizeof(struct gl_line_attrib
) );
643 if (ctx
->Driver
.Enable
) {
644 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
645 (*ctx
->Driver
.Enable
)( ctx
, GL_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
649 MEMCPY( &ctx
->List
, attr
->data
, sizeof(struct gl_list_attrib
) );
651 case GL_PIXEL_MODE_BIT
:
652 MEMCPY( &ctx
->Pixel
, attr
->data
, sizeof(struct gl_pixel_attrib
) );
655 MEMCPY( &ctx
->Point
, attr
->data
, sizeof(struct gl_point_attrib
) );
656 if (ctx
->Driver
.Enable
)
657 (*ctx
->Driver
.Enable
)( ctx
, GL_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
661 GLenum oldFrontMode
= ctx
->Polygon
.FrontMode
;
662 GLenum oldBackMode
= ctx
->Polygon
.BackMode
;
663 MEMCPY( &ctx
->Polygon
, attr
->data
,
664 sizeof(struct gl_polygon_attrib
) );
665 if ((ctx
->Polygon
.FrontMode
!= oldFrontMode
||
666 ctx
->Polygon
.BackMode
!= oldBackMode
) &&
667 ctx
->Driver
.PolygonMode
) {
668 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
669 (*ctx
->Driver
.PolygonMode
)( ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
671 if (ctx
->Driver
.CullFace
)
672 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
674 if (ctx
->Driver
.FrontFace
)
675 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
677 if (ctx
->Driver
.Enable
)
678 (*ctx
->Driver
.Enable
)( ctx
, GL_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
681 case GL_POLYGON_STIPPLE_BIT
:
682 MEMCPY( ctx
->PolygonStipple
, attr
->data
, 32*sizeof(GLuint
) );
685 MEMCPY( &ctx
->Scissor
, attr
->data
,
686 sizeof(struct gl_scissor_attrib
) );
687 if (ctx
->Driver
.Enable
)
688 (*ctx
->Driver
.Enable
)( ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
689 if (ctx
->Driver
.Scissor
)
690 ctx
->Driver
.Scissor( ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
691 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
693 case GL_STENCIL_BUFFER_BIT
:
694 MEMCPY( &ctx
->Stencil
, attr
->data
,
695 sizeof(struct gl_stencil_attrib
) );
696 if (ctx
->Driver
.StencilFunc
)
697 (*ctx
->Driver
.StencilFunc
)( ctx
, ctx
->Stencil
.Function
,
698 ctx
->Stencil
.Ref
, ctx
->Stencil
.ValueMask
);
699 if (ctx
->Driver
.StencilMask
)
700 (*ctx
->Driver
.StencilMask
)( ctx
, ctx
->Stencil
.WriteMask
);
701 if (ctx
->Driver
.StencilOp
)
702 (*ctx
->Driver
.StencilOp
)( ctx
, ctx
->Stencil
.FailFunc
,
703 ctx
->Stencil
.ZFailFunc
, ctx
->Stencil
.ZPassFunc
);
704 if (ctx
->Driver
.ClearStencil
)
705 (*ctx
->Driver
.ClearStencil
)( ctx
, ctx
->Stencil
.Clear
);
706 if (ctx
->Driver
.Enable
)
707 (*ctx
->Driver
.Enable
)( ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
708 ctx
->TriangleCaps
&= ~DD_STENCIL
;
709 if (ctx
->Stencil
.Enabled
)
710 ctx
->TriangleCaps
|= DD_STENCIL
;
713 case GL_TRANSFORM_BIT
:
714 MEMCPY( &ctx
->Transform
, attr
->data
,
715 sizeof(struct gl_transform_attrib
) );
716 if (ctx
->Driver
.Enable
) {
717 (*ctx
->Driver
.Enable
)( ctx
, GL_NORMALIZE
, ctx
->Transform
.Normalize
);
718 (*ctx
->Driver
.Enable
)( ctx
, GL_RESCALE_NORMAL_EXT
, ctx
->Transform
.RescaleNormals
);
720 ctx
->Enabled
&= ~(ENABLE_NORMALIZE
|ENABLE_RESCALE
);
721 if (ctx
->Transform
.Normalize
) ctx
->Enabled
|= ENABLE_NORMALIZE
;
722 if (ctx
->Transform
.RescaleNormals
) ctx
->Enabled
|= ENABLE_RESCALE
;
725 /* Take care of texture object reference counters */
728 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
729 ctx
->Texture
.Unit
[u
].CurrentD
[1]->RefCount
--;
730 ctx
->Texture
.Unit
[u
].CurrentD
[2]->RefCount
--;
731 ctx
->Texture
.Unit
[u
].CurrentD
[3]->RefCount
--;
733 MEMCPY( &ctx
->Texture
, attr
->data
,
734 sizeof(struct gl_texture_attrib
) );
735 /* restore state of the currently bound texture objects */
736 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
737 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[1],
738 &(ctx
->Texture
.Unit
[u
].Saved1D
) );
739 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[2],
740 &(ctx
->Texture
.Unit
[u
].Saved2D
) );
741 copy_texobj_state( ctx
->Texture
.Unit
[u
].CurrentD
[3],
742 &(ctx
->Texture
.Unit
[u
].Saved3D
) );
743 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[1] );
744 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[2] );
745 gl_put_texobj_on_dirty_list( ctx
, ctx
->Texture
.Unit
[u
].CurrentD
[3] );
750 case GL_VIEWPORT_BIT
:
752 struct gl_viewport_attrib
*v
=
753 (struct gl_viewport_attrib
*)attr
->data
;
755 gl_Viewport( ctx
, v
->X
, v
->Y
, v
->Width
, v
->Height
);
756 gl_DepthRange( ctx
, v
->Near
, v
->Far
);
760 gl_problem( ctx
, "Bad attrib flag in PopAttrib");
765 free( (void *) attr
->data
);
766 free( (void *) attr
);
770 ctx
->NewState
= NEW_ALL
;
774 #define GL_CLIENT_PACK_BIT (1<<20)
775 #define GL_CLIENT_UNPACK_BIT (1<<21)
778 void gl_PushClientAttrib( GLcontext
*ctx
, GLbitfield mask
)
780 struct gl_attrib_node
*newnode
;
781 struct gl_attrib_node
*head
;
783 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPushClientAttrib");
785 if (ctx
->ClientAttribStackDepth
>=MAX_CLIENT_ATTRIB_STACK_DEPTH
) {
786 gl_error( ctx
, GL_STACK_OVERFLOW
, "glPushClientAttrib" );
790 /* Build linked list of attribute nodes which save all attribute */
791 /* groups specified by the mask. */
794 if (mask
& GL_CLIENT_PIXEL_STORE_BIT
) {
795 struct gl_pixelstore_attrib
*attr
;
796 /* packing attribs */
797 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
798 MEMCPY( attr
, &ctx
->Pack
, sizeof(struct gl_pixelstore_attrib
) );
799 newnode
= new_attrib_node( GL_CLIENT_PACK_BIT
);
800 newnode
->data
= attr
;
801 newnode
->next
= head
;
803 /* unpacking attribs */
804 attr
= MALLOC_STRUCT( gl_pixelstore_attrib
);
805 MEMCPY( attr
, &ctx
->Unpack
, sizeof(struct gl_pixelstore_attrib
) );
806 newnode
= new_attrib_node( GL_CLIENT_UNPACK_BIT
);
807 newnode
->data
= attr
;
808 newnode
->next
= head
;
811 if (mask
& GL_CLIENT_VERTEX_ARRAY_BIT
) {
812 struct gl_array_attrib
*attr
;
813 attr
= MALLOC_STRUCT( gl_array_attrib
);
814 MEMCPY( attr
, &ctx
->Array
, sizeof(struct gl_array_attrib
) );
815 newnode
= new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT
);
816 newnode
->data
= attr
;
817 newnode
->next
= head
;
821 ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
] = head
;
822 ctx
->ClientAttribStackDepth
++;
828 void gl_PopClientAttrib( GLcontext
*ctx
)
830 struct gl_attrib_node
*attr
, *next
;
832 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPopClientAttrib");
834 if (ctx
->ClientAttribStackDepth
==0) {
835 gl_error( ctx
, GL_STACK_UNDERFLOW
, "glPopClientAttrib" );
839 ctx
->ClientAttribStackDepth
--;
840 attr
= ctx
->ClientAttribStack
[ctx
->ClientAttribStackDepth
];
843 switch (attr
->kind
) {
844 case GL_CLIENT_PACK_BIT
:
845 MEMCPY( &ctx
->Pack
, attr
->data
,
846 sizeof(struct gl_pixelstore_attrib
) );
848 case GL_CLIENT_UNPACK_BIT
:
849 MEMCPY( &ctx
->Unpack
, attr
->data
,
850 sizeof(struct gl_pixelstore_attrib
) );
852 case GL_CLIENT_VERTEX_ARRAY_BIT
:
853 MEMCPY( &ctx
->Array
, attr
->data
,
854 sizeof(struct gl_array_attrib
) );
857 gl_problem( ctx
, "Bad attrib flag in PopClientAttrib");
862 free( (void *) attr
->data
);
863 free( (void *) attr
);
867 ctx
->NewState
= NEW_ALL
;