blob: 527cd2d8bb7fe66f1c3e9a3f224eb22951935b9c [file] [log] [blame]
Keith Whitwelle3f37861999-09-16 11:54:56 +00001/* $Id: attrib.c,v 1.2 1999/09/16 11:54:56 keithw Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28
29
30
31#ifdef PC_HEADER
32#include "all.h"
33#else
34#include <stdlib.h>
35#include <stdio.h>
36#include <string.h>
37#include "attrib.h"
38#include "context.h"
39#include "enable.h"
40#include "enums.h"
41#include "macros.h"
42#include "misc.h"
43#include "simple_list.h"
44#include "texstate.h"
45#include "types.h"
46#ifdef XFree86Server
47#undef MISC_H
48#include "GL/xf86glx.h"
49#endif
50#endif
51
52
53#define MALLOC_STRUCT(T) (struct T *) malloc( sizeof(struct T) )
54
55
56
57/*
58 * Allocate a new attribute state node. These nodes have a
59 * "kind" value and a pointer to a struct of state data.
60 */
61static struct gl_attrib_node *new_attrib_node( GLbitfield kind )
62{
63 struct gl_attrib_node *an;
64
65 an = (struct gl_attrib_node *) malloc( sizeof(struct gl_attrib_node) );
66 if (an) {
67 an->kind = kind;
68 }
69 return an;
70}
71
72
73
74/*
75 * Copy texture object state from one texture object to another.
76 */
77static void copy_texobj_state( struct gl_texture_object *dest,
78 const struct gl_texture_object *src )
79{
80 /*
81 dest->Name = src->Name;
82 dest->Dimensions = src->Dimensions;
83 */
84 dest->Priority = src->Priority;
85 dest->BorderColor[0] = src->BorderColor[0];
86 dest->BorderColor[1] = src->BorderColor[1];
87 dest->BorderColor[2] = src->BorderColor[2];
88 dest->BorderColor[3] = src->BorderColor[3];
89 dest->WrapS = src->WrapS;
90 dest->WrapT = src->WrapT;
91 dest->WrapR = src->WrapR;
92 dest->MinFilter = src->MinFilter;
93 dest->MagFilter = src->MagFilter;
94 dest->MinLod = src->MinLod;
95 dest->MaxLod = src->MaxLod;
96 dest->BaseLevel = src->BaseLevel;
97 dest->MaxLevel = src->MaxLevel;
98 dest->P = src->P;
99 dest->M = src->M;
100 dest->MinMagThresh = src->MinMagThresh;
101 memcpy( dest->Palette, src->Palette,
102 sizeof(GLubyte) * MAX_TEXTURE_PALETTE_SIZE * 4 );
103 dest->PaletteSize = src->PaletteSize;
104 dest->PaletteIntFormat = src->PaletteIntFormat;
105 dest->PaletteFormat = src->PaletteFormat;
106 dest->Complete = src->Complete;
107 dest->SampleFunc = src->SampleFunc;
108}
109
110
111
112void gl_PushAttrib( GLcontext* ctx, GLbitfield mask )
113{
114 struct gl_attrib_node *newnode;
115 struct gl_attrib_node *head;
116
117 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
118
119 if (MESA_VERBOSE&VERBOSE_API)
120 fprintf(stderr, "glPushAttrib %x\n", mask);
121
122 if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
123 gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
124 return;
125 }
126
127 /* Build linked list of attribute nodes which save all attribute */
128 /* groups specified by the mask. */
129 head = NULL;
130
131 if (mask & GL_ACCUM_BUFFER_BIT) {
132 struct gl_accum_attrib *attr;
133 attr = MALLOC_STRUCT( gl_accum_attrib );
134 MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
135 newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
136 newnode->data = attr;
137 newnode->next = head;
138 head = newnode;
139 }
140
141 if (mask & GL_COLOR_BUFFER_BIT) {
142 struct gl_colorbuffer_attrib *attr;
143 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
144 MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
145 newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
146 newnode->data = attr;
147 newnode->next = head;
148 head = newnode;
149 }
150
151 if (mask & GL_CURRENT_BIT) {
152 struct gl_current_attrib *attr;
153 attr = MALLOC_STRUCT( gl_current_attrib );
154 MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
155 newnode = new_attrib_node( GL_CURRENT_BIT );
156 newnode->data = attr;
157 newnode->next = head;
158 head = newnode;
159 }
160
161 if (mask & GL_DEPTH_BUFFER_BIT) {
162 struct gl_depthbuffer_attrib *attr;
163 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
164 MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
165 newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
166 newnode->data = attr;
167 newnode->next = head;
168 head = newnode;
169 }
170
171 if (mask & GL_ENABLE_BIT) {
172 struct gl_enable_attrib *attr;
173 GLuint i;
174 attr = MALLOC_STRUCT( gl_enable_attrib );
175 /* Copy enable flags from all other attributes into the enable struct. */
176 attr->AlphaTest = ctx->Color.AlphaEnabled;
177 attr->AutoNormal = ctx->Eval.AutoNormal;
178 attr->Blend = ctx->Color.BlendEnabled;
179 for (i=0;i<MAX_CLIP_PLANES;i++) {
180 attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
181 }
182 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
183 attr->CullFace = ctx->Polygon.CullFlag;
184 attr->DepthTest = ctx->Depth.Test;
185 attr->Dither = ctx->Color.DitherFlag;
186 attr->Fog = ctx->Fog.Enabled;
187 for (i=0;i<MAX_LIGHTS;i++) {
188 attr->Light[i] = ctx->Light.Light[i].Enabled;
189 }
190 attr->Lighting = ctx->Light.Enabled;
191 attr->LineSmooth = ctx->Line.SmoothFlag;
192 attr->LineStipple = ctx->Line.StippleFlag;
193 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
194 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
195 attr->Map1Color4 = ctx->Eval.Map1Color4;
196 attr->Map1Index = ctx->Eval.Map1Index;
197 attr->Map1Normal = ctx->Eval.Map1Normal;
198 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
199 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
200 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
201 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
202 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
203 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
204 attr->Map2Color4 = ctx->Eval.Map2Color4;
205 attr->Map2Index = ctx->Eval.Map2Index;
206 attr->Map2Normal = ctx->Eval.Map2Normal;
207 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
208 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
209 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
210 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
211 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
212 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
213 attr->Normalize = ctx->Transform.Normalize;
214 attr->PointSmooth = ctx->Point.SmoothFlag;
215 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
216 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
217 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
218 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
219 attr->PolygonStipple = ctx->Polygon.StippleFlag;
220 attr->RescaleNormals = ctx->Transform.RescaleNormals;
221 attr->Scissor = ctx->Scissor.Enabled;
222 attr->Stencil = ctx->Stencil.Enabled;
223 attr->Texture = ctx->Texture.Enabled;
224 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
225 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
226 }
227 newnode = new_attrib_node( GL_ENABLE_BIT );
228 newnode->data = attr;
229 newnode->next = head;
230 head = newnode;
231 }
232
233 if (mask & GL_EVAL_BIT) {
234 struct gl_eval_attrib *attr;
235 attr = MALLOC_STRUCT( gl_eval_attrib );
236 MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
237 newnode = new_attrib_node( GL_EVAL_BIT );
238 newnode->data = attr;
239 newnode->next = head;
240 head = newnode;
241 }
242
243 if (mask & GL_FOG_BIT) {
244 struct gl_fog_attrib *attr;
245 attr = MALLOC_STRUCT( gl_fog_attrib );
246 MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
247 newnode = new_attrib_node( GL_FOG_BIT );
248 newnode->data = attr;
249 newnode->next = head;
250 head = newnode;
251 }
252
253 if (mask & GL_HINT_BIT) {
254 struct gl_hint_attrib *attr;
255 attr = MALLOC_STRUCT( gl_hint_attrib );
256 MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
257 newnode = new_attrib_node( GL_HINT_BIT );
258 newnode->data = attr;
259 newnode->next = head;
260 head = newnode;
261 }
262
263 if (mask & GL_LIGHTING_BIT) {
264 struct gl_light_attrib *attr;
265 attr = MALLOC_STRUCT( gl_light_attrib );
266 MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
267 newnode = new_attrib_node( GL_LIGHTING_BIT );
268 newnode->data = attr;
269 newnode->next = head;
270 head = newnode;
271 }
272
273 if (mask & GL_LINE_BIT) {
274 struct gl_line_attrib *attr;
275 attr = MALLOC_STRUCT( gl_line_attrib );
276 MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
277 newnode = new_attrib_node( GL_LINE_BIT );
278 newnode->data = attr;
279 newnode->next = head;
280 head = newnode;
281 }
282
283 if (mask & GL_LIST_BIT) {
284 struct gl_list_attrib *attr;
285 attr = MALLOC_STRUCT( gl_list_attrib );
286 MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
287 newnode = new_attrib_node( GL_LIST_BIT );
288 newnode->data = attr;
289 newnode->next = head;
290 head = newnode;
291 }
292
293 if (mask & GL_PIXEL_MODE_BIT) {
294 struct gl_pixel_attrib *attr;
295 attr = MALLOC_STRUCT( gl_pixel_attrib );
296 MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
297 newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
298 newnode->data = attr;
299 newnode->next = head;
300 head = newnode;
301 }
302
303 if (mask & GL_POINT_BIT) {
304 struct gl_point_attrib *attr;
305 attr = MALLOC_STRUCT( gl_point_attrib );
306 MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
307 newnode = new_attrib_node( GL_POINT_BIT );
308 newnode->data = attr;
309 newnode->next = head;
310 head = newnode;
311 }
312
313 if (mask & GL_POLYGON_BIT) {
314 struct gl_polygon_attrib *attr;
315 attr = MALLOC_STRUCT( gl_polygon_attrib );
316 MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
317 newnode = new_attrib_node( GL_POLYGON_BIT );
318 newnode->data = attr;
319 newnode->next = head;
320 head = newnode;
321 }
322
323 if (mask & GL_POLYGON_STIPPLE_BIT) {
324 GLuint *stipple;
325 stipple = (GLuint *) malloc( 32*sizeof(GLuint) );
326 MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
327 newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
328 newnode->data = stipple;
329 newnode->next = head;
330 head = newnode;
331 }
332
333 if (mask & GL_SCISSOR_BIT) {
334 struct gl_scissor_attrib *attr;
335 attr = MALLOC_STRUCT( gl_scissor_attrib );
336 MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
337 newnode = new_attrib_node( GL_SCISSOR_BIT );
338 newnode->data = attr;
339 newnode->next = head;
340 head = newnode;
341 }
342
343 if (mask & GL_STENCIL_BUFFER_BIT) {
344 struct gl_stencil_attrib *attr;
345 attr = MALLOC_STRUCT( gl_stencil_attrib );
346 MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
347 newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
348 newnode->data = attr;
349 newnode->next = head;
350 head = newnode;
351 }
352
353 if (mask & GL_TEXTURE_BIT) {
354 struct gl_texture_attrib *attr;
355 GLuint u;
356 /* Take care of texture object reference counters */
357 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
358 ctx->Texture.Unit[u].CurrentD[1]->RefCount++;
359 ctx->Texture.Unit[u].CurrentD[2]->RefCount++;
360 ctx->Texture.Unit[u].CurrentD[3]->RefCount++;
361 }
362 attr = MALLOC_STRUCT( gl_texture_attrib );
363 MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
364 /* copy state of the currently bound texture objects */
365 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
366 copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]);
367 copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]);
368 copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]);
369 }
370 newnode = new_attrib_node( GL_TEXTURE_BIT );
371 newnode->data = attr;
372 newnode->next = head;
373 head = newnode;
374 }
375
376 if (mask & GL_TRANSFORM_BIT) {
377 struct gl_transform_attrib *attr;
378 attr = MALLOC_STRUCT( gl_transform_attrib );
379 MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
380 newnode = new_attrib_node( GL_TRANSFORM_BIT );
381 newnode->data = attr;
382 newnode->next = head;
383 head = newnode;
384 }
385
386 if (mask & GL_VIEWPORT_BIT) {
387 struct gl_viewport_attrib *attr;
388 attr = MALLOC_STRUCT( gl_viewport_attrib );
389 MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
390 newnode = new_attrib_node( GL_VIEWPORT_BIT );
391 newnode->data = attr;
392 newnode->next = head;
393 head = newnode;
394 }
395
396 ctx->AttribStack[ctx->AttribStackDepth] = head;
397 ctx->AttribStackDepth++;
398}
399
400
401
402/*
403 * This function is kind of long just because we have to call a lot
404 * of device driver functions to update device driver state.
405 */
406void gl_PopAttrib( GLcontext* ctx )
407{
408 struct gl_attrib_node *attr, *next;
409
410 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
411
412
413 if (ctx->AttribStackDepth==0) {
414 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
415 return;
416 }
417
418 ctx->AttribStackDepth--;
419 attr = ctx->AttribStack[ctx->AttribStackDepth];
420
421 while (attr) {
422
423 if (MESA_VERBOSE&VERBOSE_API)
424 fprintf(stderr, "glPopAttrib %s\n", gl_lookup_enum_by_nr(attr->kind));
425
426 switch (attr->kind) {
427 case GL_ACCUM_BUFFER_BIT:
428 MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
429 break;
430 case GL_COLOR_BUFFER_BIT:
431 {
432 GLenum oldDrawBuffer = ctx->Color.DrawBuffer;
433 GLenum oldAlphaFunc = ctx->Color.AlphaFunc;
434 GLubyte oldAlphaRef = ctx->Color.AlphaRef;
435 GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
436 GLenum oldBlendDst = ctx->Color.BlendDstRGB;
437 MEMCPY( &ctx->Color, attr->data,
438 sizeof(struct gl_colorbuffer_attrib) );
439 if (ctx->Color.DrawBuffer != oldDrawBuffer) {
440 gl_DrawBuffer(ctx, ctx->Color.DrawBuffer);
441 }
442 if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
443 ctx->Color.AlphaRef != oldAlphaRef) &&
444 ctx->Driver.AlphaFunc)
445 (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
446 ctx->Color.AlphaRef / 255.0F);
447 if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
448 ctx->Color.BlendSrcRGB != oldBlendDst) &&
449 ctx->Driver.BlendFunc)
450 (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
451 ctx->Color.BlendDstRGB);
452 }
453 break;
454 case GL_CURRENT_BIT:
455 MEMCPY( &ctx->Current, attr->data,
456 sizeof(struct gl_current_attrib) );
457 break;
458 case GL_DEPTH_BUFFER_BIT:
459 {
460 GLenum oldDepthFunc = ctx->Depth.Func;
461 GLboolean oldDepthMask = ctx->Depth.Mask;
462 GLfloat oldDepthClear = ctx->Depth.Clear;
463 MEMCPY( &ctx->Depth, attr->data,
464 sizeof(struct gl_depthbuffer_attrib) );
465 if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
466 (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func );
467 if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask)
468 (*ctx->Driver.DepthMask)( ctx, ctx->Depth.Mask );
469 if (ctx->Depth.Clear != oldDepthClear && ctx->Driver.ClearDepth)
470 (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
471 }
472 break;
473 case GL_ENABLE_BIT:
474 {
475 const struct gl_enable_attrib *enable;
476 enable = (const struct gl_enable_attrib *) attr->data;
477
478#define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
479 if ((VALUE) != (NEWVALUE)) { \
480 gl_set_enable( ctx, ENUM, (NEWVALUE) ); \
481 }
482
483 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
484 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE);
485 TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND);
486 {
487 GLuint i;
488 for (i=0;i<MAX_CLIP_PLANES;i++) {
489 if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i])
490 gl_set_enable( ctx, (GLenum) (GL_CLIP_PLANE0 + i), enable->ClipPlane[i] );
491 }
492 }
493 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, GL_COLOR_MATERIAL);
494 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
495 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
496 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
497 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
498 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
499 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, GL_LINE_STIPPLE);
500 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, GL_INDEX_LOGIC_OP);
501 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, GL_COLOR_LOGIC_OP);
502 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
503 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
504 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
505 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, GL_MAP1_TEXTURE_COORD_1);
506 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, GL_MAP1_TEXTURE_COORD_2);
507 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, GL_MAP1_TEXTURE_COORD_3);
508 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, GL_MAP1_TEXTURE_COORD_4);
509 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, GL_MAP1_VERTEX_3);
510 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, GL_MAP1_VERTEX_4);
511 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
512 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
513 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
514 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, GL_MAP2_TEXTURE_COORD_1);
515 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, GL_MAP2_TEXTURE_COORD_2);
516 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, GL_MAP2_TEXTURE_COORD_3);
517 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, GL_MAP2_TEXTURE_COORD_4);
518 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, GL_MAP2_VERTEX_3);
519 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, GL_MAP2_VERTEX_4);
520 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
521 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, GL_RESCALE_NORMAL_EXT);
522 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, GL_POINT_SMOOTH);
523 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, GL_POLYGON_OFFSET_POINT);
524 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, GL_POLYGON_OFFSET_LINE);
525 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, GL_POLYGON_OFFSET_FILL);
526 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, GL_POLYGON_SMOOTH);
527 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, GL_POLYGON_STIPPLE);
528 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
529 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
530 if (ctx->Texture.Enabled != enable->Texture) {
531 ctx->Texture.Enabled = enable->Texture;
532 if (ctx->Driver.Enable) {
533 if (ctx->Driver.ActiveTexture)
534 (*ctx->Driver.ActiveTexture)( ctx, 0 );
535 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE0_1D) );
536 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE0_2D) );
537 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE0_3D) );
538 if (ctx->Driver.ActiveTexture)
539 (*ctx->Driver.ActiveTexture)( ctx, 1 );
540 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, (GLboolean) (enable->Texture & TEXTURE1_1D) );
541 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, (GLboolean) (enable->Texture & TEXTURE1_2D) );
542 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, (GLboolean) (enable->Texture & TEXTURE1_3D) );
543 if (ctx->Driver.ActiveTexture)
544 (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
545 }
546 }
547#undef TEST_AND_UPDATE
548 {
549 GLuint i;
550 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
551 if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
552 ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
553
554 /* ctx->Enabled recalculated in state change
555 processing */
556
557 if (ctx->Driver.Enable) {
558 if (ctx->Driver.ActiveTexture)
559 (*ctx->Driver.ActiveTexture)( ctx, i );
560 if (enable->TexGen[i] & S_BIT)
561 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
562 else
563 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
564 if (enable->TexGen[i] & T_BIT)
565 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
566 else
567 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
568 if (enable->TexGen[i] & R_BIT)
569 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
570 else
571 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
572 if (enable->TexGen[i] & Q_BIT)
573 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
574 else
575 (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
576 }
577 }
578 }
579 if (ctx->Driver.ActiveTexture)
580 (*ctx->Driver.ActiveTexture)( ctx, ctx->Texture.CurrentUnit );
581 }
582 }
583 break;
584 case GL_EVAL_BIT:
585 MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
586 break;
587 case GL_FOG_BIT:
588 {
589 GLboolean anyChange = (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
590 MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
591 if (anyChange && ctx->Driver.Fogfv) {
592 const GLfloat mode = ctx->Fog.Mode;
593 const GLfloat density = ctx->Fog.Density;
594 const GLfloat start = ctx->Fog.Start;
595 const GLfloat end = ctx->Fog.End;
596 const GLfloat index = ctx->Fog.Index;
597 (*ctx->Driver.Fogfv)( ctx, GL_FOG_MODE, &mode);
598 (*ctx->Driver.Fogfv)( ctx, GL_FOG_DENSITY, &density );
599 (*ctx->Driver.Fogfv)( ctx, GL_FOG_START, &start );
600 (*ctx->Driver.Fogfv)( ctx, GL_FOG_END, &end );
601 (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
602 (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
603 }
604 ctx->Enabled &= ENABLE_FOG;
605 if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
606 }
607 break;
608 case GL_HINT_BIT:
609 MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
610 if (ctx->Driver.Hint) {
611 (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
612 ctx->Hint.PerspectiveCorrection );
613 (*ctx->Driver.Hint)( ctx, GL_POINT_SMOOTH_HINT,
614 ctx->Hint.PointSmooth);
615 (*ctx->Driver.Hint)( ctx, GL_LINE_SMOOTH_HINT,
616 ctx->Hint.LineSmooth );
617 (*ctx->Driver.Hint)( ctx, GL_POLYGON_SMOOTH_HINT,
618 ctx->Hint.PolygonSmooth );
619 (*ctx->Driver.Hint)( ctx, GL_FOG_HINT, ctx->Hint.Fog );
620 }
621 break;
622 case GL_LIGHTING_BIT:
623 MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
624 if (ctx->Driver.Enable) {
625 GLuint i;
626 for (i = 0; i < MAX_LIGHTS; i++) {
627 GLenum light = (GLenum) (GL_LIGHT0 + i);
628 (*ctx->Driver.Enable)( ctx, light, ctx->Light.Light[i].Enabled );
629 }
630 (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
631 }
632 ctx->Enabled &= ENABLE_LIGHT;
633 if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
634 ctx->Enabled |= ENABLE_LIGHT;
635 break;
636 case GL_LINE_BIT:
637 MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
638 if (ctx->Driver.Enable) {
639 (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
640 (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
641 }
642 break;
643 case GL_LIST_BIT:
644 MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
645 break;
646 case GL_PIXEL_MODE_BIT:
647 MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
648 break;
649 case GL_POINT_BIT:
650 MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
651 if (ctx->Driver.Enable)
652 (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag );
653 break;
654 case GL_POLYGON_BIT:
655 {
656 GLenum oldFrontMode = ctx->Polygon.FrontMode;
657 GLenum oldBackMode = ctx->Polygon.BackMode;
658 MEMCPY( &ctx->Polygon, attr->data,
659 sizeof(struct gl_polygon_attrib) );
660 if ((ctx->Polygon.FrontMode != oldFrontMode ||
661 ctx->Polygon.BackMode != oldBackMode) &&
662 ctx->Driver.PolygonMode) {
663 (*ctx->Driver.PolygonMode)( ctx, GL_FRONT, ctx->Polygon.FrontMode);
664 (*ctx->Driver.PolygonMode)( ctx, GL_BACK, ctx->Polygon.BackMode);
665 }
666 if (ctx->Driver.CullFace)
667 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
668
669 if (ctx->Driver.FrontFace)
670 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
671
672 if (ctx->Driver.Enable)
673 (*ctx->Driver.Enable)( ctx, GL_POLYGON_SMOOTH, ctx->Polygon.SmoothFlag );
674 }
675 break;
676 case GL_POLYGON_STIPPLE_BIT:
677 MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
678 break;
679 case GL_SCISSOR_BIT:
680 MEMCPY( &ctx->Scissor, attr->data,
681 sizeof(struct gl_scissor_attrib) );
682 if (ctx->Driver.Enable)
683 (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
684 if (ctx->Driver.Scissor)
685 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
686 ctx->Scissor.Width, ctx->Scissor.Height );
687 break;
688 case GL_STENCIL_BUFFER_BIT:
689 MEMCPY( &ctx->Stencil, attr->data,
690 sizeof(struct gl_stencil_attrib) );
691 if (ctx->Driver.StencilFunc)
692 (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
693 ctx->Stencil.Ref, ctx->Stencil.ValueMask);
694 if (ctx->Driver.StencilMask)
695 (*ctx->Driver.StencilMask)( ctx, ctx->Stencil.WriteMask );
696 if (ctx->Driver.StencilOp)
697 (*ctx->Driver.StencilOp)( ctx, ctx->Stencil.FailFunc,
698 ctx->Stencil.ZFailFunc, ctx->Stencil.ZPassFunc);
699 if (ctx->Driver.ClearStencil)
700 (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
701 if (ctx->Driver.Enable)
702 (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
Keith Whitwelle3f37861999-09-16 11:54:56 +0000703/* ctx->TriangleCaps &= ~DD_STENCIL; */
704/* if (ctx->Stencil.Enabled) */
705/* ctx->TriangleCaps |= DD_STENCIL; */
706
jtgafb833d1999-08-19 00:55:39 +0000707 break;
708 case GL_TRANSFORM_BIT:
709 MEMCPY( &ctx->Transform, attr->data,
710 sizeof(struct gl_transform_attrib) );
711 if (ctx->Driver.Enable) {
712 (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
713 (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
714 }
715 ctx->Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
716 if (ctx->Transform.Normalize) ctx->Enabled |= ENABLE_NORMALIZE;
717 if (ctx->Transform.RescaleNormals) ctx->Enabled |= ENABLE_RESCALE;
718 break;
719 case GL_TEXTURE_BIT:
720 /* Take care of texture object reference counters */
721 {
722 GLuint u;
723 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
724 ctx->Texture.Unit[u].CurrentD[1]->RefCount--;
725 ctx->Texture.Unit[u].CurrentD[2]->RefCount--;
726 ctx->Texture.Unit[u].CurrentD[3]->RefCount--;
727 }
728 MEMCPY( &ctx->Texture, attr->data,
729 sizeof(struct gl_texture_attrib) );
730 /* restore state of the currently bound texture objects */
731 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
732 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1],
733 &(ctx->Texture.Unit[u].Saved1D) );
734 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2],
735 &(ctx->Texture.Unit[u].Saved2D) );
736 copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3],
737 &(ctx->Texture.Unit[u].Saved3D) );
738 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] );
739 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] );
740 gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] );
741
742 }
743 }
744 break;
Keith Whitwelle3f37861999-09-16 11:54:56 +0000745 case GL_VIEWPORT_BIT:
746 {
747 struct gl_viewport_attrib *v =
748 (struct gl_viewport_attrib *)attr->data;
749
750 gl_Viewport( ctx, v->X, v->Y, v->Width, v->Height );
751 gl_DepthRange( ctx, v->Near, v->Far );
752 break;
753 }
jtgafb833d1999-08-19 00:55:39 +0000754 default:
755 gl_problem( ctx, "Bad attrib flag in PopAttrib");
756 break;
757 }
758
759 next = attr->next;
760 free( (void *) attr->data );
761 free( (void *) attr );
762 attr = next;
763 }
764
765 ctx->NewState = NEW_ALL;
766}
767
768
769#define GL_CLIENT_PACK_BIT (1<<20)
770#define GL_CLIENT_UNPACK_BIT (1<<21)
771
772
773void gl_PushClientAttrib( GLcontext *ctx, GLbitfield mask )
774{
775 struct gl_attrib_node *newnode;
776 struct gl_attrib_node *head;
777
778 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
779
780 if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
781 gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
782 return;
783 }
784
785 /* Build linked list of attribute nodes which save all attribute */
786 /* groups specified by the mask. */
787 head = NULL;
788
789 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
790 struct gl_pixelstore_attrib *attr;
791 /* packing attribs */
792 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
793 MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
794 newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
795 newnode->data = attr;
796 newnode->next = head;
797 head = newnode;
798 /* unpacking attribs */
799 attr = MALLOC_STRUCT( gl_pixelstore_attrib );
800 MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
801 newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
802 newnode->data = attr;
803 newnode->next = head;
804 head = newnode;
805 }
806 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
807 struct gl_array_attrib *attr;
808 attr = MALLOC_STRUCT( gl_array_attrib );
809 MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
810 newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
811 newnode->data = attr;
812 newnode->next = head;
813 head = newnode;
814 }
815
816 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
817 ctx->ClientAttribStackDepth++;
818}
819
820
821
822
823void gl_PopClientAttrib( GLcontext *ctx )
824{
825 struct gl_attrib_node *attr, *next;
826
827 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
828
829 if (ctx->ClientAttribStackDepth==0) {
830 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
831 return;
832 }
833
834 ctx->ClientAttribStackDepth--;
835 attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
836
837 while (attr) {
838 switch (attr->kind) {
839 case GL_CLIENT_PACK_BIT:
840 MEMCPY( &ctx->Pack, attr->data,
841 sizeof(struct gl_pixelstore_attrib) );
842 break;
843 case GL_CLIENT_UNPACK_BIT:
844 MEMCPY( &ctx->Unpack, attr->data,
845 sizeof(struct gl_pixelstore_attrib) );
846 break;
847 case GL_CLIENT_VERTEX_ARRAY_BIT:
848 MEMCPY( &ctx->Array, attr->data,
849 sizeof(struct gl_array_attrib) );
850 break;
851 default:
852 gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
853 break;
854 }
855
856 next = attr->next;
857 free( (void *) attr->data );
858 free( (void *) attr );
859 attr = next;
860 }
861
862 ctx->NewState = NEW_ALL;
863}
864