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