Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 1 | /* $Id: attrib.c,v 1.51 2001/05/29 15:23:48 brianp Exp $ */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 5 | * Version: 3.5 |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 6 | * |
Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 8 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 15 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 18 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 32 | #include "accum.h" |
| 33 | #include "alpha.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 34 | #include "attrib.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 35 | #include "blend.h" |
Brian Paul | ea39f04 | 2000-02-02 19:17:57 +0000 | [diff] [blame] | 36 | #include "buffers.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 37 | #include "clip.h" |
| 38 | #include "colormac.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 39 | #include "context.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 40 | #include "depth.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 41 | #include "enable.h" |
| 42 | #include "enums.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 43 | #include "fog.h" |
| 44 | #include "hint.h" |
| 45 | #include "light.h" |
| 46 | #include "lines.h" |
| 47 | #include "logic.h" |
| 48 | #include "masking.h" |
Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 49 | #include "matrix.h" |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 50 | #include "mem.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 51 | #include "points.h" |
| 52 | #include "polygon.h" |
| 53 | #include "scissor.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 54 | #include "simple_list.h" |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 55 | #include "stencil.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 56 | #include "texstate.h" |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 57 | #include "mtypes.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | /* |
| 64 | * Allocate a new attribute state node. These nodes have a |
| 65 | * "kind" value and a pointer to a struct of state data. |
| 66 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 67 | static struct gl_attrib_node * |
| 68 | new_attrib_node( GLbitfield kind ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 69 | { |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 70 | struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 71 | if (an) { |
| 72 | an->kind = kind; |
| 73 | } |
| 74 | return an; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | |
| 79 | /* |
| 80 | * Copy texture object state from one texture object to another. |
| 81 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 82 | static void |
| 83 | copy_texobj_state( struct gl_texture_object *dest, |
| 84 | const struct gl_texture_object *src ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 85 | { |
| 86 | /* |
| 87 | dest->Name = src->Name; |
| 88 | dest->Dimensions = src->Dimensions; |
| 89 | */ |
| 90 | dest->Priority = src->Priority; |
| 91 | dest->BorderColor[0] = src->BorderColor[0]; |
| 92 | dest->BorderColor[1] = src->BorderColor[1]; |
| 93 | dest->BorderColor[2] = src->BorderColor[2]; |
| 94 | dest->BorderColor[3] = src->BorderColor[3]; |
| 95 | dest->WrapS = src->WrapS; |
| 96 | dest->WrapT = src->WrapT; |
| 97 | dest->WrapR = src->WrapR; |
| 98 | dest->MinFilter = src->MinFilter; |
| 99 | dest->MagFilter = src->MagFilter; |
| 100 | dest->MinLod = src->MinLod; |
| 101 | dest->MaxLod = src->MaxLod; |
| 102 | dest->BaseLevel = src->BaseLevel; |
| 103 | dest->MaxLevel = src->MaxLevel; |
Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 104 | dest->MaxAnisotropy = src->MaxAnisotropy; |
Brian Paul | c499ce3 | 2001-02-20 16:42:25 +0000 | [diff] [blame] | 105 | dest->CompareFlag = src->CompareFlag; |
| 106 | dest->CompareOperator = src->CompareOperator; |
| 107 | dest->ShadowAmbient = src->ShadowAmbient; |
Brian Paul | 083e466 | 2000-12-14 20:25:56 +0000 | [diff] [blame] | 108 | dest->_MaxLevel = src->_MaxLevel; |
| 109 | dest->_MaxLambda = src->_MaxLambda; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 110 | dest->Palette = src->Palette; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 111 | dest->Complete = src->Complete; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 116 | void |
| 117 | _mesa_PushAttrib(GLbitfield mask) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 118 | { |
| 119 | struct gl_attrib_node *newnode; |
| 120 | struct gl_attrib_node *head; |
| 121 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 122 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 123 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 124 | |
| 125 | if (MESA_VERBOSE&VERBOSE_API) |
Keith Whitwell | e5ed37f | 2000-02-27 20:38:15 +0000 | [diff] [blame] | 126 | fprintf(stderr, "glPushAttrib %x\n", (int)mask); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 127 | |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 128 | if (ctx->AttribStackDepth >= MAX_ATTRIB_STACK_DEPTH) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 129 | _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
| 133 | /* Build linked list of attribute nodes which save all attribute */ |
| 134 | /* groups specified by the mask. */ |
| 135 | head = NULL; |
| 136 | |
| 137 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| 138 | struct gl_accum_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 139 | attr = MALLOC_STRUCT( gl_accum_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 140 | MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) ); |
| 141 | newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT ); |
| 142 | newnode->data = attr; |
| 143 | newnode->next = head; |
| 144 | head = newnode; |
| 145 | } |
| 146 | |
| 147 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 148 | struct gl_colorbuffer_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 149 | attr = MALLOC_STRUCT( gl_colorbuffer_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 150 | MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) ); |
| 151 | newnode = new_attrib_node( GL_COLOR_BUFFER_BIT ); |
| 152 | newnode->data = attr; |
| 153 | newnode->next = head; |
| 154 | head = newnode; |
| 155 | } |
| 156 | |
| 157 | if (mask & GL_CURRENT_BIT) { |
| 158 | struct gl_current_attrib *attr; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 159 | FLUSH_CURRENT( ctx, 0 ); |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 160 | attr = MALLOC_STRUCT( gl_current_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 161 | MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) ); |
| 162 | newnode = new_attrib_node( GL_CURRENT_BIT ); |
| 163 | newnode->data = attr; |
| 164 | newnode->next = head; |
| 165 | head = newnode; |
| 166 | } |
| 167 | |
| 168 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| 169 | struct gl_depthbuffer_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 170 | attr = MALLOC_STRUCT( gl_depthbuffer_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 171 | MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) ); |
| 172 | newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT ); |
| 173 | newnode->data = attr; |
| 174 | newnode->next = head; |
| 175 | head = newnode; |
| 176 | } |
| 177 | |
| 178 | if (mask & GL_ENABLE_BIT) { |
| 179 | struct gl_enable_attrib *attr; |
| 180 | GLuint i; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 181 | attr = MALLOC_STRUCT( gl_enable_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 182 | /* Copy enable flags from all other attributes into the enable struct. */ |
| 183 | attr->AlphaTest = ctx->Color.AlphaEnabled; |
| 184 | attr->AutoNormal = ctx->Eval.AutoNormal; |
| 185 | attr->Blend = ctx->Color.BlendEnabled; |
| 186 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 187 | attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i]; |
| 188 | } |
| 189 | attr->ColorMaterial = ctx->Light.ColorMaterialEnabled; |
Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 190 | attr->Convolution1D = ctx->Pixel.Convolution1DEnabled; |
| 191 | attr->Convolution2D = ctx->Pixel.Convolution2DEnabled; |
| 192 | attr->Separable2D = ctx->Pixel.Separable2DEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 193 | attr->CullFace = ctx->Polygon.CullFlag; |
| 194 | attr->DepthTest = ctx->Depth.Test; |
| 195 | attr->Dither = ctx->Color.DitherFlag; |
| 196 | attr->Fog = ctx->Fog.Enabled; |
| 197 | for (i=0;i<MAX_LIGHTS;i++) { |
| 198 | attr->Light[i] = ctx->Light.Light[i].Enabled; |
| 199 | } |
| 200 | attr->Lighting = ctx->Light.Enabled; |
| 201 | attr->LineSmooth = ctx->Line.SmoothFlag; |
| 202 | attr->LineStipple = ctx->Line.StippleFlag; |
Brian Paul | 2b2e925 | 2000-04-07 16:27:26 +0000 | [diff] [blame] | 203 | attr->Histogram = ctx->Pixel.HistogramEnabled; |
| 204 | attr->MinMax = ctx->Pixel.MinMaxEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 205 | attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled; |
| 206 | attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled; |
| 207 | attr->Map1Color4 = ctx->Eval.Map1Color4; |
| 208 | attr->Map1Index = ctx->Eval.Map1Index; |
| 209 | attr->Map1Normal = ctx->Eval.Map1Normal; |
| 210 | attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1; |
| 211 | attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2; |
| 212 | attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3; |
| 213 | attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4; |
| 214 | attr->Map1Vertex3 = ctx->Eval.Map1Vertex3; |
| 215 | attr->Map1Vertex4 = ctx->Eval.Map1Vertex4; |
| 216 | attr->Map2Color4 = ctx->Eval.Map2Color4; |
| 217 | attr->Map2Index = ctx->Eval.Map2Index; |
| 218 | attr->Map2Normal = ctx->Eval.Map2Normal; |
| 219 | attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1; |
| 220 | attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2; |
| 221 | attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3; |
| 222 | attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4; |
| 223 | attr->Map2Vertex3 = ctx->Eval.Map2Vertex3; |
| 224 | attr->Map2Vertex4 = ctx->Eval.Map2Vertex4; |
| 225 | attr->Normalize = ctx->Transform.Normalize; |
Brian Paul | 2b2e925 | 2000-04-07 16:27:26 +0000 | [diff] [blame] | 226 | attr->PixelTexture = ctx->Pixel.PixelTextureEnabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 227 | attr->PointSmooth = ctx->Point.SmoothFlag; |
| 228 | attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint; |
| 229 | attr->PolygonOffsetLine = ctx->Polygon.OffsetLine; |
| 230 | attr->PolygonOffsetFill = ctx->Polygon.OffsetFill; |
| 231 | attr->PolygonSmooth = ctx->Polygon.SmoothFlag; |
| 232 | attr->PolygonStipple = ctx->Polygon.StippleFlag; |
| 233 | attr->RescaleNormals = ctx->Transform.RescaleNormals; |
| 234 | attr->Scissor = ctx->Scissor.Enabled; |
| 235 | attr->Stencil = ctx->Stencil.Enabled; |
Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 236 | attr->MultisampleEnabled = ctx->Multisample.Enabled; |
| 237 | attr->SampleAlphaToCoverage = ctx->Multisample.SampleAlphaToCoverage; |
| 238 | attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne; |
| 239 | attr->SampleCoverage = ctx->Multisample.SampleCoverage; |
| 240 | attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 241 | for (i=0; i<MAX_TEXTURE_UNITS; i++) { |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 242 | attr->Texture[i] = ctx->Texture.Unit[i].Enabled; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 243 | attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled; |
| 244 | } |
| 245 | newnode = new_attrib_node( GL_ENABLE_BIT ); |
| 246 | newnode->data = attr; |
| 247 | newnode->next = head; |
| 248 | head = newnode; |
| 249 | } |
| 250 | |
| 251 | if (mask & GL_EVAL_BIT) { |
| 252 | struct gl_eval_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 253 | attr = MALLOC_STRUCT( gl_eval_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 254 | MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) ); |
| 255 | newnode = new_attrib_node( GL_EVAL_BIT ); |
| 256 | newnode->data = attr; |
| 257 | newnode->next = head; |
| 258 | head = newnode; |
| 259 | } |
| 260 | |
| 261 | if (mask & GL_FOG_BIT) { |
| 262 | struct gl_fog_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 263 | attr = MALLOC_STRUCT( gl_fog_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 264 | MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) ); |
| 265 | newnode = new_attrib_node( GL_FOG_BIT ); |
| 266 | newnode->data = attr; |
| 267 | newnode->next = head; |
| 268 | head = newnode; |
| 269 | } |
| 270 | |
| 271 | if (mask & GL_HINT_BIT) { |
| 272 | struct gl_hint_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 273 | attr = MALLOC_STRUCT( gl_hint_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 274 | MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) ); |
| 275 | newnode = new_attrib_node( GL_HINT_BIT ); |
| 276 | newnode->data = attr; |
| 277 | newnode->next = head; |
| 278 | head = newnode; |
| 279 | } |
| 280 | |
| 281 | if (mask & GL_LIGHTING_BIT) { |
| 282 | struct gl_light_attrib *attr; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 283 | FLUSH_CURRENT(ctx, 0); /* flush material changes */ |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 284 | attr = MALLOC_STRUCT( gl_light_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 285 | MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) ); |
| 286 | newnode = new_attrib_node( GL_LIGHTING_BIT ); |
| 287 | newnode->data = attr; |
| 288 | newnode->next = head; |
| 289 | head = newnode; |
| 290 | } |
| 291 | |
| 292 | if (mask & GL_LINE_BIT) { |
| 293 | struct gl_line_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 294 | attr = MALLOC_STRUCT( gl_line_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 295 | MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) ); |
| 296 | newnode = new_attrib_node( GL_LINE_BIT ); |
| 297 | newnode->data = attr; |
| 298 | newnode->next = head; |
| 299 | head = newnode; |
| 300 | } |
| 301 | |
| 302 | if (mask & GL_LIST_BIT) { |
| 303 | struct gl_list_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 304 | attr = MALLOC_STRUCT( gl_list_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 305 | MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) ); |
| 306 | newnode = new_attrib_node( GL_LIST_BIT ); |
| 307 | newnode->data = attr; |
| 308 | newnode->next = head; |
| 309 | head = newnode; |
| 310 | } |
| 311 | |
| 312 | if (mask & GL_PIXEL_MODE_BIT) { |
| 313 | struct gl_pixel_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 314 | attr = MALLOC_STRUCT( gl_pixel_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 315 | MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) ); |
| 316 | newnode = new_attrib_node( GL_PIXEL_MODE_BIT ); |
| 317 | newnode->data = attr; |
| 318 | newnode->next = head; |
| 319 | head = newnode; |
| 320 | } |
| 321 | |
| 322 | if (mask & GL_POINT_BIT) { |
| 323 | struct gl_point_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 324 | attr = MALLOC_STRUCT( gl_point_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 325 | MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) ); |
| 326 | newnode = new_attrib_node( GL_POINT_BIT ); |
| 327 | newnode->data = attr; |
| 328 | newnode->next = head; |
| 329 | head = newnode; |
| 330 | } |
| 331 | |
| 332 | if (mask & GL_POLYGON_BIT) { |
| 333 | struct gl_polygon_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 334 | attr = MALLOC_STRUCT( gl_polygon_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 335 | MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) ); |
| 336 | newnode = new_attrib_node( GL_POLYGON_BIT ); |
| 337 | newnode->data = attr; |
| 338 | newnode->next = head; |
| 339 | head = newnode; |
| 340 | } |
| 341 | |
| 342 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 343 | GLuint *stipple; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 344 | stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 345 | MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) ); |
| 346 | newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT ); |
| 347 | newnode->data = stipple; |
| 348 | newnode->next = head; |
| 349 | head = newnode; |
| 350 | } |
| 351 | |
| 352 | if (mask & GL_SCISSOR_BIT) { |
| 353 | struct gl_scissor_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 354 | attr = MALLOC_STRUCT( gl_scissor_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 355 | MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) ); |
| 356 | newnode = new_attrib_node( GL_SCISSOR_BIT ); |
| 357 | newnode->data = attr; |
| 358 | newnode->next = head; |
| 359 | head = newnode; |
| 360 | } |
| 361 | |
| 362 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| 363 | struct gl_stencil_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 364 | attr = MALLOC_STRUCT( gl_stencil_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 365 | MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) ); |
| 366 | newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT ); |
| 367 | newnode->data = attr; |
| 368 | newnode->next = head; |
| 369 | head = newnode; |
| 370 | } |
| 371 | |
| 372 | if (mask & GL_TEXTURE_BIT) { |
| 373 | struct gl_texture_attrib *attr; |
| 374 | GLuint u; |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 375 | /* Bump the texture object reference counts so that they don't |
| 376 | * inadvertantly get deleted. |
| 377 | */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 378 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 379 | ctx->Texture.Unit[u].Current1D->RefCount++; |
| 380 | ctx->Texture.Unit[u].Current2D->RefCount++; |
| 381 | ctx->Texture.Unit[u].Current3D->RefCount++; |
| 382 | ctx->Texture.Unit[u].CurrentCubeMap->RefCount++; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 383 | } |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 384 | attr = MALLOC_STRUCT( gl_texture_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 385 | MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) ); |
| 386 | /* copy state of the currently bound texture objects */ |
| 387 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 388 | copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].Current1D); |
| 389 | copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].Current2D); |
| 390 | copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].Current3D); |
Brian Paul | 6479a17 | 2000-07-05 22:26:43 +0000 | [diff] [blame] | 391 | copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 392 | } |
| 393 | newnode = new_attrib_node( GL_TEXTURE_BIT ); |
| 394 | newnode->data = attr; |
| 395 | newnode->next = head; |
| 396 | head = newnode; |
| 397 | } |
| 398 | |
| 399 | if (mask & GL_TRANSFORM_BIT) { |
| 400 | struct gl_transform_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 401 | attr = MALLOC_STRUCT( gl_transform_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 402 | MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) ); |
| 403 | newnode = new_attrib_node( GL_TRANSFORM_BIT ); |
| 404 | newnode->data = attr; |
| 405 | newnode->next = head; |
| 406 | head = newnode; |
| 407 | } |
| 408 | |
| 409 | if (mask & GL_VIEWPORT_BIT) { |
| 410 | struct gl_viewport_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 411 | attr = MALLOC_STRUCT( gl_viewport_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 412 | MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) ); |
| 413 | newnode = new_attrib_node( GL_VIEWPORT_BIT ); |
| 414 | newnode->data = attr; |
| 415 | newnode->next = head; |
| 416 | head = newnode; |
| 417 | } |
| 418 | |
Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 419 | /* GL_ARB_multisample */ |
| 420 | if (mask & GL_MULTISAMPLE_BIT_ARB) { |
| 421 | struct gl_multisample_attrib *attr; |
| 422 | attr = MALLOC_STRUCT( gl_multisample_attrib ); |
| 423 | MEMCPY( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) ); |
| 424 | newnode = new_attrib_node( GL_MULTISAMPLE_BIT_ARB ); |
| 425 | newnode->data = attr; |
| 426 | newnode->next = head; |
| 427 | head = newnode; |
| 428 | } |
| 429 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 430 | ctx->AttribStack[ctx->AttribStackDepth] = head; |
| 431 | ctx->AttribStackDepth++; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 436 | static void |
| 437 | pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable) |
| 438 | { |
| 439 | GLuint i; |
| 440 | |
| 441 | #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM) \ |
| 442 | if ((VALUE) != (NEWVALUE)) { \ |
| 443 | _mesa_set_enable( ctx, ENUM, (NEWVALUE) ); \ |
| 444 | } |
| 445 | |
| 446 | TEST_AND_UPDATE(ctx->Color.AlphaEnabled, enable->AlphaTest, GL_ALPHA_TEST); |
| 447 | TEST_AND_UPDATE(ctx->Transform.Normalize, enable->AutoNormal, GL_NORMALIZE); |
| 448 | TEST_AND_UPDATE(ctx->Color.BlendEnabled, enable->Blend, GL_BLEND); |
| 449 | |
| 450 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 451 | if (ctx->Transform.ClipEnabled[i] != enable->ClipPlane[i]) |
| 452 | _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i), |
| 453 | enable->ClipPlane[i]); |
| 454 | } |
| 455 | |
| 456 | TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, |
| 457 | GL_COLOR_MATERIAL); |
| 458 | TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE); |
| 459 | TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST); |
| 460 | TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER); |
| 461 | TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D, |
| 462 | GL_CONVOLUTION_1D); |
| 463 | TEST_AND_UPDATE(ctx->Pixel.Convolution2DEnabled, enable->Convolution2D, |
| 464 | GL_CONVOLUTION_2D); |
| 465 | TEST_AND_UPDATE(ctx->Pixel.Separable2DEnabled, enable->Separable2D, |
| 466 | GL_SEPARABLE_2D); |
| 467 | TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG); |
| 468 | TEST_AND_UPDATE(ctx->Light.Enabled, enable->Lighting, GL_LIGHTING); |
| 469 | TEST_AND_UPDATE(ctx->Line.SmoothFlag, enable->LineSmooth, GL_LINE_SMOOTH); |
| 470 | TEST_AND_UPDATE(ctx->Line.StippleFlag, enable->LineStipple, |
| 471 | GL_LINE_STIPPLE); |
| 472 | TEST_AND_UPDATE(ctx->Color.IndexLogicOpEnabled, enable->IndexLogicOp, |
| 473 | GL_INDEX_LOGIC_OP); |
| 474 | TEST_AND_UPDATE(ctx->Color.ColorLogicOpEnabled, enable->ColorLogicOp, |
| 475 | GL_COLOR_LOGIC_OP); |
| 476 | TEST_AND_UPDATE(ctx->Eval.Map1Color4, enable->Map1Color4, GL_MAP1_COLOR_4); |
| 477 | TEST_AND_UPDATE(ctx->Eval.Map1Index, enable->Map1Index, GL_MAP1_INDEX); |
| 478 | TEST_AND_UPDATE(ctx->Eval.Map1Normal, enable->Map1Normal, GL_MAP1_NORMAL); |
| 479 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord1, enable->Map1TextureCoord1, |
| 480 | GL_MAP1_TEXTURE_COORD_1); |
| 481 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord2, enable->Map1TextureCoord2, |
| 482 | GL_MAP1_TEXTURE_COORD_2); |
| 483 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord3, enable->Map1TextureCoord3, |
| 484 | GL_MAP1_TEXTURE_COORD_3); |
| 485 | TEST_AND_UPDATE(ctx->Eval.Map1TextureCoord4, enable->Map1TextureCoord4, |
| 486 | GL_MAP1_TEXTURE_COORD_4); |
| 487 | TEST_AND_UPDATE(ctx->Eval.Map1Vertex3, enable->Map1Vertex3, |
| 488 | GL_MAP1_VERTEX_3); |
| 489 | TEST_AND_UPDATE(ctx->Eval.Map1Vertex4, enable->Map1Vertex4, |
| 490 | GL_MAP1_VERTEX_4); |
| 491 | TEST_AND_UPDATE(ctx->Eval.Map2Color4, enable->Map2Color4, GL_MAP2_COLOR_4); |
| 492 | TEST_AND_UPDATE(ctx->Eval.Map2Index, enable->Map2Index, GL_MAP2_INDEX); |
| 493 | TEST_AND_UPDATE(ctx->Eval.Map2Normal, enable->Map2Normal, GL_MAP2_NORMAL); |
| 494 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord1, enable->Map2TextureCoord1, |
| 495 | GL_MAP2_TEXTURE_COORD_1); |
| 496 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord2, enable->Map2TextureCoord2, |
| 497 | GL_MAP2_TEXTURE_COORD_2); |
| 498 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord3, enable->Map2TextureCoord3, |
| 499 | GL_MAP2_TEXTURE_COORD_3); |
| 500 | TEST_AND_UPDATE(ctx->Eval.Map2TextureCoord4, enable->Map2TextureCoord4, |
| 501 | GL_MAP2_TEXTURE_COORD_4); |
| 502 | TEST_AND_UPDATE(ctx->Eval.Map2Vertex3, enable->Map2Vertex3, |
| 503 | GL_MAP2_VERTEX_3); |
| 504 | TEST_AND_UPDATE(ctx->Eval.Map2Vertex4, enable->Map2Vertex4, |
| 505 | GL_MAP2_VERTEX_4); |
| 506 | TEST_AND_UPDATE(ctx->Transform.Normalize, enable->Normalize, GL_NORMALIZE); |
| 507 | TEST_AND_UPDATE(ctx->Transform.RescaleNormals, enable->RescaleNormals, |
| 508 | GL_RESCALE_NORMAL_EXT); |
| 509 | TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture, |
| 510 | GL_POINT_SMOOTH); |
| 511 | TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth, |
| 512 | GL_POINT_SMOOTH); |
| 513 | TEST_AND_UPDATE(ctx->Polygon.OffsetPoint, enable->PolygonOffsetPoint, |
| 514 | GL_POLYGON_OFFSET_POINT); |
| 515 | TEST_AND_UPDATE(ctx->Polygon.OffsetLine, enable->PolygonOffsetLine, |
| 516 | GL_POLYGON_OFFSET_LINE); |
| 517 | TEST_AND_UPDATE(ctx->Polygon.OffsetFill, enable->PolygonOffsetFill, |
| 518 | GL_POLYGON_OFFSET_FILL); |
| 519 | TEST_AND_UPDATE(ctx->Polygon.SmoothFlag, enable->PolygonSmooth, |
| 520 | GL_POLYGON_SMOOTH); |
| 521 | TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, |
| 522 | GL_POLYGON_STIPPLE); |
| 523 | TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST); |
| 524 | TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST); |
Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 525 | TEST_AND_UPDATE(ctx->Multisample.Enabled, enable->MultisampleEnabled, |
| 526 | GL_MULTISAMPLE_ARB); |
| 527 | TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToCoverage, |
| 528 | enable->SampleAlphaToCoverage, |
| 529 | GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); |
| 530 | TEST_AND_UPDATE(ctx->Multisample.SampleAlphaToOne, |
| 531 | enable->SampleAlphaToOne, |
| 532 | GL_SAMPLE_ALPHA_TO_ONE_ARB); |
| 533 | TEST_AND_UPDATE(ctx->Multisample.SampleCoverage, |
| 534 | enable->SampleCoverage, |
| 535 | GL_SAMPLE_COVERAGE_ARB); |
| 536 | TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert, |
| 537 | enable->SampleCoverageInvert, |
| 538 | GL_SAMPLE_COVERAGE_INVERT_ARB); |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 539 | #undef TEST_AND_UPDATE |
| 540 | |
| 541 | /* texture unit enables */ |
| 542 | for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { |
| 543 | if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) { |
| 544 | ctx->Texture.Unit[i].Enabled = enable->Texture[i]; |
| 545 | if (ctx->Driver.Enable) { |
| 546 | if (ctx->Driver.ActiveTexture) { |
| 547 | (*ctx->Driver.ActiveTexture)(ctx, i); |
| 548 | } |
| 549 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D, |
| 550 | (GLboolean) (enable->Texture[i] & TEXTURE0_1D) ); |
| 551 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D, |
| 552 | (GLboolean) (enable->Texture[i] & TEXTURE0_2D) ); |
| 553 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D, |
| 554 | (GLboolean) (enable->Texture[i] & TEXTURE0_3D) ); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) { |
| 559 | ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i]; |
| 560 | if (ctx->Driver.Enable) { |
| 561 | if (ctx->Driver.ActiveTexture) { |
| 562 | (*ctx->Driver.ActiveTexture)(ctx, i); |
| 563 | } |
| 564 | if (enable->TexGen[i] & S_BIT) |
| 565 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE); |
| 566 | else |
| 567 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE); |
| 568 | if (enable->TexGen[i] & T_BIT) |
| 569 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE); |
| 570 | else |
| 571 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE); |
| 572 | if (enable->TexGen[i] & R_BIT) |
| 573 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE); |
| 574 | else |
| 575 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE); |
| 576 | if (enable->TexGen[i] & Q_BIT) |
| 577 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE); |
| 578 | else |
| 579 | (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | if (ctx->Driver.ActiveTexture) { |
| 585 | (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 590 | static void |
| 591 | pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib) |
| 592 | { |
| 593 | GLuint u; |
| 594 | |
| 595 | /* "un-bump" the texture object reference counts. We did that so they |
| 596 | * wouldn't inadvertantly get deleted. |
| 597 | */ |
| 598 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 599 | ctx->Texture.Unit[u].Current1D->RefCount--; |
| 600 | ctx->Texture.Unit[u].Current2D->RefCount--; |
| 601 | ctx->Texture.Unit[u].Current3D->RefCount--; |
| 602 | ctx->Texture.Unit[u].CurrentCubeMap->RefCount--; |
| 603 | } |
| 604 | |
| 605 | for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { |
| 606 | const struct gl_texture_unit *unit = &texAttrib->Unit[u]; |
| 607 | GLuint numObjs, i; |
| 608 | |
| 609 | _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u); |
| 610 | _mesa_set_enable(ctx, GL_TEXTURE_1D, unit->Enabled & TEXTURE0_1D); |
| 611 | _mesa_set_enable(ctx, GL_TEXTURE_2D, unit->Enabled & TEXTURE0_2D); |
| 612 | _mesa_set_enable(ctx, GL_TEXTURE_3D, unit->Enabled & TEXTURE0_3D); |
| 613 | if (ctx->Extensions.ARB_texture_cube_map) { |
| 614 | _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB, |
| 615 | unit->Enabled & TEXTURE0_CUBE); |
| 616 | } |
| 617 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode); |
| 618 | _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor); |
| 619 | _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenModeS); |
| 620 | _mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenModeT); |
| 621 | _mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenModeR); |
| 622 | _mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenModeQ); |
| 623 | _mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->ObjectPlaneS); |
| 624 | _mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->ObjectPlaneT); |
| 625 | _mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->ObjectPlaneR); |
| 626 | _mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->ObjectPlaneQ); |
| 627 | _mesa_TexGenfv(GL_S, GL_EYE_PLANE, unit->EyePlaneS); |
| 628 | _mesa_TexGenfv(GL_T, GL_EYE_PLANE, unit->EyePlaneT); |
| 629 | _mesa_TexGenfv(GL_R, GL_EYE_PLANE, unit->EyePlaneR); |
| 630 | _mesa_TexGenfv(GL_Q, GL_EYE_PLANE, unit->EyePlaneQ); |
| 631 | if (ctx->Extensions.EXT_texture_lod_bias) { |
| 632 | _mesa_TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, |
| 633 | GL_TEXTURE_LOD_BIAS_EXT, unit->LodBias); |
| 634 | } |
Brian Paul | bcfe393 | 2001-04-17 21:25:53 +0000 | [diff] [blame] | 635 | if (ctx->Extensions.EXT_texture_env_combine || |
| 636 | ctx->Extensions.ARB_texture_env_combine) { |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 637 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, |
| 638 | unit->CombineModeRGB); |
| 639 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, |
| 640 | unit->CombineModeA); |
| 641 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, |
| 642 | unit->CombineSourceRGB[0]); |
| 643 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, |
| 644 | unit->CombineSourceRGB[1]); |
| 645 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, |
| 646 | unit->CombineSourceRGB[2]); |
| 647 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, |
| 648 | unit->CombineSourceA[0]); |
| 649 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, |
| 650 | unit->CombineSourceA[1]); |
| 651 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, |
| 652 | unit->CombineSourceA[2]); |
| 653 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, |
| 654 | unit->CombineOperandRGB[0]); |
| 655 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, |
| 656 | unit->CombineOperandRGB[1]); |
| 657 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, |
| 658 | unit->CombineOperandRGB[2]); |
| 659 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, |
| 660 | unit->CombineOperandA[0]); |
| 661 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, |
| 662 | unit->CombineOperandA[1]); |
| 663 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, |
| 664 | unit->CombineOperandA[2]); |
| 665 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, |
| 666 | 1 << unit->CombineScaleShiftRGB); |
| 667 | _mesa_TexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, |
| 668 | 1 << unit->CombineScaleShiftA); |
| 669 | } |
| 670 | |
| 671 | /* Restore texture object state */ |
| 672 | numObjs = ctx->Extensions.ARB_texture_cube_map ? 4 : 3; |
| 673 | |
| 674 | for (i = 0; i < numObjs; i++) { |
| 675 | GLenum target = 0; |
| 676 | const struct gl_texture_object *obj = NULL; |
| 677 | GLfloat bordColor[4]; |
| 678 | |
| 679 | switch (i) { |
| 680 | case 0: |
| 681 | target = GL_TEXTURE_1D; |
| 682 | obj = &unit->Saved1D; |
| 683 | break; |
| 684 | case 1: |
| 685 | target = GL_TEXTURE_2D; |
| 686 | obj = &unit->Saved2D; |
| 687 | break; |
| 688 | case 2: |
| 689 | target = GL_TEXTURE_3D; |
| 690 | obj = &unit->Saved3D; |
| 691 | break; |
| 692 | case 3: |
| 693 | target = GL_TEXTURE_CUBE_MAP_ARB; |
| 694 | obj = &unit->SavedCubeMap; |
| 695 | break; |
| 696 | default: |
| 697 | ; /* silence warnings */ |
| 698 | } |
| 699 | |
| 700 | bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]); |
| 701 | bordColor[1] = CHAN_TO_FLOAT(obj->BorderColor[1]); |
| 702 | bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]); |
| 703 | bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]); |
| 704 | |
Brian Paul | 9e351d5 | 2001-05-03 14:11:18 +0000 | [diff] [blame] | 705 | _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority); |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 706 | _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor); |
| 707 | _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS); |
| 708 | _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT); |
| 709 | _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR); |
| 710 | _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter); |
| 711 | _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter); |
| 712 | _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod); |
| 713 | _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod); |
| 714 | _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel); |
| 715 | _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel); |
| 716 | if (ctx->Extensions.EXT_texture_filter_anisotropic) { |
| 717 | _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, |
| 718 | obj->MaxAnisotropy); |
| 719 | } |
| 720 | if (ctx->Extensions.SGIX_shadow) { |
| 721 | _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_SGIX, |
| 722 | obj->CompareFlag); |
| 723 | _mesa_TexParameteri(target, GL_TEXTURE_COMPARE_OPERATOR_SGIX, |
| 724 | obj->CompareOperator); |
| 725 | } |
| 726 | if (ctx->Extensions.SGIX_shadow_ambient) { |
Brian Paul | 9e351d5 | 2001-05-03 14:11:18 +0000 | [diff] [blame] | 727 | _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX, |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 728 | CHAN_TO_FLOAT(obj->ShadowAmbient)); |
| 729 | } |
| 730 | |
| 731 | } |
| 732 | } |
| 733 | _mesa_ActiveTextureARB(GL_TEXTURE0_ARB |
| 734 | + texAttrib->CurrentUnit); |
| 735 | } |
| 736 | |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 737 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 738 | /* |
| 739 | * This function is kind of long just because we have to call a lot |
| 740 | * of device driver functions to update device driver state. |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 741 | * |
| 742 | * XXX As it is now, most of the pop-code calls immediate-mode Mesa functions |
| 743 | * in order to restore GL state. This isn't terribly efficient but it |
| 744 | * ensures that dirty flags and any derived state gets updated correctly. |
| 745 | * We could at least check if the value to restore equals the current value |
| 746 | * and then skip the Mesa call. |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 747 | */ |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 748 | void |
| 749 | _mesa_PopAttrib(void) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 750 | { |
| 751 | struct gl_attrib_node *attr, *next; |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 752 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 753 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 754 | |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 755 | if (ctx->AttribStackDepth == 0) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 756 | _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 757 | return; |
| 758 | } |
| 759 | |
| 760 | ctx->AttribStackDepth--; |
| 761 | attr = ctx->AttribStack[ctx->AttribStackDepth]; |
| 762 | |
| 763 | while (attr) { |
| 764 | |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 765 | if (MESA_VERBOSE&VERBOSE_API) { |
| 766 | fprintf(stderr, "glPopAttrib %s\n", |
| 767 | _mesa_lookup_enum_by_nr(attr->kind)); |
| 768 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 769 | |
| 770 | switch (attr->kind) { |
| 771 | case GL_ACCUM_BUFFER_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 772 | { |
| 773 | const struct gl_accum_attrib *accum; |
| 774 | accum = (const struct gl_accum_attrib *) attr->data; |
| 775 | _mesa_ClearAccum(accum->ClearColor[0], |
| 776 | accum->ClearColor[1], |
| 777 | accum->ClearColor[2], |
| 778 | accum->ClearColor[3]); |
| 779 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 780 | break; |
| 781 | case GL_COLOR_BUFFER_BIT: |
| 782 | { |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 783 | const struct gl_colorbuffer_attrib *color; |
| 784 | color = (const struct gl_colorbuffer_attrib *) attr->data; |
| 785 | _mesa_ClearIndex(color->ClearIndex); |
| 786 | _mesa_ClearColor(CHAN_TO_FLOAT(color->ClearColor[0]), |
| 787 | CHAN_TO_FLOAT(color->ClearColor[1]), |
| 788 | CHAN_TO_FLOAT(color->ClearColor[2]), |
| 789 | CHAN_TO_FLOAT(color->ClearColor[3])); |
| 790 | _mesa_IndexMask(color->IndexMask); |
| 791 | _mesa_ColorMask((GLboolean) (color->ColorMask[0] != 0), |
| 792 | (GLboolean) (color->ColorMask[1] != 0), |
| 793 | (GLboolean) (color->ColorMask[2] != 0), |
| 794 | (GLboolean) (color->ColorMask[3] != 0)); |
| 795 | _mesa_DrawBuffer(color->DrawBuffer); |
| 796 | _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled); |
| 797 | _mesa_AlphaFunc(color->AlphaFunc, |
| 798 | CHAN_TO_FLOAT(color->AlphaRef)); |
| 799 | _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled); |
| 800 | _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB, |
| 801 | color->BlendDstRGB, |
| 802 | color->BlendSrcA, |
| 803 | color->BlendDstA); |
| 804 | _mesa_BlendEquation(color->BlendEquation); |
| 805 | _mesa_BlendColor(color->BlendColor[0], |
| 806 | color->BlendColor[1], |
| 807 | color->BlendColor[2], |
| 808 | color->BlendColor[3]); |
| 809 | _mesa_LogicOp(color->LogicOp); |
| 810 | _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, |
| 811 | color->ColorLogicOpEnabled); |
| 812 | _mesa_set_enable(ctx, GL_INDEX_LOGIC_OP, |
| 813 | color->IndexLogicOpEnabled); |
| 814 | _mesa_set_enable(ctx, GL_DITHER, color->DitherFlag); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 815 | } |
| 816 | break; |
| 817 | case GL_CURRENT_BIT: |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 818 | FLUSH_CURRENT( ctx, 0 ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 819 | MEMCPY( &ctx->Current, attr->data, |
| 820 | sizeof(struct gl_current_attrib) ); |
| 821 | break; |
| 822 | case GL_DEPTH_BUFFER_BIT: |
| 823 | { |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 824 | const struct gl_depthbuffer_attrib *depth; |
| 825 | depth = (const struct gl_depthbuffer_attrib *) attr->data; |
| 826 | _mesa_DepthFunc(depth->Func); |
| 827 | _mesa_ClearDepth(depth->Clear); |
| 828 | _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test); |
| 829 | _mesa_DepthMask(depth->Mask); |
| 830 | if (ctx->Extensions.HP_occlusion_test) |
| 831 | _mesa_set_enable(ctx, GL_OCCLUSION_TEST_HP, |
| 832 | depth->OcclusionTest); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 833 | } |
| 834 | break; |
| 835 | case GL_ENABLE_BIT: |
| 836 | { |
| 837 | const struct gl_enable_attrib *enable; |
| 838 | enable = (const struct gl_enable_attrib *) attr->data; |
Brian Paul | eb6c643 | 2000-09-28 22:44:30 +0000 | [diff] [blame] | 839 | pop_enable_group(ctx, enable); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 840 | ctx->NewState |= _NEW_ALL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 841 | } |
| 842 | break; |
| 843 | case GL_EVAL_BIT: |
| 844 | MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 845 | ctx->NewState |= _NEW_EVAL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 846 | break; |
| 847 | case GL_FOG_BIT: |
| 848 | { |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 849 | const struct gl_fog_attrib *fog; |
| 850 | fog = (const struct gl_fog_attrib *) attr->data; |
| 851 | _mesa_set_enable(ctx, GL_FOG, fog->Enabled); |
| 852 | _mesa_Fogfv(GL_FOG_COLOR, fog->Color); |
| 853 | _mesa_Fogf(GL_FOG_DENSITY, fog->Density); |
| 854 | _mesa_Fogf(GL_FOG_START, fog->Start); |
| 855 | _mesa_Fogf(GL_FOG_END, fog->End); |
| 856 | _mesa_Fogf(GL_FOG_INDEX, fog->Index); |
| 857 | _mesa_Fogi(GL_FOG_MODE, fog->Mode); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 858 | } |
| 859 | break; |
| 860 | case GL_HINT_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 861 | { |
| 862 | const struct gl_hint_attrib *hint; |
| 863 | hint = (const struct gl_hint_attrib *) attr->data; |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 864 | _mesa_Hint(GL_PERSPECTIVE_CORRECTION_HINT, |
| 865 | hint->PerspectiveCorrection ); |
| 866 | _mesa_Hint(GL_POINT_SMOOTH_HINT, hint->PointSmooth); |
| 867 | _mesa_Hint(GL_LINE_SMOOTH_HINT, hint->LineSmooth); |
| 868 | _mesa_Hint(GL_POLYGON_SMOOTH_HINT, hint->PolygonSmooth); |
| 869 | _mesa_Hint(GL_FOG_HINT, hint->Fog); |
| 870 | _mesa_Hint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, |
| 871 | hint->ClipVolumeClipping); |
| 872 | if (ctx->Extensions.ARB_texture_compression) |
| 873 | _mesa_Hint(GL_TEXTURE_COMPRESSION_HINT_ARB, |
| 874 | hint->TextureCompression); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 875 | } |
| 876 | break; |
| 877 | case GL_LIGHTING_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 878 | { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 879 | GLuint i; |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 880 | const struct gl_light_attrib *light; |
| 881 | light = (const struct gl_light_attrib *) attr->data; |
| 882 | /* lighting enable */ |
| 883 | _mesa_set_enable(ctx, GL_LIGHTING, light->Enabled); |
| 884 | /* per-light state */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 885 | for (i = 0; i < MAX_LIGHTS; i++) { |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 886 | GLenum lgt = (GLenum) (GL_LIGHT0 + i); |
| 887 | _mesa_set_enable(ctx, lgt, light->Light[i].Enabled); |
| 888 | MEMCPY(&ctx->Light.Light[i], &light->Light[i], |
| 889 | sizeof(struct gl_light)); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 890 | } |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 891 | /* light model */ |
| 892 | _mesa_LightModelfv(GL_LIGHT_MODEL_AMBIENT, |
| 893 | light->Model.Ambient); |
| 894 | _mesa_LightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, |
| 895 | (GLfloat) light->Model.LocalViewer); |
| 896 | _mesa_LightModelf(GL_LIGHT_MODEL_TWO_SIDE, |
| 897 | (GLfloat) light->Model.TwoSide); |
| 898 | _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL, |
| 899 | (GLfloat) light->Model.ColorControl); |
| 900 | /* materials */ |
| 901 | MEMCPY(ctx->Light.Material, light->Material, |
| 902 | 2 * sizeof(struct gl_material)); |
| 903 | /* shade model */ |
Brian Paul | ba70e59 | 2001-01-29 22:15:44 +0000 | [diff] [blame] | 904 | _mesa_ShadeModel(light->ShadeModel); |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 905 | /* color material */ |
| 906 | _mesa_ColorMaterial(light->ColorMaterialFace, |
| 907 | light->ColorMaterialMode); |
| 908 | _mesa_set_enable(ctx, GL_COLOR_MATERIAL, |
| 909 | light->ColorMaterialEnabled); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 910 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 911 | break; |
| 912 | case GL_LINE_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 913 | { |
| 914 | const struct gl_line_attrib *line; |
| 915 | line = (const struct gl_line_attrib *) attr->data; |
| 916 | _mesa_set_enable(ctx, GL_LINE_SMOOTH, line->SmoothFlag); |
| 917 | _mesa_set_enable(ctx, GL_LINE_STIPPLE, line->StippleFlag); |
| 918 | _mesa_LineStipple(line->StippleFactor, line->StipplePattern); |
| 919 | _mesa_LineWidth(line->Width); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 920 | } |
| 921 | break; |
| 922 | case GL_LIST_BIT: |
| 923 | MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) ); |
| 924 | break; |
| 925 | case GL_PIXEL_MODE_BIT: |
| 926 | MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 927 | ctx->NewState |= _NEW_PIXEL; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 928 | break; |
| 929 | case GL_POINT_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 930 | { |
| 931 | const struct gl_point_attrib *point; |
| 932 | point = (const struct gl_point_attrib *) attr->data; |
| 933 | _mesa_PointSize(point->Size); |
| 934 | _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag); |
| 935 | _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, |
| 936 | point->Params); |
| 937 | _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT, point->MinSize); |
| 938 | _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT, point->MaxSize); |
| 939 | _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, |
| 940 | point->Threshold); |
| 941 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 942 | break; |
| 943 | case GL_POLYGON_BIT: |
| 944 | { |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 945 | const struct gl_polygon_attrib *polygon; |
| 946 | polygon = (const struct gl_polygon_attrib *) attr->data; |
| 947 | _mesa_CullFace(polygon->CullFaceMode); |
| 948 | _mesa_FrontFace(polygon->FrontFace); |
| 949 | _mesa_PolygonMode(GL_FRONT, polygon->FrontMode); |
| 950 | _mesa_PolygonMode(GL_BACK, polygon->BackMode); |
| 951 | _mesa_PolygonOffset(polygon->OffsetFactor, |
| 952 | polygon->OffsetUnits); |
| 953 | _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag); |
| 954 | _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag); |
| 955 | _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag); |
| 956 | _mesa_set_enable(ctx, GL_POLYGON_OFFSET_POINT, |
| 957 | polygon->OffsetPoint); |
| 958 | _mesa_set_enable(ctx, GL_POLYGON_OFFSET_LINE, |
| 959 | polygon->OffsetLine); |
| 960 | _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, |
| 961 | polygon->OffsetFill); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 962 | } |
| 963 | break; |
| 964 | case GL_POLYGON_STIPPLE_BIT: |
| 965 | MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) ); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 966 | ctx->NewState |= _NEW_POLYGONSTIPPLE; |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 967 | if (ctx->Driver.PolygonStipple) |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 968 | ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 969 | break; |
| 970 | case GL_SCISSOR_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 971 | { |
| 972 | const struct gl_scissor_attrib *scissor; |
| 973 | scissor = (const struct gl_scissor_attrib *) attr->data; |
| 974 | _mesa_Scissor(scissor->X, scissor->Y, |
| 975 | scissor->Width, scissor->Height); |
| 976 | _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled); |
| 977 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 978 | break; |
| 979 | case GL_STENCIL_BUFFER_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 980 | { |
| 981 | const struct gl_stencil_attrib *stencil; |
| 982 | stencil = (const struct gl_stencil_attrib *) attr->data; |
| 983 | _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled); |
| 984 | _mesa_ClearStencil(stencil->Clear); |
| 985 | _mesa_StencilFunc(stencil->Function, stencil->Ref, |
| 986 | stencil->ValueMask); |
| 987 | _mesa_StencilMask(stencil->WriteMask); |
| 988 | _mesa_StencilOp(stencil->FailFunc, stencil->ZFailFunc, |
| 989 | stencil->ZPassFunc); |
| 990 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 991 | break; |
| 992 | case GL_TRANSFORM_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 993 | { |
| 994 | GLuint i; |
| 995 | const struct gl_transform_attrib *xform; |
| 996 | xform = (const struct gl_transform_attrib *) attr->data; |
| 997 | _mesa_MatrixMode(xform->MatrixMode); |
| 998 | /* clip planes */ |
| 999 | MEMCPY(ctx->Transform.EyeUserPlane, xform->EyeUserPlane, |
| 1000 | sizeof(xform->EyeUserPlane)); |
| 1001 | MEMCPY(ctx->Transform._ClipUserPlane, xform->_ClipUserPlane, |
| 1002 | sizeof(xform->EyeUserPlane)); |
| 1003 | /* clip plane enable flags */ |
| 1004 | for (i = 0; i < MAX_CLIP_PLANES; i++) { |
| 1005 | _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, |
| 1006 | xform->ClipEnabled[i]); |
| 1007 | } |
| 1008 | /* normalize/rescale */ |
| 1009 | _mesa_set_enable(ctx, GL_NORMALIZE, ctx->Transform.Normalize); |
| 1010 | _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT, |
| 1011 | ctx->Transform.RescaleNormals); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1012 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1013 | break; |
| 1014 | case GL_TEXTURE_BIT: |
| 1015 | /* Take care of texture object reference counters */ |
| 1016 | { |
Brian Paul | 93de8d3 | 2001-04-11 23:22:20 +0000 | [diff] [blame] | 1017 | const struct gl_texture_attrib *texture; |
| 1018 | texture = (const struct gl_texture_attrib *) attr->data; |
| 1019 | pop_texture_group(ctx, texture); |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1020 | ctx->NewState |= _NEW_TEXTURE; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1021 | } |
| 1022 | break; |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1023 | case GL_VIEWPORT_BIT: |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 1024 | { |
| 1025 | const struct gl_viewport_attrib *vp; |
Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 1026 | vp = (const struct gl_viewport_attrib *) attr->data; |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 1027 | _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height); |
| 1028 | _mesa_DepthRange(vp->Near, vp->Far); |
| 1029 | } |
| 1030 | break; |
Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame^] | 1031 | case GL_MULTISAMPLE_BIT_ARB: |
| 1032 | { |
| 1033 | const struct gl_multisample_attrib *ms; |
| 1034 | ms = (const struct gl_multisample_attrib *) attr->data; |
| 1035 | _mesa_SampleCoverageARB(ms->SampleCoverageValue, |
| 1036 | ms->SampleCoverageInvert); |
| 1037 | } |
| 1038 | break; |
| 1039 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1040 | default: |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1041 | _mesa_problem( ctx, "Bad attrib flag in PopAttrib"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | } |
| 1044 | |
| 1045 | next = attr->next; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1046 | FREE( attr->data ); |
| 1047 | FREE( attr ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1048 | attr = next; |
| 1049 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | #define GL_CLIENT_PACK_BIT (1<<20) |
| 1054 | #define GL_CLIENT_UNPACK_BIT (1<<21) |
| 1055 | |
| 1056 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 1057 | void |
| 1058 | _mesa_PushClientAttrib(GLbitfield mask) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1059 | { |
| 1060 | struct gl_attrib_node *newnode; |
| 1061 | struct gl_attrib_node *head; |
| 1062 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 1063 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1064 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1065 | |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 1066 | if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1067 | _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | /* Build linked list of attribute nodes which save all attribute */ |
| 1072 | /* groups specified by the mask. */ |
| 1073 | head = NULL; |
| 1074 | |
| 1075 | if (mask & GL_CLIENT_PIXEL_STORE_BIT) { |
| 1076 | struct gl_pixelstore_attrib *attr; |
| 1077 | /* packing attribs */ |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1078 | attr = MALLOC_STRUCT( gl_pixelstore_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1079 | MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) ); |
| 1080 | newnode = new_attrib_node( GL_CLIENT_PACK_BIT ); |
| 1081 | newnode->data = attr; |
| 1082 | newnode->next = head; |
| 1083 | head = newnode; |
| 1084 | /* unpacking attribs */ |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1085 | attr = MALLOC_STRUCT( gl_pixelstore_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1086 | MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) ); |
| 1087 | newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT ); |
| 1088 | newnode->data = attr; |
| 1089 | newnode->next = head; |
| 1090 | head = newnode; |
| 1091 | } |
| 1092 | if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { |
| 1093 | struct gl_array_attrib *attr; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1094 | attr = MALLOC_STRUCT( gl_array_attrib ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1095 | MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) ); |
| 1096 | newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT ); |
| 1097 | newnode->data = attr; |
| 1098 | newnode->next = head; |
| 1099 | head = newnode; |
| 1100 | } |
| 1101 | |
| 1102 | ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head; |
| 1103 | ctx->ClientAttribStackDepth++; |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 1109 | void |
| 1110 | _mesa_PopClientAttrib(void) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1111 | { |
| 1112 | struct gl_attrib_node *attr, *next; |
| 1113 | |
Brian Paul | 42fcf03 | 2000-02-02 22:03:31 +0000 | [diff] [blame] | 1114 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1115 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1116 | |
Brian Paul | f3da389 | 2001-01-24 15:27:10 +0000 | [diff] [blame] | 1117 | if (ctx->ClientAttribStackDepth == 0) { |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1118 | _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | ctx->ClientAttribStackDepth--; |
| 1123 | attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth]; |
| 1124 | |
| 1125 | while (attr) { |
| 1126 | switch (attr->kind) { |
| 1127 | case GL_CLIENT_PACK_BIT: |
| 1128 | MEMCPY( &ctx->Pack, attr->data, |
| 1129 | sizeof(struct gl_pixelstore_attrib) ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1130 | ctx->NewState = _NEW_PACKUNPACK; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | case GL_CLIENT_UNPACK_BIT: |
| 1133 | MEMCPY( &ctx->Unpack, attr->data, |
| 1134 | sizeof(struct gl_pixelstore_attrib) ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1135 | ctx->NewState = _NEW_PACKUNPACK; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1136 | break; |
| 1137 | case GL_CLIENT_VERTEX_ARRAY_BIT: |
| 1138 | MEMCPY( &ctx->Array, attr->data, |
| 1139 | sizeof(struct gl_array_attrib) ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1140 | ctx->NewState = _NEW_ARRAY; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1141 | break; |
| 1142 | default: |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1143 | _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | next = attr->next; |
Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1148 | FREE( attr->data ); |
| 1149 | FREE( attr ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1150 | attr = next; |
| 1151 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1152 | } |