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