blob: 7d4199e27f490d95395b3e12667873e255c52843 [file] [log] [blame]
Brian Paul699bc7b2000-10-29 18:12:14 +00001/* $Id: attrib.c,v 1.30 2000/10/29 18:12:14 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
jtgafb833d1999-08-19 00:55:39 +00006 *
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 Paul699bc7b2000-10-29 18:12:14 +000037#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000038#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000039#include "simple_list.h"
40#include "texstate.h"
41#include "types.h"
jtgafb833d1999-08-19 00:55:39 +000042#endif
43
44
jtgafb833d1999-08-19 00:55:39 +000045
46
47/*
48 * Allocate a new attribute state node. These nodes have a
49 * "kind" value and a pointer to a struct of state data.
50 */
Brian Paul42fcf032000-02-02 22:03:31 +000051static struct gl_attrib_node *
52new_attrib_node( GLbitfield kind )
jtgafb833d1999-08-19 00:55:39 +000053{
Brian Paulbd5cdaf1999-10-13 18:42:49 +000054 struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
jtgafb833d1999-08-19 00:55:39 +000055 if (an) {
56 an->kind = kind;
57 }
58 return an;
59}
60
61
62
63/*
64 * Copy texture object state from one texture object to another.
65 */
Brian Paul42fcf032000-02-02 22:03:31 +000066static void
67copy_texobj_state( struct gl_texture_object *dest,
68 const struct gl_texture_object *src )
jtgafb833d1999-08-19 00:55:39 +000069{
70 /*
71 dest->Name = src->Name;
72 dest->Dimensions = src->Dimensions;
73 */
74 dest->Priority = src->Priority;
75 dest->BorderColor[0] = src->BorderColor[0];
76 dest->BorderColor[1] = src->BorderColor[1];
77 dest->BorderColor[2] = src->BorderColor[2];
78 dest->BorderColor[3] = src->BorderColor[3];
79 dest->WrapS = src->WrapS;
80 dest->WrapT = src->WrapT;
81 dest->WrapR = src->WrapR;
82 dest->MinFilter = src->MinFilter;
83 dest->MagFilter = src->MagFilter;
84 dest->MinLod = src->MinLod;
85 dest->MaxLod = src->MaxLod;
86 dest->BaseLevel = src->BaseLevel;
87 dest->MaxLevel = src->MaxLevel;
88 dest->P = src->P;
89 dest->M = src->M;
90 dest->MinMagThresh = src->MinMagThresh;
Brian Paulfbd8f211999-11-11 01:22:25 +000091 dest->Palette = src->Palette;
jtgafb833d1999-08-19 00:55:39 +000092 dest->Complete = src->Complete;
93 dest->SampleFunc = src->SampleFunc;
94}
95
96
97
Brian Paul42fcf032000-02-02 22:03:31 +000098void
99_mesa_PushAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000100{
101 struct gl_attrib_node *newnode;
102 struct gl_attrib_node *head;
103
Brian Paul42fcf032000-02-02 22:03:31 +0000104 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000105 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
106
107 if (MESA_VERBOSE&VERBOSE_API)
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000108 fprintf(stderr, "glPushAttrib %x\n", (int)mask);
jtgafb833d1999-08-19 00:55:39 +0000109
110 if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
111 gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
112 return;
113 }
114
115 /* Build linked list of attribute nodes which save all attribute */
116 /* groups specified by the mask. */
117 head = NULL;
118
119 if (mask & GL_ACCUM_BUFFER_BIT) {
120 struct gl_accum_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000121 attr = MALLOC_STRUCT( gl_accum_attrib );
jtgafb833d1999-08-19 00:55:39 +0000122 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
123 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
124 newnode->data = attr;
125 newnode->next = head;
126 head = newnode;
127 }
128
129 if (mask & GL_COLOR_BUFFER_BIT) {
130 struct gl_colorbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000131 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000132 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
133 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
134 newnode->data = attr;
135 newnode->next = head;
136 head = newnode;
137 }
138
139 if (mask & GL_CURRENT_BIT) {
140 struct gl_current_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000141 attr = MALLOC_STRUCT( gl_current_attrib );
jtgafb833d1999-08-19 00:55:39 +0000142 MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
143 newnode = new_attrib_node( GL_CURRENT_BIT );
144 newnode->data = attr;
145 newnode->next = head;
146 head = newnode;
147 }
148
149 if (mask & GL_DEPTH_BUFFER_BIT) {
150 struct gl_depthbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000151 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000152 MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
153 newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
154 newnode->data = attr;
155 newnode->next = head;
156 head = newnode;
157 }
158
159 if (mask & GL_ENABLE_BIT) {
160 struct gl_enable_attrib *attr;
161 GLuint i;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000162 attr = MALLOC_STRUCT( gl_enable_attrib );
jtgafb833d1999-08-19 00:55:39 +0000163 /* Copy enable flags from all other attributes into the enable struct. */
164 attr->AlphaTest = ctx->Color.AlphaEnabled;
165 attr->AutoNormal = ctx->Eval.AutoNormal;
166 attr->Blend = ctx->Color.BlendEnabled;
167 for (i=0;i<MAX_CLIP_PLANES;i++) {
168 attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
169 }
170 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
Brian Paul82b02f02000-05-07 20:37:40 +0000171 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
172 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
173 attr->Separable2D = ctx->Pixel.Separable2DEnabled;
jtgafb833d1999-08-19 00:55:39 +0000174 attr->CullFace = ctx->Polygon.CullFlag;
175 attr->DepthTest = ctx->Depth.Test;
176 attr->Dither = ctx->Color.DitherFlag;
177 attr->Fog = ctx->Fog.Enabled;
178 for (i=0;i<MAX_LIGHTS;i++) {
179 attr->Light[i] = ctx->Light.Light[i].Enabled;
180 }
181 attr->Lighting = ctx->Light.Enabled;
182 attr->LineSmooth = ctx->Line.SmoothFlag;
183 attr->LineStipple = ctx->Line.StippleFlag;
Brian Paul2b2e9252000-04-07 16:27:26 +0000184 attr->Histogram = ctx->Pixel.HistogramEnabled;
185 attr->MinMax = ctx->Pixel.MinMaxEnabled;
jtgafb833d1999-08-19 00:55:39 +0000186 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
187 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
188 attr->Map1Color4 = ctx->Eval.Map1Color4;
189 attr->Map1Index = ctx->Eval.Map1Index;
190 attr->Map1Normal = ctx->Eval.Map1Normal;
191 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
192 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
193 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
194 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
195 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
196 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
197 attr->Map2Color4 = ctx->Eval.Map2Color4;
198 attr->Map2Index = ctx->Eval.Map2Index;
199 attr->Map2Normal = ctx->Eval.Map2Normal;
200 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
201 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
202 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
203 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
204 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
205 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
206 attr->Normalize = ctx->Transform.Normalize;
Brian Paul2b2e9252000-04-07 16:27:26 +0000207 attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
jtgafb833d1999-08-19 00:55:39 +0000208 attr->PointSmooth = ctx->Point.SmoothFlag;
209 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
210 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
211 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
212 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
213 attr->PolygonStipple = ctx->Polygon.StippleFlag;
214 attr->RescaleNormals = ctx->Transform.RescaleNormals;
215 attr->Scissor = ctx->Scissor.Enabled;
216 attr->Stencil = ctx->Stencil.Enabled;
jtgafb833d1999-08-19 00:55:39 +0000217 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
Brian Pauleb6c6432000-09-28 22:44:30 +0000218 attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
jtgafb833d1999-08-19 00:55:39 +0000219 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
220 }
221 newnode = new_attrib_node( GL_ENABLE_BIT );
222 newnode->data = attr;
223 newnode->next = head;
224 head = newnode;
225 }
226
227 if (mask & GL_EVAL_BIT) {
228 struct gl_eval_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000229 attr = MALLOC_STRUCT( gl_eval_attrib );
jtgafb833d1999-08-19 00:55:39 +0000230 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
231 newnode = new_attrib_node( GL_EVAL_BIT );
232 newnode->data = attr;
233 newnode->next = head;
234 head = newnode;
235 }
236
237 if (mask & GL_FOG_BIT) {
238 struct gl_fog_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000239 attr = MALLOC_STRUCT( gl_fog_attrib );
jtgafb833d1999-08-19 00:55:39 +0000240 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
241 newnode = new_attrib_node( GL_FOG_BIT );
242 newnode->data = attr;
243 newnode->next = head;
244 head = newnode;
245 }
246
247 if (mask & GL_HINT_BIT) {
248 struct gl_hint_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000249 attr = MALLOC_STRUCT( gl_hint_attrib );
jtgafb833d1999-08-19 00:55:39 +0000250 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
251 newnode = new_attrib_node( GL_HINT_BIT );
252 newnode->data = attr;
253 newnode->next = head;
254 head = newnode;
255 }
256
257 if (mask & GL_LIGHTING_BIT) {
258 struct gl_light_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000259 attr = MALLOC_STRUCT( gl_light_attrib );
jtgafb833d1999-08-19 00:55:39 +0000260 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
261 newnode = new_attrib_node( GL_LIGHTING_BIT );
262 newnode->data = attr;
263 newnode->next = head;
264 head = newnode;
265 }
266
267 if (mask & GL_LINE_BIT) {
268 struct gl_line_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000269 attr = MALLOC_STRUCT( gl_line_attrib );
jtgafb833d1999-08-19 00:55:39 +0000270 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
271 newnode = new_attrib_node( GL_LINE_BIT );
272 newnode->data = attr;
273 newnode->next = head;
274 head = newnode;
275 }
276
277 if (mask & GL_LIST_BIT) {
278 struct gl_list_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000279 attr = MALLOC_STRUCT( gl_list_attrib );
jtgafb833d1999-08-19 00:55:39 +0000280 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
281 newnode = new_attrib_node( GL_LIST_BIT );
282 newnode->data = attr;
283 newnode->next = head;
284 head = newnode;
285 }
286
287 if (mask & GL_PIXEL_MODE_BIT) {
288 struct gl_pixel_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000289 attr = MALLOC_STRUCT( gl_pixel_attrib );
jtgafb833d1999-08-19 00:55:39 +0000290 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
291 newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
292 newnode->data = attr;
293 newnode->next = head;
294 head = newnode;
295 }
296
297 if (mask & GL_POINT_BIT) {
298 struct gl_point_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000299 attr = MALLOC_STRUCT( gl_point_attrib );
jtgafb833d1999-08-19 00:55:39 +0000300 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
301 newnode = new_attrib_node( GL_POINT_BIT );
302 newnode->data = attr;
303 newnode->next = head;
304 head = newnode;
305 }
306
307 if (mask & GL_POLYGON_BIT) {
308 struct gl_polygon_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000309 attr = MALLOC_STRUCT( gl_polygon_attrib );
jtgafb833d1999-08-19 00:55:39 +0000310 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
311 newnode = new_attrib_node( GL_POLYGON_BIT );
312 newnode->data = attr;
313 newnode->next = head;
314 head = newnode;
315 }
316
317 if (mask & GL_POLYGON_STIPPLE_BIT) {
318 GLuint *stipple;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000319 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +0000320 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
321 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
322 newnode->data = stipple;
323 newnode->next = head;
324 head = newnode;
325 }
326
327 if (mask & GL_SCISSOR_BIT) {
328 struct gl_scissor_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000329 attr = MALLOC_STRUCT( gl_scissor_attrib );
jtgafb833d1999-08-19 00:55:39 +0000330 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
331 newnode = new_attrib_node( GL_SCISSOR_BIT );
332 newnode->data = attr;
333 newnode->next = head;
334 head = newnode;
335 }
336
337 if (mask & GL_STENCIL_BUFFER_BIT) {
338 struct gl_stencil_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000339 attr = MALLOC_STRUCT( gl_stencil_attrib );
jtgafb833d1999-08-19 00:55:39 +0000340 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
341 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
342 newnode->data = attr;
343 newnode->next = head;
344 head = newnode;
345 }
346
347 if (mask & GL_TEXTURE_BIT) {
348 struct gl_texture_attrib *attr;
349 GLuint u;
350 /* Take care of texture object reference counters */
351 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
352 ctx->Texture.Unit[u].CurrentD[1]->RefCount++;
353 ctx->Texture.Unit[u].CurrentD[2]->RefCount++;
354 ctx->Texture.Unit[u].CurrentD[3]->RefCount++;
355 }
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000356 attr = MALLOC_STRUCT( gl_texture_attrib );
jtgafb833d1999-08-19 00:55:39 +0000357 MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
358 /* copy state of the currently bound texture objects */
359 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
360 copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]);
361 copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]);
362 copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]);
Brian Paul6479a172000-07-05 22:26:43 +0000363 copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap);
jtgafb833d1999-08-19 00:55:39 +0000364 }
365 newnode = new_attrib_node( GL_TEXTURE_BIT );
366 newnode->data = attr;
367 newnode->next = head;
368 head = newnode;
369 }
370
371 if (mask & GL_TRANSFORM_BIT) {
372 struct gl_transform_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000373 attr = MALLOC_STRUCT( gl_transform_attrib );
jtgafb833d1999-08-19 00:55:39 +0000374 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
375 newnode = new_attrib_node( GL_TRANSFORM_BIT );
376 newnode->data = attr;
377 newnode->next = head;
378 head = newnode;
379 }
380
381 if (mask & GL_VIEWPORT_BIT) {
382 struct gl_viewport_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000383 attr = MALLOC_STRUCT( gl_viewport_attrib );
jtgafb833d1999-08-19 00:55:39 +0000384 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
385 newnode = new_attrib_node( GL_VIEWPORT_BIT );
386 newnode->data = attr;
387 newnode->next = head;
388 head = newnode;
389 }
390
391 ctx->AttribStack[ctx->AttribStackDepth] = head;
392 ctx->AttribStackDepth++;
393}
394
395
396
Brian Pauleb6c6432000-09-28 22:44:30 +0000397static void
398pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
399{
400 GLuint i;
401
402#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
403 if ((VALUE) != (NEWVALUE)) { \
404 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
405 }
406
407 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
408 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
409 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
410
411 for (i=0;i<MAX_CLIP_PLANES;i++) {
412 if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
413 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
414 enable->ClipPlane[i]);
415 }
416
417 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
418 GL_COLOR_MATERIAL);
419 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
420 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
421 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
422 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
423 GL_CONVOLUTION_1D);
424 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D,
425 GL_CONVOLUTION_2D);
426 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D,
427 GL_SEPARABLE_2D);
428 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
429 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
430 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
431 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
432 GL_LINE_STIPPLE);
433 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
434 GL_INDEX_LOGIC_OP);
435 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
436 GL_COLOR_LOGIC_OP);
437 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
438 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
439 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
440 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
441 GL_MAP1_TEXTURE_COORD_1);
442 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
443 GL_MAP1_TEXTURE_COORD_2);
444 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
445 GL_MAP1_TEXTURE_COORD_3);
446 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
447 GL_MAP1_TEXTURE_COORD_4);
448 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
449 GL_MAP1_VERTEX_3);
450 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
451 GL_MAP1_VERTEX_4);
452 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
453 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
454 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
455 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
456 GL_MAP2_TEXTURE_COORD_1);
457 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
458 GL_MAP2_TEXTURE_COORD_2);
459 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
460 GL_MAP2_TEXTURE_COORD_3);
461 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
462 GL_MAP2_TEXTURE_COORD_4);
463 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
464 GL_MAP2_VERTEX_3);
465 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
466 GL_MAP2_VERTEX_4);
467 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
468 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
469 GL_RESCALE_NORMAL_EXT);
470 TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture,
471 GL_POINT_SMOOTH);
472 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
473 GL_POINT_SMOOTH);
474 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
475 GL_POLYGON_OFFSET_POINT);
476 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
477 GL_POLYGON_OFFSET_LINE);
478 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
479 GL_POLYGON_OFFSET_FILL);
480 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
481 GL_POLYGON_SMOOTH);
482 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
483 GL_POLYGON_STIPPLE);
484 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
485 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
486#undef TEST_AND_UPDATE
487
488 /* texture unit enables */
489 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
490 if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) {
491 ctx->Texture.Unit[i].Enabled = enable->Texture[i];
492 if (ctx->Driver.Enable) {
493 if (ctx->Driver.ActiveTexture) {
494 (*ctx->Driver.ActiveTexture)(ctx, i);
495 }
496 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D,
497 (GLboolean) (enable->Texture[i] & TEXTURE0_1D) );
498 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D,
499 (GLboolean) (enable->Texture[i] & TEXTURE0_2D) );
500 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D,
501 (GLboolean) (enable->Texture[i] & TEXTURE0_3D) );
502 }
503 }
504
505 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
506 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
507 if (ctx->Driver.Enable) {
508 if (ctx->Driver.ActiveTexture) {
509 (*ctx->Driver.ActiveTexture)(ctx, i);
510 }
511 if (enable->TexGen[i] & S_BIT)
512 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
513 else
514 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
515 if (enable->TexGen[i] & T_BIT)
516 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
517 else
518 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
519 if (enable->TexGen[i] & R_BIT)
520 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
521 else
522 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
523 if (enable->TexGen[i] & Q_BIT)
524 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
525 else
526 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
527 }
528 }
529 }
530
531 if (ctx->Driver.ActiveTexture) {
532 (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit);
533 }
534}
535
536
537
jtgafb833d1999-08-19 00:55:39 +0000538/*
539 * This function is kind of long just because we have to call a lot
540 * of device driver functions to update device driver state.
541 */
Brian Paul42fcf032000-02-02 22:03:31 +0000542void
543_mesa_PopAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000544{
545 struct gl_attrib_node *attr, *next;
Brian Paul42fcf032000-02-02 22:03:31 +0000546 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000547
548 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
549
550
551 if (ctx->AttribStackDepth==0) {
552 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
553 return;
554 }
555
556 ctx->AttribStackDepth--;
557 attr = ctx->AttribStack[ctx->AttribStackDepth];
558
559 while (attr) {
560
561 if (MESA_VERBOSE&VERBOSE_API)
562 fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind));
563
564 switch (attr->kind) {
565 case GL_ACCUM_BUFFER_BIT:
566 MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
567 break;
568 case GL_COLOR_BUFFER_BIT:
569 {
570 GLenum oldDrawBuffer = ctx->Color.DrawBuffer;
571 GLenum oldAlphaFunc = ctx->Color.AlphaFunc;
Brian Paulba643a22000-10-28 18:34:48 +0000572 GLchan oldAlphaRef = ctx->Color.AlphaRef;
jtgafb833d1999-08-19 00:55:39 +0000573 GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
574 GLenum oldBlendDst = ctx->Color.BlendDstRGB;
Keith Whitwelle828bc82000-02-25 03:55:39 +0000575 GLenum oldLogicOp = ctx->Color.LogicOp;
jtgafb833d1999-08-19 00:55:39 +0000576 MEMCPY( &ctx->Color, attr->data,
577 sizeof(struct gl_colorbuffer_attrib) );
578 if (ctx->Color.DrawBuffer != oldDrawBuffer) {
Brian Paulfbd8f211999-11-11 01:22:25 +0000579 _mesa_DrawBuffer( ctx->Color.DrawBuffer);
jtgafb833d1999-08-19 00:55:39 +0000580 }
jtgafb833d1999-08-19 00:55:39 +0000581 if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
Brian Paul516b8362000-03-10 22:12:22 +0000582 ctx->Color.BlendDstRGB != oldBlendDst) &&
jtgafb833d1999-08-19 00:55:39 +0000583 ctx->Driver.BlendFunc)
584 (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
585 ctx->Color.BlendDstRGB);
Keith Whitwelle828bc82000-02-25 03:55:39 +0000586 if (ctx->Color.LogicOp != oldLogicOp &&
Brian Paul516b8362000-03-10 22:12:22 +0000587 ctx->Driver.LogicOpcode) {
Keith Whitwelle828bc82000-02-25 03:55:39 +0000588 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
Brian Paul516b8362000-03-10 22:12:22 +0000589 }
Brian Paulb1394fa2000-09-26 20:53:53 +0000590 if (ctx->Visual.RGBAflag) {
Brian Paulba643a22000-10-28 18:34:48 +0000591 GLchan r = (GLint) (ctx->Color.ClearColor[0] * CHAN_MAXF);
592 GLchan g = (GLint) (ctx->Color.ClearColor[1] * CHAN_MAXF);
593 GLchan b = (GLint) (ctx->Color.ClearColor[2] * CHAN_MAXF);
594 GLchan a = (GLint) (ctx->Color.ClearColor[3] * CHAN_MAXF);
Brian Paul516b8362000-03-10 22:12:22 +0000595 (*ctx->Driver.ClearColor)( ctx, r, g, b, a );
596 if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
597 ctx->Color.AlphaRef != oldAlphaRef) &&
598 ctx->Driver.AlphaFunc)
599 (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
Brian Paulba643a22000-10-28 18:34:48 +0000600 ctx->Color.AlphaRef / CHAN_MAXF);
Brian Paul516b8362000-03-10 22:12:22 +0000601 if (ctx->Driver.ColorMask) {
602 (*ctx->Driver.ColorMask)(ctx,
603 ctx->Color.ColorMask[0],
604 ctx->Color.ColorMask[1],
605 ctx->Color.ColorMask[2],
606 ctx->Color.ColorMask[3]);
607 }
608 }
609 else {
610 (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex);
611 }
jtgafb833d1999-08-19 00:55:39 +0000612 }
613 break;
614 case GL_CURRENT_BIT:
615 MEMCPY( &ctx->Current, attr->data,
616 sizeof(struct gl_current_attrib) );
617 break;
618 case GL_DEPTH_BUFFER_BIT:
619 {
Brian Pauld283df62000-07-19 18:34:00 +0000620 GLboolean oldDepthTest = ctx->Depth.Test;
jtgafb833d1999-08-19 00:55:39 +0000621 GLenum oldDepthFunc = ctx->Depth.Func;
622 GLboolean oldDepthMask = ctx->Depth.Mask;
623 GLfloat oldDepthClear = ctx->Depth.Clear;
624 MEMCPY( &ctx->Depth, attr->data,
625 sizeof(struct gl_depthbuffer_attrib) );
Brian Pauld283df62000-07-19 18:34:00 +0000626 if (ctx->Depth.Test != oldDepthTest && ctx->Driver.Enable)
627 (*ctx->Driver.Enable)( ctx, GL_DEPTH_TEST, ctx->Depth.Test);
jtgafb833d1999-08-19 00:55:39 +0000628 if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
629 (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func );
630 if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask)
631 (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask );
632 if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth)
633 (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
634 }
635 break;
636 case GL_ENABLE_BIT:
637 {
638 const struct gl_enable_attrib *enable;
639 enable = (const struct gl_enable_attrib *) attr->data;
Brian Pauleb6c6432000-09-28 22:44:30 +0000640 pop_enable_group(ctx, enable);
jtgafb833d1999-08-19 00:55:39 +0000641 }
642 break;
643 case GL_EVAL_BIT:
644 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
645 break;
646 case GL_FOG_BIT:
647 {
Brian Paul99f16d01999-11-08 15:28:08 +0000648 GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
jtgafb833d1999-08-19 00:55:39 +0000649 MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
650 if (anyChange && ctx->Driver.Fogfv) {
Brian Paul99f16d01999-11-08 15:28:08 +0000651 const GLfloat mode = (GLfloat) ctx->Fog.Mode;
jtgafb833d1999-08-19 00:55:39 +0000652 const GLfloat density = ctx->Fog.Density;
653 const GLfloat start = ctx->Fog.Start;
654 const GLfloat end = ctx->Fog.End;
655 const GLfloat index = ctx->Fog.Index;
656 (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode);
657 (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density );
658 (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start );
659 (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end );
660 (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
661 (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
662 }
Keith Whitwell04c43de1999-11-23 21:15:37 +0000663 ctx->Enabled &= ~ENABLE_FOG;
jtgafb833d1999-08-19 00:55:39 +0000664 if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
665 }
666 break;
667 case GL_HINT_BIT:
668 MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
669 if (ctx->Driver.Hint) {
670 (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
671 ctx->Hint.PerspectiveCorrection );
672 (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT,
673 ctx->Hint.PointSmooth);
674 (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT,
675 ctx->Hint.LineSmooth );
676 (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT,
677 ctx->Hint.PolygonSmooth );
678 (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog );
679 }
680 break;
681 case GL_LIGHTING_BIT:
682 MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
683 if (ctx->Driver.Enable) {
684 GLuint i;
685 for (i = 0; i < MAX_LIGHTS; i++) {
686 GLenum light = (GLenum) (GL_LIGHT0 + i);
687 (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled );
688 }
689 (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
690 }
Brian Paulf2db7ed1999-11-22 18:28:39 +0000691 if (ctx->Light.ShadeModel == GL_FLAT)
692 ctx->TriangleCaps |= DD_FLATSHADE;
693 else
694 ctx->TriangleCaps &= ~DD_FLATSHADE;
695 if (ctx->Driver.ShadeModel)
696 (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
697 ctx->Enabled &= ~ENABLE_LIGHT;
jtgafb833d1999-08-19 00:55:39 +0000698 if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
699 ctx->Enabled |= ENABLE_LIGHT;
700 break;
701 case GL_LINE_BIT:
702 MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
703 if (ctx->Driver.Enable) {
704 (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
705 (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
706 }
Brian Paul1b6592a2000-03-03 18:55:45 +0000707 if (ctx->Driver.LineStipple)
708 (*ctx->Driver.LineStipple)(ctx, ctx->Line.StippleFactor,
709 ctx->Line.StipplePattern);
710 if (ctx->Driver.LineWidth)
711 (*ctx->Driver.LineWidth)(ctx, ctx->Line.Width);
jtgafb833d1999-08-19 00:55:39 +0000712 break;
713 case GL_LIST_BIT:
714 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
715 break;
716 case GL_PIXEL_MODE_BIT:
717 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
718 break;
719 case GL_POINT_BIT:
720 MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
721 if (ctx->Driver.Enable)
722 (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag );
723 break;
724 case GL_POLYGON_BIT:
725 {
726 GLenum oldFrontMode = ctx->Polygon.FrontMode;
727 GLenum oldBackMode = ctx->Polygon.BackMode;
728 MEMCPY( &ctx->Polygon, attr->data,
729 sizeof(struct gl_polygon_attrib) );
730 if ((ctx->Polygon.FrontMode != oldFrontMode ||
731 ctx->Polygon.BackMode != oldBackMode) &&
732 ctx->Driver.PolygonMode) {
733 (*ctx->Driver.PolygonMode)( ctx, GL_FRONT, ctx->Polygon.FrontMode);
734 (*ctx->Driver.PolygonMode)( ctx, GL_BACK, ctx->Polygon.BackMode);
735 }
736 if (ctx->Driver.CullFace)
737 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
738
739 if (ctx->Driver.FrontFace)
740 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
741
742 if (ctx->Driver.Enable)
743 (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag );
744 }
745 break;
746 case GL_POLYGON_STIPPLE_BIT:
747 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000748 if (ctx->Driver.PolygonStipple)
Brian Paul959f8022000-03-19 01:10:11 +0000749 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
jtgafb833d1999-08-19 00:55:39 +0000750 break;
751 case GL_SCISSOR_BIT:
752 MEMCPY( &ctx->Scissor, attr->data,
753 sizeof(struct gl_scissor_attrib) );
754 if (ctx->Driver.Enable)
755 (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
756 if (ctx->Driver.Scissor)
757 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
758 ctx->Scissor.Width, ctx->Scissor.Height );
759 break;
760 case GL_STENCIL_BUFFER_BIT:
761 MEMCPY( &ctx->Stencil, attr->data,
762 sizeof(struct gl_stencil_attrib) );
763 if (ctx->Driver.StencilFunc)
764 (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
765 ctx->Stencil.Ref, ctx->Stencil.ValueMask);
766 if (ctx->Driver.StencilMask)
767 (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask );
768 if (ctx->Driver.StencilOp)
769 (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc,
770 ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc);
771 if (ctx->Driver.ClearStencil)
772 (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
773 if (ctx->Driver.Enable)
774 (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
Keith Whitwell1bf9dfa1999-09-18 20:41:22 +0000775 ctx->TriangleCaps &= ~DD_STENCIL;
776 if (ctx->Stencil.Enabled)
777 ctx->TriangleCaps |= DD_STENCIL;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000778
jtgafb833d1999-08-19 00:55:39 +0000779 break;
780 case GL_TRANSFORM_BIT:
781 MEMCPY( &ctx->Transform, attr->data,
782 sizeof(struct gl_transform_attrib) );
783 if (ctx->Driver.Enable) {
784 (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
785 (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
786 }
787 ctx->Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
788 if (ctx->Transform.Normalize) ctx->Enabled |= ENABLE_NORMALIZE;
789 if (ctx->Transform.RescaleNormals) ctx->Enabled |= ENABLE_RESCALE;
790 break;
791 case GL_TEXTURE_BIT:
792 /* Take care of texture object reference counters */
793 {
794 GLuint u;
795 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
796 ctx->Texture.Unit[u].CurrentD[1]->RefCount--;
797 ctx->Texture.Unit[u].CurrentD[2]->RefCount--;
798 ctx->Texture.Unit[u].CurrentD[3]->RefCount--;
799 }
800 MEMCPY( &ctx->Texture, attr->data,
801 sizeof(struct gl_texture_attrib) );
802 /* restore state of the currently bound texture objects */
803 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
804 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1],
805 &(ctx->Texture.Unit[u].Saved1D) );
806 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2],
807 &(ctx->Texture.Unit[u].Saved2D) );
808 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3],
809 &(ctx->Texture.Unit[u].Saved3D) );
Brian Paul6479a172000-07-05 22:26:43 +0000810 copy_texobj_state( ctx->Texture.Unit[u].CurrentCubeMap,
811 &(ctx->Texture.Unit[u].SavedCubeMap) );
812
jtgafb833d1999-08-19 00:55:39 +0000813 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] );
814 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] );
815 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] );
Brian Paul6479a172000-07-05 22:26:43 +0000816 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentCubeMap );
jtgafb833d1999-08-19 00:55:39 +0000817
818 }
819 }
820 break;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000821 case GL_VIEWPORT_BIT:
822 {
823 struct gl_viewport_attrib *v =
824 (struct gl_viewport_attrib *)attr->data;
825
Brian Paulfbd8f211999-11-11 01:22:25 +0000826 _mesa_Viewport( v->X, v->Y, v->Width, v->Height );
827 _mesa_DepthRange( v->Near, v->Far );
Keith Whitwelle3f37861999-09-16 11:54:56 +0000828 break;
829 }
jtgafb833d1999-08-19 00:55:39 +0000830 default:
831 gl_problem( ctx, "Bad attrib flag in PopAttrib");
832 break;
833 }
834
835 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000836 FREE( attr->data );
837 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000838 attr = next;
839 }
840
841 ctx->NewState = NEW_ALL;
Brian Paulfa4525e2000-08-21 14:22:24 +0000842 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
jtgafb833d1999-08-19 00:55:39 +0000843}
844
845
846#define GL_CLIENT_PACK_BIT (1<<20)
847#define GL_CLIENT_UNPACK_BIT (1<<21)
848
849
Brian Paul42fcf032000-02-02 22:03:31 +0000850void
851_mesa_PushClientAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000852{
853 struct gl_attrib_node *newnode;
854 struct gl_attrib_node *head;
855
Brian Paul42fcf032000-02-02 22:03:31 +0000856 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000857 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
858
859 if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
860 gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
861 return;
862 }
863
864 /* Build linked list of attribute nodes which save all attribute */
865 /* groups specified by the mask. */
866 head = NULL;
867
868 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
869 struct gl_pixelstore_attrib *attr;
870 /* packing attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000871 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000872 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
873 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
874 newnode->data = attr;
875 newnode->next = head;
876 head = newnode;
877 /* unpacking attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000878 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000879 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
880 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
881 newnode->data = attr;
882 newnode->next = head;
883 head = newnode;
884 }
885 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
886 struct gl_array_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000887 attr = MALLOC_STRUCT( gl_array_attrib );
jtgafb833d1999-08-19 00:55:39 +0000888 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
889 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
890 newnode->data = attr;
891 newnode->next = head;
892 head = newnode;
893 }
894
895 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
896 ctx->ClientAttribStackDepth++;
897}
898
899
900
901
Brian Paul42fcf032000-02-02 22:03:31 +0000902void
903_mesa_PopClientAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000904{
905 struct gl_attrib_node *attr, *next;
906
Brian Paul42fcf032000-02-02 22:03:31 +0000907 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000908 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
909
910 if (ctx->ClientAttribStackDepth==0) {
911 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
912 return;
913 }
914
915 ctx->ClientAttribStackDepth--;
916 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
917
918 while (attr) {
919 switch (attr->kind) {
920 case GL_CLIENT_PACK_BIT:
921 MEMCPY( &ctx->Pack, attr->data,
922 sizeof(struct gl_pixelstore_attrib) );
923 break;
924 case GL_CLIENT_UNPACK_BIT:
925 MEMCPY( &ctx->Unpack, attr->data,
926 sizeof(struct gl_pixelstore_attrib) );
927 break;
928 case GL_CLIENT_VERTEX_ARRAY_BIT:
929 MEMCPY( &ctx->Array, attr->data,
930 sizeof(struct gl_array_attrib) );
931 break;
932 default:
933 gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
934 break;
935 }
936
937 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000938 FREE( attr->data );
939 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000940 attr = next;
941 }
942
943 ctx->NewState = NEW_ALL;
944}
945
Brian Paulfbd8f211999-11-11 01:22:25 +0000946
947