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