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