mesa: remove unused header
[mesa.git] / src / mesa / main / attrib.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "accum.h"
29 #include "arrayobj.h"
30 #include "attrib.h"
31 #include "blend.h"
32 #include "buffers.h"
33 #include "bufferobj.h"
34 #include "clear.h"
35 #include "colormac.h"
36 #include "context.h"
37 #include "depth.h"
38 #include "enable.h"
39 #include "enums.h"
40 #include "fog.h"
41 #include "hint.h"
42 #include "light.h"
43 #include "lines.h"
44 #include "matrix.h"
45 #include "multisample.h"
46 #include "points.h"
47 #include "polygon.h"
48 #include "scissor.h"
49 #include "stencil.h"
50 #include "texenv.h"
51 #include "texgen.h"
52 #include "texobj.h"
53 #include "texparam.h"
54 #include "texstate.h"
55 #include "varray.h"
56 #include "viewport.h"
57 #include "mtypes.h"
58 #include "main/dispatch.h"
59
60
61 /**
62 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
63 */
64 struct gl_enable_attrib
65 {
66 GLboolean AlphaTest;
67 GLboolean AutoNormal;
68 GLboolean Blend;
69 GLbitfield ClipPlanes;
70 GLboolean ColorMaterial;
71 GLboolean ColorTable[COLORTABLE_MAX];
72 GLboolean Convolution1D;
73 GLboolean Convolution2D;
74 GLboolean Separable2D;
75 GLboolean CullFace;
76 GLboolean DepthClamp;
77 GLboolean DepthTest;
78 GLboolean Dither;
79 GLboolean Fog;
80 GLboolean Histogram;
81 GLboolean Light[MAX_LIGHTS];
82 GLboolean Lighting;
83 GLboolean LineSmooth;
84 GLboolean LineStipple;
85 GLboolean IndexLogicOp;
86 GLboolean ColorLogicOp;
87
88 GLboolean Map1Color4;
89 GLboolean Map1Index;
90 GLboolean Map1Normal;
91 GLboolean Map1TextureCoord1;
92 GLboolean Map1TextureCoord2;
93 GLboolean Map1TextureCoord3;
94 GLboolean Map1TextureCoord4;
95 GLboolean Map1Vertex3;
96 GLboolean Map1Vertex4;
97 GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
98 GLboolean Map2Color4;
99 GLboolean Map2Index;
100 GLboolean Map2Normal;
101 GLboolean Map2TextureCoord1;
102 GLboolean Map2TextureCoord2;
103 GLboolean Map2TextureCoord3;
104 GLboolean Map2TextureCoord4;
105 GLboolean Map2Vertex3;
106 GLboolean Map2Vertex4;
107 GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
108
109 GLboolean MinMax;
110 GLboolean Normalize;
111 GLboolean PixelTexture;
112 GLboolean PointSmooth;
113 GLboolean PolygonOffsetPoint;
114 GLboolean PolygonOffsetLine;
115 GLboolean PolygonOffsetFill;
116 GLboolean PolygonSmooth;
117 GLboolean PolygonStipple;
118 GLboolean RescaleNormals;
119 GLboolean Scissor;
120 GLboolean Stencil;
121 GLboolean StencilTwoSide; /* GL_EXT_stencil_two_side */
122 GLboolean MultisampleEnabled; /* GL_ARB_multisample */
123 GLboolean SampleAlphaToCoverage; /* GL_ARB_multisample */
124 GLboolean SampleAlphaToOne; /* GL_ARB_multisample */
125 GLboolean SampleCoverage; /* GL_ARB_multisample */
126 GLboolean SampleCoverageInvert; /* GL_ARB_multisample */
127 GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
128
129 GLbitfield Texture[MAX_TEXTURE_UNITS];
130 GLbitfield TexGen[MAX_TEXTURE_UNITS];
131
132 /* SGI_texture_color_table */
133 GLboolean TextureColorTable[MAX_TEXTURE_UNITS];
134
135 /* GL_ARB_vertex_program / GL_NV_vertex_program */
136 GLboolean VertexProgram;
137 GLboolean VertexProgramPointSize;
138 GLboolean VertexProgramTwoSide;
139
140 /* GL_ARB_point_sprite / GL_NV_point_sprite */
141 GLboolean PointSprite;
142 GLboolean FragmentShaderATI;
143 };
144
145
146 /**
147 * Node for the attribute stack.
148 */
149 struct gl_attrib_node
150 {
151 GLbitfield kind;
152 void *data;
153 struct gl_attrib_node *next;
154 };
155
156
157
158 /**
159 * Special struct for saving/restoring texture state (GL_TEXTURE_BIT)
160 */
161 struct texture_state
162 {
163 struct gl_texture_attrib Texture; /**< The usual context state */
164
165 /** to save per texture object state (wrap modes, filters, etc): */
166 struct gl_texture_object SavedObj[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
167
168 /**
169 * To save references to texture objects (so they don't get accidentally
170 * deleted while saved in the attribute stack).
171 */
172 struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
173 };
174
175
176 #if FEATURE_attrib_stack
177
178
179 /**
180 * Allocate new attribute node of given type/kind. Attach payload data.
181 * Insert it into the linked list named by 'head'.
182 */
183 static void
184 save_attrib_data(struct gl_attrib_node **head,
185 GLbitfield kind, void *payload)
186 {
187 struct gl_attrib_node *n = MALLOC_STRUCT(gl_attrib_node);
188 if (n) {
189 n->kind = kind;
190 n->data = payload;
191 /* insert at head */
192 n->next = *head;
193 *head = n;
194 }
195 else {
196 /* out of memory! */
197 }
198 }
199
200
201 void GLAPIENTRY
202 _mesa_PushAttrib(GLbitfield mask)
203 {
204 struct gl_attrib_node *head;
205
206 GET_CURRENT_CONTEXT(ctx);
207 ASSERT_OUTSIDE_BEGIN_END(ctx);
208
209 if (MESA_VERBOSE & VERBOSE_API)
210 _mesa_debug(ctx, "glPushAttrib %x\n", (int) mask);
211
212 if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) {
213 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
214 return;
215 }
216
217 /* Build linked list of attribute nodes which save all attribute */
218 /* groups specified by the mask. */
219 head = NULL;
220
221 if (mask & GL_ACCUM_BUFFER_BIT) {
222 struct gl_accum_attrib *attr;
223 attr = MALLOC_STRUCT( gl_accum_attrib );
224 memcpy( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
225 save_attrib_data(&head, GL_ACCUM_BUFFER_BIT, attr);
226 }
227
228 if (mask & GL_COLOR_BUFFER_BIT) {
229 GLuint i;
230 struct gl_colorbuffer_attrib *attr;
231 attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
232 memcpy( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
233 /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
234 for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++)
235 attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i];
236 save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr);
237 }
238
239 if (mask & GL_CURRENT_BIT) {
240 struct gl_current_attrib *attr;
241 FLUSH_CURRENT( ctx, 0 );
242 attr = MALLOC_STRUCT( gl_current_attrib );
243 memcpy( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
244 save_attrib_data(&head, GL_CURRENT_BIT, attr);
245 }
246
247 if (mask & GL_DEPTH_BUFFER_BIT) {
248 struct gl_depthbuffer_attrib *attr;
249 attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
250 memcpy( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
251 save_attrib_data(&head, GL_DEPTH_BUFFER_BIT, attr);
252 }
253
254 if (mask & GL_ENABLE_BIT) {
255 struct gl_enable_attrib *attr;
256 GLuint i;
257 attr = MALLOC_STRUCT( gl_enable_attrib );
258 /* Copy enable flags from all other attributes into the enable struct. */
259 attr->AlphaTest = ctx->Color.AlphaEnabled;
260 attr->AutoNormal = ctx->Eval.AutoNormal;
261 attr->Blend = ctx->Color.BlendEnabled;
262 attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
263 attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
264 for (i = 0; i < COLORTABLE_MAX; i++) {
265 attr->ColorTable[i] = ctx->Pixel.ColorTableEnabled[i];
266 }
267 attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
268 attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
269 attr->Separable2D = ctx->Pixel.Separable2DEnabled;
270 attr->CullFace = ctx->Polygon.CullFlag;
271 attr->DepthClamp = ctx->Transform.DepthClamp;
272 attr->DepthTest = ctx->Depth.Test;
273 attr->Dither = ctx->Color.DitherFlag;
274 attr->Fog = ctx->Fog.Enabled;
275 for (i = 0; i < ctx->Const.MaxLights; i++) {
276 attr->Light[i] = ctx->Light.Light[i].Enabled;
277 }
278 attr->Lighting = ctx->Light.Enabled;
279 attr->LineSmooth = ctx->Line.SmoothFlag;
280 attr->LineStipple = ctx->Line.StippleFlag;
281 attr->Histogram = ctx->Pixel.HistogramEnabled;
282 attr->MinMax = ctx->Pixel.MinMaxEnabled;
283 attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
284 attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
285 attr->Map1Color4 = ctx->Eval.Map1Color4;
286 attr->Map1Index = ctx->Eval.Map1Index;
287 attr->Map1Normal = ctx->Eval.Map1Normal;
288 attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
289 attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
290 attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
291 attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
292 attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
293 attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
294 memcpy(attr->Map1Attrib, ctx->Eval.Map1Attrib, sizeof(ctx->Eval.Map1Attrib));
295 attr->Map2Color4 = ctx->Eval.Map2Color4;
296 attr->Map2Index = ctx->Eval.Map2Index;
297 attr->Map2Normal = ctx->Eval.Map2Normal;
298 attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
299 attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
300 attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
301 attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
302 attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
303 attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
304 memcpy(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
305 attr->Normalize = ctx->Transform.Normalize;
306 attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
307 attr->PointSmooth = ctx->Point.SmoothFlag;
308 attr->PointSprite = ctx->Point.PointSprite;
309 attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
310 attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
311 attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
312 attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
313 attr->PolygonStipple = ctx->Polygon.StippleFlag;
314 attr->RescaleNormals = ctx->Transform.RescaleNormals;
315 attr->Scissor = ctx->Scissor.Enabled;
316 attr->Stencil = ctx->Stencil.Enabled;
317 attr->StencilTwoSide = ctx->Stencil.TestTwoSide;
318 attr->MultisampleEnabled = ctx->Multisample.Enabled;
319 attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage;
320 attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne;
321 attr->SampleCoverage = ctx->Multisample.SampleCoverage;
322 attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert;
323 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
324 attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
325 attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
326 attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled;
327 }
328 /* GL_NV_vertex_program */
329 attr->VertexProgram = ctx->VertexProgram.Enabled;
330 attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
331 attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
332 save_attrib_data(&head, GL_ENABLE_BIT, attr);
333 }
334
335 if (mask & GL_EVAL_BIT) {
336 struct gl_eval_attrib *attr;
337 attr = MALLOC_STRUCT( gl_eval_attrib );
338 memcpy( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
339 save_attrib_data(&head, GL_EVAL_BIT, attr);
340 }
341
342 if (mask & GL_FOG_BIT) {
343 struct gl_fog_attrib *attr;
344 attr = MALLOC_STRUCT( gl_fog_attrib );
345 memcpy( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
346 save_attrib_data(&head, GL_FOG_BIT, attr);
347 }
348
349 if (mask & GL_HINT_BIT) {
350 struct gl_hint_attrib *attr;
351 attr = MALLOC_STRUCT( gl_hint_attrib );
352 memcpy( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
353 save_attrib_data(&head, GL_HINT_BIT, attr);
354 }
355
356 if (mask & GL_LIGHTING_BIT) {
357 struct gl_light_attrib *attr;
358 FLUSH_CURRENT(ctx, 0); /* flush material changes */
359 attr = MALLOC_STRUCT( gl_light_attrib );
360 memcpy( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
361 save_attrib_data(&head, GL_LIGHTING_BIT, attr);
362 }
363
364 if (mask & GL_LINE_BIT) {
365 struct gl_line_attrib *attr;
366 attr = MALLOC_STRUCT( gl_line_attrib );
367 memcpy( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
368 save_attrib_data(&head, GL_LINE_BIT, attr);
369 }
370
371 if (mask & GL_LIST_BIT) {
372 struct gl_list_attrib *attr;
373 attr = MALLOC_STRUCT( gl_list_attrib );
374 memcpy( attr, &ctx->List, sizeof(struct gl_list_attrib) );
375 save_attrib_data(&head, GL_LIST_BIT, attr);
376 }
377
378 if (mask & GL_PIXEL_MODE_BIT) {
379 struct gl_pixel_attrib *attr;
380 attr = MALLOC_STRUCT( gl_pixel_attrib );
381 memcpy( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
382 /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
383 attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer;
384 save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr);
385 }
386
387 if (mask & GL_POINT_BIT) {
388 struct gl_point_attrib *attr;
389 attr = MALLOC_STRUCT( gl_point_attrib );
390 memcpy( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
391 save_attrib_data(&head, GL_POINT_BIT, attr);
392 }
393
394 if (mask & GL_POLYGON_BIT) {
395 struct gl_polygon_attrib *attr;
396 attr = MALLOC_STRUCT( gl_polygon_attrib );
397 memcpy( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
398 save_attrib_data(&head, GL_POLYGON_BIT, attr);
399 }
400
401 if (mask & GL_POLYGON_STIPPLE_BIT) {
402 GLuint *stipple;
403 stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
404 memcpy( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
405 save_attrib_data(&head, GL_POLYGON_STIPPLE_BIT, stipple);
406 }
407
408 if (mask & GL_SCISSOR_BIT) {
409 struct gl_scissor_attrib *attr;
410 attr = MALLOC_STRUCT( gl_scissor_attrib );
411 memcpy( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
412 save_attrib_data(&head, GL_SCISSOR_BIT, attr);
413 }
414
415 if (mask & GL_STENCIL_BUFFER_BIT) {
416 struct gl_stencil_attrib *attr;
417 attr = MALLOC_STRUCT( gl_stencil_attrib );
418 memcpy( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
419 save_attrib_data(&head, GL_STENCIL_BUFFER_BIT, attr);
420 }
421
422 if (mask & GL_TEXTURE_BIT) {
423 struct texture_state *texstate = CALLOC_STRUCT(texture_state);
424 GLuint u, tex;
425
426 if (!texstate) {
427 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)");
428 goto end;
429 }
430
431 _mesa_lock_context_textures(ctx);
432
433 /* copy/save the bulk of texture state here */
434 memcpy(&texstate->Texture, &ctx->Texture, sizeof(ctx->Texture));
435
436 /* Save references to the currently bound texture objects so they don't
437 * accidentally get deleted while referenced in the attribute stack.
438 */
439 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
440 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
441 _mesa_reference_texobj(&texstate->SavedTexRef[u][tex],
442 ctx->Texture.Unit[u].CurrentTex[tex]);
443 }
444 }
445
446 /* copy state/contents of the currently bound texture objects */
447 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
448 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
449 _mesa_copy_texture_object(&texstate->SavedObj[u][tex],
450 ctx->Texture.Unit[u].CurrentTex[tex]);
451 }
452 }
453
454 _mesa_unlock_context_textures(ctx);
455
456 save_attrib_data(&head, GL_TEXTURE_BIT, texstate);
457 }
458
459 if (mask & GL_TRANSFORM_BIT) {
460 struct gl_transform_attrib *attr;
461 attr = MALLOC_STRUCT( gl_transform_attrib );
462 memcpy( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
463 save_attrib_data(&head, GL_TRANSFORM_BIT, attr);
464 }
465
466 if (mask & GL_VIEWPORT_BIT) {
467 struct gl_viewport_attrib *attr;
468 attr = MALLOC_STRUCT( gl_viewport_attrib );
469 memcpy( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
470 save_attrib_data(&head, GL_VIEWPORT_BIT, attr);
471 }
472
473 /* GL_ARB_multisample */
474 if (mask & GL_MULTISAMPLE_BIT_ARB) {
475 struct gl_multisample_attrib *attr;
476 attr = MALLOC_STRUCT( gl_multisample_attrib );
477 memcpy( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
478 save_attrib_data(&head, GL_MULTISAMPLE_BIT_ARB, attr);
479 }
480
481 end:
482 ctx->AttribStack[ctx->AttribStackDepth] = head;
483 ctx->AttribStackDepth++;
484 }
485
486
487
488 static void
489 pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
490 {
491 const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
492 GLuint i;
493
494 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \
495 if ((VALUE) != (NEWVALUE)) { \
496 _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \
497 }
498
499 TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST);
500 if (ctx->Color.BlendEnabled != enable->Blend) {
501 if (ctx->Extensions.EXT_draw_buffers2) {
502 GLuint i;
503 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
504 _mesa_set_enablei(ctx, GL_BLEND, i, (enable->Blend >> i) & 1);
505 }
506 }
507 else {
508 _mesa_set_enable(ctx, GL_BLEND, (enable->Blend & 1));
509 }
510 }
511
512 for (i=0;i<MAX_CLIP_PLANES;i++) {
513 const GLuint mask = 1 << i;
514 if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask))
515 _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
516 (GLboolean) ((enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE));
517 }
518
519 TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
520 GL_COLOR_MATERIAL);
521 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION],
522 enable->ColorTable[COLORTABLE_PRECONVOLUTION],
523 GL_COLOR_TABLE);
524 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION],
525 enable->ColorTable[COLORTABLE_POSTCONVOLUTION],
526 GL_POST_CONVOLUTION_COLOR_TABLE);
527 TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX],
528 enable->ColorTable[COLORTABLE_POSTCOLORMATRIX],
529 GL_POST_COLOR_MATRIX_COLOR_TABLE);
530 TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
531 TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp,
532 GL_DEPTH_CLAMP);
533 TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
534 TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
535 TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D,
536 GL_CONVOLUTION_1D);
537 TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D,
538 GL_CONVOLUTION_2D);
539 TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D,
540 GL_SEPARABLE_2D);
541 TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG);
542 TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING);
543 TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH);
544 TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple,
545 GL_LINE_STIPPLE);
546 TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp,
547 GL_INDEX_LOGIC_OP);
548 TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp,
549 GL_COLOR_LOGIC_OP);
550
551 TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4);
552 TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX);
553 TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL);
554 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1,
555 GL_MAP1_TEXTURE_COORD_1);
556 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2,
557 GL_MAP1_TEXTURE_COORD_2);
558 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3,
559 GL_MAP1_TEXTURE_COORD_3);
560 TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4,
561 GL_MAP1_TEXTURE_COORD_4);
562 TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3,
563 GL_MAP1_VERTEX_3);
564 TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4,
565 GL_MAP1_VERTEX_4);
566 for (i = 0; i < 16; i++) {
567 TEST_AND_UPDATE(ctx->Eval.Map1Attrib[i], enable->Map1Attrib[i],
568 GL_MAP1_VERTEX_ATTRIB0_4_NV + i);
569 }
570
571 TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4);
572 TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX);
573 TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL);
574 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1,
575 GL_MAP2_TEXTURE_COORD_1);
576 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2,
577 GL_MAP2_TEXTURE_COORD_2);
578 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3,
579 GL_MAP2_TEXTURE_COORD_3);
580 TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4,
581 GL_MAP2_TEXTURE_COORD_4);
582 TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3,
583 GL_MAP2_VERTEX_3);
584 TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4,
585 GL_MAP2_VERTEX_4);
586 for (i = 0; i < 16; i++) {
587 TEST_AND_UPDATE(ctx->Eval.Map2Attrib[i], enable->Map2Attrib[i],
588 GL_MAP2_VERTEX_ATTRIB0_4_NV + i);
589 }
590
591 TEST_AND_UPDATE(ctx->Eval.AutoNormal, enable->AutoNormal, GL_AUTO_NORMAL);
592 TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE);
593 TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals,
594 GL_RESCALE_NORMAL_EXT);
595 TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped,
596 enable->RasterPositionUnclipped,
597 GL_RASTER_POSITION_UNCLIPPED_IBM);
598 TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
599 GL_POINT_SMOOTH);
600 if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) {
601 TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite,
602 GL_POINT_SPRITE_NV);
603 }
604 TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint,
605 GL_POLYGON_OFFSET_POINT);
606 TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine,
607 GL_POLYGON_OFFSET_LINE);
608 TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill,
609 GL_POLYGON_OFFSET_FILL);
610 TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth,
611 GL_POLYGON_SMOOTH);
612 TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple,
613 GL_POLYGON_STIPPLE);
614 TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST);
615 TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST);
616 if (ctx->Extensions.EXT_stencil_two_side) {
617 TEST_AND_UPDATE(ctx->Stencil.TestTwoSide, enable->StencilTwoSide, GL_STENCIL_TEST_TWO_SIDE_EXT);
618 }
619 TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled,
620 GL_MULTISAMPLE_ARB);
621 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage,
622 enable->SampleAlphaToCoverage,
623 GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
624 TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne,
625 enable->SampleAlphaToOne,
626 GL_SAMPLE_ALPHA_TO_ONE_ARB);
627 TEST_AND_UPDATE(ctx->Multisample.SampleCoverage,
628 enable->SampleCoverage,
629 GL_SAMPLE_COVERAGE_ARB);
630 TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
631 enable->SampleCoverageInvert,
632 GL_SAMPLE_COVERAGE_INVERT_ARB);
633 /* GL_ARB_vertex_program, GL_NV_vertex_program */
634 TEST_AND_UPDATE(ctx->VertexProgram.Enabled,
635 enable->VertexProgram,
636 GL_VERTEX_PROGRAM_ARB);
637 TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled,
638 enable->VertexProgramPointSize,
639 GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
640 TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled,
641 enable->VertexProgramTwoSide,
642 GL_VERTEX_PROGRAM_TWO_SIDE_ARB);
643
644 #undef TEST_AND_UPDATE
645
646 /* texture unit enables */
647 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
648 const GLbitfield enabled = enable->Texture[i];
649 const GLbitfield genEnabled = enable->TexGen[i];
650
651 if (ctx->Texture.Unit[i].Enabled != enabled) {
652 _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
653
654 _mesa_set_enable(ctx, GL_TEXTURE_1D,
655 (enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
656 _mesa_set_enable(ctx, GL_TEXTURE_2D,
657 (enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
658 _mesa_set_enable(ctx, GL_TEXTURE_3D,
659 (enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
660 if (ctx->Extensions.NV_texture_rectangle) {
661 _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_ARB,
662 (enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
663 }
664 if (ctx->Extensions.ARB_texture_cube_map) {
665 _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP,
666 (enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
667 }
668 if (ctx->Extensions.MESA_texture_array) {
669 _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
670 (enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
671 _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
672 (enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
673 }
674 }
675
676 if (ctx->Texture.Unit[i].TexGenEnabled != genEnabled) {
677 _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
678 _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
679 (genEnabled & S_BIT) ? GL_TRUE : GL_FALSE);
680 _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
681 (genEnabled & T_BIT) ? GL_TRUE : GL_FALSE);
682 _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
683 (genEnabled & R_BIT) ? GL_TRUE : GL_FALSE);
684 _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
685 (genEnabled & Q_BIT) ? GL_TRUE : GL_FALSE);
686 }
687
688 /* GL_SGI_texture_color_table */
689 ctx->Texture.Unit[i].ColorTableEnabled = enable->TextureColorTable[i];
690 }
691
692 _mesa_ActiveTextureARB(GL_TEXTURE0 + curTexUnitSave);
693 }
694
695
696 /**
697 * Pop/restore texture attribute/group state.
698 */
699 static void
700 pop_texture_group(GLcontext *ctx, struct texture_state *texstate)
701 {
702 GLuint u;
703
704 _mesa_lock_context_textures(ctx);
705
706 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
707 const struct gl_texture_unit *unit = &texstate->Texture.Unit[u];
708 GLuint tgt;
709
710 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u);
711 _mesa_set_enable(ctx, GL_TEXTURE_1D,
712 (unit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
713 _mesa_set_enable(ctx, GL_TEXTURE_2D,
714 (unit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
715 _mesa_set_enable(ctx, GL_TEXTURE_3D,
716 (unit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
717 if (ctx->Extensions.ARB_texture_cube_map) {
718 _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB,
719 (unit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
720 }
721 if (ctx->Extensions.NV_texture_rectangle) {
722 _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
723 (unit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
724 }
725 if (ctx->Extensions.MESA_texture_array) {
726 _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
727 (unit->Enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
728 _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
729 (unit->Enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
730 }
731
732 if (ctx->Extensions.SGI_texture_color_table) {
733 _mesa_set_enable(ctx, GL_TEXTURE_COLOR_TABLE_SGI,
734 unit->ColorTableEnabled);
735 }
736 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
737 _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
738 _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenS.Mode);
739 _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenT.Mode);
740 _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenR.Mode);
741 _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenQ.Mode);
742 _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->GenS.ObjectPlane);
743 _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->GenT.ObjectPlane);
744 _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->GenR.ObjectPlane);
745 _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->GenQ.ObjectPlane);
746 /* Eye plane done differently to avoid re-transformation */
747 {
748 struct gl_texture_unit *destUnit = &ctx->Texture.Unit[u];
749 COPY_4FV(destUnit->GenS.EyePlane, unit->GenS.EyePlane);
750 COPY_4FV(destUnit->GenT.EyePlane, unit->GenT.EyePlane);
751 COPY_4FV(destUnit->GenR.EyePlane, unit->GenR.EyePlane);
752 COPY_4FV(destUnit->GenQ.EyePlane, unit->GenQ.EyePlane);
753 if (ctx->Driver.TexGen) {
754 ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->GenS.EyePlane);
755 ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->GenT.EyePlane);
756 ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->GenR.EyePlane);
757 ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->GenQ.EyePlane);
758 }
759 }
760 _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
761 ((unit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE));
762 _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
763 ((unit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE));
764 _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
765 ((unit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE));
766 _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
767 ((unit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE));
768 if (ctx->Extensions.EXT_texture_lod_bias) {
769 _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
770 GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias);
771 }
772 if (ctx->Extensions.EXT_texture_env_combine ||
773 ctx->Extensions.ARB_texture_env_combine) {
774 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,
775 unit->Combine.ModeRGB);
776 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,
777 unit->Combine.ModeA);
778 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB,
779 unit->Combine.SourceRGB[0]);
780 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB,
781 unit->Combine.SourceRGB[1]);
782 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB,
783 unit->Combine.SourceRGB[2]);
784 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA,
785 unit->Combine.SourceA[0]);
786 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA,
787 unit->Combine.SourceA[1]);
788 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA,
789 unit->Combine.SourceA[2]);
790 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,
791 unit->Combine.OperandRGB[0]);
792 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB,
793 unit->Combine.OperandRGB[1]);
794 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,
795 unit->Combine.OperandRGB[2]);
796 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
797 unit->Combine.OperandA[0]);
798 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
799 unit->Combine.OperandA[1]);
800 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
801 unit->Combine.OperandA[2]);
802 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE,
803 1 << unit->Combine.ScaleShiftRGB);
804 _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE,
805 1 << unit->Combine.ScaleShiftA);
806 }
807
808 /* Restore texture object state for each target */
809 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
810 const struct gl_texture_object *obj = NULL;
811 GLenum target;
812
813 obj = &texstate->SavedObj[u][tgt];
814
815 /* don't restore state for unsupported targets to prevent
816 * raising GL errors.
817 */
818 if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
819 !ctx->Extensions.ARB_texture_cube_map) {
820 continue;
821 }
822 else if (obj->Target == GL_TEXTURE_RECTANGLE_NV &&
823 !ctx->Extensions.NV_texture_rectangle) {
824 continue;
825 }
826 else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT ||
827 obj->Target == GL_TEXTURE_2D_ARRAY_EXT) &&
828 !ctx->Extensions.MESA_texture_array) {
829 continue;
830 }
831
832 target = obj->Target;
833
834 _mesa_BindTexture(target, obj->Name);
835
836 _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, obj->BorderColor.f);
837 _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
838 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
839 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
840 _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR);
841 _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter);
842 _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter);
843 _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
844 _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
845 _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, obj->LodBias);
846 _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
847 if (target != GL_TEXTURE_RECTANGLE_ARB)
848 _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
849 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
850 _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
851 obj->MaxAnisotropy);
852 }
853 if (ctx->Extensions.ARB_shadow_ambient) {
854 _mesa_TexParameterf(target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB,
855 obj->CompareFailValue);
856 }
857 }
858
859 /* remove saved references to the texture objects */
860 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
861 _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
862 }
863 }
864
865 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit);
866
867 _mesa_unlock_context_textures(ctx);
868 }
869
870
871 /*
872 * This function is kind of long just because we have to call a lot
873 * of device driver functions to update device driver state.
874 *
875 * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions
876 * in order to restore GL state. This isn't terribly efficient but it
877 * ensures that dirty flags and any derived state gets updated correctly.
878 * We could at least check if the value to restore equals the current value
879 * and then skip the Mesa call.
880 */
881 void GLAPIENTRY
882 _mesa_PopAttrib(void)
883 {
884 struct gl_attrib_node *attr, *next;
885 GET_CURRENT_CONTEXT(ctx);
886 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
887
888 if (ctx->AttribStackDepth == 0) {
889 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
890 return;
891 }
892
893 ctx->AttribStackDepth--;
894 attr = ctx->AttribStack[ctx->AttribStackDepth];
895
896 while (attr) {
897
898 if (MESA_VERBOSE & VERBOSE_API) {
899 _mesa_debug(ctx, "glPopAttrib %s\n",
900 _mesa_lookup_enum_by_nr(attr->kind));
901 }
902
903 switch (attr->kind) {
904 case GL_ACCUM_BUFFER_BIT:
905 {
906 const struct gl_accum_attrib *accum;
907 accum = (const struct gl_accum_attrib *) attr->data;
908 _mesa_ClearAccum(accum->ClearColor[0],
909 accum->ClearColor[1],
910 accum->ClearColor[2],
911 accum->ClearColor[3]);
912 }
913 break;
914 case GL_COLOR_BUFFER_BIT:
915 {
916 const struct gl_colorbuffer_attrib *color;
917
918 color = (const struct gl_colorbuffer_attrib *) attr->data;
919 _mesa_ClearIndex((GLfloat) color->ClearIndex);
920 _mesa_ClearColor(color->ClearColor[0],
921 color->ClearColor[1],
922 color->ClearColor[2],
923 color->ClearColor[3]);
924 _mesa_IndexMask(color->IndexMask);
925 if (!ctx->Extensions.EXT_draw_buffers2) {
926 _mesa_ColorMask((GLboolean) (color->ColorMask[0][0] != 0),
927 (GLboolean) (color->ColorMask[0][1] != 0),
928 (GLboolean) (color->ColorMask[0][2] != 0),
929 (GLboolean) (color->ColorMask[0][3] != 0));
930 }
931 else {
932 GLuint i;
933 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
934 _mesa_ColorMaskIndexed(i,
935 (GLboolean) (color->ColorMask[i][0] != 0),
936 (GLboolean) (color->ColorMask[i][1] != 0),
937 (GLboolean) (color->ColorMask[i][2] != 0),
938 (GLboolean) (color->ColorMask[i][3] != 0));
939 }
940 }
941 {
942 /* Need to determine if more than one color output is
943 * specified. If so, call glDrawBuffersARB, else call
944 * glDrawBuffer(). This is a subtle, but essential point
945 * since GL_FRONT (for example) is illegal for the former
946 * function, but legal for the later.
947 */
948 GLboolean multipleBuffers = GL_FALSE;
949 GLuint i;
950
951 for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
952 if (color->DrawBuffer[i] != GL_NONE) {
953 multipleBuffers = GL_TRUE;
954 break;
955 }
956 }
957 /* Call the API_level functions, not _mesa_drawbuffers()
958 * since we need to do error checking on the pop'd
959 * GL_DRAW_BUFFER.
960 * Ex: if GL_FRONT were pushed, but we're popping with a
961 * user FBO bound, GL_FRONT will be illegal and we'll need
962 * to record that error. Per OpenGL ARB decision.
963 */
964 if (multipleBuffers)
965 _mesa_DrawBuffersARB(ctx->Const.MaxDrawBuffers,
966 color->DrawBuffer);
967 else
968 _mesa_DrawBuffer(color->DrawBuffer[0]);
969 }
970 _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
971 _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef);
972 if (ctx->Color.BlendEnabled != color->BlendEnabled) {
973 if (ctx->Extensions.EXT_draw_buffers2) {
974 GLuint i;
975 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
976 _mesa_set_enablei(ctx, GL_BLEND, i,
977 (color->BlendEnabled >> i) & 1);
978 }
979 }
980 else {
981 _mesa_set_enable(ctx, GL_BLEND, (color->BlendEnabled & 1));
982 }
983 }
984 _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB,
985 color->BlendDstRGB,
986 color->BlendSrcA,
987 color->BlendDstA);
988 /* This special case is because glBlendEquationSeparateEXT
989 * cannot take GL_LOGIC_OP as a parameter.
990 */
991 if ( color->BlendEquationRGB == color->BlendEquationA ) {
992 _mesa_BlendEquation(color->BlendEquationRGB);
993 }
994 else {
995 _mesa_BlendEquationSeparateEXT(color->BlendEquationRGB,
996 color->BlendEquationA);
997 }
998 _mesa_BlendColor(color->BlendColor[0],
999 color->BlendColor[1],
1000 color->BlendColor[2],
1001 color->BlendColor[3]);
1002 _mesa_LogicOp(color->LogicOp);
1003 _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP,
1004 color->ColorLogicOpEnabled);
1005 _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP,
1006 color->IndexLogicOpEnabled);
1007 _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag);
1008 }
1009 break;
1010 case GL_CURRENT_BIT:
1011 FLUSH_CURRENT( ctx, 0 );
1012 memcpy( &ctx->Current, attr->data,
1013 sizeof(struct gl_current_attrib) );
1014 break;
1015 case GL_DEPTH_BUFFER_BIT:
1016 {
1017 const struct gl_depthbuffer_attrib *depth;
1018 depth = (const struct gl_depthbuffer_attrib *) attr->data;
1019 _mesa_DepthFunc(depth->Func);
1020 _mesa_ClearDepth(depth->Clear);
1021 _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test);
1022 _mesa_DepthMask(depth->Mask);
1023 }
1024 break;
1025 case GL_ENABLE_BIT:
1026 {
1027 const struct gl_enable_attrib *enable;
1028 enable = (const struct gl_enable_attrib *) attr->data;
1029 pop_enable_group(ctx, enable);
1030 ctx->NewState |= _NEW_ALL;
1031 }
1032 break;
1033 case GL_EVAL_BIT:
1034 memcpy( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
1035 ctx->NewState |= _NEW_EVAL;
1036 break;
1037 case GL_FOG_BIT:
1038 {
1039 const struct gl_fog_attrib *fog;
1040 fog = (const struct gl_fog_attrib *) attr->data;
1041 _mesa_set_enable(ctx, GL_FOG, fog->Enabled);
1042 _mesa_Fogfv(GL_FOG_COLOR, fog->Color);
1043 _mesa_Fogf(GL_FOG_DENSITY, fog->Density);
1044 _mesa_Fogf(GL_FOG_START, fog->Start);
1045 _mesa_Fogf(GL_FOG_END, fog->End);
1046 _mesa_Fogf(GL_FOG_INDEX, fog->Index);
1047 _mesa_Fogi(GL_FOG_MODE, fog->Mode);
1048 }
1049 break;
1050 case GL_HINT_BIT:
1051 {
1052 const struct gl_hint_attrib *hint;
1053 hint = (const struct gl_hint_attrib *) attr->data;
1054 _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT,
1055 hint->PerspectiveCorrection );
1056 _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth);
1057 _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth);
1058 _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth);
1059 _mesa_Hint(GL_FOG_HINT, hint->Fog);
1060 _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,
1061 hint->ClipVolumeClipping);
1062 _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB,
1063 hint->TextureCompression);
1064 }
1065 break;
1066 case GL_LIGHTING_BIT:
1067 {
1068 GLuint i;
1069 const struct gl_light_attrib *light;
1070 light = (const struct gl_light_attrib *) attr->data;
1071 /* lighting enable */
1072 _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled);
1073 /* per-light state */
1074 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top))
1075 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
1076
1077 for (i = 0; i < ctx->Const.MaxLights; i++) {
1078 const struct gl_light *l = &light->Light[i];
1079 _mesa_set_enable(ctx, GL_LIGHT0 + i, l->Enabled);
1080 _mesa_light(ctx, i, GL_AMBIENT, l->Ambient);
1081 _mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse);
1082 _mesa_light(ctx, i, GL_SPECULAR, l->Specular );
1083 _mesa_light(ctx, i, GL_POSITION, l->EyePosition);
1084 _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->SpotDirection);
1085 {
1086 GLfloat p[4] = { 0 };
1087 p[0] = l->SpotExponent;
1088 _mesa_light(ctx, i, GL_SPOT_EXPONENT, p);
1089 }
1090 {
1091 GLfloat p[4] = { 0 };
1092 p[0] = l->SpotCutoff;
1093 _mesa_light(ctx, i, GL_SPOT_CUTOFF, p);
1094 }
1095 {
1096 GLfloat p[4] = { 0 };
1097 p[0] = l->ConstantAttenuation;
1098 _mesa_light(ctx, i, GL_CONSTANT_ATTENUATION, p);
1099 }
1100 {
1101 GLfloat p[4] = { 0 };
1102 p[0] = l->LinearAttenuation;
1103 _mesa_light(ctx, i, GL_LINEAR_ATTENUATION, p);
1104 }
1105 {
1106 GLfloat p[4] = { 0 };
1107 p[0] = l->QuadraticAttenuation;
1108 _mesa_light(ctx, i, GL_QUADRATIC_ATTENUATION, p);
1109 }
1110 }
1111 /* light model */
1112 _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT,
1113 light->Model.Ambient);
1114 _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,
1115 (GLfloat) light->Model.LocalViewer);
1116 _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE,
1117 (GLfloat) light->Model.TwoSide);
1118 _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
1119 (GLfloat) light->Model.ColorControl);
1120 /* shade model */
1121 _mesa_ShadeModel(light->ShadeModel);
1122 /* color material */
1123 _mesa_ColorMaterial(light->ColorMaterialFace,
1124 light->ColorMaterialMode);
1125 _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
1126 light->ColorMaterialEnabled);
1127 /* materials */
1128 memcpy(&ctx->Light.Material, &light->Material,
1129 sizeof(struct gl_material));
1130 }
1131 break;
1132 case GL_LINE_BIT:
1133 {
1134 const struct gl_line_attrib *line;
1135 line = (const struct gl_line_attrib *) attr->data;
1136 _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag);
1137 _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag);
1138 _mesa_LineStipple(line->StippleFactor, line->StipplePattern);
1139 _mesa_LineWidth(line->Width);
1140 }
1141 break;
1142 case GL_LIST_BIT:
1143 memcpy( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
1144 break;
1145 case GL_PIXEL_MODE_BIT:
1146 memcpy( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
1147 /* XXX what other pixel state needs to be set by function calls? */
1148 _mesa_ReadBuffer(ctx->Pixel.ReadBuffer);
1149 ctx->NewState |= _NEW_PIXEL;
1150 break;
1151 case GL_POINT_BIT:
1152 {
1153 const struct gl_point_attrib *point;
1154 point = (const struct gl_point_attrib *) attr->data;
1155 _mesa_PointSize(point->Size);
1156 _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
1157 if (ctx->Extensions.EXT_point_parameters) {
1158 _mesa_PointParameterfv(GL_DISTANCE_ATTENUATION_EXT,
1159 point->Params);
1160 _mesa_PointParameterf(GL_POINT_SIZE_MIN_EXT,
1161 point->MinSize);
1162 _mesa_PointParameterf(GL_POINT_SIZE_MAX_EXT,
1163 point->MaxSize);
1164 _mesa_PointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
1165 point->Threshold);
1166 }
1167 if (ctx->Extensions.NV_point_sprite
1168 || ctx->Extensions.ARB_point_sprite) {
1169 GLuint u;
1170 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
1171 _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
1172 (GLint) point->CoordReplace[u]);
1173 }
1174 _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
1175 if (ctx->Extensions.NV_point_sprite)
1176 _mesa_PointParameteri(GL_POINT_SPRITE_R_MODE_NV,
1177 ctx->Point.SpriteRMode);
1178 _mesa_PointParameterf(GL_POINT_SPRITE_COORD_ORIGIN,
1179 (GLfloat)ctx->Point.SpriteOrigin);
1180 }
1181 }
1182 break;
1183 case GL_POLYGON_BIT:
1184 {
1185 const struct gl_polygon_attrib *polygon;
1186 polygon = (const struct gl_polygon_attrib *) attr->data;
1187 _mesa_CullFace(polygon->CullFaceMode);
1188 _mesa_FrontFace(polygon->FrontFace);
1189 _mesa_PolygonMode(GL_FRONT, polygon->FrontMode);
1190 _mesa_PolygonMode(GL_BACK, polygon->BackMode);
1191 _mesa_PolygonOffset(polygon->OffsetFactor,
1192 polygon->OffsetUnits);
1193 _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag);
1194 _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag);
1195 _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag);
1196 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT,
1197 polygon->OffsetPoint);
1198 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE,
1199 polygon->OffsetLine);
1200 _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL,
1201 polygon->OffsetFill);
1202 }
1203 break;
1204 case GL_POLYGON_STIPPLE_BIT:
1205 memcpy( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
1206 ctx->NewState |= _NEW_POLYGONSTIPPLE;
1207 if (ctx->Driver.PolygonStipple)
1208 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
1209 break;
1210 case GL_SCISSOR_BIT:
1211 {
1212 const struct gl_scissor_attrib *scissor;
1213 scissor = (const struct gl_scissor_attrib *) attr->data;
1214 _mesa_Scissor(scissor->X, scissor->Y,
1215 scissor->Width, scissor->Height);
1216 _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled);
1217 }
1218 break;
1219 case GL_STENCIL_BUFFER_BIT:
1220 {
1221 const struct gl_stencil_attrib *stencil;
1222 stencil = (const struct gl_stencil_attrib *) attr->data;
1223 _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled);
1224 _mesa_ClearStencil(stencil->Clear);
1225 if (ctx->Extensions.EXT_stencil_two_side) {
1226 _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT,
1227 stencil->TestTwoSide);
1228 _mesa_ActiveStencilFaceEXT(stencil->ActiveFace
1229 ? GL_BACK : GL_FRONT);
1230 }
1231 /* front state */
1232 _mesa_StencilFuncSeparate(GL_FRONT,
1233 stencil->Function[0],
1234 stencil->Ref[0],
1235 stencil->ValueMask[0]);
1236 _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]);
1237 _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0],
1238 stencil->ZFailFunc[0],
1239 stencil->ZPassFunc[0]);
1240 /* back state */
1241 _mesa_StencilFuncSeparate(GL_BACK,
1242 stencil->Function[1],
1243 stencil->Ref[1],
1244 stencil->ValueMask[1]);
1245 _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]);
1246 _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1],
1247 stencil->ZFailFunc[1],
1248 stencil->ZPassFunc[1]);
1249 }
1250 break;
1251 case GL_TRANSFORM_BIT:
1252 {
1253 GLuint i;
1254 const struct gl_transform_attrib *xform;
1255 xform = (const struct gl_transform_attrib *) attr->data;
1256 _mesa_MatrixMode(xform->MatrixMode);
1257 if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
1258 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
1259
1260 /* restore clip planes */
1261 for (i = 0; i < MAX_CLIP_PLANES; i++) {
1262 const GLuint mask = 1 << i;
1263 const GLfloat *eyePlane = xform->EyeUserPlane[i];
1264 COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane);
1265 if (xform->ClipPlanesEnabled & mask) {
1266 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
1267 }
1268 else {
1269 _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
1270 }
1271 if (ctx->Driver.ClipPlane)
1272 ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, eyePlane );
1273 }
1274
1275 /* normalize/rescale */
1276 if (xform->Normalize != ctx->Transform.Normalize)
1277 _mesa_set_enable(ctx, GL_NORMALIZE,ctx->Transform.Normalize);
1278 if (xform->RescaleNormals != ctx->Transform.RescaleNormals)
1279 _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT,
1280 ctx->Transform.RescaleNormals);
1281 if (xform->DepthClamp != ctx->Transform.DepthClamp)
1282 _mesa_set_enable(ctx, GL_DEPTH_CLAMP,
1283 ctx->Transform.DepthClamp);
1284 }
1285 break;
1286 case GL_TEXTURE_BIT:
1287 /* Take care of texture object reference counters */
1288 {
1289 struct texture_state *texstate
1290 = (struct texture_state *) attr->data;
1291 pop_texture_group(ctx, texstate);
1292 ctx->NewState |= _NEW_TEXTURE;
1293 }
1294 break;
1295 case GL_VIEWPORT_BIT:
1296 {
1297 const struct gl_viewport_attrib *vp;
1298 vp = (const struct gl_viewport_attrib *) attr->data;
1299 _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height);
1300 _mesa_DepthRange(vp->Near, vp->Far);
1301 }
1302 break;
1303 case GL_MULTISAMPLE_BIT_ARB:
1304 {
1305 const struct gl_multisample_attrib *ms;
1306 ms = (const struct gl_multisample_attrib *) attr->data;
1307 _mesa_SampleCoverageARB(ms->SampleCoverageValue,
1308 ms->SampleCoverageInvert);
1309 }
1310 break;
1311
1312 default:
1313 _mesa_problem( ctx, "Bad attrib flag in PopAttrib");
1314 break;
1315 }
1316
1317 next = attr->next;
1318 FREE( attr->data );
1319 FREE( attr );
1320 attr = next;
1321 }
1322 }
1323
1324
1325 /**
1326 * Helper for incrementing/decrementing vertex buffer object reference
1327 * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
1328 */
1329 static void
1330 adjust_buffer_object_ref_counts(struct gl_array_object *arrayObj, GLint step)
1331 {
1332 GLuint i;
1333
1334 arrayObj->Vertex.BufferObj->RefCount += step;
1335 arrayObj->Weight.BufferObj->RefCount += step;
1336 arrayObj->Normal.BufferObj->RefCount += step;
1337 arrayObj->Color.BufferObj->RefCount += step;
1338 arrayObj->SecondaryColor.BufferObj->RefCount += step;
1339 arrayObj->FogCoord.BufferObj->RefCount += step;
1340 arrayObj->Index.BufferObj->RefCount += step;
1341 arrayObj->EdgeFlag.BufferObj->RefCount += step;
1342 for (i = 0; i < Elements(arrayObj->TexCoord); i++)
1343 arrayObj->TexCoord[i].BufferObj->RefCount += step;
1344 for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
1345 arrayObj->VertexAttrib[i].BufferObj->RefCount += step;
1346 }
1347
1348
1349 /**
1350 * Copy gl_pixelstore_attrib from src to dst, updating buffer
1351 * object refcounts.
1352 */
1353 static void
1354 copy_pixelstore(GLcontext *ctx,
1355 struct gl_pixelstore_attrib *dst,
1356 const struct gl_pixelstore_attrib *src)
1357 {
1358 dst->Alignment = src->Alignment;
1359 dst->RowLength = src->RowLength;
1360 dst->SkipPixels = src->SkipPixels;
1361 dst->SkipRows = src->SkipRows;
1362 dst->ImageHeight = src->ImageHeight;
1363 dst->SkipImages = src->SkipImages;
1364 dst->SwapBytes = src->SwapBytes;
1365 dst->LsbFirst = src->LsbFirst;
1366 dst->ClientStorage = src->ClientStorage;
1367 dst->Invert = src->Invert;
1368 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1369 }
1370
1371
1372 #define GL_CLIENT_PACK_BIT (1<<20)
1373 #define GL_CLIENT_UNPACK_BIT (1<<21)
1374
1375
1376 void GLAPIENTRY
1377 _mesa_PushClientAttrib(GLbitfield mask)
1378 {
1379 struct gl_attrib_node *head;
1380
1381 GET_CURRENT_CONTEXT(ctx);
1382 ASSERT_OUTSIDE_BEGIN_END(ctx);
1383
1384 if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
1385 _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
1386 return;
1387 }
1388
1389 /* Build linked list of attribute nodes which save all attribute
1390 * groups specified by the mask.
1391 */
1392 head = NULL;
1393
1394 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
1395 struct gl_pixelstore_attrib *attr;
1396 /* packing attribs */
1397 attr = CALLOC_STRUCT( gl_pixelstore_attrib );
1398 copy_pixelstore(ctx, attr, &ctx->Pack);
1399 save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr);
1400 /* unpacking attribs */
1401 attr = CALLOC_STRUCT( gl_pixelstore_attrib );
1402 copy_pixelstore(ctx, attr, &ctx->Unpack);
1403 save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr);
1404 }
1405
1406 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
1407 struct gl_array_attrib *attr;
1408 struct gl_array_object *obj;
1409
1410 attr = MALLOC_STRUCT( gl_array_attrib );
1411 obj = MALLOC_STRUCT( gl_array_object );
1412
1413 #if FEATURE_ARB_vertex_buffer_object
1414 /* increment ref counts since we're copying pointers to these objects */
1415 ctx->Array.ArrayBufferObj->RefCount++;
1416 ctx->Array.ElementArrayBufferObj->RefCount++;
1417 #endif
1418
1419 memcpy( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
1420 memcpy( obj, ctx->Array.ArrayObj, sizeof(struct gl_array_object) );
1421
1422 attr->ArrayObj = obj;
1423
1424 save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr);
1425
1426 /* bump reference counts on buffer objects */
1427 adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, 1);
1428 }
1429
1430 ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
1431 ctx->ClientAttribStackDepth++;
1432 }
1433
1434
1435
1436
1437 void GLAPIENTRY
1438 _mesa_PopClientAttrib(void)
1439 {
1440 struct gl_attrib_node *node, *next;
1441
1442 GET_CURRENT_CONTEXT(ctx);
1443 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1444
1445 if (ctx->ClientAttribStackDepth == 0) {
1446 _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
1447 return;
1448 }
1449
1450 ctx->ClientAttribStackDepth--;
1451 node = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
1452
1453 while (node) {
1454 switch (node->kind) {
1455 case GL_CLIENT_PACK_BIT:
1456 {
1457 struct gl_pixelstore_attrib *store =
1458 (struct gl_pixelstore_attrib *) node->data;
1459 copy_pixelstore(ctx, &ctx->Pack, store);
1460 _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
1461 }
1462 ctx->NewState |= _NEW_PACKUNPACK;
1463 break;
1464 case GL_CLIENT_UNPACK_BIT:
1465 {
1466 struct gl_pixelstore_attrib *store =
1467 (struct gl_pixelstore_attrib *) node->data;
1468 copy_pixelstore(ctx, &ctx->Unpack, store);
1469 _mesa_reference_buffer_object(ctx, &store->BufferObj, NULL);
1470 }
1471 ctx->NewState |= _NEW_PACKUNPACK;
1472 break;
1473 case GL_CLIENT_VERTEX_ARRAY_BIT: {
1474 struct gl_array_attrib * data =
1475 (struct gl_array_attrib *) node->data;
1476
1477 adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, -1);
1478
1479 ctx->Array.ActiveTexture = data->ActiveTexture;
1480 if (data->LockCount != 0)
1481 _mesa_LockArraysEXT(data->LockFirst, data->LockCount);
1482 else if (ctx->Array.LockCount)
1483 _mesa_UnlockArraysEXT();
1484
1485 _mesa_BindVertexArrayAPPLE( data->ArrayObj->Name );
1486
1487 #if FEATURE_ARB_vertex_buffer_object
1488 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
1489 data->ArrayBufferObj->Name);
1490 _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
1491 data->ElementArrayBufferObj->Name);
1492 #endif
1493
1494 memcpy( ctx->Array.ArrayObj, data->ArrayObj,
1495 sizeof( struct gl_array_object ) );
1496
1497 FREE( data->ArrayObj );
1498
1499 /* FIXME: Should some bits in ctx->Array->NewState also be set
1500 * FIXME: here? It seems like it should be set to inclusive-or
1501 * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
1502 */
1503
1504 ctx->NewState |= _NEW_ARRAY;
1505 break;
1506 }
1507 default:
1508 _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
1509 break;
1510 }
1511
1512 next = node->next;
1513 FREE( node->data );
1514 FREE( node );
1515 node = next;
1516 }
1517 }
1518
1519
1520 void
1521 _mesa_init_attrib_dispatch(struct _glapi_table *disp)
1522 {
1523 SET_PopAttrib(disp, _mesa_PopAttrib);
1524 SET_PushAttrib(disp, _mesa_PushAttrib);
1525 SET_PopClientAttrib(disp, _mesa_PopClientAttrib);
1526 SET_PushClientAttrib(disp, _mesa_PushClientAttrib);
1527 }
1528
1529
1530 #endif /* FEATURE_attrib_stack */
1531
1532
1533 /**
1534 * Free any attribute state data that might be attached to the context.
1535 */
1536 void
1537 _mesa_free_attrib_data(GLcontext *ctx)
1538 {
1539 while (ctx->AttribStackDepth > 0) {
1540 struct gl_attrib_node *attr, *next;
1541
1542 ctx->AttribStackDepth--;
1543 attr = ctx->AttribStack[ctx->AttribStackDepth];
1544
1545 while (attr) {
1546 if (attr->kind == GL_TEXTURE_BIT) {
1547 struct texture_state *texstate = (struct texture_state*)attr->data;
1548 GLuint u, tgt;
1549 /* clear references to the saved texture objects */
1550 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
1551 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
1552 _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
1553 }
1554 }
1555 }
1556 else {
1557 /* any other chunks of state that requires special handling? */
1558 }
1559
1560 next = attr->next;
1561 free(attr->data);
1562 free(attr);
1563 attr = next;
1564 }
1565 }
1566 }
1567
1568
1569 void _mesa_init_attrib( GLcontext *ctx )
1570 {
1571 /* Renderer and client attribute stacks */
1572 ctx->AttribStackDepth = 0;
1573 ctx->ClientAttribStackDepth = 0;
1574 }