blob: 4ad733b3cdf64c332588bbff3c1f6a6b6ee99fc0 [file] [log] [blame]
Brian Paul1b6592a2000-03-03 18:55:45 +00001/* $Id: attrib.c,v 1.18 2000/03/03 18:55:45 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
Brian Paul42fcf032000-02-02 22:03:31 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "attrib.h"
Brian Paulea39f042000-02-02 19:17:57 +000033#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "context.h"
35#include "enable.h"
36#include "enums.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000037#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000038#include "simple_list.h"
39#include "texstate.h"
40#include "types.h"
jtgafb833d1999-08-19 00:55:39 +000041#endif
42
43
jtgafb833d1999-08-19 00:55:39 +000044
45
46/*
47 * Allocate a new attribute state node. These nodes have a
48 * "kind" value and a pointer to a struct of state data.
49 */
Brian Paul42fcf032000-02-02 22:03:31 +000050static struct gl_attrib_node *
51new_attrib_node( GLbitfield kind )
jtgafb833d1999-08-19 00:55:39 +000052{
Brian Paulbd5cdaf1999-10-13 18:42:49 +000053 struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
jtgafb833d1999-08-19 00:55:39 +000054 if (an) {
55 an->kind = kind;
56 }
57 return an;
58}
59
60
61
62/*
63 * Copy texture object state from one texture object to another.
64 */
Brian Paul42fcf032000-02-02 22:03:31 +000065static void
66copy_texobj_state( struct gl_texture_object *dest,
67 const struct gl_texture_object *src )
jtgafb833d1999-08-19 00:55:39 +000068{
69 /*
70 dest->Name = src->Name;
71 dest->Dimensions = src->Dimensions;
72 */
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;
87 dest->P = src->P;
88 dest->M = src->M;
89 dest->MinMagThresh = src->MinMagThresh;
Brian Paulfbd8f211999-11-11 01:22:25 +000090 dest->Palette = src->Palette;
jtgafb833d1999-08-19 00:55:39 +000091 dest->Complete = src->Complete;
92 dest->SampleFunc = src->SampleFunc;
93}
94
95
96
Brian Paul42fcf032000-02-02 22:03:31 +000097void
98_mesa_PushAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +000099{
100 struct gl_attrib_node *newnode;
101 struct gl_attrib_node *head;
102
Brian Paul42fcf032000-02-02 22:03:31 +0000103 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
105
106 if (MESA_VERBOSE&VERBOSE_API)
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000107 fprintf(stderr, "glPushAttrib %x\n", (int)mask);
jtgafb833d1999-08-19 00:55:39 +0000108
109 if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
110 gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
111 return;
112 }
113
114 /* Build linked list of attribute nodes which save all attribute */
115 /* groups specified by the mask. */
116 head = NULL;
117
118 if (mask & GL_ACCUM_BUFFER_BIT) {
119 struct gl_accum_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000120 attr = MALLOC_STRUCT( gl_accum_attrib );
jtgafb833d1999-08-19 00:55:39 +0000121 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;
125 head = newnode;
126 }
127
128 if (mask & GL_COLOR_BUFFER_BIT) {
129 struct gl_colorbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000130 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000131 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;
135 head = newnode;
136 }
137
138 if (mask & GL_CURRENT_BIT) {
139 struct gl_current_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000140 attr = MALLOC_STRUCT( gl_current_attrib );
jtgafb833d1999-08-19 00:55:39 +0000141 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;
145 head = newnode;
146 }
147
148 if (mask & GL_DEPTH_BUFFER_BIT) {
149 struct gl_depthbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000150 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000151 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;
155 head = newnode;
156 }
157
158 if (mask & GL_ENABLE_BIT) {
159 struct gl_enable_attrib *attr;
160 GLuint i;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000161 attr = MALLOC_STRUCT( gl_enable_attrib );
jtgafb833d1999-08-19 00:55:39 +0000162 /* 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];
168 }
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;
176 }
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;
213 }
214 newnode = new_attrib_node( GL_ENABLE_BIT );
215 newnode->data = attr;
216 newnode->next = head;
217 head = newnode;
218 }
219
220 if (mask & GL_EVAL_BIT) {
221 struct gl_eval_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000222 attr = MALLOC_STRUCT( gl_eval_attrib );
jtgafb833d1999-08-19 00:55:39 +0000223 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;
227 head = newnode;
228 }
229
230 if (mask & GL_FOG_BIT) {
231 struct gl_fog_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000232 attr = MALLOC_STRUCT( gl_fog_attrib );
jtgafb833d1999-08-19 00:55:39 +0000233 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;
237 head = newnode;
238 }
239
240 if (mask & GL_HINT_BIT) {
241 struct gl_hint_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000242 attr = MALLOC_STRUCT( gl_hint_attrib );
jtgafb833d1999-08-19 00:55:39 +0000243 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;
247 head = newnode;
248 }
249
250 if (mask & GL_LIGHTING_BIT) {
251 struct gl_light_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000252 attr = MALLOC_STRUCT( gl_light_attrib );
jtgafb833d1999-08-19 00:55:39 +0000253 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;
257 head = newnode;
258 }
259
260 if (mask & GL_LINE_BIT) {
261 struct gl_line_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000262 attr = MALLOC_STRUCT( gl_line_attrib );
jtgafb833d1999-08-19 00:55:39 +0000263 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;
267 head = newnode;
268 }
269
270 if (mask & GL_LIST_BIT) {
271 struct gl_list_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000272 attr = MALLOC_STRUCT( gl_list_attrib );
jtgafb833d1999-08-19 00:55:39 +0000273 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;
277 head = newnode;
278 }
279
280 if (mask & GL_PIXEL_MODE_BIT) {
281 struct gl_pixel_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000282 attr = MALLOC_STRUCT( gl_pixel_attrib );
jtgafb833d1999-08-19 00:55:39 +0000283 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;
287 head = newnode;
288 }
289
290 if (mask & GL_POINT_BIT) {
291 struct gl_point_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000292 attr = MALLOC_STRUCT( gl_point_attrib );
jtgafb833d1999-08-19 00:55:39 +0000293 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;
297 head = newnode;
298 }
299
300 if (mask & GL_POLYGON_BIT) {
301 struct gl_polygon_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000302 attr = MALLOC_STRUCT( gl_polygon_attrib );
jtgafb833d1999-08-19 00:55:39 +0000303 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;
307 head = newnode;
308 }
309
310 if (mask & GL_POLYGON_STIPPLE_BIT) {
311 GLuint *stipple;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000312 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +0000313 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
314 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
315 newnode->data = stipple;
316 newnode->next = head;
317 head = newnode;
318 }
319
320 if (mask & GL_SCISSOR_BIT) {
321 struct gl_scissor_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000322 attr = MALLOC_STRUCT( gl_scissor_attrib );
jtgafb833d1999-08-19 00:55:39 +0000323 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;
327 head = newnode;
328 }
329
330 if (mask & GL_STENCIL_BUFFER_BIT) {
331 struct gl_stencil_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000332 attr = MALLOC_STRUCT( gl_stencil_attrib );
jtgafb833d1999-08-19 00:55:39 +0000333 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;
337 head = newnode;
338 }
339
340 if (mask & GL_TEXTURE_BIT) {
341 struct gl_texture_attrib *attr;
342 GLuint u;
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++;
348 }
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000349 attr = MALLOC_STRUCT( gl_texture_attrib );
jtgafb833d1999-08-19 00:55:39 +0000350 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]);
356 }
357 newnode = new_attrib_node( GL_TEXTURE_BIT );
358 newnode->data = attr;
359 newnode->next = head;
360 head = newnode;
361 }
362
363 if (mask & GL_TRANSFORM_BIT) {
364 struct gl_transform_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000365 attr = MALLOC_STRUCT( gl_transform_attrib );
jtgafb833d1999-08-19 00:55:39 +0000366 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;
370 head = newnode;
371 }
372
373 if (mask & GL_VIEWPORT_BIT) {
374 struct gl_viewport_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000375 attr = MALLOC_STRUCT( gl_viewport_attrib );
jtgafb833d1999-08-19 00:55:39 +0000376 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;
380 head = newnode;
381 }
382
383 ctx->AttribStack[ctx->AttribStackDepth] = head;
384 ctx->AttribStackDepth++;
385}
386
387
388
389/*
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.
392 */
Brian Paul42fcf032000-02-02 22:03:31 +0000393void
394_mesa_PopAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000395{
396 struct gl_attrib_node *attr, *next;
Brian Paul42fcf032000-02-02 22:03:31 +0000397 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000398
399 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
400
401
402 if (ctx->AttribStackDepth==0) {
403 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
404 return;
405 }
406
407 ctx->AttribStackDepth--;
408 attr = ctx->AttribStack[ctx->AttribStackDepth];
409
410 while (attr) {
411
412 if (MESA_VERBOSE&VERBOSE_API)
413 fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind));
414
415 switch (attr->kind) {
416 case GL_ACCUM_BUFFER_BIT:
417 MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
418 break;
419 case GL_COLOR_BUFFER_BIT:
420 {
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;
Keith Whitwelle828bc82000-02-25 03:55:39 +0000426 GLenum oldLogicOp = ctx->Color.LogicOp;
jtgafb833d1999-08-19 00:55:39 +0000427 MEMCPY( &ctx->Color, attr->data,
428 sizeof(struct gl_colorbuffer_attrib) );
429 if (ctx->Color.DrawBuffer != oldDrawBuffer) {
Brian Paulfbd8f211999-11-11 01:22:25 +0000430 _mesa_DrawBuffer( ctx->Color.DrawBuffer);
jtgafb833d1999-08-19 00:55:39 +0000431 }
432 if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
433 ctx->Color.AlphaRef != oldAlphaRef) &&
434 ctx->Driver.AlphaFunc)
435 (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
436 ctx->Color.AlphaRef / 255.0F);
437 if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
438 ctx->Color.BlendSrcRGB != oldBlendDst) &&
439 ctx->Driver.BlendFunc)
440 (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
441 ctx->Color.BlendDstRGB);
Keith Whitwelle828bc82000-02-25 03:55:39 +0000442 if (ctx->Color.LogicOp != oldLogicOp &&
443 ctx->Driver.LogicOpcode)
444 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
jtgafb833d1999-08-19 00:55:39 +0000445 }
446 break;
447 case GL_CURRENT_BIT:
448 MEMCPY( &ctx->Current, attr->data,
449 sizeof(struct gl_current_attrib) );
450 break;
451 case GL_DEPTH_BUFFER_BIT:
452 {
453 GLenum oldDepthFunc = ctx->Depth.Func;
454 GLboolean oldDepthMask = ctx->Depth.Mask;
455 GLfloat oldDepthClear = ctx->Depth.Clear;
456 MEMCPY( &ctx->Depth, attr->data,
457 sizeof(struct gl_depthbuffer_attrib) );
458 if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
459 (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func );
460 if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask)
461 (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask );
462 if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth)
463 (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
464 }
465 break;
466 case GL_ENABLE_BIT:
467 {
468 const struct gl_enable_attrib *enable;
469 enable = (const struct gl_enable_attrib *) attr->data;
470
471#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
472 if ((VALUE) != (NEWVALUE)) { \
Brian Paulfbd8f211999-11-11 01:22:25 +0000473 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
jtgafb833d1999-08-19 00:55:39 +0000474 }
475
476 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
477 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
478 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
479 {
480 GLuint i;
481 for (i=0;i<MAX_CLIP_PLANES;i++) {
482 if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
Brian Paulfbd8f211999-11-11 01:22:25 +0000483 _mesa_set_enable( ctx, (GLenum) (GL_CLIP_PLANE0 + i), enable->ClipPlane[i] );
jtgafb833d1999-08-19 00:55:39 +0000484 }
485 }
486 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, GL_COLOR_MATERIAL);
487 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
Keith Whitwell5a437d51999-09-19 23:43:02 +0000488 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
jtgafb833d1999-08-19 00:55:39 +0000489 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
490 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
491 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
492 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
493 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, GL_LINE_STIPPLE);
494 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, GL_INDEX_LOGIC_OP);
495 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, GL_COLOR_LOGIC_OP);
496 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
497 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
498 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
499 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, GL_MAP1_TEXTURE_COORD_1);
500 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, GL_MAP1_TEXTURE_COORD_2);
501 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, GL_MAP1_TEXTURE_COORD_3);
502 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, GL_MAP1_TEXTURE_COORD_4);
503 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, GL_MAP1_VERTEX_3);
504 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, GL_MAP1_VERTEX_4);
505 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
506 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
507 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
508 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, GL_MAP2_TEXTURE_COORD_1);
509 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, GL_MAP2_TEXTURE_COORD_2);
510 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, GL_MAP2_TEXTURE_COORD_3);
511 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, GL_MAP2_TEXTURE_COORD_4);
512 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, GL_MAP2_VERTEX_3);
513 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, GL_MAP2_VERTEX_4);
514 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
515 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, GL_RESCALE_NORMAL_EXT);
516 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, GL_POINT_SMOOTH);
517 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, GL_POLYGON_OFFSET_POINT);
518 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, GL_POLYGON_OFFSET_LINE);
519 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, GL_POLYGON_OFFSET_FILL);
520 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, GL_POLYGON_SMOOTH);
521 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, GL_POLYGON_STIPPLE);
522 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
523 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
524 if (ctx->Texture.Enabled != enable->Texture) {
525 ctx->Texture.Enabled = enable->Texture;
526 if (ctx->Driver.Enable) {
527 if (ctx->Driver.ActiveTexture)
528 (*ctx->Driver.ActiveTexture)( ctx, 0 );
529 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE0_1D) );
530 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE0_2D) );
531 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE0_3D) );
532 if (ctx->Driver.ActiveTexture)
533 (*ctx->Driver.ActiveTexture)( ctx, 1 );
534 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE1_1D) );
535 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE1_2D) );
536 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE1_3D) );
537 if (ctx->Driver.ActiveTexture)
538 (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
539 }
540 }
541#undef TEST_AND_UPDATE
542 {
543 GLuint i;
544 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
545 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
546 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
547
548 /* ctx->Enabled recalculated in state change
549 processing */
550
551 if (ctx->Driver.Enable) {
552 if (ctx->Driver.ActiveTexture)
553 (*ctx->Driver.ActiveTexture)( ctx, i );
554 if (enable->TexGen[i] & S_BIT)
555 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
556 else
557 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
558 if (enable->TexGen[i] & T_BIT)
559 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
560 else
561 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
562 if (enable->TexGen[i] & R_BIT)
563 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
564 else
565 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
566 if (enable->TexGen[i] & Q_BIT)
567 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
568 else
569 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
570 }
571 }
572 }
573 if (ctx->Driver.ActiveTexture)
574 (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
575 }
576 }
577 break;
578 case GL_EVAL_BIT:
579 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
580 break;
581 case GL_FOG_BIT:
582 {
Brian Paul99f16d01999-11-08 15:28:08 +0000583 GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
jtgafb833d1999-08-19 00:55:39 +0000584 MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
585 if (anyChange && ctx->Driver.Fogfv) {
Brian Paul99f16d01999-11-08 15:28:08 +0000586 const GLfloat mode = (GLfloat) ctx->Fog.Mode;
jtgafb833d1999-08-19 00:55:39 +0000587 const GLfloat density = ctx->Fog.Density;
588 const GLfloat start = ctx->Fog.Start;
589 const GLfloat end = ctx->Fog.End;
590 const GLfloat index = ctx->Fog.Index;
591 (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode);
592 (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density );
593 (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start );
594 (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end );
595 (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
596 (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
597 }
Keith Whitwell04c43de1999-11-23 21:15:37 +0000598 ctx->Enabled &= ~ENABLE_FOG;
jtgafb833d1999-08-19 00:55:39 +0000599 if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
600 }
601 break;
602 case GL_HINT_BIT:
603 MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
604 if (ctx->Driver.Hint) {
605 (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
606 ctx->Hint.PerspectiveCorrection );
607 (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT,
608 ctx->Hint.PointSmooth);
609 (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT,
610 ctx->Hint.LineSmooth );
611 (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT,
612 ctx->Hint.PolygonSmooth );
613 (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog );
614 }
615 break;
616 case GL_LIGHTING_BIT:
617 MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
618 if (ctx->Driver.Enable) {
619 GLuint i;
620 for (i = 0; i < MAX_LIGHTS; i++) {
621 GLenum light = (GLenum) (GL_LIGHT0 + i);
622 (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled );
623 }
624 (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
625 }
Brian Paulf2db7ed1999-11-22 18:28:39 +0000626 if (ctx->Light.ShadeModel == GL_FLAT)
627 ctx->TriangleCaps |= DD_FLATSHADE;
628 else
629 ctx->TriangleCaps &= ~DD_FLATSHADE;
630 if (ctx->Driver.ShadeModel)
631 (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
632 ctx->Enabled &= ~ENABLE_LIGHT;
jtgafb833d1999-08-19 00:55:39 +0000633 if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
634 ctx->Enabled |= ENABLE_LIGHT;
635 break;
636 case GL_LINE_BIT:
637 MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
638 if (ctx->Driver.Enable) {
639 (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
640 (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
641 }
Brian Paul1b6592a2000-03-03 18:55:45 +0000642 if (ctx->Driver.LineStipple)
643 (*ctx->Driver.LineStipple)(ctx, ctx->Line.StippleFactor,
644 ctx->Line.StipplePattern);
645 if (ctx->Driver.LineWidth)
646 (*ctx->Driver.LineWidth)(ctx, ctx->Line.Width);
jtgafb833d1999-08-19 00:55:39 +0000647 break;
648 case GL_LIST_BIT:
649 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
650 break;
651 case GL_PIXEL_MODE_BIT:
652 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
653 break;
654 case GL_POINT_BIT:
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 );
658 break;
659 case GL_POLYGON_BIT:
660 {
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);
670 }
671 if (ctx->Driver.CullFace)
672 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
673
674 if (ctx->Driver.FrontFace)
675 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
676
677 if (ctx->Driver.Enable)
678 (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag );
679 }
680 break;
681 case GL_POLYGON_STIPPLE_BIT:
682 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000683 if (ctx->Driver.PolygonStipple)
684 ctx->Driver.PolygonStipple( ctx, attr->data );
jtgafb833d1999-08-19 00:55:39 +0000685 break;
686 case GL_SCISSOR_BIT:
687 MEMCPY( &ctx->Scissor, attr->data,
688 sizeof(struct gl_scissor_attrib) );
689 if (ctx->Driver.Enable)
690 (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
691 if (ctx->Driver.Scissor)
692 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
693 ctx->Scissor.Width, ctx->Scissor.Height );
694 break;
695 case GL_STENCIL_BUFFER_BIT:
696 MEMCPY( &ctx->Stencil, attr->data,
697 sizeof(struct gl_stencil_attrib) );
698 if (ctx->Driver.StencilFunc)
699 (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
700 ctx->Stencil.Ref, ctx->Stencil.ValueMask);
701 if (ctx->Driver.StencilMask)
702 (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask );
703 if (ctx->Driver.StencilOp)
704 (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc,
705 ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc);
706 if (ctx->Driver.ClearStencil)
707 (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
708 if (ctx->Driver.Enable)
709 (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
Keith Whitwell1bf9dfa1999-09-18 20:41:22 +0000710 ctx->TriangleCaps &= ~DD_STENCIL;
711 if (ctx->Stencil.Enabled)
712 ctx->TriangleCaps |= DD_STENCIL;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000713
jtgafb833d1999-08-19 00:55:39 +0000714 break;
715 case GL_TRANSFORM_BIT:
716 MEMCPY( &ctx->Transform, attr->data,
717 sizeof(struct gl_transform_attrib) );
718 if (ctx->Driver.Enable) {
719 (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
720 (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
721 }
722 ctx->Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
723 if (ctx->Transform.Normalize) ctx->Enabled |= ENABLE_NORMALIZE;
724 if (ctx->Transform.RescaleNormals) ctx->Enabled |= ENABLE_RESCALE;
725 break;
726 case GL_TEXTURE_BIT:
727 /* Take care of texture object reference counters */
728 {
729 GLuint u;
730 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
731 ctx->Texture.Unit[u].CurrentD[1]->RefCount--;
732 ctx->Texture.Unit[u].CurrentD[2]->RefCount--;
733 ctx->Texture.Unit[u].CurrentD[3]->RefCount--;
734 }
735 MEMCPY( &ctx->Texture, attr->data,
736 sizeof(struct gl_texture_attrib) );
737 /* restore state of the currently bound texture objects */
738 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
739 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1],
740 &(ctx->Texture.Unit[u].Saved1D) );
741 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2],
742 &(ctx->Texture.Unit[u].Saved2D) );
743 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3],
744 &(ctx->Texture.Unit[u].Saved3D) );
745 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] );
746 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] );
747 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] );
748
749 }
750 }
751 break;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000752 case GL_VIEWPORT_BIT:
753 {
754 struct gl_viewport_attrib *v =
755 (struct gl_viewport_attrib *)attr->data;
756
Brian Paulfbd8f211999-11-11 01:22:25 +0000757 _mesa_Viewport( v->X, v->Y, v->Width, v->Height );
758 _mesa_DepthRange( v->Near, v->Far );
Keith Whitwelle3f37861999-09-16 11:54:56 +0000759 break;
760 }
jtgafb833d1999-08-19 00:55:39 +0000761 default:
762 gl_problem( ctx, "Bad attrib flag in PopAttrib");
763 break;
764 }
765
766 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000767 FREE( attr->data );
768 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000769 attr = next;
770 }
771
772 ctx->NewState = NEW_ALL;
773}
774
775
776#define GL_CLIENT_PACK_BIT (1<<20)
777#define GL_CLIENT_UNPACK_BIT (1<<21)
778
779
Brian Paul42fcf032000-02-02 22:03:31 +0000780void
781_mesa_PushClientAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000782{
783 struct gl_attrib_node *newnode;
784 struct gl_attrib_node *head;
785
Brian Paul42fcf032000-02-02 22:03:31 +0000786 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000787 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
788
789 if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
790 gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
791 return;
792 }
793
794 /* Build linked list of attribute nodes which save all attribute */
795 /* groups specified by the mask. */
796 head = NULL;
797
798 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
799 struct gl_pixelstore_attrib *attr;
800 /* packing attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000801 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000802 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
803 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
804 newnode->data = attr;
805 newnode->next = head;
806 head = newnode;
807 /* unpacking attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000808 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000809 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
810 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
811 newnode->data = attr;
812 newnode->next = head;
813 head = newnode;
814 }
815 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
816 struct gl_array_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000817 attr = MALLOC_STRUCT( gl_array_attrib );
jtgafb833d1999-08-19 00:55:39 +0000818 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
819 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
820 newnode->data = attr;
821 newnode->next = head;
822 head = newnode;
823 }
824
825 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
826 ctx->ClientAttribStackDepth++;
827}
828
829
830
831
Brian Paul42fcf032000-02-02 22:03:31 +0000832void
833_mesa_PopClientAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000834{
835 struct gl_attrib_node *attr, *next;
836
Brian Paul42fcf032000-02-02 22:03:31 +0000837 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000838 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
839
840 if (ctx->ClientAttribStackDepth==0) {
841 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
842 return;
843 }
844
845 ctx->ClientAttribStackDepth--;
846 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
847
848 while (attr) {
849 switch (attr->kind) {
850 case GL_CLIENT_PACK_BIT:
851 MEMCPY( &ctx->Pack, attr->data,
852 sizeof(struct gl_pixelstore_attrib) );
853 break;
854 case GL_CLIENT_UNPACK_BIT:
855 MEMCPY( &ctx->Unpack, attr->data,
856 sizeof(struct gl_pixelstore_attrib) );
857 break;
858 case GL_CLIENT_VERTEX_ARRAY_BIT:
859 MEMCPY( &ctx->Array, attr->data,
860 sizeof(struct gl_array_attrib) );
861 break;
862 default:
863 gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
864 break;
865 }
866
867 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000868 FREE( attr->data );
869 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000870 attr = next;
871 }
872
873 ctx->NewState = NEW_ALL;
874}
875
Brian Paulfbd8f211999-11-11 01:22:25 +0000876
877