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