blob: 3fab9416884025af45fe89ac0b61c08bcbf4f5e5 [file] [log] [blame]
Brian Paul083e4662000-12-14 20:25:56 +00001/* $Id: attrib.c,v 1.38 2000/12/14 20:25:56 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 Paul42fcf032000-02-02 22:03:31 +00007 * Copyright (C) 1999-2000 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"
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"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000041#include "mtypes.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;
Brian Paul083e4662000-12-14 20:25:56 +000088 dest->_MaxLevel = src->_MaxLevel;
89 dest->_MaxLambda = src->_MaxLambda;
Brian Paulfbd8f211999-11-11 01:22:25 +000090 dest->Palette = src->Palette;
jtgafb833d1999-08-19 00:55:39 +000091 dest->Complete = src->Complete;
jtgafb833d1999-08-19 00:55:39 +000092}
93
94
95
Brian Paul42fcf032000-02-02 22:03:31 +000096void
97_mesa_PushAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +000098{
99 struct gl_attrib_node *newnode;
100 struct gl_attrib_node *head;
101
Brian Paul42fcf032000-02-02 22:03:31 +0000102 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000103 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
104
105 if (MESA_VERBOSE&VERBOSE_API)
Keith Whitwelle5ed37f2000-02-27 20:38:15 +0000106 fprintf(stderr, "glPushAttrib %x\n", (int)mask);
jtgafb833d1999-08-19 00:55:39 +0000107
108 if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
109 gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
110 return;
111 }
112
113 /* Build linked list of attribute nodes which save all attribute */
114 /* groups specified by the mask. */
115 head = NULL;
116
117 if (mask & GL_ACCUM_BUFFER_BIT) {
118 struct gl_accum_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000119 attr = MALLOC_STRUCT( gl_accum_attrib );
jtgafb833d1999-08-19 00:55:39 +0000120 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
121 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
122 newnode->data = attr;
123 newnode->next = head;
124 head = newnode;
125 }
126
127 if (mask & GL_COLOR_BUFFER_BIT) {
128 struct gl_colorbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000129 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000130 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
131 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
132 newnode->data = attr;
133 newnode->next = head;
134 head = newnode;
135 }
136
137 if (mask & GL_CURRENT_BIT) {
138 struct gl_current_attrib *attr;
Keith Whitwell23caf202000-11-16 21:05:34 +0000139
140 FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT );
141
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000142 attr = MALLOC_STRUCT( gl_current_attrib );
jtgafb833d1999-08-19 00:55:39 +0000143 MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
144 newnode = new_attrib_node( GL_CURRENT_BIT );
145 newnode->data = attr;
146 newnode->next = head;
147 head = newnode;
148 }
149
150 if (mask & GL_DEPTH_BUFFER_BIT) {
151 struct gl_depthbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000152 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000153 MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
154 newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
155 newnode->data = attr;
156 newnode->next = head;
157 head = newnode;
158 }
159
160 if (mask & GL_ENABLE_BIT) {
161 struct gl_enable_attrib *attr;
162 GLuint i;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000163 attr = MALLOC_STRUCT( gl_enable_attrib );
jtgafb833d1999-08-19 00:55:39 +0000164 /* Copy enable flags from all other attributes into the enable struct. */
165 attr->AlphaTest = ctx->Color.AlphaEnabled;
166 attr->AutoNormal = ctx->Eval.AutoNormal;
167 attr->Blend = ctx->Color.BlendEnabled;
168 for (i=0;i<MAX_CLIP_PLANES;i++) {
169 attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
170 }
171 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
Brian Paul82b02f02000-05-07 20:37:40 +0000172 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
173 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
174 attr->Separable2D = ctx->Pixel.Separable2DEnabled;
jtgafb833d1999-08-19 00:55:39 +0000175 attr->CullFace = ctx->Polygon.CullFlag;
176 attr->DepthTest = ctx->Depth.Test;
177 attr->Dither = ctx->Color.DitherFlag;
178 attr->Fog = ctx->Fog.Enabled;
179 for (i=0;i<MAX_LIGHTS;i++) {
180 attr->Light[i] = ctx->Light.Light[i].Enabled;
181 }
182 attr->Lighting = ctx->Light.Enabled;
183 attr->LineSmooth = ctx->Line.SmoothFlag;
184 attr->LineStipple = ctx->Line.StippleFlag;
Brian Paul2b2e9252000-04-07 16:27:26 +0000185 attr->Histogram = ctx->Pixel.HistogramEnabled;
186 attr->MinMax = ctx->Pixel.MinMaxEnabled;
jtgafb833d1999-08-19 00:55:39 +0000187 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
188 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
189 attr->Map1Color4 = ctx->Eval.Map1Color4;
190 attr->Map1Index = ctx->Eval.Map1Index;
191 attr->Map1Normal = ctx->Eval.Map1Normal;
192 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
193 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
194 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
195 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
196 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
197 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
198 attr->Map2Color4 = ctx->Eval.Map2Color4;
199 attr->Map2Index = ctx->Eval.Map2Index;
200 attr->Map2Normal = ctx->Eval.Map2Normal;
201 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
202 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
203 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
204 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
205 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
206 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
207 attr->Normalize = ctx->Transform.Normalize;
Brian Paul2b2e9252000-04-07 16:27:26 +0000208 attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
jtgafb833d1999-08-19 00:55:39 +0000209 attr->PointSmooth = ctx->Point.SmoothFlag;
210 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
211 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
212 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
213 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
214 attr->PolygonStipple = ctx->Polygon.StippleFlag;
215 attr->RescaleNormals = ctx->Transform.RescaleNormals;
216 attr->Scissor = ctx->Scissor.Enabled;
217 attr->Stencil = ctx->Stencil.Enabled;
jtgafb833d1999-08-19 00:55:39 +0000218 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
Brian Pauleb6c6432000-09-28 22:44:30 +0000219 attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
jtgafb833d1999-08-19 00:55:39 +0000220 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
221 }
222 newnode = new_attrib_node( GL_ENABLE_BIT );
223 newnode->data = attr;
224 newnode->next = head;
225 head = newnode;
226 }
227
228 if (mask & GL_EVAL_BIT) {
229 struct gl_eval_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000230 attr = MALLOC_STRUCT( gl_eval_attrib );
jtgafb833d1999-08-19 00:55:39 +0000231 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
232 newnode = new_attrib_node( GL_EVAL_BIT );
233 newnode->data = attr;
234 newnode->next = head;
235 head = newnode;
236 }
237
238 if (mask & GL_FOG_BIT) {
239 struct gl_fog_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000240 attr = MALLOC_STRUCT( gl_fog_attrib );
jtgafb833d1999-08-19 00:55:39 +0000241 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
242 newnode = new_attrib_node( GL_FOG_BIT );
243 newnode->data = attr;
244 newnode->next = head;
245 head = newnode;
246 }
247
248 if (mask & GL_HINT_BIT) {
249 struct gl_hint_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000250 attr = MALLOC_STRUCT( gl_hint_attrib );
jtgafb833d1999-08-19 00:55:39 +0000251 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
252 newnode = new_attrib_node( GL_HINT_BIT );
253 newnode->data = attr;
254 newnode->next = head;
255 head = newnode;
256 }
257
258 if (mask & GL_LIGHTING_BIT) {
259 struct gl_light_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000260 attr = MALLOC_STRUCT( gl_light_attrib );
jtgafb833d1999-08-19 00:55:39 +0000261 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
262 newnode = new_attrib_node( GL_LIGHTING_BIT );
263 newnode->data = attr;
264 newnode->next = head;
265 head = newnode;
266 }
267
268 if (mask & GL_LINE_BIT) {
269 struct gl_line_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000270 attr = MALLOC_STRUCT( gl_line_attrib );
jtgafb833d1999-08-19 00:55:39 +0000271 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
272 newnode = new_attrib_node( GL_LINE_BIT );
273 newnode->data = attr;
274 newnode->next = head;
275 head = newnode;
276 }
277
278 if (mask & GL_LIST_BIT) {
279 struct gl_list_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000280 attr = MALLOC_STRUCT( gl_list_attrib );
jtgafb833d1999-08-19 00:55:39 +0000281 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
282 newnode = new_attrib_node( GL_LIST_BIT );
283 newnode->data = attr;
284 newnode->next = head;
285 head = newnode;
286 }
287
288 if (mask & GL_PIXEL_MODE_BIT) {
289 struct gl_pixel_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000290 attr = MALLOC_STRUCT( gl_pixel_attrib );
jtgafb833d1999-08-19 00:55:39 +0000291 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
292 newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
293 newnode->data = attr;
294 newnode->next = head;
295 head = newnode;
296 }
297
298 if (mask & GL_POINT_BIT) {
299 struct gl_point_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000300 attr = MALLOC_STRUCT( gl_point_attrib );
jtgafb833d1999-08-19 00:55:39 +0000301 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
302 newnode = new_attrib_node( GL_POINT_BIT );
303 newnode->data = attr;
304 newnode->next = head;
305 head = newnode;
306 }
307
308 if (mask & GL_POLYGON_BIT) {
309 struct gl_polygon_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000310 attr = MALLOC_STRUCT( gl_polygon_attrib );
jtgafb833d1999-08-19 00:55:39 +0000311 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
312 newnode = new_attrib_node( GL_POLYGON_BIT );
313 newnode->data = attr;
314 newnode->next = head;
315 head = newnode;
316 }
317
318 if (mask & GL_POLYGON_STIPPLE_BIT) {
319 GLuint *stipple;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000320 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +0000321 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
322 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
323 newnode->data = stipple;
324 newnode->next = head;
325 head = newnode;
326 }
327
328 if (mask & GL_SCISSOR_BIT) {
329 struct gl_scissor_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000330 attr = MALLOC_STRUCT( gl_scissor_attrib );
jtgafb833d1999-08-19 00:55:39 +0000331 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
332 newnode = new_attrib_node( GL_SCISSOR_BIT );
333 newnode->data = attr;
334 newnode->next = head;
335 head = newnode;
336 }
337
338 if (mask & GL_STENCIL_BUFFER_BIT) {
339 struct gl_stencil_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000340 attr = MALLOC_STRUCT( gl_stencil_attrib );
jtgafb833d1999-08-19 00:55:39 +0000341 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
342 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
343 newnode->data = attr;
344 newnode->next = head;
345 head = newnode;
346 }
347
348 if (mask & GL_TEXTURE_BIT) {
349 struct gl_texture_attrib *attr;
350 GLuint u;
351 /* Take care of texture object reference counters */
352 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000353 ctx->Texture.Unit[u].Current1D->RefCount++;
354 ctx->Texture.Unit[u].Current2D->RefCount++;
355 ctx->Texture.Unit[u].Current3D->RefCount++;
356 ctx->Texture.Unit[u].CurrentCubeMap->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000357 }
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000358 attr = MALLOC_STRUCT( gl_texture_attrib );
jtgafb833d1999-08-19 00:55:39 +0000359 MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
360 /* copy state of the currently bound texture objects */
361 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000362 copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].Current1D);
363 copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].Current2D);
364 copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].Current3D);
Brian Paul6479a172000-07-05 22:26:43 +0000365 copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap);
jtgafb833d1999-08-19 00:55:39 +0000366 }
367 newnode = new_attrib_node( GL_TEXTURE_BIT );
368 newnode->data = attr;
369 newnode->next = head;
370 head = newnode;
371 }
372
373 if (mask & GL_TRANSFORM_BIT) {
374 struct gl_transform_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000375 attr = MALLOC_STRUCT( gl_transform_attrib );
jtgafb833d1999-08-19 00:55:39 +0000376 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
377 newnode = new_attrib_node( GL_TRANSFORM_BIT );
378 newnode->data = attr;
379 newnode->next = head;
380 head = newnode;
381 }
382
383 if (mask & GL_VIEWPORT_BIT) {
384 struct gl_viewport_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000385 attr = MALLOC_STRUCT( gl_viewport_attrib );
jtgafb833d1999-08-19 00:55:39 +0000386 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
387 newnode = new_attrib_node( GL_VIEWPORT_BIT );
388 newnode->data = attr;
389 newnode->next = head;
390 head = newnode;
391 }
392
393 ctx->AttribStack[ctx->AttribStackDepth] = head;
394 ctx->AttribStackDepth++;
395}
396
397
398
Brian Pauleb6c6432000-09-28 22:44:30 +0000399static void
400pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
401{
402 GLuint i;
403
404#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
405 if ((VALUE) != (NEWVALUE)) { \
406 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
407 }
408
409 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
410 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
411 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
412
413 for (i=0;i<MAX_CLIP_PLANES;i++) {
414 if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
415 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
416 enable->ClipPlane[i]);
417 }
418
419 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
420 GL_COLOR_MATERIAL);
421 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
422 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
423 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
424 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
425 GL_CONVOLUTION_1D);
426 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D,
427 GL_CONVOLUTION_2D);
428 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D,
429 GL_SEPARABLE_2D);
430 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
431 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
432 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
433 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
434 GL_LINE_STIPPLE);
435 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
436 GL_INDEX_LOGIC_OP);
437 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
438 GL_COLOR_LOGIC_OP);
439 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
440 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
441 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
442 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
443 GL_MAP1_TEXTURE_COORD_1);
444 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
445 GL_MAP1_TEXTURE_COORD_2);
446 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
447 GL_MAP1_TEXTURE_COORD_3);
448 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
449 GL_MAP1_TEXTURE_COORD_4);
450 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
451 GL_MAP1_VERTEX_3);
452 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
453 GL_MAP1_VERTEX_4);
454 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
455 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
456 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
457 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
458 GL_MAP2_TEXTURE_COORD_1);
459 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
460 GL_MAP2_TEXTURE_COORD_2);
461 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
462 GL_MAP2_TEXTURE_COORD_3);
463 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
464 GL_MAP2_TEXTURE_COORD_4);
465 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
466 GL_MAP2_VERTEX_3);
467 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
468 GL_MAP2_VERTEX_4);
469 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
470 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
471 GL_RESCALE_NORMAL_EXT);
472 TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture,
473 GL_POINT_SMOOTH);
474 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
475 GL_POINT_SMOOTH);
476 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
477 GL_POLYGON_OFFSET_POINT);
478 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
479 GL_POLYGON_OFFSET_LINE);
480 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
481 GL_POLYGON_OFFSET_FILL);
482 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
483 GL_POLYGON_SMOOTH);
484 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
485 GL_POLYGON_STIPPLE);
486 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
487 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
488#undef TEST_AND_UPDATE
489
490 /* texture unit enables */
491 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
492 if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) {
493 ctx->Texture.Unit[i].Enabled = enable->Texture[i];
494 if (ctx->Driver.Enable) {
495 if (ctx->Driver.ActiveTexture) {
496 (*ctx->Driver.ActiveTexture)(ctx, i);
497 }
498 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D,
499 (GLboolean) (enable->Texture[i] & TEXTURE0_1D) );
500 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D,
501 (GLboolean) (enable->Texture[i] & TEXTURE0_2D) );
502 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D,
503 (GLboolean) (enable->Texture[i] & TEXTURE0_3D) );
504 }
505 }
506
507 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
508 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
509 if (ctx->Driver.Enable) {
510 if (ctx->Driver.ActiveTexture) {
511 (*ctx->Driver.ActiveTexture)(ctx, i);
512 }
513 if (enable->TexGen[i] & S_BIT)
514 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
515 else
516 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
517 if (enable->TexGen[i] & T_BIT)
518 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
519 else
520 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
521 if (enable->TexGen[i] & R_BIT)
522 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
523 else
524 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
525 if (enable->TexGen[i] & Q_BIT)
526 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
527 else
528 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
529 }
530 }
531 }
532
533 if (ctx->Driver.ActiveTexture) {
534 (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit);
535 }
536}
537
538
539
jtgafb833d1999-08-19 00:55:39 +0000540/*
541 * This function is kind of long just because we have to call a lot
542 * of device driver functions to update device driver state.
543 */
Brian Paul42fcf032000-02-02 22:03:31 +0000544void
545_mesa_PopAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000546{
547 struct gl_attrib_node *attr, *next;
Brian Paul42fcf032000-02-02 22:03:31 +0000548 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000549
550 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
551
552
553 if (ctx->AttribStackDepth==0) {
554 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
555 return;
556 }
557
558 ctx->AttribStackDepth--;
559 attr = ctx->AttribStack[ctx->AttribStackDepth];
560
561 while (attr) {
562
563 if (MESA_VERBOSE&VERBOSE_API)
564 fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind));
565
566 switch (attr->kind) {
567 case GL_ACCUM_BUFFER_BIT:
568 MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000569 ctx->NewState |= _NEW_ACCUM;
jtgafb833d1999-08-19 00:55:39 +0000570 break;
571 case GL_COLOR_BUFFER_BIT:
572 {
573 GLenum oldDrawBuffer = ctx->Color.DrawBuffer;
574 GLenum oldAlphaFunc = ctx->Color.AlphaFunc;
Brian Paulba643a22000-10-28 18:34:48 +0000575 GLchan oldAlphaRef = ctx->Color.AlphaRef;
jtgafb833d1999-08-19 00:55:39 +0000576 GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
577 GLenum oldBlendDst = ctx->Color.BlendDstRGB;
Keith Whitwelle828bc82000-02-25 03:55:39 +0000578 GLenum oldLogicOp = ctx->Color.LogicOp;
jtgafb833d1999-08-19 00:55:39 +0000579 MEMCPY( &ctx->Color, attr->data,
580 sizeof(struct gl_colorbuffer_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000581 ctx->NewState |= _NEW_COLOR;
jtgafb833d1999-08-19 00:55:39 +0000582 if (ctx->Color.DrawBuffer != oldDrawBuffer) {
Brian Paulfbd8f211999-11-11 01:22:25 +0000583 _mesa_DrawBuffer( ctx->Color.DrawBuffer);
jtgafb833d1999-08-19 00:55:39 +0000584 }
jtgafb833d1999-08-19 00:55:39 +0000585 if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
Brian Paul516b8362000-03-10 22:12:22 +0000586 ctx->Color.BlendDstRGB != oldBlendDst) &&
jtgafb833d1999-08-19 00:55:39 +0000587 ctx->Driver.BlendFunc)
588 (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
589 ctx->Color.BlendDstRGB);
Keith Whitwelle828bc82000-02-25 03:55:39 +0000590 if (ctx->Color.LogicOp != oldLogicOp &&
Brian Paul516b8362000-03-10 22:12:22 +0000591 ctx->Driver.LogicOpcode) {
Keith Whitwelle828bc82000-02-25 03:55:39 +0000592 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
Brian Paul516b8362000-03-10 22:12:22 +0000593 }
Brian Paulb1394fa2000-09-26 20:53:53 +0000594 if (ctx->Visual.RGBAflag) {
Brian Paulba643a22000-10-28 18:34:48 +0000595 GLchan r = (GLint) (ctx->Color.ClearColor[0] * CHAN_MAXF);
596 GLchan g = (GLint) (ctx->Color.ClearColor[1] * CHAN_MAXF);
597 GLchan b = (GLint) (ctx->Color.ClearColor[2] * CHAN_MAXF);
598 GLchan a = (GLint) (ctx->Color.ClearColor[3] * CHAN_MAXF);
Brian Paul516b8362000-03-10 22:12:22 +0000599 (*ctx->Driver.ClearColor)( ctx, r, g, b, a );
600 if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
601 ctx->Color.AlphaRef != oldAlphaRef) &&
602 ctx->Driver.AlphaFunc)
603 (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
Brian Paulba643a22000-10-28 18:34:48 +0000604 ctx->Color.AlphaRef / CHAN_MAXF);
Brian Paul516b8362000-03-10 22:12:22 +0000605 if (ctx->Driver.ColorMask) {
606 (*ctx->Driver.ColorMask)(ctx,
607 ctx->Color.ColorMask[0],
608 ctx->Color.ColorMask[1],
609 ctx->Color.ColorMask[2],
610 ctx->Color.ColorMask[3]);
611 }
612 }
613 else {
614 (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex);
615 }
jtgafb833d1999-08-19 00:55:39 +0000616 }
617 break;
618 case GL_CURRENT_BIT:
Keith Whitwell23caf202000-11-16 21:05:34 +0000619 FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT );
jtgafb833d1999-08-19 00:55:39 +0000620 MEMCPY( &ctx->Current, attr->data,
621 sizeof(struct gl_current_attrib) );
622 break;
623 case GL_DEPTH_BUFFER_BIT:
624 {
Brian Pauld283df62000-07-19 18:34:00 +0000625 GLboolean oldDepthTest = ctx->Depth.Test;
jtgafb833d1999-08-19 00:55:39 +0000626 GLenum oldDepthFunc = ctx->Depth.Func;
627 GLboolean oldDepthMask = ctx->Depth.Mask;
628 GLfloat oldDepthClear = ctx->Depth.Clear;
629 MEMCPY( &ctx->Depth, attr->data,
630 sizeof(struct gl_depthbuffer_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000631 ctx->NewState |= _NEW_DEPTH;
Brian Pauld283df62000-07-19 18:34:00 +0000632 if (ctx->Depth.Test != oldDepthTest && ctx->Driver.Enable)
633 (*ctx->Driver.Enable)( ctx, GL_DEPTH_TEST, ctx->Depth.Test);
jtgafb833d1999-08-19 00:55:39 +0000634 if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
635 (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func );
636 if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask)
637 (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask );
638 if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth)
639 (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
640 }
641 break;
642 case GL_ENABLE_BIT:
643 {
644 const struct gl_enable_attrib *enable;
645 enable = (const struct gl_enable_attrib *) attr->data;
Brian Pauleb6c6432000-09-28 22:44:30 +0000646 pop_enable_group(ctx, enable);
Keith Whitwella96308c2000-10-30 13:31:59 +0000647 ctx->NewState |= _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +0000648 }
649 break;
650 case GL_EVAL_BIT:
651 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000652 ctx->NewState |= _NEW_EVAL;
jtgafb833d1999-08-19 00:55:39 +0000653 break;
654 case GL_FOG_BIT:
655 {
Brian Paul99f16d01999-11-08 15:28:08 +0000656 GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
jtgafb833d1999-08-19 00:55:39 +0000657 MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000658 ctx->NewState |= _NEW_FOG;
jtgafb833d1999-08-19 00:55:39 +0000659 if (anyChange && ctx->Driver.Fogfv) {
Brian Paul99f16d01999-11-08 15:28:08 +0000660 const GLfloat mode = (GLfloat) ctx->Fog.Mode;
jtgafb833d1999-08-19 00:55:39 +0000661 const GLfloat density = ctx->Fog.Density;
662 const GLfloat start = ctx->Fog.Start;
663 const GLfloat end = ctx->Fog.End;
664 const GLfloat index = ctx->Fog.Index;
665 (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode);
666 (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density );
667 (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start );
668 (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end );
669 (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
670 (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
671 }
Keith Whitwell14940c42000-11-05 18:40:57 +0000672 ctx->_Enabled &= ~ENABLE_FOG;
673 if (ctx->Fog.Enabled) ctx->_Enabled |= ENABLE_FOG;
jtgafb833d1999-08-19 00:55:39 +0000674 }
675 break;
676 case GL_HINT_BIT:
677 MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000678 ctx->NewState |= _NEW_HINT;
jtgafb833d1999-08-19 00:55:39 +0000679 if (ctx->Driver.Hint) {
680 (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
681 ctx->Hint.PerspectiveCorrection );
682 (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT,
683 ctx->Hint.PointSmooth);
684 (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT,
685 ctx->Hint.LineSmooth );
686 (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT,
687 ctx->Hint.PolygonSmooth );
688 (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog );
689 }
690 break;
691 case GL_LIGHTING_BIT:
692 MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000693 ctx->NewState |= _NEW_LIGHT;
jtgafb833d1999-08-19 00:55:39 +0000694 if (ctx->Driver.Enable) {
695 GLuint i;
696 for (i = 0; i < MAX_LIGHTS; i++) {
697 GLenum light = (GLenum) (GL_LIGHT0 + i);
698 (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled );
699 }
700 (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
701 }
Brian Paulf2db7ed1999-11-22 18:28:39 +0000702 if (ctx->Light.ShadeModel == GL_FLAT)
Keith Whitwell14940c42000-11-05 18:40:57 +0000703 ctx->_TriangleCaps |= DD_FLATSHADE;
Brian Paulf2db7ed1999-11-22 18:28:39 +0000704 else
Keith Whitwell14940c42000-11-05 18:40:57 +0000705 ctx->_TriangleCaps &= ~DD_FLATSHADE;
Brian Paulf2db7ed1999-11-22 18:28:39 +0000706 if (ctx->Driver.ShadeModel)
707 (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
Keith Whitwell14940c42000-11-05 18:40:57 +0000708 ctx->_Enabled &= ~ENABLE_LIGHT;
Brian Paul72ef7532000-11-27 18:59:09 +0000709 if (ctx->Light.Enabled)
Keith Whitwell14940c42000-11-05 18:40:57 +0000710 ctx->_Enabled |= ENABLE_LIGHT;
jtgafb833d1999-08-19 00:55:39 +0000711 break;
712 case GL_LINE_BIT:
713 MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000714 ctx->NewState |= _NEW_LINE;
jtgafb833d1999-08-19 00:55:39 +0000715 if (ctx->Driver.Enable) {
716 (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
717 (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
718 }
Brian Paul1b6592a2000-03-03 18:55:45 +0000719 if (ctx->Driver.LineStipple)
720 (*ctx->Driver.LineStipple)(ctx, ctx->Line.StippleFactor,
721 ctx->Line.StipplePattern);
722 if (ctx->Driver.LineWidth)
723 (*ctx->Driver.LineWidth)(ctx, ctx->Line.Width);
jtgafb833d1999-08-19 00:55:39 +0000724 break;
725 case GL_LIST_BIT:
726 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
727 break;
728 case GL_PIXEL_MODE_BIT:
729 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000730 ctx->NewState |= _NEW_PIXEL;
jtgafb833d1999-08-19 00:55:39 +0000731 break;
732 case GL_POINT_BIT:
733 MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000734 ctx->NewState |= _NEW_POINT;
jtgafb833d1999-08-19 00:55:39 +0000735 if (ctx->Driver.Enable)
736 (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag );
737 break;
738 case GL_POLYGON_BIT:
739 {
740 GLenum oldFrontMode = ctx->Polygon.FrontMode;
741 GLenum oldBackMode = ctx->Polygon.BackMode;
742 MEMCPY( &ctx->Polygon, attr->data,
743 sizeof(struct gl_polygon_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000744 ctx->NewState |= _NEW_POLYGON;
jtgafb833d1999-08-19 00:55:39 +0000745 if ((ctx->Polygon.FrontMode != oldFrontMode ||
746 ctx->Polygon.BackMode != oldBackMode) &&
747 ctx->Driver.PolygonMode) {
748 (*ctx->Driver.PolygonMode)( ctx, GL_FRONT, ctx->Polygon.FrontMode);
749 (*ctx->Driver.PolygonMode)( ctx, GL_BACK, ctx->Polygon.BackMode);
750 }
751 if (ctx->Driver.CullFace)
752 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
753
754 if (ctx->Driver.FrontFace)
755 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
756
757 if (ctx->Driver.Enable)
758 (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag );
759 }
760 break;
761 case GL_POLYGON_STIPPLE_BIT:
762 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000763 ctx->NewState |= _NEW_POLYGONSTIPPLE;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000764 if (ctx->Driver.PolygonStipple)
Brian Paul959f8022000-03-19 01:10:11 +0000765 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
jtgafb833d1999-08-19 00:55:39 +0000766 break;
767 case GL_SCISSOR_BIT:
768 MEMCPY( &ctx->Scissor, attr->data,
769 sizeof(struct gl_scissor_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000770 ctx->NewState |= _NEW_SCISSOR;
jtgafb833d1999-08-19 00:55:39 +0000771 if (ctx->Driver.Enable)
772 (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
773 if (ctx->Driver.Scissor)
774 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
775 ctx->Scissor.Width, ctx->Scissor.Height );
776 break;
777 case GL_STENCIL_BUFFER_BIT:
778 MEMCPY( &ctx->Stencil, attr->data,
779 sizeof(struct gl_stencil_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000780 ctx->NewState |= _NEW_STENCIL;
jtgafb833d1999-08-19 00:55:39 +0000781 if (ctx->Driver.StencilFunc)
782 (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
783 ctx->Stencil.Ref, ctx->Stencil.ValueMask);
784 if (ctx->Driver.StencilMask)
785 (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask );
786 if (ctx->Driver.StencilOp)
787 (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc,
788 ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc);
789 if (ctx->Driver.ClearStencil)
790 (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
791 if (ctx->Driver.Enable)
792 (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
Keith Whitwell14940c42000-11-05 18:40:57 +0000793 ctx->_TriangleCaps &= ~DD_STENCIL;
Keith Whitwell1bf9dfa1999-09-18 20:41:22 +0000794 if (ctx->Stencil.Enabled)
Keith Whitwell14940c42000-11-05 18:40:57 +0000795 ctx->_TriangleCaps |= DD_STENCIL;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000796
jtgafb833d1999-08-19 00:55:39 +0000797 break;
798 case GL_TRANSFORM_BIT:
799 MEMCPY( &ctx->Transform, attr->data,
800 sizeof(struct gl_transform_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000801 ctx->NewState |= _NEW_TRANSFORM;
jtgafb833d1999-08-19 00:55:39 +0000802 if (ctx->Driver.Enable) {
803 (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
804 (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
805 }
Keith Whitwell14940c42000-11-05 18:40:57 +0000806 ctx->_Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
807 if (ctx->Transform.Normalize) ctx->_Enabled |= ENABLE_NORMALIZE;
808 if (ctx->Transform.RescaleNormals) ctx->_Enabled |= ENABLE_RESCALE;
jtgafb833d1999-08-19 00:55:39 +0000809 break;
810 case GL_TEXTURE_BIT:
811 /* Take care of texture object reference counters */
812 {
813 GLuint u;
814 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000815 ctx->Texture.Unit[u].Current1D->RefCount--;
816 ctx->Texture.Unit[u].Current2D->RefCount--;
817 ctx->Texture.Unit[u].Current3D->RefCount--;
818 ctx->Texture.Unit[u].CurrentCubeMap->RefCount--;
jtgafb833d1999-08-19 00:55:39 +0000819 }
820 MEMCPY( &ctx->Texture, attr->data,
821 sizeof(struct gl_texture_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000822 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +0000823 /* restore state of the currently bound texture objects */
824 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000825 copy_texobj_state( ctx->Texture.Unit[u].Current1D,
jtgafb833d1999-08-19 00:55:39 +0000826 &(ctx->Texture.Unit[u].Saved1D) );
Brian Paula8523782000-11-19 23:10:25 +0000827 copy_texobj_state( ctx->Texture.Unit[u].Current2D,
jtgafb833d1999-08-19 00:55:39 +0000828 &(ctx->Texture.Unit[u].Saved2D) );
Brian Paula8523782000-11-19 23:10:25 +0000829 copy_texobj_state( ctx->Texture.Unit[u].Current3D,
jtgafb833d1999-08-19 00:55:39 +0000830 &(ctx->Texture.Unit[u].Saved3D) );
Brian Paul6479a172000-07-05 22:26:43 +0000831 copy_texobj_state( ctx->Texture.Unit[u].CurrentCubeMap,
832 &(ctx->Texture.Unit[u].SavedCubeMap) );
833
Brian Paula8523782000-11-19 23:10:25 +0000834 ctx->Texture.Unit[u].Current1D->Complete = GL_FALSE;
835 ctx->Texture.Unit[u].Current2D->Complete = GL_FALSE;
836 ctx->Texture.Unit[u].Current3D->Complete = GL_FALSE;
837 ctx->Texture.Unit[u].CurrentCubeMap->Complete = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000838 }
839 }
840 break;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000841 case GL_VIEWPORT_BIT:
Keith Whitwelle3f37861999-09-16 11:54:56 +0000842 {
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +0000843 struct gl_viewport_attrib *v =
Keith Whitwelle3f37861999-09-16 11:54:56 +0000844 (struct gl_viewport_attrib *)attr->data;
Keith Whitwella96308c2000-10-30 13:31:59 +0000845
846 ctx->NewState |= _NEW_VIEWPORT;
Brian Paulfbd8f211999-11-11 01:22:25 +0000847 _mesa_Viewport( v->X, v->Y, v->Width, v->Height );
848 _mesa_DepthRange( v->Near, v->Far );
Keith Whitwelle3f37861999-09-16 11:54:56 +0000849 break;
850 }
jtgafb833d1999-08-19 00:55:39 +0000851 default:
852 gl_problem( ctx, "Bad attrib flag in PopAttrib");
853 break;
854 }
855
856 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000857 FREE( attr->data );
858 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000859 attr = next;
860 }
jtgafb833d1999-08-19 00:55:39 +0000861}
862
863
864#define GL_CLIENT_PACK_BIT (1<<20)
865#define GL_CLIENT_UNPACK_BIT (1<<21)
866
867
Brian Paul42fcf032000-02-02 22:03:31 +0000868void
869_mesa_PushClientAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000870{
871 struct gl_attrib_node *newnode;
872 struct gl_attrib_node *head;
873
Brian Paul42fcf032000-02-02 22:03:31 +0000874 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000875 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
876
877 if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
878 gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
879 return;
880 }
881
882 /* Build linked list of attribute nodes which save all attribute */
883 /* groups specified by the mask. */
884 head = NULL;
885
886 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
887 struct gl_pixelstore_attrib *attr;
888 /* packing attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000889 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000890 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
891 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
892 newnode->data = attr;
893 newnode->next = head;
894 head = newnode;
895 /* unpacking attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000896 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +0000897 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
898 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
899 newnode->data = attr;
900 newnode->next = head;
901 head = newnode;
902 }
903 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
904 struct gl_array_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000905 attr = MALLOC_STRUCT( gl_array_attrib );
jtgafb833d1999-08-19 00:55:39 +0000906 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
907 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
908 newnode->data = attr;
909 newnode->next = head;
910 head = newnode;
911 }
912
913 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
914 ctx->ClientAttribStackDepth++;
915}
916
917
918
919
Brian Paul42fcf032000-02-02 22:03:31 +0000920void
921_mesa_PopClientAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000922{
923 struct gl_attrib_node *attr, *next;
924
Brian Paul42fcf032000-02-02 22:03:31 +0000925 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000926 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
927
928 if (ctx->ClientAttribStackDepth==0) {
929 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
930 return;
931 }
932
933 ctx->ClientAttribStackDepth--;
934 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
935
936 while (attr) {
937 switch (attr->kind) {
938 case GL_CLIENT_PACK_BIT:
939 MEMCPY( &ctx->Pack, attr->data,
940 sizeof(struct gl_pixelstore_attrib) );
941 break;
942 case GL_CLIENT_UNPACK_BIT:
943 MEMCPY( &ctx->Unpack, attr->data,
944 sizeof(struct gl_pixelstore_attrib) );
945 break;
946 case GL_CLIENT_VERTEX_ARRAY_BIT:
947 MEMCPY( &ctx->Array, attr->data,
948 sizeof(struct gl_array_attrib) );
949 break;
950 default:
951 gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
952 break;
953 }
954
955 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000956 FREE( attr->data );
957 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +0000958 attr = next;
959 }
960
Keith Whitwella96308c2000-10-30 13:31:59 +0000961 ctx->NewState = _NEW_ARRAY;
jtgafb833d1999-08-19 00:55:39 +0000962}
963
Brian Paulfbd8f211999-11-11 01:22:25 +0000964
965