blob: fb5fbc8b704ce36a5817d2ea3f78d3a01b19adff [file] [log] [blame]
Brian Paul8afe7de2002-06-15 03:03:06 +00001/* $Id: attrib.c,v 1.68 2002/06/15 03:03:06 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul934bee02002-03-28 22:42:41 +00005 * Version: 4.1
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Brian Paul934bee02002-03-28 22:42:41 +00007 * Copyright (C) 1999-2002 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"
jtgafb833d1999-08-19 00:55:39 +000033#include "attrib.h"
Brian Paulf3da3892001-01-24 15:27:10 +000034#include "blend.h"
Brian Paulea39f042000-02-02 19:17:57 +000035#include "buffers.h"
Brian Paulf3da3892001-01-24 15:27:10 +000036#include "colormac.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "context.h"
Brian Paulf3da3892001-01-24 15:27:10 +000038#include "depth.h"
jtgafb833d1999-08-19 00:55:39 +000039#include "enable.h"
40#include "enums.h"
Brian Paulf3da3892001-01-24 15:27:10 +000041#include "fog.h"
42#include "hint.h"
43#include "light.h"
44#include "lines.h"
Brian Paul699bc7b2000-10-29 18:12:14 +000045#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000046#include "mem.h"
Brian Paulf3da3892001-01-24 15:27:10 +000047#include "points.h"
48#include "polygon.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulf3da3892001-01-24 15:27:10 +000050#include "stencil.h"
Brian Paul58cfa0f2001-08-07 23:10:55 +000051#include "texobj.h"
jtgafb833d1999-08-19 00:55:39 +000052#include "texstate.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
Keith Whitwell0cb28412002-02-13 00:53:19 +000054#include "math/m_xform.h"
jtgafb833d1999-08-19 00:55:39 +000055#endif
56
57
jtgafb833d1999-08-19 00:55:39 +000058
59
60/*
61 * Allocate a new attribute state node. These nodes have a
62 * "kind" value and a pointer to a struct of state data.
63 */
Brian Paul42fcf032000-02-02 22:03:31 +000064static struct gl_attrib_node *
65new_attrib_node( GLbitfield kind )
jtgafb833d1999-08-19 00:55:39 +000066{
Brian Paulbd5cdaf1999-10-13 18:42:49 +000067 struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
jtgafb833d1999-08-19 00:55:39 +000068 if (an) {
69 an->kind = kind;
70 }
71 return an;
72}
73
74
75
76/*
77 * Copy texture object state from one texture object to another.
78 */
Brian Paul42fcf032000-02-02 22:03:31 +000079static void
80copy_texobj_state( struct gl_texture_object *dest,
81 const struct gl_texture_object *src )
jtgafb833d1999-08-19 00:55:39 +000082{
jtgafb833d1999-08-19 00:55:39 +000083 dest->Name = src->Name;
Brian Paul8afe7de2002-06-15 03:03:06 +000084 /*dest->Target = src->Target*/
jtgafb833d1999-08-19 00:55:39 +000085 dest->Priority = src->Priority;
86 dest->BorderColor[0] = src->BorderColor[0];
87 dest->BorderColor[1] = src->BorderColor[1];
88 dest->BorderColor[2] = src->BorderColor[2];
89 dest->BorderColor[3] = src->BorderColor[3];
90 dest->WrapS = src->WrapS;
91 dest->WrapT = src->WrapT;
92 dest->WrapR = src->WrapR;
93 dest->MinFilter = src->MinFilter;
94 dest->MagFilter = src->MagFilter;
95 dest->MinLod = src->MinLod;
96 dest->MaxLod = src->MaxLod;
97 dest->BaseLevel = src->BaseLevel;
98 dest->MaxLevel = src->MaxLevel;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000099 dest->MaxAnisotropy = src->MaxAnisotropy;
Brian Paulc499ce32001-02-20 16:42:25 +0000100 dest->CompareFlag = src->CompareFlag;
101 dest->CompareOperator = src->CompareOperator;
102 dest->ShadowAmbient = src->ShadowAmbient;
Brian Paul083e4662000-12-14 20:25:56 +0000103 dest->_MaxLevel = src->_MaxLevel;
104 dest->_MaxLambda = src->_MaxLambda;
Brian Paulfbd8f211999-11-11 01:22:25 +0000105 dest->Palette = src->Palette;
jtgafb833d1999-08-19 00:55:39 +0000106 dest->Complete = src->Complete;
jtgafb833d1999-08-19 00:55:39 +0000107}
108
109
110
Brian Paul42fcf032000-02-02 22:03:31 +0000111void
112_mesa_PushAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +0000113{
114 struct gl_attrib_node *newnode;
115 struct gl_attrib_node *head;
116
Brian Paul42fcf032000-02-02 22:03:31 +0000117 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000118 ASSERT_OUTSIDE_BEGIN_END(ctx);
jtgafb833d1999-08-19 00:55:39 +0000119
Brian Paul9a33a112002-06-13 04:28:29 +0000120 if (MESA_VERBOSE & VERBOSE_API)
Brian Paul4753d602002-06-15 02:38:15 +0000121 _mesa_debug(ctx, "glPushAttrib %x\n", (int) mask);
jtgafb833d1999-08-19 00:55:39 +0000122
Brian Paulf3da3892001-01-24 15:27:10 +0000123 if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
Brian Paul08836342001-03-03 20:33:27 +0000124 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
jtgafb833d1999-08-19 00:55:39 +0000125 return;
126 }
127
128 /* Build linked list of attribute nodes which save all attribute */
129 /* groups specified by the mask. */
130 head = NULL;
131
132 if (mask & GL_ACCUM_BUFFER_BIT) {
133 struct gl_accum_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000134 attr = MALLOC_STRUCT( gl_accum_attrib );
jtgafb833d1999-08-19 00:55:39 +0000135 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
136 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
137 newnode->data = attr;
138 newnode->next = head;
139 head = newnode;
140 }
141
142 if (mask & GL_COLOR_BUFFER_BIT) {
143 struct gl_colorbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000144 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000145 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
146 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
147 newnode->data = attr;
148 newnode->next = head;
149 head = newnode;
150 }
151
152 if (mask & GL_CURRENT_BIT) {
153 struct gl_current_attrib *attr;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000154 FLUSH_CURRENT( ctx, 0 );
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000155 attr = MALLOC_STRUCT( gl_current_attrib );
jtgafb833d1999-08-19 00:55:39 +0000156 MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
157 newnode = new_attrib_node( GL_CURRENT_BIT );
158 newnode->data = attr;
159 newnode->next = head;
160 head = newnode;
161 }
162
163 if (mask & GL_DEPTH_BUFFER_BIT) {
164 struct gl_depthbuffer_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000165 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
jtgafb833d1999-08-19 00:55:39 +0000166 MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
167 newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
168 newnode->data = attr;
169 newnode->next = head;
170 head = newnode;
171 }
172
173 if (mask & GL_ENABLE_BIT) {
174 struct gl_enable_attrib *attr;
175 GLuint i;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000176 attr = MALLOC_STRUCT( gl_enable_attrib );
jtgafb833d1999-08-19 00:55:39 +0000177 /* Copy enable flags from all other attributes into the enable struct. */
178 attr->AlphaTest = ctx->Color.AlphaEnabled;
179 attr->AutoNormal = ctx->Eval.AutoNormal;
180 attr->Blend = ctx->Color.BlendEnabled;
Brian Paul103bc0f2002-03-29 17:27:59 +0000181 attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
jtgafb833d1999-08-19 00:55:39 +0000182 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
Brian Paul82b02f02000-05-07 20:37:40 +0000183 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
184 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
185 attr->Separable2D = ctx->Pixel.Separable2DEnabled;
jtgafb833d1999-08-19 00:55:39 +0000186 attr->CullFace = ctx->Polygon.CullFlag;
187 attr->DepthTest = ctx->Depth.Test;
188 attr->Dither = ctx->Color.DitherFlag;
189 attr->Fog = ctx->Fog.Enabled;
190 for (i=0;i<MAX_LIGHTS;i++) {
191 attr->Light[i] = ctx->Light.Light[i].Enabled;
192 }
193 attr->Lighting = ctx->Light.Enabled;
194 attr->LineSmooth = ctx->Line.SmoothFlag;
195 attr->LineStipple = ctx->Line.StippleFlag;
Brian Paul2b2e9252000-04-07 16:27:26 +0000196 attr->Histogram = ctx->Pixel.HistogramEnabled;
197 attr->MinMax = ctx->Pixel.MinMaxEnabled;
jtgafb833d1999-08-19 00:55:39 +0000198 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
199 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
200 attr->Map1Color4 = ctx->Eval.Map1Color4;
201 attr->Map1Index = ctx->Eval.Map1Index;
202 attr->Map1Normal = ctx->Eval.Map1Normal;
203 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
204 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
205 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
206 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
207 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
208 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
Brian Paulbc42c192002-01-05 21:53:20 +0000209 MEMCPY(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib));
jtgafb833d1999-08-19 00:55:39 +0000210 attr->Map2Color4 = ctx->Eval.Map2Color4;
211 attr->Map2Index = ctx->Eval.Map2Index;
212 attr->Map2Normal = ctx->Eval.Map2Normal;
213 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
214 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
215 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
216 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
217 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
218 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
Brian Paulbc42c192002-01-05 21:53:20 +0000219 MEMCPY(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
jtgafb833d1999-08-19 00:55:39 +0000220 attr->Normalize = ctx->Transform.Normalize;
Brian Paul8c2f6c52001-06-26 01:32:48 +0000221 attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
Brian Paul2b2e9252000-04-07 16:27:26 +0000222 attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
jtgafb833d1999-08-19 00:55:39 +0000223 attr->PointSmooth = ctx->Point.SmoothFlag;
Brian Paul112f7cd2002-06-07 16:01:03 +0000224 attr->PointSprite = ctx->Point.PointSprite;
jtgafb833d1999-08-19 00:55:39 +0000225 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
226 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
227 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
228 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
229 attr->PolygonStipple = ctx->Polygon.StippleFlag;
230 attr->RescaleNormals = ctx->Transform.RescaleNormals;
231 attr->Scissor = ctx->Scissor.Enabled;
232 attr->Stencil = ctx->Stencil.Enabled;
Brian Paul736fcbe2001-05-29 15:23:48 +0000233 attr->MultisampleEnabled = ctx->Multisample.Enabled;
234 attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
235 attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
236 attr->SampleCoverage = ctx->Multisample.SampleCoverage;
237 attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
jtgafb833d1999-08-19 00:55:39 +0000238 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
Brian Pauleb6c6432000-09-28 22:44:30 +0000239 attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
jtgafb833d1999-08-19 00:55:39 +0000240 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
241 }
Brian Paul86b84272001-12-14 02:50:01 +0000242 /* GL_NV_vertex_program */
243 attr->VertexProgram = ctx->VertexProgram.Enabled;
244 attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
245 attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
jtgafb833d1999-08-19 00:55:39 +0000246 newnode = new_attrib_node( GL_ENABLE_BIT );
247 newnode->data = attr;
248 newnode->next = head;
249 head = newnode;
250 }
251
252 if (mask & GL_EVAL_BIT) {
253 struct gl_eval_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000254 attr = MALLOC_STRUCT( gl_eval_attrib );
jtgafb833d1999-08-19 00:55:39 +0000255 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
256 newnode = new_attrib_node( GL_EVAL_BIT );
257 newnode->data = attr;
258 newnode->next = head;
259 head = newnode;
260 }
261
262 if (mask & GL_FOG_BIT) {
263 struct gl_fog_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000264 attr = MALLOC_STRUCT( gl_fog_attrib );
jtgafb833d1999-08-19 00:55:39 +0000265 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
266 newnode = new_attrib_node( GL_FOG_BIT );
267 newnode->data = attr;
268 newnode->next = head;
269 head = newnode;
270 }
271
272 if (mask & GL_HINT_BIT) {
273 struct gl_hint_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000274 attr = MALLOC_STRUCT( gl_hint_attrib );
jtgafb833d1999-08-19 00:55:39 +0000275 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
276 newnode = new_attrib_node( GL_HINT_BIT );
277 newnode->data = attr;
278 newnode->next = head;
279 head = newnode;
280 }
281
282 if (mask & GL_LIGHTING_BIT) {
283 struct gl_light_attrib *attr;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000284 FLUSH_CURRENT(ctx, 0); /* flush material changes */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000285 attr = MALLOC_STRUCT( gl_light_attrib );
jtgafb833d1999-08-19 00:55:39 +0000286 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
287 newnode = new_attrib_node( GL_LIGHTING_BIT );
288 newnode->data = attr;
289 newnode->next = head;
290 head = newnode;
291 }
292
293 if (mask & GL_LINE_BIT) {
294 struct gl_line_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000295 attr = MALLOC_STRUCT( gl_line_attrib );
jtgafb833d1999-08-19 00:55:39 +0000296 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
297 newnode = new_attrib_node( GL_LINE_BIT );
298 newnode->data = attr;
299 newnode->next = head;
300 head = newnode;
301 }
302
303 if (mask & GL_LIST_BIT) {
304 struct gl_list_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000305 attr = MALLOC_STRUCT( gl_list_attrib );
jtgafb833d1999-08-19 00:55:39 +0000306 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
307 newnode = new_attrib_node( GL_LIST_BIT );
308 newnode->data = attr;
309 newnode->next = head;
310 head = newnode;
311 }
312
313 if (mask & GL_PIXEL_MODE_BIT) {
314 struct gl_pixel_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000315 attr = MALLOC_STRUCT( gl_pixel_attrib );
jtgafb833d1999-08-19 00:55:39 +0000316 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
317 newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
318 newnode->data = attr;
319 newnode->next = head;
320 head = newnode;
321 }
322
323 if (mask & GL_POINT_BIT) {
324 struct gl_point_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000325 attr = MALLOC_STRUCT( gl_point_attrib );
jtgafb833d1999-08-19 00:55:39 +0000326 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
327 newnode = new_attrib_node( GL_POINT_BIT );
328 newnode->data = attr;
329 newnode->next = head;
330 head = newnode;
331 }
332
333 if (mask & GL_POLYGON_BIT) {
334 struct gl_polygon_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000335 attr = MALLOC_STRUCT( gl_polygon_attrib );
jtgafb833d1999-08-19 00:55:39 +0000336 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
337 newnode = new_attrib_node( GL_POLYGON_BIT );
338 newnode->data = attr;
339 newnode->next = head;
340 head = newnode;
341 }
342
343 if (mask & GL_POLYGON_STIPPLE_BIT) {
344 GLuint *stipple;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000345 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +0000346 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
347 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
348 newnode->data = stipple;
349 newnode->next = head;
350 head = newnode;
351 }
352
353 if (mask & GL_SCISSOR_BIT) {
354 struct gl_scissor_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000355 attr = MALLOC_STRUCT( gl_scissor_attrib );
jtgafb833d1999-08-19 00:55:39 +0000356 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
357 newnode = new_attrib_node( GL_SCISSOR_BIT );
358 newnode->data = attr;
359 newnode->next = head;
360 head = newnode;
361 }
362
363 if (mask & GL_STENCIL_BUFFER_BIT) {
364 struct gl_stencil_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000365 attr = MALLOC_STRUCT( gl_stencil_attrib );
jtgafb833d1999-08-19 00:55:39 +0000366 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
367 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
368 newnode->data = attr;
369 newnode->next = head;
370 head = newnode;
371 }
372
373 if (mask & GL_TEXTURE_BIT) {
374 struct gl_texture_attrib *attr;
375 GLuint u;
Brian Paul93de8d32001-04-11 23:22:20 +0000376 /* Bump the texture object reference counts so that they don't
377 * inadvertantly get deleted.
378 */
jtgafb833d1999-08-19 00:55:39 +0000379 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000380 ctx->Texture.Unit[u].Current1D->RefCount++;
381 ctx->Texture.Unit[u].Current2D->RefCount++;
382 ctx->Texture.Unit[u].Current3D->RefCount++;
383 ctx->Texture.Unit[u].CurrentCubeMap->RefCount++;
Brian Paul8afe7de2002-06-15 03:03:06 +0000384 ctx->Texture.Unit[u].CurrentRect->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000385 }
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000386 attr = MALLOC_STRUCT( gl_texture_attrib );
jtgafb833d1999-08-19 00:55:39 +0000387 MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
388 /* copy state of the currently bound texture objects */
389 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
Brian Paula8523782000-11-19 23:10:25 +0000390 copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].Current1D);
391 copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].Current2D);
392 copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].Current3D);
Brian Paul6479a172000-07-05 22:26:43 +0000393 copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap);
Brian Paul8afe7de2002-06-15 03:03:06 +0000394 copy_texobj_state(&attr->Unit[u].SavedRect, attr->Unit[u].CurrentRect);
jtgafb833d1999-08-19 00:55:39 +0000395 }
396 newnode = new_attrib_node( GL_TEXTURE_BIT );
397 newnode->data = attr;
398 newnode->next = head;
399 head = newnode;
400 }
401
402 if (mask & GL_TRANSFORM_BIT) {
403 struct gl_transform_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000404 attr = MALLOC_STRUCT( gl_transform_attrib );
jtgafb833d1999-08-19 00:55:39 +0000405 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
406 newnode = new_attrib_node( GL_TRANSFORM_BIT );
407 newnode->data = attr;
408 newnode->next = head;
409 head = newnode;
410 }
411
412 if (mask & GL_VIEWPORT_BIT) {
413 struct gl_viewport_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000414 attr = MALLOC_STRUCT( gl_viewport_attrib );
jtgafb833d1999-08-19 00:55:39 +0000415 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
416 newnode = new_attrib_node( GL_VIEWPORT_BIT );
417 newnode->data = attr;
418 newnode->next = head;
419 head = newnode;
420 }
421
Brian Paul736fcbe2001-05-29 15:23:48 +0000422 /* GL_ARB_multisample */
423 if (mask & GL_MULTISAMPLE_BIT_ARB) {
424 struct gl_multisample_attrib *attr;
425 attr = MALLOC_STRUCT( gl_multisample_attrib );
426 MEMCPY( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
427 newnode = new_attrib_node( GL_MULTISAMPLE_BIT_ARB );
428 newnode->data = attr;
429 newnode->next = head;
430 head = newnode;
431 }
432
jtgafb833d1999-08-19 00:55:39 +0000433 ctx->AttribStack[ctx->AttribStackDepth] = head;
434 ctx->AttribStackDepth++;
435}
436
437
438
Brian Pauleb6c6432000-09-28 22:44:30 +0000439static void
440pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
441{
442 GLuint i;
443
444#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
445 if ((VALUE) != (NEWVALUE)) { \
446 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
447 }
448
449 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
Brian Pauleb6c6432000-09-28 22:44:30 +0000450 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
451
452 for (i=0;i<MAX_CLIP_PLANES;i++) {
Brian Paul103bc0f2002-03-29 17:27:59 +0000453 const GLuint mask = 1 << i;
454 if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask))
Brian Pauleb6c6432000-09-28 22:44:30 +0000455 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
Brian Paul103bc0f2002-03-29 17:27:59 +0000456 (enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE);
Brian Pauleb6c6432000-09-28 22:44:30 +0000457 }
458
459 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
460 GL_COLOR_MATERIAL);
461 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
462 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
463 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
464 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
465 GL_CONVOLUTION_1D);
466 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D,
467 GL_CONVOLUTION_2D);
468 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D,
469 GL_SEPARABLE_2D);
470 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
471 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
472 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
473 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
474 GL_LINE_STIPPLE);
475 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
476 GL_INDEX_LOGIC_OP);
477 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
478 GL_COLOR_LOGIC_OP);
Brian Paulbc42c192002-01-05 21:53:20 +0000479
Brian Pauleb6c6432000-09-28 22:44:30 +0000480 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
481 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
482 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
483 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
484 GL_MAP1_TEXTURE_COORD_1);
485 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
486 GL_MAP1_TEXTURE_COORD_2);
487 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
488 GL_MAP1_TEXTURE_COORD_3);
489 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
490 GL_MAP1_TEXTURE_COORD_4);
491 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
492 GL_MAP1_VERTEX_3);
493 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
494 GL_MAP1_VERTEX_4);
Brian Paulbc42c192002-01-05 21:53:20 +0000495 for (i = 0; i < 16; i++) {
496 TEST_AND_UPDATE(ctx->Eval.Map1Attrib[i], enable->Map1Attrib[i],
497 GL_MAP1_VERTEX_ATTRIB0_4_NV + i);
498 }
499
Brian Pauleb6c6432000-09-28 22:44:30 +0000500 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
501 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
502 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
503 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
504 GL_MAP2_TEXTURE_COORD_1);
505 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
506 GL_MAP2_TEXTURE_COORD_2);
507 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
508 GL_MAP2_TEXTURE_COORD_3);
509 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
510 GL_MAP2_TEXTURE_COORD_4);
511 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
512 GL_MAP2_VERTEX_3);
513 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
514 GL_MAP2_VERTEX_4);
Brian Paulbc42c192002-01-05 21:53:20 +0000515 for (i = 0; i < 16; i++) {
516 TEST_AND_UPDATE(ctx->Eval.Map2Attrib[i], enable->Map2Attrib[i],
517 GL_MAP2_VERTEX_ATTRIB0_4_NV + i);
518 }
519
Brian Paul8c2f6c52001-06-26 01:32:48 +0000520 TEST_AND_UPDATE(ctx->Eval.AutoNormal, enable->AutoNormal, GL_AUTO_NORMAL);
Brian Pauleb6c6432000-09-28 22:44:30 +0000521 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
522 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
523 GL_RESCALE_NORMAL_EXT);
Brian Paul8c2f6c52001-06-26 01:32:48 +0000524 TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped,
525 enable->RasterPositionUnclipped,
526 GL_RASTER_POSITION_UNCLIPPED_IBM);
Brian Pauleb6c6432000-09-28 22:44:30 +0000527 TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture,
528 GL_POINT_SMOOTH);
529 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
530 GL_POINT_SMOOTH);
Brian Paul6c408b42002-05-27 17:04:52 +0000531 if (ctx->Extensions.NV_point_sprite) {
532 TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite,
533 GL_POINT_SPRITE_NV);
534 }
Brian Pauleb6c6432000-09-28 22:44:30 +0000535 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
536 GL_POLYGON_OFFSET_POINT);
537 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
538 GL_POLYGON_OFFSET_LINE);
539 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
540 GL_POLYGON_OFFSET_FILL);
541 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
542 GL_POLYGON_SMOOTH);
543 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
544 GL_POLYGON_STIPPLE);
545 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
546 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
Brian Paul736fcbe2001-05-29 15:23:48 +0000547 TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled,
548 GL_MULTISAMPLE_ARB);
549 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage,
550 enable->SampleAlphaToCoverage,
551 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
552 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne,
553 enable->SampleAlphaToOne,
554 GL_SAMPLE_ALPHA_TO_ONE_ARB);
555 TEST_AND_UPDATE(ctx->Multisample.SampleCoverage,
556 enable->SampleCoverage,
557 GL_SAMPLE_COVERAGE_ARB);
558 TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
559 enable->SampleCoverageInvert,
560 GL_SAMPLE_COVERAGE_INVERT_ARB);
Brian Paul86b84272001-12-14 02:50:01 +0000561 /* GL_NV_vertex_program */
562 TEST_AND_UPDATE(ctx->VertexProgram.Enabled,
563 enable->VertexProgram,
564 GL_VERTEX_PROGRAM_NV);
565 TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled,
566 enable->VertexProgramPointSize,
567 GL_VERTEX_PROGRAM_POINT_SIZE_NV);
568 TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled,
569 enable->VertexProgramTwoSide,
570 GL_VERTEX_PROGRAM_TWO_SIDE_NV);
571
Brian Pauleb6c6432000-09-28 22:44:30 +0000572#undef TEST_AND_UPDATE
573
574 /* texture unit enables */
575 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
576 if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) {
577 ctx->Texture.Unit[i].Enabled = enable->Texture[i];
578 if (ctx->Driver.Enable) {
579 if (ctx->Driver.ActiveTexture) {
580 (*ctx->Driver.ActiveTexture)(ctx, i);
581 }
582 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000583 (GLboolean) (enable->Texture[i] & TEXTURE_1D_BIT) );
Brian Pauleb6c6432000-09-28 22:44:30 +0000584 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000585 (GLboolean) (enable->Texture[i] & TEXTURE_2D_BIT) );
Brian Pauleb6c6432000-09-28 22:44:30 +0000586 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000587 (GLboolean) (enable->Texture[i] & TEXTURE_3D_BIT) );
588 if (ctx->Extensions.ARB_texture_cube_map)
589 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_CUBE_MAP_ARB,
590 (GLboolean) (enable->Texture[i] & TEXTURE_CUBE_BIT) );
591 if (ctx->Extensions.NV_texture_rectangle)
592 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_RECTANGLE_NV,
593 (GLboolean) (enable->Texture[i] & TEXTURE_RECT_BIT) );
Brian Pauleb6c6432000-09-28 22:44:30 +0000594 }
595 }
596
597 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
598 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
599 if (ctx->Driver.Enable) {
600 if (ctx->Driver.ActiveTexture) {
601 (*ctx->Driver.ActiveTexture)(ctx, i);
602 }
603 if (enable->TexGen[i] & S_BIT)
604 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
605 else
606 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
607 if (enable->TexGen[i] & T_BIT)
608 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
609 else
610 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
611 if (enable->TexGen[i] & R_BIT)
612 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
613 else
614 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
615 if (enable->TexGen[i] & Q_BIT)
616 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
617 else
618 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
619 }
620 }
621 }
622
623 if (ctx->Driver.ActiveTexture) {
624 (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit);
625 }
626}
627
628
Brian Paul93de8d32001-04-11 23:22:20 +0000629static void
630pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
631{
632 GLuint u;
633
Brian Paul93de8d32001-04-11 23:22:20 +0000634 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
635 const struct gl_texture_unit *unit = &texAttrib->Unit[u];
Brian Paul8afe7de2002-06-15 03:03:06 +0000636 GLuint i;
Brian Paul93de8d32001-04-11 23:22:20 +0000637
638 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u);
Brian Paul7c276322001-09-14 21:36:43 +0000639 _mesa_set_enable(ctx, GL_TEXTURE_1D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000640 (GLboolean) (unit->Enabled & TEXTURE_1D_BIT ? GL_TRUE : GL_FALSE));
Brian Paul7c276322001-09-14 21:36:43 +0000641 _mesa_set_enable(ctx, GL_TEXTURE_2D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000642 (GLboolean) (unit->Enabled & TEXTURE_2D_BIT ? GL_TRUE : GL_FALSE));
Brian Paul7c276322001-09-14 21:36:43 +0000643 _mesa_set_enable(ctx, GL_TEXTURE_3D,
Brian Paul8afe7de2002-06-15 03:03:06 +0000644 (GLboolean) (unit->Enabled & TEXTURE_3D_BIT ? GL_TRUE : GL_FALSE));
Brian Paul93de8d32001-04-11 23:22:20 +0000645 if (ctx->Extensions.ARB_texture_cube_map) {
646 _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB,
Brian Paul8afe7de2002-06-15 03:03:06 +0000647 (GLboolean) (unit->Enabled & TEXTURE_CUBE_BIT ? GL_TRUE : GL_FALSE));
648 }
649 if (ctx->Extensions.NV_texture_rectangle) {
650 _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
651 (GLboolean) (unit->Enabled & TEXTURE_RECT_BIT ? GL_TRUE : GL_FALSE));
Brian Paul93de8d32001-04-11 23:22:20 +0000652 }
653 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
654 _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
655 _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenModeS);
656 _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenModeT);
657 _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenModeR);
658 _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenModeQ);
659 _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->ObjectPlaneS);
660 _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->ObjectPlaneT);
661 _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->ObjectPlaneR);
662 _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->ObjectPlaneQ);
663 _mesa_TexGenfv(GL_S, GL_EYE_PLANE, unit->EyePlaneS);
664 _mesa_TexGenfv(GL_T, GL_EYE_PLANE, unit->EyePlaneT);
665 _mesa_TexGenfv(GL_R, GL_EYE_PLANE, unit->EyePlaneR);
666 _mesa_TexGenfv(GL_Q, GL_EYE_PLANE, unit->EyePlaneQ);
667 if (ctx->Extensions.EXT_texture_lod_bias) {
668 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
669 GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias);
670 }
Brian Paulbcfe3932001-04-17 21:25:53 +0000671 if (ctx->Extensions.EXT_texture_env_combine ||
672 ctx->Extensions.ARB_texture_env_combine) {
Brian Paul93de8d32001-04-11 23:22:20 +0000673 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT,
674 unit->CombineModeRGB);
675 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT,
676 unit->CombineModeA);
677 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT,
678 unit->CombineSourceRGB[0]);
679 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT,
680 unit->CombineSourceRGB[1]);
681 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT,
682 unit->CombineSourceRGB[2]);
683 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT,
684 unit->CombineSourceA[0]);
685 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT,
686 unit->CombineSourceA[1]);
687 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT,
688 unit->CombineSourceA[2]);
689 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT,
690 unit->CombineOperandRGB[0]);
691 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT,
692 unit->CombineOperandRGB[1]);
693 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT,
694 unit->CombineOperandRGB[2]);
695 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,
696 unit->CombineOperandA[0]);
697 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,
698 unit->CombineOperandA[1]);
699 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,
700 unit->CombineOperandA[2]);
701 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT,
702 1 << unit->CombineScaleShiftRGB);
703 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE,
704 1 << unit->CombineScaleShiftA);
705 }
706
707 /* Restore texture object state */
Brian Paul8afe7de2002-06-15 03:03:06 +0000708 for (i = 0; i < 5; i++) {
Brian Paul93de8d32001-04-11 23:22:20 +0000709 GLenum target = 0;
710 const struct gl_texture_object *obj = NULL;
711 GLfloat bordColor[4];
712
713 switch (i) {
714 case 0:
715 target = GL_TEXTURE_1D;
716 obj = &unit->Saved1D;
717 break;
718 case 1:
719 target = GL_TEXTURE_2D;
720 obj = &unit->Saved2D;
721 break;
722 case 2:
723 target = GL_TEXTURE_3D;
724 obj = &unit->Saved3D;
725 break;
726 case 3:
Brian Paul8afe7de2002-06-15 03:03:06 +0000727 if (!ctx->Extensions.ARB_texture_cube_map)
728 continue;
Brian Paul93de8d32001-04-11 23:22:20 +0000729 target = GL_TEXTURE_CUBE_MAP_ARB;
730 obj = &unit->SavedCubeMap;
731 break;
Brian Paul8afe7de2002-06-15 03:03:06 +0000732 case 4:
733 if (!ctx->Extensions.NV_texture_rectangle)
734 continue;
735 target = GL_TEXTURE_RECTANGLE_NV;
736 obj = &unit->SavedRect;
737 break;
Brian Paul93de8d32001-04-11 23:22:20 +0000738 default:
739 ; /* silence warnings */
740 }
741
Brian Paul58cfa0f2001-08-07 23:10:55 +0000742 _mesa_BindTexture(target, obj->Name);
743
Brian Paul93de8d32001-04-11 23:22:20 +0000744 bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]);
745 bordColor[1] = CHAN_TO_FLOAT(obj->BorderColor[1]);
746 bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]);
747 bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]);
748
Brian Paul9e351d52001-05-03 14:11:18 +0000749 _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
Brian Paul93de8d32001-04-11 23:22:20 +0000750 _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor);
751 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
752 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
753 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR);
754 _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter);
755 _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter);
756 _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
757 _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
758 _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
759 _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
760 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
761 _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
762 obj->MaxAnisotropy);
763 }
764 if (ctx->Extensions.SGIX_shadow) {
765 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_SGIX,
766 obj->CompareFlag);
767 _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_OPERATOR_SGIX,
768 obj->CompareOperator);
769 }
770 if (ctx->Extensions.SGIX_shadow_ambient) {
Brian Paul9e351d52001-05-03 14:11:18 +0000771 _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX,
Brian Paul93de8d32001-04-11 23:22:20 +0000772 CHAN_TO_FLOAT(obj->ShadowAmbient));
773 }
774
775 }
776 }
777 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
778 + texAttrib->CurrentUnit);
Brian Paul58cfa0f2001-08-07 23:10:55 +0000779
780 /* "un-bump" the texture object reference counts. We did that so they
781 * wouldn't inadvertantly get deleted while they were still referenced
782 * inside the attribute state stack.
783 */
784 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
785 ctx->Texture.Unit[u].Current1D->RefCount--;
786 ctx->Texture.Unit[u].Current2D->RefCount--;
787 ctx->Texture.Unit[u].Current3D->RefCount--;
788 ctx->Texture.Unit[u].CurrentCubeMap->RefCount--;
Brian Paul8afe7de2002-06-15 03:03:06 +0000789 ctx->Texture.Unit[u].CurrentRect->RefCount--;
Brian Paul58cfa0f2001-08-07 23:10:55 +0000790 }
Brian Paul93de8d32001-04-11 23:22:20 +0000791}
792
Brian Pauleb6c6432000-09-28 22:44:30 +0000793
jtgafb833d1999-08-19 00:55:39 +0000794/*
795 * This function is kind of long just because we have to call a lot
796 * of device driver functions to update device driver state.
Brian Paulf3da3892001-01-24 15:27:10 +0000797 *
798 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
799 * in order to restore GL state. This isn't terribly efficient but it
800 * ensures that dirty flags and any derived state gets updated correctly.
801 * We could at least check if the value to restore equals the current value
802 * and then skip the Mesa call.
jtgafb833d1999-08-19 00:55:39 +0000803 */
Brian Paul42fcf032000-02-02 22:03:31 +0000804void
805_mesa_PopAttrib(void)
jtgafb833d1999-08-19 00:55:39 +0000806{
807 struct gl_attrib_node *attr, *next;
Brian Paul42fcf032000-02-02 22:03:31 +0000808 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000809 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +0000810
Brian Paulf3da3892001-01-24 15:27:10 +0000811 if (ctx->AttribStackDepth == 0) {
Brian Paul08836342001-03-03 20:33:27 +0000812 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
jtgafb833d1999-08-19 00:55:39 +0000813 return;
814 }
815
816 ctx->AttribStackDepth--;
817 attr = ctx->AttribStack[ctx->AttribStackDepth];
818
819 while (attr) {
820
Brian Paul9a33a112002-06-13 04:28:29 +0000821 if (MESA_VERBOSE & VERBOSE_API) {
Brian Paul4753d602002-06-15 02:38:15 +0000822 _mesa_debug(ctx, "glPopAttrib %s\n",
823 _mesa_lookup_enum_by_nr(attr->kind));
Brian Paul93de8d32001-04-11 23:22:20 +0000824 }
jtgafb833d1999-08-19 00:55:39 +0000825
826 switch (attr->kind) {
827 case GL_ACCUM_BUFFER_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000828 {
829 const struct gl_accum_attrib *accum;
830 accum = (const struct gl_accum_attrib *) attr->data;
831 _mesa_ClearAccum(accum->ClearColor[0],
832 accum->ClearColor[1],
833 accum->ClearColor[2],
834 accum->ClearColor[3]);
835 }
jtgafb833d1999-08-19 00:55:39 +0000836 break;
837 case GL_COLOR_BUFFER_BIT:
838 {
Brian Paulf3da3892001-01-24 15:27:10 +0000839 const struct gl_colorbuffer_attrib *color;
840 color = (const struct gl_colorbuffer_attrib *) attr->data;
Brian Paul7c276322001-09-14 21:36:43 +0000841 _mesa_ClearIndex((GLfloat) color->ClearIndex);
Brian Paulf3da3892001-01-24 15:27:10 +0000842 _mesa_ClearColor(CHAN_TO_FLOAT(color->ClearColor[0]),
843 CHAN_TO_FLOAT(color->ClearColor[1]),
844 CHAN_TO_FLOAT(color->ClearColor[2]),
845 CHAN_TO_FLOAT(color->ClearColor[3]));
846 _mesa_IndexMask(color->IndexMask);
847 _mesa_ColorMask((GLboolean) (color->ColorMask[0] != 0),
848 (GLboolean) (color->ColorMask[1] != 0),
849 (GLboolean) (color->ColorMask[2] != 0),
850 (GLboolean) (color->ColorMask[3] != 0));
851 _mesa_DrawBuffer(color->DrawBuffer);
852 _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
853 _mesa_AlphaFunc(color->AlphaFunc,
854 CHAN_TO_FLOAT(color->AlphaRef));
855 _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled);
856 _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB,
857 color->BlendDstRGB,
858 color->BlendSrcA,
859 color->BlendDstA);
860 _mesa_BlendEquation(color->BlendEquation);
861 _mesa_BlendColor(color->BlendColor[0],
862 color->BlendColor[1],
863 color->BlendColor[2],
864 color->BlendColor[3]);
865 _mesa_LogicOp(color->LogicOp);
866 _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP,
867 color->ColorLogicOpEnabled);
868 _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP,
869 color->IndexLogicOpEnabled);
870 _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag);
jtgafb833d1999-08-19 00:55:39 +0000871 }
872 break;
873 case GL_CURRENT_BIT:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000874 FLUSH_CURRENT( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +0000875 MEMCPY( &ctx->Current, attr->data,
876 sizeof(struct gl_current_attrib) );
877 break;
878 case GL_DEPTH_BUFFER_BIT:
879 {
Brian Paulf3da3892001-01-24 15:27:10 +0000880 const struct gl_depthbuffer_attrib *depth;
881 depth = (const struct gl_depthbuffer_attrib *) attr->data;
882 _mesa_DepthFunc(depth->Func);
883 _mesa_ClearDepth(depth->Clear);
884 _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test);
885 _mesa_DepthMask(depth->Mask);
886 if (ctx->Extensions.HP_occlusion_test)
887 _mesa_set_enable(ctx, GL_OCCLUSION_TEST_HP,
888 depth->OcclusionTest);
jtgafb833d1999-08-19 00:55:39 +0000889 }
890 break;
891 case GL_ENABLE_BIT:
892 {
893 const struct gl_enable_attrib *enable;
894 enable = (const struct gl_enable_attrib *) attr->data;
Brian Pauleb6c6432000-09-28 22:44:30 +0000895 pop_enable_group(ctx, enable);
Keith Whitwella96308c2000-10-30 13:31:59 +0000896 ctx->NewState |= _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +0000897 }
898 break;
899 case GL_EVAL_BIT:
900 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +0000901 ctx->NewState |= _NEW_EVAL;
jtgafb833d1999-08-19 00:55:39 +0000902 break;
903 case GL_FOG_BIT:
904 {
Brian Paulf3da3892001-01-24 15:27:10 +0000905 const struct gl_fog_attrib *fog;
906 fog = (const struct gl_fog_attrib *) attr->data;
907 _mesa_set_enable(ctx, GL_FOG, fog->Enabled);
908 _mesa_Fogfv(GL_FOG_COLOR, fog->Color);
909 _mesa_Fogf(GL_FOG_DENSITY, fog->Density);
910 _mesa_Fogf(GL_FOG_START, fog->Start);
911 _mesa_Fogf(GL_FOG_END, fog->End);
912 _mesa_Fogf(GL_FOG_INDEX, fog->Index);
913 _mesa_Fogi(GL_FOG_MODE, fog->Mode);
jtgafb833d1999-08-19 00:55:39 +0000914 }
915 break;
916 case GL_HINT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000917 {
918 const struct gl_hint_attrib *hint;
919 hint = (const struct gl_hint_attrib *) attr->data;
Brian Paulf3da3892001-01-24 15:27:10 +0000920 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT,
921 hint->PerspectiveCorrection );
922 _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth);
923 _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth);
924 _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth);
925 _mesa_Hint(GL_FOG_HINT, hint->Fog);
926 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,
927 hint->ClipVolumeClipping);
928 if (ctx->Extensions.ARB_texture_compression)
929 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB,
930 hint->TextureCompression);
jtgafb833d1999-08-19 00:55:39 +0000931 }
932 break;
933 case GL_LIGHTING_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000934 {
jtgafb833d1999-08-19 00:55:39 +0000935 GLuint i;
Brian Paulf3da3892001-01-24 15:27:10 +0000936 const struct gl_light_attrib *light;
937 light = (const struct gl_light_attrib *) attr->data;
938 /* lighting enable */
939 _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled);
940 /* per-light state */
Keith Whitwell0cb28412002-02-13 00:53:19 +0000941
942 if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY_INVERSE)
943 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
944
jtgafb833d1999-08-19 00:55:39 +0000945 for (i = 0; i < MAX_LIGHTS; i++) {
Brian Paulf3da3892001-01-24 15:27:10 +0000946 GLenum lgt = (GLenum) (GL_LIGHT0 + i);
Keith Whitwell0cb28412002-02-13 00:53:19 +0000947 const struct gl_light *l = &light->Light[i];
948 GLfloat tmp[4];
949 _mesa_set_enable(ctx, lgt, l->Enabled);
950 _mesa_Lightfv( lgt, GL_AMBIENT, l->Ambient );
951 _mesa_Lightfv( lgt, GL_DIFFUSE, l->Diffuse );
952 _mesa_Lightfv( lgt, GL_SPECULAR, l->Specular );
953 TRANSFORM_POINT( tmp, ctx->ModelviewMatrixStack.Top->inv, l->EyePosition );
954 _mesa_Lightfv( lgt, GL_POSITION, tmp );
955 TRANSFORM_POINT( tmp, ctx->ModelviewMatrixStack.Top->m, l->EyeDirection );
956 _mesa_Lightfv( lgt, GL_SPOT_DIRECTION, tmp );
957 _mesa_Lightfv( lgt, GL_SPOT_EXPONENT, &l->SpotExponent );
958 _mesa_Lightfv( lgt, GL_SPOT_CUTOFF, &l->SpotCutoff );
959 _mesa_Lightfv( lgt, GL_CONSTANT_ATTENUATION,
960 &l->ConstantAttenuation );
961 _mesa_Lightfv( lgt, GL_LINEAR_ATTENUATION,
962 &l->LinearAttenuation );
963 _mesa_Lightfv( lgt, GL_QUADRATIC_ATTENUATION,
964 &l->QuadraticAttenuation );
jtgafb833d1999-08-19 00:55:39 +0000965 }
Brian Paulf3da3892001-01-24 15:27:10 +0000966 /* light model */
967 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT,
968 light->Model.Ambient);
969 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,
970 (GLfloat) light->Model.LocalViewer);
971 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE,
972 (GLfloat) light->Model.TwoSide);
973 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
974 (GLfloat) light->Model.ColorControl);
975 /* materials */
976 MEMCPY(ctx->Light.Material, light->Material,
977 2 * sizeof(struct gl_material));
978 /* shade model */
Brian Paulba70e592001-01-29 22:15:44 +0000979 _mesa_ShadeModel(light->ShadeModel);
Brian Paulf3da3892001-01-24 15:27:10 +0000980 /* color material */
981 _mesa_ColorMaterial(light->ColorMaterialFace,
982 light->ColorMaterialMode);
983 _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
984 light->ColorMaterialEnabled);
jtgafb833d1999-08-19 00:55:39 +0000985 }
jtgafb833d1999-08-19 00:55:39 +0000986 break;
987 case GL_LINE_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +0000988 {
989 const struct gl_line_attrib *line;
990 line = (const struct gl_line_attrib *) attr->data;
991 _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag);
992 _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag);
993 _mesa_LineStipple(line->StippleFactor, line->StipplePattern);
994 _mesa_LineWidth(line->Width);
jtgafb833d1999-08-19 00:55:39 +0000995 }
996 break;
997 case GL_LIST_BIT:
998 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
999 break;
1000 case GL_PIXEL_MODE_BIT:
1001 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
Keith Whitwella96308c2000-10-30 13:31:59 +00001002 ctx->NewState |= _NEW_PIXEL;
jtgafb833d1999-08-19 00:55:39 +00001003 break;
1004 case GL_POINT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001005 {
1006 const struct gl_point_attrib *point;
1007 point = (const struct gl_point_attrib *) attr->data;
1008 _mesa_PointSize(point->Size);
1009 _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
1010 _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
1011 point->Params);
1012 _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT, point->MinSize);
1013 _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT, point->MaxSize);
1014 _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
1015 point->Threshold);
Brian Paul6c408b42002-05-27 17:04:52 +00001016 if (ctx->Extensions.NV_point_sprite) {
1017 GLuint u;
1018 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
1019 _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
1020 (GLint) point->CoordReplace[u]);
1021 }
1022 _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
1023 _mesa_PointParameteriNV(GL_POINT_SPRITE_R_MODE_NV,
1024 ctx->Point.SpriteRMode);
1025 }
Brian Paulf3da3892001-01-24 15:27:10 +00001026 }
jtgafb833d1999-08-19 00:55:39 +00001027 break;
1028 case GL_POLYGON_BIT:
1029 {
Brian Paulf3da3892001-01-24 15:27:10 +00001030 const struct gl_polygon_attrib *polygon;
1031 polygon = (const struct gl_polygon_attrib *) attr->data;
1032 _mesa_CullFace(polygon->CullFaceMode);
1033 _mesa_FrontFace(polygon->FrontFace);
1034 _mesa_PolygonMode(GL_FRONT, polygon->FrontMode);
1035 _mesa_PolygonMode(GL_BACK, polygon->BackMode);
1036 _mesa_PolygonOffset(polygon->OffsetFactor,
1037 polygon->OffsetUnits);
1038 _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag);
1039 _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag);
1040 _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag);
1041 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT,
1042 polygon->OffsetPoint);
1043 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE,
1044 polygon->OffsetLine);
1045 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL,
1046 polygon->OffsetFill);
jtgafb833d1999-08-19 00:55:39 +00001047 }
1048 break;
1049 case GL_POLYGON_STIPPLE_BIT:
1050 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
Keith Whitwella96308c2000-10-30 13:31:59 +00001051 ctx->NewState |= _NEW_POLYGONSTIPPLE;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001052 if (ctx->Driver.PolygonStipple)
Brian Paul959f8022000-03-19 01:10:11 +00001053 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
jtgafb833d1999-08-19 00:55:39 +00001054 break;
1055 case GL_SCISSOR_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001056 {
1057 const struct gl_scissor_attrib *scissor;
1058 scissor = (const struct gl_scissor_attrib *) attr->data;
1059 _mesa_Scissor(scissor->X, scissor->Y,
1060 scissor->Width, scissor->Height);
1061 _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled);
1062 }
jtgafb833d1999-08-19 00:55:39 +00001063 break;
1064 case GL_STENCIL_BUFFER_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001065 {
1066 const struct gl_stencil_attrib *stencil;
1067 stencil = (const struct gl_stencil_attrib *) attr->data;
1068 _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
1069 _mesa_ClearStencil(stencil->Clear);
1070 _mesa_StencilFunc(stencil->Function, stencil->Ref,
1071 stencil->ValueMask);
1072 _mesa_StencilMask(stencil->WriteMask);
1073 _mesa_StencilOp(stencil->FailFunc, stencil->ZFailFunc,
1074 stencil->ZPassFunc);
1075 }
jtgafb833d1999-08-19 00:55:39 +00001076 break;
1077 case GL_TRANSFORM_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001078 {
1079 GLuint i;
1080 const struct gl_transform_attrib *xform;
1081 xform = (const struct gl_transform_attrib *) attr->data;
1082 _mesa_MatrixMode(xform->MatrixMode);
Brian Paul934bee02002-03-28 22:42:41 +00001083
1084 if (ctx->ProjectionMatrixStack.Top->flags & MAT_DIRTY)
1085 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
1086
1087 /* restore clip planes */
Brian Paulf3da3892001-01-24 15:27:10 +00001088 for (i = 0; i < MAX_CLIP_PLANES; i++) {
Brian Paul103bc0f2002-03-29 17:27:59 +00001089 const GLuint mask = 1 << 1;
Brian Paul934bee02002-03-28 22:42:41 +00001090 const GLfloat *eyePlane = xform->EyeUserPlane[i];
1091 COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane);
Brian Paul103bc0f2002-03-29 17:27:59 +00001092 if (xform->ClipPlanesEnabled & mask) {
Brian Paul934bee02002-03-28 22:42:41 +00001093 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
1094 }
1095 else {
1096 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
1097 }
1098 if (ctx->Driver.ClipPlane)
Brian Paul4753d602002-06-15 02:38:15 +00001099 ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, eyePlane );
Brian Paulf3da3892001-01-24 15:27:10 +00001100 }
Brian Paul934bee02002-03-28 22:42:41 +00001101
Brian Paulf3da3892001-01-24 15:27:10 +00001102 /* normalize/rescale */
Brian Paul86a7cc62002-04-01 17:03:38 +00001103 if (xform->Normalize != ctx->Transform.Normalize)
1104 _mesa_set_enable(ctx, GL_NORMALIZE,ctx->Transform.Normalize);
1105 if (xform->RescaleNormals != ctx->Transform.RescaleNormals)
1106 _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
1107 ctx->Transform.RescaleNormals);
jtgafb833d1999-08-19 00:55:39 +00001108 }
jtgafb833d1999-08-19 00:55:39 +00001109 break;
1110 case GL_TEXTURE_BIT:
1111 /* Take care of texture object reference counters */
1112 {
Brian Paul93de8d32001-04-11 23:22:20 +00001113 const struct gl_texture_attrib *texture;
1114 texture = (const struct gl_texture_attrib *) attr->data;
1115 pop_texture_group(ctx, texture);
Keith Whitwella96308c2000-10-30 13:31:59 +00001116 ctx->NewState |= _NEW_TEXTURE;
jtgafb833d1999-08-19 00:55:39 +00001117 }
1118 break;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001119 case GL_VIEWPORT_BIT:
Brian Paulf3da3892001-01-24 15:27:10 +00001120 {
1121 const struct gl_viewport_attrib *vp;
Brian Paul736fcbe2001-05-29 15:23:48 +00001122 vp = (const struct gl_viewport_attrib *) attr->data;
Brian Paulf3da3892001-01-24 15:27:10 +00001123 _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height);
1124 _mesa_DepthRange(vp->Near, vp->Far);
1125 }
1126 break;
Brian Paul736fcbe2001-05-29 15:23:48 +00001127 case GL_MULTISAMPLE_BIT_ARB:
1128 {
1129 const struct gl_multisample_attrib *ms;
1130 ms = (const struct gl_multisample_attrib *) attr->data;
1131 _mesa_SampleCoverageARB(ms->SampleCoverageValue,
1132 ms->SampleCoverageInvert);
1133 }
1134 break;
1135
jtgafb833d1999-08-19 00:55:39 +00001136 default:
Brian Paul08836342001-03-03 20:33:27 +00001137 _mesa_problem( ctx, "Bad attrib flag in PopAttrib");
jtgafb833d1999-08-19 00:55:39 +00001138 break;
1139 }
1140
1141 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001142 FREE( attr->data );
1143 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +00001144 attr = next;
1145 }
jtgafb833d1999-08-19 00:55:39 +00001146}
1147
1148
1149#define GL_CLIENT_PACK_BIT (1<<20)
1150#define GL_CLIENT_UNPACK_BIT (1<<21)
1151
1152
Brian Paul42fcf032000-02-02 22:03:31 +00001153void
1154_mesa_PushClientAttrib(GLbitfield mask)
jtgafb833d1999-08-19 00:55:39 +00001155{
1156 struct gl_attrib_node *newnode;
1157 struct gl_attrib_node *head;
1158
Brian Paul42fcf032000-02-02 22:03:31 +00001159 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001160 ASSERT_OUTSIDE_BEGIN_END(ctx);
jtgafb833d1999-08-19 00:55:39 +00001161
Brian Paulf3da3892001-01-24 15:27:10 +00001162 if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
Brian Paul08836342001-03-03 20:33:27 +00001163 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
jtgafb833d1999-08-19 00:55:39 +00001164 return;
1165 }
1166
1167 /* Build linked list of attribute nodes which save all attribute */
1168 /* groups specified by the mask. */
1169 head = NULL;
1170
1171 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
1172 struct gl_pixelstore_attrib *attr;
1173 /* packing attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001174 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +00001175 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
1176 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
1177 newnode->data = attr;
1178 newnode->next = head;
1179 head = newnode;
1180 /* unpacking attribs */
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001181 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
jtgafb833d1999-08-19 00:55:39 +00001182 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
1183 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
1184 newnode->data = attr;
1185 newnode->next = head;
1186 head = newnode;
1187 }
1188 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
1189 struct gl_array_attrib *attr;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001190 attr = MALLOC_STRUCT( gl_array_attrib );
jtgafb833d1999-08-19 00:55:39 +00001191 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
1192 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
1193 newnode->data = attr;
1194 newnode->next = head;
1195 head = newnode;
1196 }
1197
1198 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
1199 ctx->ClientAttribStackDepth++;
1200}
1201
1202
1203
1204
Brian Paul42fcf032000-02-02 22:03:31 +00001205void
1206_mesa_PopClientAttrib(void)
jtgafb833d1999-08-19 00:55:39 +00001207{
1208 struct gl_attrib_node *attr, *next;
1209
Brian Paul42fcf032000-02-02 22:03:31 +00001210 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001211 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +00001212
Brian Paulf3da3892001-01-24 15:27:10 +00001213 if (ctx->ClientAttribStackDepth == 0) {
Brian Paul08836342001-03-03 20:33:27 +00001214 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
jtgafb833d1999-08-19 00:55:39 +00001215 return;
1216 }
1217
1218 ctx->ClientAttribStackDepth--;
1219 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
1220
1221 while (attr) {
1222 switch (attr->kind) {
1223 case GL_CLIENT_PACK_BIT:
1224 MEMCPY( &ctx->Pack, attr->data,
1225 sizeof(struct gl_pixelstore_attrib) );
Brian Paulebc9f222001-08-07 21:46:52 +00001226 ctx->NewState |= _NEW_PACKUNPACK;
jtgafb833d1999-08-19 00:55:39 +00001227 break;
1228 case GL_CLIENT_UNPACK_BIT:
1229 MEMCPY( &ctx->Unpack, attr->data,
1230 sizeof(struct gl_pixelstore_attrib) );
Brian Paulebc9f222001-08-07 21:46:52 +00001231 ctx->NewState |= _NEW_PACKUNPACK;
jtgafb833d1999-08-19 00:55:39 +00001232 break;
1233 case GL_CLIENT_VERTEX_ARRAY_BIT:
1234 MEMCPY( &ctx->Array, attr->data,
1235 sizeof(struct gl_array_attrib) );
Brian Paulebc9f222001-08-07 21:46:52 +00001236 ctx->NewState |= _NEW_ARRAY;
jtgafb833d1999-08-19 00:55:39 +00001237 break;
1238 default:
Brian Paul08836342001-03-03 20:33:27 +00001239 _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
jtgafb833d1999-08-19 00:55:39 +00001240 break;
1241 }
1242
1243 next = attr->next;
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001244 FREE( attr->data );
1245 FREE( attr );
jtgafb833d1999-08-19 00:55:39 +00001246 attr = next;
1247 }
jtgafb833d1999-08-19 00:55:39 +00001248}