blob: 145ff9e93888aa5c301050d02eb7ee60adb4daa9 [file] [log] [blame]
Brian Paul736fcbe2001-05-29 15:23:48 +00001/* $Id: attrib.c,v 1.51 2001/05/29 15:23:48 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulba643a22000-10-28 18:34:48 +00005 * Version: 3.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Brian Paulb6bcae52001-01-23 23:39:36 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00008 *
jtgafb833d1999-08-19 00:55:39 +00009 * 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:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
jtgafb833d1999-08-19 00:55:39 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000018 *
jtgafb833d1999-08-19 00:55:39 +000019 * 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"
Brian Paulf3da3892001-01-24 15:27:10 +000032#include "accum.h"
33#include "alpha.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "attrib.h"
Brian Paulf3da3892001-01-24 15:27:10 +000035#include "blend.h"
Brian Paulea39f042000-02-02 19:17:57 +000036#include "buffers.h"
Brian Paulf3da3892001-01-24 15:27:10 +000037#include "clip.h"
38#include "colormac.h"
jtgafb833d1999-08-19 00:55:39 +000039#include "context.h"
Brian Paulf3da3892001-01-24 15:27:10 +000040#include "depth.h"
jtgafb833d1999-08-19 00:55:39 +000041#include "enable.h"
42#include "enums.h"
Brian Paulf3da3892001-01-24 15:27:10 +000043#include "fog.h"
44#include "hint.h"
45#include "light.h"
46#include "lines.h"
47#include "logic.h"
48#include "masking.h"
Brian Paul699bc7b2000-10-29 18:12:14 +000049#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000050#include "mem.h"
Brian Paulf3da3892001-01-24 15:27:10 +000051#include "points.h"
52#include "polygon.h"
53#include "scissor.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "simple_list.h"
Brian Paulf3da3892001-01-24 15:27:10 +000055#include "stencil.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000057#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000058#endif
59
60
jtgafb833d1999-08-19 00:55:39 +000061
62
63/*
64 * Allocate a new attribute state node. These nodes have a
65 * "kind" value and a pointer to a struct of state data.
66 */
Brian Paul42fcf032000-02-02 22:03:31 +000067static struct gl_attrib_node *
68new_attrib_node( GLbitfield kind )
jtgafb833d1999-08-19 00:55:39 +000069{
Brian Paulbd5cdaf1999-10-13 18:42:49 +000070 struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
jtgafb833d1999-08-19 00:55:39 +000071 if (an) {
72 an->kind = kind;
73 }
74 return an;
75}
76
77
78
79/*
80 * Copy texture object state from one texture object to another.
81 */
Brian Paul42fcf032000-02-02 22:03:31 +000082static void
83copy_texobj_state( struct gl_texture_object *dest,
84 const struct gl_texture_object *src )
jtgafb833d1999-08-19 00:55:39 +000085{
86 /*
87 dest->Name = src->Name;
88 dest->Dimensions = src->Dimensions;
89 */
90 dest->Priority = src->Priority;
91 dest->BorderColor[0] = src->BorderColor[0];
92 dest->BorderColor[1] = src->BorderColor[1];
93 dest->BorderColor[2] = src->BorderColor[2];
94 dest->BorderColor[3] = src->BorderColor[3];
95 dest->WrapS = src->WrapS;
96 dest->WrapT = src->WrapT;
97 dest->WrapR = src->WrapR;
98 dest->MinFilter = src->MinFilter;
99 dest->MagFilter = src->MagFilter;
100 dest->MinLod = src->MinLod;
101 dest->MaxLod = src->MaxLod;
102 dest->BaseLevel = src->BaseLevel;
103 dest->MaxLevel = src->MaxLevel;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000104 dest->MaxAnisotropy = src->MaxAnisotropy;
Brian Paulc499ce32001-02-20 16:42:25 +0000105 dest->CompareFlag = src->CompareFlag;
106 dest->CompareOperator = src->CompareOperator;
107 dest->ShadowAmbient = src->ShadowAmbient;
Brian Paul083e4662000-12-14 20:25:56 +0000108 dest->_MaxLevel = src->_MaxLevel;
109 dest->_MaxLambda = src->_MaxLambda;
Brian Paulfbd8f211999-11-11 01:22:25 +0000110 dest->Palette = src->Palette;
jtgafb833d1999-08-19 00:55:39 +0000111 dest->Complete = src->Complete;
jtgafb833d1999-08-19 00:55:39 +0000112}
113
114
115
Brian Paul42fcf032000-02-02 22:03:31 +0000116void
117_mesa_PushAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000118{
119 struct gl_attrib_node *newnode;
120 struct gl_attrib_node *head;
121
Brian Paul42fcf032000-02-02 22:03:31 +0000122 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000123 ASSERT_OUTSIDE_BEGIN_END(ctx);
jtgafb833d1999-08-19 00:55:39 +0000124
125 if (MESA_VERBOSE&VERBOSE_API)
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000126 fprintf(stderr, "glPushAttrib %x\n", (int)mask);
jtgafb833d1999-08-19 00:55:39 +0000127
Brian Paulf3da3892001-01-24 15:27:10 +0000128 if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
Brian Paul08836342001-03-03 20:33:27 +0000129 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
jtgafb833d1999-08-19 00:55:39 +0000130 return;
131 }
132
133 /* Build linked list of attribute nodes which save all attribute */
134 /* groups specified by the mask. */
135 head = NULL;
136
137 if (mask & GL_ACCUM_BUFFER_BIT) {
138 struct gl_accum_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000139 attr = MALLOC_STRUCT( gl_accum_attrib );
jtgafb833d1999-08-19 00:55:39 +0000140 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
141 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
142 newnode->data = attr;
143 newnode->next = head;
144 head = newnode;
145 }
146
147 if (mask & GL_COLOR_BUFFER_BIT) {
148 struct gl_colorbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000149 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000150 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
151 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
152 newnode->data = attr;
153 newnode->next = head;
154 head = newnode;
155 }
156
157 if (mask & GL_CURRENT_BIT) {
158 struct gl_current_attrib *attr;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000159 FLUSH_CURRENT( ctx, 0 );
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000160 attr = MALLOC_STRUCT( gl_current_attrib );
jtgafb833d1999-08-19 00:55:39 +0000161 MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
162 newnode = new_attrib_node( GL_CURRENT_BIT );
163 newnode->data = attr;
164 newnode->next = head;
165 head = newnode;
166 }
167
168 if (mask & GL_DEPTH_BUFFER_BIT) {
169 struct gl_depthbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000170 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000171 MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
172 newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
173 newnode->data = attr;
174 newnode->next = head;
175 head = newnode;
176 }
177
178 if (mask & GL_ENABLE_BIT) {
179 struct gl_enable_attrib *attr;
180 GLuint i;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000181 attr = MALLOC_STRUCT( gl_enable_attrib );
jtgafb833d1999-08-19 00:55:39 +0000182 /* Copy enable flags from all other attributes into the enable struct. */
183 attr->AlphaTest = ctx->Color.AlphaEnabled;
184 attr->AutoNormal = ctx->Eval.AutoNormal;
185 attr->Blend = ctx->Color.BlendEnabled;
186 for (i=0;i<MAX_CLIP_PLANES;i++) {
187 attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
188 }
189 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
Brian Paul82b02f02000-05-07 20:37:40 +0000190 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
191 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
192 attr->Separable2D = ctx->Pixel.Separable2DEnabled;
jtgafb833d1999-08-19 00:55:39 +0000193 attr->CullFace = ctx->Polygon.CullFlag;
194 attr->DepthTest = ctx->Depth.Test;
195 attr->Dither = ctx->Color.DitherFlag;
196 attr->Fog = ctx->Fog.Enabled;
197 for (i=0;i<MAX_LIGHTS;i++) {
198 attr->Light[i] = ctx->Light.Light[i].Enabled;
199 }
200 attr->Lighting = ctx->Light.Enabled;
201 attr->LineSmooth = ctx->Line.SmoothFlag;
202 attr->LineStipple = ctx->Line.StippleFlag;
Brian Paul2b2e9252000-04-07 16:27:26 +0000203 attr->Histogram = ctx->Pixel.HistogramEnabled;
204 attr->MinMax = ctx->Pixel.MinMaxEnabled;
jtgafb833d1999-08-19 00:55:39 +0000205 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
206 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
207 attr->Map1Color4 = ctx->Eval.Map1Color4;
208 attr->Map1Index = ctx->Eval.Map1Index;
209 attr->Map1Normal = ctx->Eval.Map1Normal;
210 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
211 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
212 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
213 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
214 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
215 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
216 attr->Map2Color4 = ctx->Eval.Map2Color4;
217 attr->Map2Index = ctx->Eval.Map2Index;
218 attr->Map2Normal = ctx->Eval.Map2Normal;
219 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
220 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
221 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
222 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
223 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
224 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
225 attr->Normalize = ctx->Transform.Normalize;
Brian Paul2b2e9252000-04-07 16:27:26 +0000226 attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
jtgafb833d1999-08-19 00:55:39 +0000227 attr->PointSmooth = ctx->Point.SmoothFlag;
228 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
229 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
230 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
231 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
232 attr->PolygonStipple = ctx->Polygon.StippleFlag;
233 attr->RescaleNormals = ctx->Transform.RescaleNormals;
234 attr->Scissor = ctx->Scissor.Enabled;
235 attr->Stencil = ctx->Stencil.Enabled;
Brian Paul736fcbe2001-05-29 15:23:48 +0000236 attr->MultisampleEnabled = ctx->Multisample.Enabled;
237 attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
238 attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
239 attr->SampleCoverage = ctx->Multisample.SampleCoverage;
240 attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
jtgafb833d1999-08-19 00:55:39 +0000241 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
Brian Pauleb6c6432000-09-28 22:44:30 +0000242 attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
jtgafb833d1999-08-19 00:55:39 +0000243 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
244 }
245 newnode = new_attrib_node( GL_ENABLE_BIT );
246 newnode->data = attr;
247 newnode->next = head;
248 head = newnode;
249 }
250
251 if (mask & GL_EVAL_BIT) {
252 struct gl_eval_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000253 attr = MALLOC_STRUCT( gl_eval_attrib );
jtgafb833d1999-08-19 00:55:39 +0000254 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
255 newnode = new_attrib_node( GL_EVAL_BIT );
256 newnode->data = attr;
257 newnode->next = head;
258 head = newnode;
259 }
260
261 if (mask & GL_FOG_BIT) {
262 struct gl_fog_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000263 attr = MALLOC_STRUCT( gl_fog_attrib );
jtgafb833d1999-08-19 00:55:39 +0000264 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
265 newnode = new_attrib_node( GL_FOG_BIT );
266 newnode->data = attr;
267 newnode->next = head;
268 head = newnode;
269 }
270
271 if (mask & GL_HINT_BIT) {
272 struct gl_hint_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000273 attr = MALLOC_STRUCT( gl_hint_attrib );
jtgafb833d1999-08-19 00:55:39 +0000274 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
275 newnode = new_attrib_node( GL_HINT_BIT );
276 newnode->data = attr;
277 newnode->next = head;
278 head = newnode;
279 }
280
281 if (mask & GL_LIGHTING_BIT) {
282 struct gl_light_attrib *attr;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000283 FLUSH_CURRENT(ctx, 0); /* flush material changes */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000284 attr = MALLOC_STRUCT( gl_light_attrib );
jtgafb833d1999-08-19 00:55:39 +0000285 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
286 newnode = new_attrib_node( GL_LIGHTING_BIT );
287 newnode->data = attr;
288 newnode->next = head;
289 head = newnode;
290 }
291
292 if (mask & GL_LINE_BIT) {
293 struct gl_line_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000294 attr = MALLOC_STRUCT( gl_line_attrib );
jtgafb833d1999-08-19 00:55:39 +0000295 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
296 newnode = new_attrib_node( GL_LINE_BIT );
297 newnode->data = attr;
298 newnode->next = head;
299 head = newnode;
300 }
301
302 if (mask & GL_LIST_BIT) {
303 struct gl_list_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000304 attr = MALLOC_STRUCT( gl_list_attrib );
jtgafb833d1999-08-19 00:55:39 +0000305 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
306 newnode = new_attrib_node( GL_LIST_BIT );
307 newnode->data = attr;
308 newnode->next = head;
309 head = newnode;
310 }
311
312 if (mask & GL_PIXEL_MODE_BIT) {
313 struct gl_pixel_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000314 attr = MALLOC_STRUCT( gl_pixel_attrib );
jtgafb833d1999-08-19 00:55:39 +0000315 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
316 newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
317 newnode->data = attr;
318 newnode->next = head;
319 head = newnode;
320 }
321
322 if (mask & GL_POINT_BIT) {
323 struct gl_point_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000324 attr = MALLOC_STRUCT( gl_point_attrib );
jtgafb833d1999-08-19 00:55:39 +0000325 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
326 newnode = new_attrib_node( GL_POINT_BIT );
327 newnode->data = attr;
328 newnode->next = head;
329 head = newnode;
330 }
331
332 if (mask & GL_POLYGON_BIT) {
333 struct gl_polygon_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000334 attr = MALLOC_STRUCT( gl_polygon_attrib );
jtgafb833d1999-08-19 00:55:39 +0000335 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
336 newnode = new_attrib_node( GL_POLYGON_BIT );
337 newnode->data = attr;
338 newnode->next = head;
339 head = newnode;
340 }
341
342 if (mask & GL_POLYGON_STIPPLE_BIT) {
343 GLuint *stipple;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000344 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +0000345 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
346 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
347 newnode->data = stipple;
348 newnode->next = head;
349 head = newnode;
350 }
351
352 if (mask & GL_SCISSOR_BIT) {
353 struct gl_scissor_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000354 attr = MALLOC_STRUCT( gl_scissor_attrib );
jtgafb833d1999-08-19 00:55:39 +0000355 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
356 newnode = new_attrib_node( GL_SCISSOR_BIT );
357 newnode->data = attr;
358 newnode->next = head;
359 head = newnode;
360 }
361
362 if (mask & GL_STENCIL_BUFFER_BIT) {
363 struct gl_stencil_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000364 attr = MALLOC_STRUCT( gl_stencil_attrib );
jtgafb833d1999-08-19 00:55:39 +0000365 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
366 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
367 newnode->data = attr;
368 newnode->next = head;
369 head = newnode;
370 }
371
372 if (mask & GL_TEXTURE_BIT) {
373 struct gl_texture_attrib *attr;
374 GLuint u;
Brian Paul93de8d32001-04-11 23:22:20 +0000375 /* Bump the texture object reference counts so that they don't
376 * inadvertantly get deleted.
377 */
jtgafb833d1999-08-19 00:55:39 +0000378 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000379 ctx->Texture.Unit[u].Current1D->RefCount++;
380 ctx->Texture.Unit[u].Current2D->RefCount++;
381 ctx->Texture.Unit[u].Current3D->RefCount++;
382 ctx->Texture.Unit[u].CurrentCubeMap->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000383 }
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000384 attr = MALLOC_STRUCT( gl_texture_attrib );
jtgafb833d1999-08-19 00:55:39 +0000385 MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
386 /* copy state of the currently bound texture objects */
387 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000388 copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].Current1D);
389 copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].Current2D);
390 copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].Current3D);
Brian Paul6479a172000-07-05 22:26:43 +0000391 copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap);
jtgafb833d1999-08-19 00:55:39 +0000392 }
393 newnode = new_attrib_node( GL_TEXTURE_BIT );
394 newnode->data = attr;
395 newnode->next = head;
396 head = newnode;
397 }
398
399 if (mask & GL_TRANSFORM_BIT) {
400 struct gl_transform_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000401 attr = MALLOC_STRUCT( gl_transform_attrib );
jtgafb833d1999-08-19 00:55:39 +0000402 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
403 newnode = new_attrib_node( GL_TRANSFORM_BIT );
404 newnode->data = attr;
405 newnode->next = head;
406 head = newnode;
407 }
408
409 if (mask & GL_VIEWPORT_BIT) {
410 struct gl_viewport_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000411 attr = MALLOC_STRUCT( gl_viewport_attrib );
jtgafb833d1999-08-19 00:55:39 +0000412 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
413 newnode = new_attrib_node( GL_VIEWPORT_BIT );
414 newnode->data = attr;
415 newnode->next = head;
416 head = newnode;
417 }
418
Brian Paul736fcbe2001-05-29 15:23:48 +0000419 /* GL_ARB_multisample */
420 if (mask & GL_MULTISAMPLE_BIT_ARB) {
421 struct gl_multisample_attrib *attr;
422 attr = MALLOC_STRUCT( gl_multisample_attrib );
423 MEMCPY( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
424 newnode = new_attrib_node( GL_MULTISAMPLE_BIT_ARB );
425 newnode->data = attr;
426 newnode->next = head;
427 head = newnode;
428 }
429
jtgafb833d1999-08-19 00:55:39 +0000430 ctx->AttribStack[ctx->AttribStackDepth] = head;
431 ctx->AttribStackDepth++;
432}
433
434
435
Brian Pauleb6c6432000-09-28 22:44:30 +0000436static void
437pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
438{
439 GLuint i;
440
441#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
442 if ((VALUE) != (NEWVALUE)) { \
443 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
444 }
445
446 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
447 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
448 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
449
450 for (i=0;i<MAX_CLIP_PLANES;i++) {
451 if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
452 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
453 enable->ClipPlane[i]);
454 }
455
456 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
457 GL_COLOR_MATERIAL);
458 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
459 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
460 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
461 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
462 GL_CONVOLUTION_1D);
463 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D,
464 GL_CONVOLUTION_2D);
465 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D,
466 GL_SEPARABLE_2D);
467 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
468 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
469 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
470 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
471 GL_LINE_STIPPLE);
472 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
473 GL_INDEX_LOGIC_OP);
474 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
475 GL_COLOR_LOGIC_OP);
476 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
477 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
478 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
479 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
480 GL_MAP1_TEXTURE_COORD_1);
481 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
482 GL_MAP1_TEXTURE_COORD_2);
483 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
484 GL_MAP1_TEXTURE_COORD_3);
485 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
486 GL_MAP1_TEXTURE_COORD_4);
487 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
488 GL_MAP1_VERTEX_3);
489 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
490 GL_MAP1_VERTEX_4);
491 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
492 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
493 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
494 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
495 GL_MAP2_TEXTURE_COORD_1);
496 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
497 GL_MAP2_TEXTURE_COORD_2);
498 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
499 GL_MAP2_TEXTURE_COORD_3);
500 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
501 GL_MAP2_TEXTURE_COORD_4);
502 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
503 GL_MAP2_VERTEX_3);
504 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
505 GL_MAP2_VERTEX_4);
506 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
507 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
508 GL_RESCALE_NORMAL_EXT);
509 TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture,
510 GL_POINT_SMOOTH);
511 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
512 GL_POINT_SMOOTH);
513 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
514 GL_POLYGON_OFFSET_POINT);
515 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
516 GL_POLYGON_OFFSET_LINE);
517 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
518 GL_POLYGON_OFFSET_FILL);
519 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
520 GL_POLYGON_SMOOTH);
521 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
522 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);
Brian Paul736fcbe2001-05-29 15:23:48 +0000525 TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled,
526 GL_MULTISAMPLE_ARB);
527 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage,
528 enable->SampleAlphaToCoverage,
529 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
530 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne,
531 enable->SampleAlphaToOne,
532 GL_SAMPLE_ALPHA_TO_ONE_ARB);
533 TEST_AND_UPDATE(ctx->Multisample.SampleCoverage,
534 enable->SampleCoverage,
535 GL_SAMPLE_COVERAGE_ARB);
536 TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
537 enable->SampleCoverageInvert,
538 GL_SAMPLE_COVERAGE_INVERT_ARB);
Brian Pauleb6c6432000-09-28 22:44:30 +0000539#undef TEST_AND_UPDATE
540
541 /* texture unit enables */
542 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
543 if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) {
544 ctx->Texture.Unit[i].Enabled = enable->Texture[i];
545 if (ctx->Driver.Enable) {
546 if (ctx->Driver.ActiveTexture) {
547 (*ctx->Driver.ActiveTexture)(ctx, i);
548 }
549 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D,
550 (GLboolean) (enable->Texture[i] & TEXTURE0_1D) );
551 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D,
552 (GLboolean) (enable->Texture[i] & TEXTURE0_2D) );
553 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D,
554 (GLboolean) (enable->Texture[i] & TEXTURE0_3D) );
555 }
556 }
557
558 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
559 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
560 if (ctx->Driver.Enable) {
561 if (ctx->Driver.ActiveTexture) {
562 (*ctx->Driver.ActiveTexture)(ctx, i);
563 }
564 if (enable->TexGen[i] & S_BIT)
565 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
566 else
567 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
568 if (enable->TexGen[i] & T_BIT)
569 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
570 else
571 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
572 if (enable->TexGen[i] & R_BIT)
573 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
574 else
575 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
576 if (enable->TexGen[i] & Q_BIT)
577 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
578 else
579 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
580 }
581 }
582 }
583
584 if (ctx->Driver.ActiveTexture) {
585 (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit);
586 }
587}
588
589
Brian Paul93de8d32001-04-11 23:22:20 +0000590static void
591pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
592{
593 GLuint u;
594
595 /* "un-bump" the texture object reference counts. We did that so they
596 * wouldn't inadvertantly get deleted.
597 */
598 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
599 ctx->Texture.Unit[u].Current1D->RefCount--;
600 ctx->Texture.Unit[u].Current2D->RefCount--;
601 ctx->Texture.Unit[u].Current3D->RefCount--;
602 ctx->Texture.Unit[u].CurrentCubeMap->RefCount--;
603 }
604
605 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
606 const struct gl_texture_unit *unit = &texAttrib->Unit[u];
607 GLuint numObjs, i;
608
609 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u);
610 _mesa_set_enable(ctx, GL_TEXTURE_1D, unit->Enabled & TEXTURE0_1D);
611 _mesa_set_enable(ctx, GL_TEXTURE_2D, unit->Enabled & TEXTURE0_2D);
612 _mesa_set_enable(ctx, GL_TEXTURE_3D, unit->Enabled & TEXTURE0_3D);
613 if (ctx->Extensions.ARB_texture_cube_map) {
614 _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB,
615 unit->Enabled & TEXTURE0_CUBE);
616 }
617 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
618 _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
619 _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenModeS);
620 _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenModeT);
621 _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenModeR);
622 _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenModeQ);
623 _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->ObjectPlaneS);
624 _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->ObjectPlaneT);
625 _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->ObjectPlaneR);
626 _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->ObjectPlaneQ);
627 _mesa_TexGenfv(GL_S, GL_EYE_PLANE, unit->EyePlaneS);
628 _mesa_TexGenfv(GL_T, GL_EYE_PLANE, unit->EyePlaneT);
629 _mesa_TexGenfv(GL_R, GL_EYE_PLANE, unit->EyePlaneR);
630 _mesa_TexGenfv(GL_Q, GL_EYE_PLANE, unit->EyePlaneQ);
631 if (ctx->Extensions.EXT_texture_lod_bias) {
632 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
633 GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias);
634 }
Brian Paulbcfe3932001-04-17 21:25:53 +0000635 if (ctx->Extensions.EXT_texture_env_combine ||
636 ctx->Extensions.ARB_texture_env_combine) {
Brian Paul93de8d32001-04-11 23:22:20 +0000637 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT,
638 unit->CombineModeRGB);
639 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT,
640 unit->CombineModeA);
641 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT,
642 unit->CombineSourceRGB[0]);
643 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT,
644 unit->CombineSourceRGB[1]);
645 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT,
646 unit->CombineSourceRGB[2]);
647 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT,
648 unit->CombineSourceA[0]);
649 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT,
650 unit->CombineSourceA[1]);
651 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT,
652 unit->CombineSourceA[2]);
653 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT,
654 unit->CombineOperandRGB[0]);
655 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT,
656 unit->CombineOperandRGB[1]);
657 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT,
658 unit->CombineOperandRGB[2]);
659 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,
660 unit->CombineOperandA[0]);
661 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,
662 unit->CombineOperandA[1]);
663 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,
664 unit->CombineOperandA[2]);
665 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT,
666 1 << unit->CombineScaleShiftRGB);
667 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE,
668 1 << unit->CombineScaleShiftA);
669 }
670
671 /* Restore texture object state */
672 numObjs = ctx->Extensions.ARB_texture_cube_map ? 4 : 3;
673
674 for (i = 0; i < numObjs; i++) {
675 GLenum target = 0;
676 const struct gl_texture_object *obj = NULL;
677 GLfloat bordColor[4];
678
679 switch (i) {
680 case 0:
681 target = GL_TEXTURE_1D;
682 obj = &unit->Saved1D;
683 break;
684 case 1:
685 target = GL_TEXTURE_2D;
686 obj = &unit->Saved2D;
687 break;
688 case 2:
689 target = GL_TEXTURE_3D;
690 obj = &unit->Saved3D;
691 break;
692 case 3:
693 target = GL_TEXTURE_CUBE_MAP_ARB;
694 obj = &unit->SavedCubeMap;
695 break;
696 default:
697 ; /* silence warnings */
698 }
699
700 bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]);
701 bordColor[1] = CHAN_TO_FLOAT(obj->BorderColor[1]);
702 bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]);
703 bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]);
704
Brian Paul9e351d52001-05-03 14:11:18 +0000705 _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
Brian Paul93de8d32001-04-11 23:22:20 +0000706 _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor);
707 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
708 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
709 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR);
710 _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter);
711 _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter);
712 _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
713 _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
714 _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
715 _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
716 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
717 _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
718 obj->MaxAnisotropy);
719 }
720 if (ctx->Extensions.SGIX_shadow) {
721 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_SGIX,
722 obj->CompareFlag);
723 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_OPERATOR_SGIX,
724 obj->CompareOperator);
725 }
726 if (ctx->Extensions.SGIX_shadow_ambient) {
Brian Paul9e351d52001-05-03 14:11:18 +0000727 _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX,
Brian Paul93de8d32001-04-11 23:22:20 +0000728 CHAN_TO_FLOAT(obj->ShadowAmbient));
729 }
730
731 }
732 }
733 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
734 + texAttrib->CurrentUnit);
735}
736
Brian Pauleb6c6432000-09-28 22:44:30 +0000737
jtgafb833d1999-08-19 00:55:39 +0000738/*
739 * This function is kind of long just because we have to call a lot
740 * of device driver functions to update device driver state.
Brian Paulf3da3892001-01-24 15:27:10 +0000741 *
742 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
743 * in order to restore GL state. This isn't terribly efficient but it
744 * ensures that dirty flags and any derived state gets updated correctly.
745 * We could at least check if the value to restore equals the current value
746 * and then skip the Mesa call.
jtgafb833d1999-08-19 00:55:39 +0000747 */
Brian Paul42fcf032000-02-02 22:03:31 +0000748void
749_mesa_PopAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000750{
751 struct gl_attrib_node *attr, *next;
Brian Paul42fcf032000-02-02 22:03:31 +0000752 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000753 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +0000754
Brian Paulf3da3892001-01-24 15:27:10 +0000755 if (ctx->AttribStackDepth == 0) {
Brian Paul08836342001-03-03 20:33:27 +0000756 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
jtgafb833d1999-08-19 00:55:39 +0000757 return;
758 }
759
760 ctx->AttribStackDepth--;
761 attr = ctx->AttribStack[ctx->AttribStackDepth];
762
763 while (attr) {
764
Brian Paul93de8d32001-04-11 23:22:20 +0000765 if (MESA_VERBOSE&VERBOSE_API) {
766 fprintf(stderr, "glPopAttrib %s\n",
767 _mesa_lookup_enum_by_nr(attr->kind));
768 }
jtgafb833d1999-08-19 00:55:39 +0000769
770 switch (attr->kind) {
771 case GL_ACCUM_BUFFER_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000772 {
773 const struct gl_accum_attrib *accum;
774 accum = (const struct gl_accum_attrib *) attr->data;
775 _mesa_ClearAccum(accum->ClearColor[0],
776 accum->ClearColor[1],
777 accum->ClearColor[2],
778 accum->ClearColor[3]);
779 }
jtgafb833d1999-08-19 00:55:39 +0000780 break;
781 case GL_COLOR_BUFFER_BIT:
782 {
Brian Paulf3da3892001-01-24 15:27:10 +0000783 const struct gl_colorbuffer_attrib *color;
784 color = (const struct gl_colorbuffer_attrib *) attr->data;
785 _mesa_ClearIndex(color->ClearIndex);
786 _mesa_ClearColor(CHAN_TO_FLOAT(color->ClearColor[0]),
787 CHAN_TO_FLOAT(color->ClearColor[1]),
788 CHAN_TO_FLOAT(color->ClearColor[2]),
789 CHAN_TO_FLOAT(color->ClearColor[3]));
790 _mesa_IndexMask(color->IndexMask);
791 _mesa_ColorMask((GLboolean) (color->ColorMask[0] != 0),
792 (GLboolean) (color->ColorMask[1] != 0),
793 (GLboolean) (color->ColorMask[2] != 0),
794 (GLboolean) (color->ColorMask[3] != 0));
795 _mesa_DrawBuffer(color->DrawBuffer);
796 _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
797 _mesa_AlphaFunc(color->AlphaFunc,
798 CHAN_TO_FLOAT(color->AlphaRef));
799 _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled);
800 _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB,
801 color->BlendDstRGB,
802 color->BlendSrcA,
803 color->BlendDstA);
804 _mesa_BlendEquation(color->BlendEquation);
805 _mesa_BlendColor(color->BlendColor[0],
806 color->BlendColor[1],
807 color->BlendColor[2],
808 color->BlendColor[3]);
809 _mesa_LogicOp(color->LogicOp);
810 _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP,
811 color->ColorLogicOpEnabled);
812 _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP,
813 color->IndexLogicOpEnabled);
814 _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag);
jtgafb833d1999-08-19 00:55:39 +0000815 }
816 break;
817 case GL_CURRENT_BIT:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000818 FLUSH_CURRENT( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +0000819 MEMCPY( &ctx->Current, attr->data,
820 sizeof(struct gl_current_attrib) );
821 break;
822 case GL_DEPTH_BUFFER_BIT:
823 {
Brian Paulf3da3892001-01-24 15:27:10 +0000824 const struct gl_depthbuffer_attrib *depth;
825 depth = (const struct gl_depthbuffer_attrib *) attr->data;
826 _mesa_DepthFunc(depth->Func);
827 _mesa_ClearDepth(depth->Clear);
828 _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test);
829 _mesa_DepthMask(depth->Mask);
830 if (ctx->Extensions.HP_occlusion_test)
831 _mesa_set_enable(ctx, GL_OCCLUSION_TEST_HP,
832 depth->OcclusionTest);
jtgafb833d1999-08-19 00:55:39 +0000833 }
834 break;
835 case GL_ENABLE_BIT:
836 {
837 const struct gl_enable_attrib *enable;
838 enable = (const struct gl_enable_attrib *) attr->data;
Brian Pauleb6c6432000-09-28 22:44:30 +0000839 pop_enable_group(ctx, enable);
Keith Whitwella96308c2000-10-30 13:31:59 +0000840 ctx->NewState |= _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +0000841 }
842 break;
843 case GL_EVAL_BIT:
844 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000845 ctx->NewState |= _NEW_EVAL;
jtgafb833d1999-08-19 00:55:39 +0000846 break;
847 case GL_FOG_BIT:
848 {
Brian Paulf3da3892001-01-24 15:27:10 +0000849 const struct gl_fog_attrib *fog;
850 fog = (const struct gl_fog_attrib *) attr->data;
851 _mesa_set_enable(ctx, GL_FOG, fog->Enabled);
852 _mesa_Fogfv(GL_FOG_COLOR, fog->Color);
853 _mesa_Fogf(GL_FOG_DENSITY, fog->Density);
854 _mesa_Fogf(GL_FOG_START, fog->Start);
855 _mesa_Fogf(GL_FOG_END, fog->End);
856 _mesa_Fogf(GL_FOG_INDEX, fog->Index);
857 _mesa_Fogi(GL_FOG_MODE, fog->Mode);
jtgafb833d1999-08-19 00:55:39 +0000858 }
859 break;
860 case GL_HINT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000861 {
862 const struct gl_hint_attrib *hint;
863 hint = (const struct gl_hint_attrib *) attr->data;
Brian Paulf3da3892001-01-24 15:27:10 +0000864 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT,
865 hint->PerspectiveCorrection );
866 _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth);
867 _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth);
868 _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth);
869 _mesa_Hint(GL_FOG_HINT, hint->Fog);
870 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,
871 hint->ClipVolumeClipping);
872 if (ctx->Extensions.ARB_texture_compression)
873 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB,
874 hint->TextureCompression);
jtgafb833d1999-08-19 00:55:39 +0000875 }
876 break;
877 case GL_LIGHTING_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000878 {
jtgafb833d1999-08-19 00:55:39 +0000879 GLuint i;
Brian Paulf3da3892001-01-24 15:27:10 +0000880 const struct gl_light_attrib *light;
881 light = (const struct gl_light_attrib *) attr->data;
882 /* lighting enable */
883 _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled);
884 /* per-light state */
jtgafb833d1999-08-19 00:55:39 +0000885 for (i = 0; i < MAX_LIGHTS; i++) {
Brian Paulf3da3892001-01-24 15:27:10 +0000886 GLenum lgt = (GLenum) (GL_LIGHT0 + i);
887 _mesa_set_enable(ctx, lgt, light->Light[i].Enabled);
888 MEMCPY(&ctx->Light.Light[i], &light->Light[i],
889 sizeof(struct gl_light));
jtgafb833d1999-08-19 00:55:39 +0000890 }
Brian Paulf3da3892001-01-24 15:27:10 +0000891 /* light model */
892 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT,
893 light->Model.Ambient);
894 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,
895 (GLfloat) light->Model.LocalViewer);
896 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE,
897 (GLfloat) light->Model.TwoSide);
898 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
899 (GLfloat) light->Model.ColorControl);
900 /* materials */
901 MEMCPY(ctx->Light.Material, light->Material,
902 2 * sizeof(struct gl_material));
903 /* shade model */
Brian Paulba70e592001-01-29 22:15:44 +0000904 _mesa_ShadeModel(light->ShadeModel);
Brian Paulf3da3892001-01-24 15:27:10 +0000905 /* color material */
906 _mesa_ColorMaterial(light->ColorMaterialFace,
907 light->ColorMaterialMode);
908 _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
909 light->ColorMaterialEnabled);
jtgafb833d1999-08-19 00:55:39 +0000910 }
jtgafb833d1999-08-19 00:55:39 +0000911 break;
912 case GL_LINE_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000913 {
914 const struct gl_line_attrib *line;
915 line = (const struct gl_line_attrib *) attr->data;
916 _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag);
917 _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag);
918 _mesa_LineStipple(line->StippleFactor, line->StipplePattern);
919 _mesa_LineWidth(line->Width);
jtgafb833d1999-08-19 00:55:39 +0000920 }
921 break;
922 case GL_LIST_BIT:
923 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
924 break;
925 case GL_PIXEL_MODE_BIT:
926 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000927 ctx->NewState |= _NEW_PIXEL;
jtgafb833d1999-08-19 00:55:39 +0000928 break;
929 case GL_POINT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000930 {
931 const struct gl_point_attrib *point;
932 point = (const struct gl_point_attrib *) attr->data;
933 _mesa_PointSize(point->Size);
934 _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
935 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
936 point->Params);
937 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT, point->MinSize);
938 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT, point->MaxSize);
939 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
940 point->Threshold);
941 }
jtgafb833d1999-08-19 00:55:39 +0000942 break;
943 case GL_POLYGON_BIT:
944 {
Brian Paulf3da3892001-01-24 15:27:10 +0000945 const struct gl_polygon_attrib *polygon;
946 polygon = (const struct gl_polygon_attrib *) attr->data;
947 _mesa_CullFace(polygon->CullFaceMode);
948 _mesa_FrontFace(polygon->FrontFace);
949 _mesa_PolygonMode(GL_FRONT, polygon->FrontMode);
950 _mesa_PolygonMode(GL_BACK, polygon->BackMode);
951 _mesa_PolygonOffset(polygon->OffsetFactor,
952 polygon->OffsetUnits);
953 _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag);
954 _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag);
955 _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag);
956 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT,
957 polygon->OffsetPoint);
958 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE,
959 polygon->OffsetLine);
960 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL,
961 polygon->OffsetFill);
jtgafb833d1999-08-19 00:55:39 +0000962 }
963 break;
964 case GL_POLYGON_STIPPLE_BIT:
965 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000966 ctx->NewState |= _NEW_POLYGONSTIPPLE;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000967 if (ctx->Driver.PolygonStipple)
Brian Paul959f8022000-03-19 01:10:11 +0000968 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
jtgafb833d1999-08-19 00:55:39 +0000969 break;
970 case GL_SCISSOR_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000971 {
972 const struct gl_scissor_attrib *scissor;
973 scissor = (const struct gl_scissor_attrib *) attr->data;
974 _mesa_Scissor(scissor->X, scissor->Y,
975 scissor->Width, scissor->Height);
976 _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled);
977 }
jtgafb833d1999-08-19 00:55:39 +0000978 break;
979 case GL_STENCIL_BUFFER_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000980 {
981 const struct gl_stencil_attrib *stencil;
982 stencil = (const struct gl_stencil_attrib *) attr->data;
983 _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
984 _mesa_ClearStencil(stencil->Clear);
985 _mesa_StencilFunc(stencil->Function, stencil->Ref,
986 stencil->ValueMask);
987 _mesa_StencilMask(stencil->WriteMask);
988 _mesa_StencilOp(stencil->FailFunc, stencil->ZFailFunc,
989 stencil->ZPassFunc);
990 }
jtgafb833d1999-08-19 00:55:39 +0000991 break;
992 case GL_TRANSFORM_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000993 {
994 GLuint i;
995 const struct gl_transform_attrib *xform;
996 xform = (const struct gl_transform_attrib *) attr->data;
997 _mesa_MatrixMode(xform->MatrixMode);
998 /* clip planes */
999 MEMCPY(ctx->Transform.EyeUserPlane, xform->EyeUserPlane,
1000 sizeof(xform->EyeUserPlane));
1001 MEMCPY(ctx->Transform._ClipUserPlane, xform->_ClipUserPlane,
1002 sizeof(xform->EyeUserPlane));
1003 /* clip plane enable flags */
1004 for (i = 0; i < MAX_CLIP_PLANES; i++) {
1005 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i,
1006 xform->ClipEnabled[i]);
1007 }
1008 /* normalize/rescale */
1009 _mesa_set_enable(ctx, GL_NORMALIZE, ctx->Transform.Normalize);
1010 _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
1011 ctx->Transform.RescaleNormals);
jtgafb833d1999-08-19 00:55:39 +00001012 }
jtgafb833d1999-08-19 00:55:39 +00001013 break;
1014 case GL_TEXTURE_BIT:
1015 /* Take care of texture object reference counters */
1016 {
Brian Paul93de8d32001-04-11 23:22:20 +00001017 const struct gl_texture_attrib *texture;
1018 texture = (const struct gl_texture_attrib *) attr->data;
1019 pop_texture_group(ctx, texture);
Keith Whitwella96308c2000-10-30 13:31:59 +00001020 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +00001021 }
1022 break;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001023 case GL_VIEWPORT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001024 {
1025 const struct gl_viewport_attrib *vp;
Brian Paul736fcbe2001-05-29 15:23:48 +00001026 vp = (const struct gl_viewport_attrib *) attr->data;
Brian Paulf3da3892001-01-24 15:27:10 +00001027 _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height);
1028 _mesa_DepthRange(vp->Near, vp->Far);
1029 }
1030 break;
Brian Paul736fcbe2001-05-29 15:23:48 +00001031 case GL_MULTISAMPLE_BIT_ARB:
1032 {
1033 const struct gl_multisample_attrib *ms;
1034 ms = (const struct gl_multisample_attrib *) attr->data;
1035 _mesa_SampleCoverageARB(ms->SampleCoverageValue,
1036 ms->SampleCoverageInvert);
1037 }
1038 break;
1039
jtgafb833d1999-08-19 00:55:39 +00001040 default:
Brian Paul08836342001-03-03 20:33:27 +00001041 _mesa_problem( ctx, "Bad attrib flag in PopAttrib");
jtgafb833d1999-08-19 00:55:39 +00001042 break;
1043 }
1044
1045 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001046 FREE( attr->data );
1047 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +00001048 attr = next;
1049 }
jtgafb833d1999-08-19 00:55:39 +00001050}
1051
1052
1053#define GL_CLIENT_PACK_BIT (1<<20)
1054#define GL_CLIENT_UNPACK_BIT (1<<21)
1055
1056
Brian Paul42fcf032000-02-02 22:03:31 +00001057void
1058_mesa_PushClientAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +00001059{
1060 struct gl_attrib_node *newnode;
1061 struct gl_attrib_node *head;
1062
Brian Paul42fcf032000-02-02 22:03:31 +00001063 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001064 ASSERT_OUTSIDE_BEGIN_END(ctx);
jtgafb833d1999-08-19 00:55:39 +00001065
Brian Paulf3da3892001-01-24 15:27:10 +00001066 if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
Brian Paul08836342001-03-03 20:33:27 +00001067 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
jtgafb833d1999-08-19 00:55:39 +00001068 return;
1069 }
1070
1071 /* Build linked list of attribute nodes which save all attribute */
1072 /* groups specified by the mask. */
1073 head = NULL;
1074
1075 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
1076 struct gl_pixelstore_attrib *attr;
1077 /* packing attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001078 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +00001079 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
1080 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
1081 newnode->data = attr;
1082 newnode->next = head;
1083 head = newnode;
1084 /* unpacking attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001085 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +00001086 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
1087 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
1088 newnode->data = attr;
1089 newnode->next = head;
1090 head = newnode;
1091 }
1092 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
1093 struct gl_array_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001094 attr = MALLOC_STRUCT( gl_array_attrib );
jtgafb833d1999-08-19 00:55:39 +00001095 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
1096 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
1097 newnode->data = attr;
1098 newnode->next = head;
1099 head = newnode;
1100 }
1101
1102 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
1103 ctx->ClientAttribStackDepth++;
1104}
1105
1106
1107
1108
Brian Paul42fcf032000-02-02 22:03:31 +00001109void
1110_mesa_PopClientAttrib(void)
jtgafb833d1999-08-19 00:55:39 +00001111{
1112 struct gl_attrib_node *attr, *next;
1113
Brian Paul42fcf032000-02-02 22:03:31 +00001114 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001115 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001116
Brian Paulf3da3892001-01-24 15:27:10 +00001117 if (ctx->ClientAttribStackDepth == 0) {
Brian Paul08836342001-03-03 20:33:27 +00001118 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
jtgafb833d1999-08-19 00:55:39 +00001119 return;
1120 }
1121
1122 ctx->ClientAttribStackDepth--;
1123 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
1124
1125 while (attr) {
1126 switch (attr->kind) {
1127 case GL_CLIENT_PACK_BIT:
1128 MEMCPY( &ctx->Pack, attr->data,
1129 sizeof(struct gl_pixelstore_attrib) );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001130 ctx->NewState = _NEW_PACKUNPACK;
jtgafb833d1999-08-19 00:55:39 +00001131 break;
1132 case GL_CLIENT_UNPACK_BIT:
1133 MEMCPY( &ctx->Unpack, attr->data,
1134 sizeof(struct gl_pixelstore_attrib) );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001135 ctx->NewState = _NEW_PACKUNPACK;
jtgafb833d1999-08-19 00:55:39 +00001136 break;
1137 case GL_CLIENT_VERTEX_ARRAY_BIT:
1138 MEMCPY( &ctx->Array, attr->data,
1139 sizeof(struct gl_array_attrib) );
Keith Whitwellcab974c2000-12-26 05:09:27 +00001140 ctx->NewState = _NEW_ARRAY;
jtgafb833d1999-08-19 00:55:39 +00001141 break;
1142 default:
Brian Paul08836342001-03-03 20:33:27 +00001143 _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
jtgafb833d1999-08-19 00:55:39 +00001144 break;
1145 }
1146
1147 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001148 FREE( attr->data );
1149 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +00001150 attr = next;
1151 }
jtgafb833d1999-08-19 00:55:39 +00001152}