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