| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1 | /* $Id: light.c,v 1.31 2000/12/26 05:09:28 keithw 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 | 16a9efe | 2000-01-13 00:29:02 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 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 | c893a01 | 2000-10-28 20:41:13 +0000 | [diff] [blame] | 32 | #include "colormac.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | #include "context.h" |
| 34 | #include "enums.h" |
| 35 | #include "light.h" |
| 36 | #include "macros.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 37 | #include "mem.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 38 | #include "mmath.h" |
| 39 | #include "simple_list.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 40 | #include "mtypes.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 41 | |
| 42 | #include "math/m_xform.h" |
| 43 | #include "math/m_matrix.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | |
| Brian Paul | 075398b | 2000-01-31 23:33:53 +0000 | [diff] [blame] | 47 | /* XXX this is a bit of a hack needed for compilation within XFree86 */ |
| 48 | #ifndef FLT_MIN |
| 49 | #define FLT_MIN 1e-37 |
| 50 | #endif |
| 51 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 52 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 53 | void |
| 54 | _mesa_ShadeModel( GLenum mode ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 55 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 56 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 57 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 58 | |
| 59 | if (MESA_VERBOSE & VERBOSE_API) |
| 60 | fprintf(stderr, "glShadeModel %s\n", gl_lookup_enum_by_nr(mode)); |
| 61 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 62 | if (mode != GL_FLAT && mode != GL_SMOOTH) { |
| Keith Whitwell | 1bf9dfa | 1999-09-18 20:41:22 +0000 | [diff] [blame] | 63 | gl_error( ctx, GL_INVALID_ENUM, "glShadeModel" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 64 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 65 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 66 | |
| 67 | if (ctx->Light.ShadeModel == mode) |
| 68 | return; |
| 69 | |
| 70 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 71 | ctx->Light.ShadeModel = mode; |
| 72 | ctx->_TriangleCaps ^= DD_FLATSHADE; |
| 73 | if (ctx->Driver.ShadeModel) |
| 74 | (*ctx->Driver.ShadeModel)( ctx, mode ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 79 | void |
| 80 | _mesa_Lightf( GLenum light, GLenum pname, GLfloat param ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 81 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 82 | _mesa_Lightfv( light, pname, ¶m ); |
| 83 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 84 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 85 | |
| 86 | void |
| 87 | _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params ) |
| 88 | { |
| 89 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 90 | GLint i = (GLint) (light - GL_LIGHT0); |
| 91 | struct gl_light *l = &ctx->Light.Light[i]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 92 | |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 93 | if (i < 0 || i >= ctx->Const.MaxLights) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 94 | gl_error( ctx, GL_INVALID_ENUM, "glLight" ); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | switch (pname) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 99 | case GL_AMBIENT: |
| 100 | if (TEST_EQ_4V(l->Ambient, params)) |
| 101 | return; |
| 102 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 103 | COPY_4V( l->Ambient, params ); |
| 104 | break; |
| 105 | case GL_DIFFUSE: |
| 106 | if (TEST_EQ_4V(l->Diffuse, params)) |
| 107 | return; |
| 108 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 109 | COPY_4V( l->Diffuse, params ); |
| 110 | break; |
| 111 | case GL_SPECULAR: |
| 112 | if (TEST_EQ_4V(l->Specular, params)) |
| 113 | return; |
| 114 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 115 | COPY_4V( l->Specular, params ); |
| 116 | break; |
| 117 | case GL_POSITION: { |
| 118 | GLfloat tmp[4]; |
| 119 | /* transform position by ModelView matrix */ |
| 120 | TRANSFORM_POINT( tmp, ctx->ModelView.m, params ); |
| 121 | if (TEST_EQ_4V(l->EyePosition, tmp)) |
| 122 | return; |
| 123 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 124 | COPY_4V(l->EyePosition, tmp); |
| 125 | if (l->EyePosition[3] != 0.0F) |
| 126 | l->_Flags |= LIGHT_POSITIONAL; |
| 127 | else |
| 128 | l->_Flags &= ~LIGHT_POSITIONAL; |
| 129 | break; |
| 130 | } |
| 131 | case GL_SPOT_DIRECTION: { |
| 132 | GLfloat tmp[4]; |
| 133 | /* transform direction by inverse modelview */ |
| 134 | if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) { |
| 135 | _math_matrix_analyse( &ctx->ModelView ); |
| 136 | } |
| 137 | TRANSFORM_NORMAL( tmp, params, ctx->ModelView.inv ); |
| 138 | if (TEST_EQ_3V(l->EyeDirection, tmp)) |
| 139 | return; |
| 140 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 141 | COPY_3V(l->EyeDirection, tmp); |
| 142 | break; |
| 143 | } |
| 144 | case GL_SPOT_EXPONENT: |
| 145 | if (params[0]<0.0 || params[0]>128.0) { |
| 146 | gl_error( ctx, GL_INVALID_VALUE, "glLight" ); |
| 147 | return; |
| 148 | } |
| 149 | if (l->SpotExponent == params[0]) |
| 150 | return; |
| 151 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 152 | l->SpotExponent = params[0]; |
| 153 | gl_invalidate_spot_exp_table( l ); |
| 154 | break; |
| 155 | case GL_SPOT_CUTOFF: |
| 156 | if ((params[0]<0.0 || params[0]>90.0) && params[0]!=180.0) { |
| 157 | gl_error( ctx, GL_INVALID_VALUE, "glLight" ); |
| 158 | return; |
| 159 | } |
| 160 | if (l->SpotCutoff == params[0]) |
| 161 | return; |
| 162 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 163 | l->SpotCutoff = params[0]; |
| 164 | l->_CosCutoff = cos(params[0]*DEG2RAD); |
| 165 | if (l->_CosCutoff < 0) |
| 166 | l->_CosCutoff = 0; |
| 167 | if (l->SpotCutoff != 180.0F) |
| 168 | l->_Flags |= LIGHT_SPOT; |
| 169 | else |
| 170 | l->_Flags &= ~LIGHT_SPOT; |
| 171 | break; |
| 172 | case GL_CONSTANT_ATTENUATION: |
| 173 | if (params[0]<0.0) { |
| 174 | gl_error( ctx, GL_INVALID_VALUE, "glLight" ); |
| 175 | return; |
| 176 | } |
| 177 | if (l->ConstantAttenuation == params[0]) |
| 178 | return; |
| 179 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 180 | l->ConstantAttenuation = params[0]; |
| 181 | break; |
| 182 | case GL_LINEAR_ATTENUATION: |
| 183 | if (params[0]<0.0) { |
| 184 | gl_error( ctx, GL_INVALID_VALUE, "glLight" ); |
| 185 | return; |
| 186 | } |
| 187 | if (l->LinearAttenuation == params[0]) |
| 188 | return; |
| 189 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 190 | l->LinearAttenuation = params[0]; |
| 191 | break; |
| 192 | case GL_QUADRATIC_ATTENUATION: |
| 193 | if (params[0]<0.0) { |
| 194 | gl_error( ctx, GL_INVALID_VALUE, "glLight" ); |
| 195 | return; |
| 196 | } |
| 197 | if (l->QuadraticAttenuation == params[0]) |
| 198 | return; |
| 199 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 200 | l->QuadraticAttenuation = params[0]; |
| 201 | break; |
| 202 | default: |
| 203 | gl_error( ctx, GL_INVALID_ENUM, "glLight" ); |
| 204 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 207 | if (ctx->Driver.Lightfv) |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 208 | ctx->Driver.Lightfv( ctx, light, pname, params ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 212 | void |
| 213 | _mesa_Lighti( GLenum light, GLenum pname, GLint param ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 214 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 215 | _mesa_Lightiv( light, pname, ¶m ); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | void |
| 220 | _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params ) |
| 221 | { |
| 222 | GLfloat fparam[4]; |
| 223 | |
| 224 | switch (pname) { |
| 225 | case GL_AMBIENT: |
| 226 | case GL_DIFFUSE: |
| 227 | case GL_SPECULAR: |
| 228 | fparam[0] = INT_TO_FLOAT( params[0] ); |
| 229 | fparam[1] = INT_TO_FLOAT( params[1] ); |
| 230 | fparam[2] = INT_TO_FLOAT( params[2] ); |
| 231 | fparam[3] = INT_TO_FLOAT( params[3] ); |
| 232 | break; |
| 233 | case GL_POSITION: |
| 234 | fparam[0] = (GLfloat) params[0]; |
| 235 | fparam[1] = (GLfloat) params[1]; |
| 236 | fparam[2] = (GLfloat) params[2]; |
| 237 | fparam[3] = (GLfloat) params[3]; |
| 238 | break; |
| 239 | case GL_SPOT_DIRECTION: |
| 240 | fparam[0] = (GLfloat) params[0]; |
| 241 | fparam[1] = (GLfloat) params[1]; |
| 242 | fparam[2] = (GLfloat) params[2]; |
| 243 | break; |
| 244 | case GL_SPOT_EXPONENT: |
| 245 | case GL_SPOT_CUTOFF: |
| 246 | case GL_CONSTANT_ATTENUATION: |
| 247 | case GL_LINEAR_ATTENUATION: |
| 248 | case GL_QUADRATIC_ATTENUATION: |
| 249 | fparam[0] = (GLfloat) params[0]; |
| 250 | break; |
| 251 | default: |
| 252 | /* error will be caught later in gl_Lightfv */ |
| 253 | ; |
| 254 | } |
| 255 | |
| 256 | _mesa_Lightfv( light, pname, fparam ); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | |
| 261 | void |
| 262 | _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params ) |
| 263 | { |
| 264 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 265 | GLint l = (GLint) (light - GL_LIGHT0); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 266 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 267 | |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 268 | if (l < 0 || l >= ctx->Const.MaxLights) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 269 | gl_error( ctx, GL_INVALID_ENUM, "glGetLightfv" ); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | switch (pname) { |
| 274 | case GL_AMBIENT: |
| 275 | COPY_4V( params, ctx->Light.Light[l].Ambient ); |
| 276 | break; |
| 277 | case GL_DIFFUSE: |
| 278 | COPY_4V( params, ctx->Light.Light[l].Diffuse ); |
| 279 | break; |
| 280 | case GL_SPECULAR: |
| 281 | COPY_4V( params, ctx->Light.Light[l].Specular ); |
| 282 | break; |
| 283 | case GL_POSITION: |
| 284 | COPY_4V( params, ctx->Light.Light[l].EyePosition ); |
| 285 | break; |
| 286 | case GL_SPOT_DIRECTION: |
| 287 | COPY_3V( params, ctx->Light.Light[l].EyeDirection ); |
| 288 | break; |
| 289 | case GL_SPOT_EXPONENT: |
| 290 | params[0] = ctx->Light.Light[l].SpotExponent; |
| 291 | break; |
| 292 | case GL_SPOT_CUTOFF: |
| 293 | params[0] = ctx->Light.Light[l].SpotCutoff; |
| 294 | break; |
| 295 | case GL_CONSTANT_ATTENUATION: |
| 296 | params[0] = ctx->Light.Light[l].ConstantAttenuation; |
| 297 | break; |
| 298 | case GL_LINEAR_ATTENUATION: |
| 299 | params[0] = ctx->Light.Light[l].LinearAttenuation; |
| 300 | break; |
| 301 | case GL_QUADRATIC_ATTENUATION: |
| 302 | params[0] = ctx->Light.Light[l].QuadraticAttenuation; |
| 303 | break; |
| 304 | default: |
| 305 | gl_error( ctx, GL_INVALID_ENUM, "glGetLightfv" ); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 312 | void |
| 313 | _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 314 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 315 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 316 | GLint l = (GLint) (light - GL_LIGHT0); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 317 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 318 | |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 319 | if (l < 0 || l >= ctx->Const.MaxLights) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 320 | gl_error( ctx, GL_INVALID_ENUM, "glGetLightiv" ); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | switch (pname) { |
| 325 | case GL_AMBIENT: |
| 326 | params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]); |
| 327 | params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]); |
| 328 | params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]); |
| 329 | params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]); |
| 330 | break; |
| 331 | case GL_DIFFUSE: |
| 332 | params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]); |
| 333 | params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]); |
| 334 | params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]); |
| 335 | params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]); |
| 336 | break; |
| 337 | case GL_SPECULAR: |
| 338 | params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]); |
| 339 | params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]); |
| 340 | params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]); |
| 341 | params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]); |
| 342 | break; |
| 343 | case GL_POSITION: |
| 344 | params[0] = (GLint) ctx->Light.Light[l].EyePosition[0]; |
| 345 | params[1] = (GLint) ctx->Light.Light[l].EyePosition[1]; |
| 346 | params[2] = (GLint) ctx->Light.Light[l].EyePosition[2]; |
| 347 | params[3] = (GLint) ctx->Light.Light[l].EyePosition[3]; |
| 348 | break; |
| 349 | case GL_SPOT_DIRECTION: |
| 350 | params[0] = (GLint) ctx->Light.Light[l].EyeDirection[0]; |
| 351 | params[1] = (GLint) ctx->Light.Light[l].EyeDirection[1]; |
| 352 | params[2] = (GLint) ctx->Light.Light[l].EyeDirection[2]; |
| 353 | break; |
| 354 | case GL_SPOT_EXPONENT: |
| 355 | params[0] = (GLint) ctx->Light.Light[l].SpotExponent; |
| 356 | break; |
| 357 | case GL_SPOT_CUTOFF: |
| 358 | params[0] = (GLint) ctx->Light.Light[l].SpotCutoff; |
| 359 | break; |
| 360 | case GL_CONSTANT_ATTENUATION: |
| 361 | params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation; |
| 362 | break; |
| 363 | case GL_LINEAR_ATTENUATION: |
| 364 | params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation; |
| 365 | break; |
| 366 | case GL_QUADRATIC_ATTENUATION: |
| 367 | params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation; |
| 368 | break; |
| 369 | default: |
| 370 | gl_error( ctx, GL_INVALID_ENUM, "glGetLightiv" ); |
| 371 | break; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | |
| 376 | |
| 377 | /**********************************************************************/ |
| 378 | /*** Light Model ***/ |
| 379 | /**********************************************************************/ |
| 380 | |
| 381 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 382 | void |
| 383 | _mesa_LightModelfv( GLenum pname, const GLfloat *params ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 384 | { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 385 | GLenum newenum; |
| 386 | GLboolean newbool; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 387 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 388 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 389 | |
| 390 | switch (pname) { |
| 391 | case GL_LIGHT_MODEL_AMBIENT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 392 | if (TEST_EQ_4V( ctx->Light.Model.Ambient, params )) |
| 393 | return; |
| 394 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 395 | COPY_4V( ctx->Light.Model.Ambient, params ); |
| 396 | break; |
| 397 | case GL_LIGHT_MODEL_LOCAL_VIEWER: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 398 | newbool = (params[0]!=0.0); |
| 399 | if (ctx->Light.Model.LocalViewer == newbool) |
| 400 | return; |
| 401 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 402 | ctx->Light.Model.LocalViewer = newbool; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 403 | break; |
| 404 | case GL_LIGHT_MODEL_TWO_SIDE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 405 | newbool = (params[0]!=0.0); |
| 406 | if (ctx->Light.Model.TwoSide == newbool) |
| 407 | return; |
| 408 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 409 | ctx->Light.Model.TwoSide = newbool; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 410 | break; |
| 411 | case GL_LIGHT_MODEL_COLOR_CONTROL: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 412 | if (params[0] == (GLfloat) GL_SINGLE_COLOR) |
| 413 | newenum = GL_SINGLE_COLOR; |
| 414 | else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR) |
| 415 | newenum = GL_SEPARATE_SPECULAR_COLOR; |
| 416 | else { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 417 | gl_error( ctx, GL_INVALID_ENUM, "glLightModel(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 418 | return; |
| Brian Paul | f3f9b77 | 1999-10-19 20:32:40 +0000 | [diff] [blame] | 419 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 420 | if (ctx->Light.Model.ColorControl == newenum) |
| 421 | return; |
| 422 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 423 | ctx->Light.Model.ColorControl = newenum; |
| 424 | ctx->_TriangleCaps ^= DD_SEPERATE_SPECULAR; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 425 | break; |
| 426 | default: |
| 427 | gl_error( ctx, GL_INVALID_ENUM, "glLightModel" ); |
| 428 | break; |
| 429 | } |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 430 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 431 | if (ctx->Driver.LightModelfv) |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 432 | ctx->Driver.LightModelfv( ctx, pname, params ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 436 | void |
| 437 | _mesa_LightModeliv( GLenum pname, const GLint *params ) |
| 438 | { |
| 439 | GLfloat fparam[4]; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 440 | |
| 441 | switch (pname) { |
| 442 | case GL_LIGHT_MODEL_AMBIENT: |
| 443 | fparam[0] = INT_TO_FLOAT( params[0] ); |
| 444 | fparam[1] = INT_TO_FLOAT( params[1] ); |
| 445 | fparam[2] = INT_TO_FLOAT( params[2] ); |
| 446 | fparam[3] = INT_TO_FLOAT( params[3] ); |
| 447 | break; |
| 448 | case GL_LIGHT_MODEL_LOCAL_VIEWER: |
| 449 | case GL_LIGHT_MODEL_TWO_SIDE: |
| 450 | case GL_LIGHT_MODEL_COLOR_CONTROL: |
| 451 | fparam[0] = (GLfloat) params[0]; |
| 452 | break; |
| 453 | default: |
| 454 | /* Error will be caught later in gl_LightModelfv */ |
| 455 | ; |
| 456 | } |
| 457 | _mesa_LightModelfv( pname, fparam ); |
| 458 | } |
| 459 | |
| 460 | |
| 461 | void |
| 462 | _mesa_LightModeli( GLenum pname, GLint param ) |
| 463 | { |
| 464 | _mesa_LightModeliv( pname, ¶m ); |
| 465 | } |
| 466 | |
| 467 | |
| 468 | void |
| 469 | _mesa_LightModelf( GLenum pname, GLfloat param ) |
| 470 | { |
| 471 | _mesa_LightModelfv( pname, ¶m ); |
| 472 | } |
| 473 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 474 | |
| 475 | |
| 476 | /********** MATERIAL **********/ |
| 477 | |
| 478 | |
| 479 | /* |
| 480 | * Given a face and pname value (ala glColorMaterial), compute a bitmask |
| 481 | * of the targeted material values. |
| 482 | */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 483 | GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 484 | GLuint legal, |
| 485 | const char *where ) |
| 486 | { |
| 487 | GLuint bitmask = 0; |
| 488 | |
| 489 | /* Make a bitmask indicating what material attribute(s) we're updating */ |
| 490 | switch (pname) { |
| 491 | case GL_EMISSION: |
| 492 | bitmask |= FRONT_EMISSION_BIT | BACK_EMISSION_BIT; |
| 493 | break; |
| 494 | case GL_AMBIENT: |
| 495 | bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT; |
| 496 | break; |
| 497 | case GL_DIFFUSE: |
| 498 | bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT; |
| 499 | break; |
| 500 | case GL_SPECULAR: |
| 501 | bitmask |= FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT; |
| 502 | break; |
| 503 | case GL_SHININESS: |
| 504 | bitmask |= FRONT_SHININESS_BIT | BACK_SHININESS_BIT; |
| 505 | break; |
| 506 | case GL_AMBIENT_AND_DIFFUSE: |
| 507 | bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT; |
| 508 | bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT; |
| 509 | break; |
| 510 | case GL_COLOR_INDEXES: |
| 511 | bitmask |= FRONT_INDEXES_BIT | BACK_INDEXES_BIT; |
| 512 | break; |
| 513 | default: |
| 514 | gl_error( ctx, GL_INVALID_ENUM, where ); |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | if (face==GL_FRONT) { |
| 519 | bitmask &= FRONT_MATERIAL_BITS; |
| 520 | } |
| 521 | else if (face==GL_BACK) { |
| 522 | bitmask &= BACK_MATERIAL_BITS; |
| 523 | } |
| 524 | else if (face != GL_FRONT_AND_BACK) { |
| 525 | gl_error( ctx, GL_INVALID_ENUM, where ); |
| 526 | return 0; |
| 527 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 528 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 529 | if (bitmask & ~legal) { |
| 530 | gl_error( ctx, GL_INVALID_ENUM, where ); |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | return bitmask; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 539 | /* |
| 540 | * Check if the global material has to be updated with info that was |
| 541 | * associated with a vertex via glMaterial. |
| 542 | * This function is used when any material values get changed between |
| 543 | * glBegin/glEnd either by calling glMaterial() or by calling glColor() |
| 544 | * when GL_COLOR_MATERIAL is enabled. |
| 545 | * |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 546 | * src[0] is front material, src[1] is back material |
| 547 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 548 | * KW: Added code here to keep the precomputed variables uptodate. |
| 549 | * This means we can use the faster shade functions when using |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 550 | * GL_COLOR_MATERIAL, and we can also now use the precomputed |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 551 | * values in the slower shading functions, which further offsets |
| 552 | * the cost of doing this here. |
| 553 | */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 554 | void gl_update_material( GLcontext *ctx, |
| 555 | const struct gl_material src[2], |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 556 | GLuint bitmask ) |
| 557 | { |
| 558 | struct gl_light *light, *list = &ctx->Light.EnabledList; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 559 | |
| 560 | if (ctx->Light.ColorMaterialEnabled) |
| 561 | bitmask &= ~ctx->Light.ColorMaterialBitmask; |
| 562 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 563 | if (MESA_VERBOSE&VERBOSE_IMMEDIATE) |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 564 | fprintf(stderr, "gl_update_material, mask 0x%x\n", bitmask); |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 565 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 566 | if (!bitmask) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 567 | return; |
| 568 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 569 | /* update material emission */ |
| 570 | if (bitmask & FRONT_EMISSION_BIT) { |
| 571 | struct gl_material *mat = &ctx->Light.Material[0]; |
| 572 | COPY_4FV( mat->Emission, src[0].Emission ); |
| 573 | } |
| 574 | if (bitmask & BACK_EMISSION_BIT) { |
| 575 | struct gl_material *mat = &ctx->Light.Material[1]; |
| 576 | COPY_4FV( mat->Emission, src[1].Emission ); |
| 577 | } |
| 578 | |
| 579 | /* update material ambience */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 580 | if (bitmask & FRONT_AMBIENT_BIT) { |
| 581 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 582 | COPY_4FV( mat->Ambient, src[0].Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 583 | foreach (light, list) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 584 | SCALE_3V( light->_MatAmbient[0], light->Ambient, src[0].Ambient); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 585 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 586 | } |
| 587 | if (bitmask & BACK_AMBIENT_BIT) { |
| 588 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 589 | COPY_4FV( mat->Ambient, src[1].Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 590 | foreach (light, list) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 591 | SCALE_3V( light->_MatAmbient[1], light->Ambient, src[1].Ambient); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 592 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 593 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 594 | |
| 595 | /* update BaseColor = emission + scene's ambience * material's ambience */ |
| 596 | if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) { |
| 597 | struct gl_material *mat = &ctx->Light.Material[0]; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 598 | COPY_3V( ctx->Light._BaseColor[0], mat->Emission ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 599 | ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient, |
| 600 | ctx->Light.Model.Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 601 | } |
| 602 | if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) { |
| 603 | struct gl_material *mat = &ctx->Light.Material[1]; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 604 | COPY_3V( ctx->Light._BaseColor[1], mat->Emission ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 605 | ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient, |
| 606 | ctx->Light.Model.Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /* update material diffuse values */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 610 | if (bitmask & FRONT_DIFFUSE_BIT) { |
| 611 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 612 | COPY_4FV( mat->Diffuse, src[0].Diffuse ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 613 | /* fprintf(stderr, "FRONT_DIFFUSE %f %f %f %f\n", */ |
| 614 | /* mat->Diffuse[0], mat->Diffuse[1], */ |
| 615 | /* mat->Diffuse[2], mat->Diffuse[3]); */ |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 616 | foreach (light, list) { |
| 617 | SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse ); |
| 618 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 619 | FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 620 | } |
| 621 | if (bitmask & BACK_DIFFUSE_BIT) { |
| 622 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 623 | COPY_4FV( mat->Diffuse, src[1].Diffuse ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 624 | /* fprintf(stderr, "BACK_DIFFUSE %f %f %f %f\n", */ |
| 625 | /* mat->Diffuse[0], mat->Diffuse[1], */ |
| 626 | /* mat->Diffuse[2], mat->Diffuse[3]); */ |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 627 | foreach (light, list) { |
| 628 | SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse ); |
| 629 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 630 | FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 631 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 632 | |
| 633 | /* update material specular values */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 634 | if (bitmask & FRONT_SPECULAR_BIT) { |
| 635 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 636 | COPY_4FV( mat->Specular, src[0].Specular ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 637 | foreach (light, list) { |
| Keith Whitwell | 9aff6cf | 2000-11-24 15:21:59 +0000 | [diff] [blame] | 638 | SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 639 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 640 | } |
| 641 | if (bitmask & BACK_SPECULAR_BIT) { |
| 642 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 643 | COPY_4FV( mat->Specular, src[1].Specular ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 644 | foreach (light, list) { |
| Keith Whitwell | 9aff6cf | 2000-11-24 15:21:59 +0000 | [diff] [blame] | 645 | SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 646 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 647 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 648 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 649 | if (bitmask & FRONT_SHININESS_BIT) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 650 | /* fprintf(stderr, "FRONT_SHININESS_BIT %f\n", src[0].Shininess); */ |
| 651 | ctx->Light.Material[0].Shininess = src[0].Shininess; |
| 652 | gl_invalidate_shine_table( ctx, 0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 653 | } |
| 654 | if (bitmask & BACK_SHININESS_BIT) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 655 | ctx->Light.Material[1].Shininess = src[1].Shininess; |
| 656 | gl_invalidate_shine_table( ctx, 1 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 657 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 658 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 659 | if (bitmask & FRONT_INDEXES_BIT) { |
| 660 | ctx->Light.Material[0].AmbientIndex = src[0].AmbientIndex; |
| 661 | ctx->Light.Material[0].DiffuseIndex = src[0].DiffuseIndex; |
| 662 | ctx->Light.Material[0].SpecularIndex = src[0].SpecularIndex; |
| 663 | } |
| 664 | if (bitmask & BACK_INDEXES_BIT) { |
| 665 | ctx->Light.Material[1].AmbientIndex = src[1].AmbientIndex; |
| 666 | ctx->Light.Material[1].DiffuseIndex = src[1].DiffuseIndex; |
| 667 | ctx->Light.Material[1].SpecularIndex = src[1].SpecularIndex; |
| 668 | } |
| 669 | |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 670 | if (0) |
| 671 | { |
| 672 | struct gl_material *mat = &ctx->Light.Material[0]; |
| 673 | fprintf(stderr, "update_mat emission : %f %f %f\n", |
| 674 | mat->Emission[0], |
| 675 | mat->Emission[1], |
| 676 | mat->Emission[2]); |
| 677 | fprintf(stderr, "update_mat specular : %f %f %f\n", |
| 678 | mat->Specular[0], |
| 679 | mat->Specular[1], |
| 680 | mat->Specular[2]); |
| 681 | fprintf(stderr, "update_mat diffuse : %f %f %f\n", |
| 682 | mat->Diffuse[0], |
| 683 | mat->Diffuse[1], |
| 684 | mat->Diffuse[2]); |
| 685 | fprintf(stderr, "update_mat ambient : %f %f %f\n", |
| 686 | mat->Ambient[0], |
| 687 | mat->Ambient[1], |
| 688 | mat->Ambient[2]); |
| 689 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 695 | /* |
| 696 | * Update the current materials from the given rgba color |
| 697 | * according to the bitmask in ColorMaterialBitmask, which is |
| 698 | * set by glColorMaterial(). |
| 699 | */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 700 | void gl_update_color_material( GLcontext *ctx, |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 701 | const GLchan rgba[4] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 702 | { |
| 703 | struct gl_light *light, *list = &ctx->Light.EnabledList; |
| 704 | GLuint bitmask = ctx->Light.ColorMaterialBitmask; |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 705 | GLfloat color[4]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 706 | |
| Brian Paul | c893a01 | 2000-10-28 20:41:13 +0000 | [diff] [blame] | 707 | color[0] = CHAN_TO_FLOAT(rgba[0]); |
| 708 | color[1] = CHAN_TO_FLOAT(rgba[1]); |
| 709 | color[2] = CHAN_TO_FLOAT(rgba[2]); |
| 710 | color[3] = CHAN_TO_FLOAT(rgba[3]); |
| 711 | |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 712 | if (MESA_VERBOSE&VERBOSE_IMMEDIATE) |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 713 | fprintf(stderr, "gl_update_color_material, mask 0x%x\n", bitmask); |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 714 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 715 | /* update emissive colors */ |
| 716 | if (bitmask & FRONT_EMISSION_BIT) { |
| 717 | struct gl_material *mat = &ctx->Light.Material[0]; |
| 718 | COPY_4FV( mat->Emission, color ); |
| 719 | } |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 720 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 721 | if (bitmask & BACK_EMISSION_BIT) { |
| 722 | struct gl_material *mat = &ctx->Light.Material[1]; |
| 723 | COPY_4FV( mat->Emission, color ); |
| 724 | } |
| 725 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 726 | /* update light->_MatAmbient = light's ambient * material's ambient */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 727 | if (bitmask & FRONT_AMBIENT_BIT) { |
| 728 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 729 | foreach (light, list) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 730 | SCALE_3V( light->_MatAmbient[0], light->Ambient, color); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 731 | } |
| 732 | COPY_4FV( mat->Ambient, color ); |
| 733 | } |
| 734 | |
| 735 | if (bitmask & BACK_AMBIENT_BIT) { |
| 736 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 737 | foreach (light, list) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 738 | SCALE_3V( light->_MatAmbient[1], light->Ambient, color); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 739 | } |
| 740 | COPY_4FV( mat->Ambient, color ); |
| 741 | } |
| 742 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 743 | /* update BaseColor = emission + scene's ambience * material's ambience */ |
| 744 | if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) { |
| 745 | struct gl_material *mat = &ctx->Light.Material[0]; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 746 | COPY_3V( ctx->Light._BaseColor[0], mat->Emission ); |
| 747 | ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) { |
| 751 | struct gl_material *mat = &ctx->Light.Material[1]; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 752 | COPY_3V( ctx->Light._BaseColor[1], mat->Emission ); |
| 753 | ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 756 | /* update light->_MatDiffuse = light's diffuse * material's diffuse */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 757 | if (bitmask & FRONT_DIFFUSE_BIT) { |
| 758 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 759 | COPY_4FV( mat->Diffuse, color ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 760 | foreach (light, list) { |
| 761 | SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse ); |
| 762 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 763 | FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | if (bitmask & BACK_DIFFUSE_BIT) { |
| 767 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 768 | COPY_4FV( mat->Diffuse, color ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 769 | foreach (light, list) { |
| 770 | SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse ); |
| 771 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 772 | FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 775 | /* update light->_MatSpecular = light's specular * material's specular */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 776 | if (bitmask & FRONT_SPECULAR_BIT) { |
| 777 | struct gl_material *mat = &ctx->Light.Material[0]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 778 | COPY_4FV( mat->Specular, color ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 779 | foreach (light, list) { |
| 780 | ACC_SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular); |
| 781 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 782 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 783 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 784 | if (bitmask & BACK_SPECULAR_BIT) { |
| 785 | struct gl_material *mat = &ctx->Light.Material[1]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 786 | COPY_4FV( mat->Specular, color ); |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 787 | foreach (light, list) { |
| 788 | ACC_SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular); |
| 789 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 790 | } |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 791 | |
| 792 | if (0) |
| 793 | { |
| 794 | struct gl_material *mat = &ctx->Light.Material[0]; |
| 795 | fprintf(stderr, "update_color_mat emission : %f %f %f\n", |
| 796 | mat->Emission[0], |
| 797 | mat->Emission[1], |
| 798 | mat->Emission[2]); |
| 799 | fprintf(stderr, "update_color_mat specular : %f %f %f\n", |
| 800 | mat->Specular[0], |
| 801 | mat->Specular[1], |
| 802 | mat->Specular[2]); |
| 803 | fprintf(stderr, "update_color_mat diffuse : %f %f %f\n", |
| 804 | mat->Diffuse[0], |
| 805 | mat->Diffuse[1], |
| 806 | mat->Diffuse[2]); |
| 807 | fprintf(stderr, "update_color_mat ambient : %f %f %f\n", |
| 808 | mat->Ambient[0], |
| 809 | mat->Ambient[1], |
| 810 | mat->Ambient[2]); |
| 811 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 817 | void |
| 818 | _mesa_ColorMaterial( GLenum face, GLenum mode ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 819 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 820 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 821 | GLuint bitmask; |
| 822 | GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT | |
| 823 | FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT | |
| 824 | FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT | |
| 825 | FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 826 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 827 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 828 | if (MESA_VERBOSE&VERBOSE_API) |
| 829 | fprintf(stderr, "glColorMaterial %s %s\n", |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 830 | gl_lookup_enum_by_nr(face), |
| 831 | gl_lookup_enum_by_nr(mode)); |
| 832 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 833 | bitmask = gl_material_bitmask( ctx, face, mode, legal, "glColorMaterial" ); |
| 834 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 835 | if (ctx->Light.ColorMaterialBitmask == bitmask && |
| 836 | ctx->Light.ColorMaterialFace == face && |
| 837 | ctx->Light.ColorMaterialMode == mode) |
| 838 | return; |
| 839 | |
| 840 | FLUSH_VERTICES(ctx, _NEW_LIGHT); |
| 841 | ctx->Light.ColorMaterialBitmask = bitmask; |
| 842 | ctx->Light.ColorMaterialFace = face; |
| 843 | ctx->Light.ColorMaterialMode = mode; |
| Keith Whitwell | 06ac592 | 1999-11-10 06:29:44 +0000 | [diff] [blame] | 844 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 845 | if (ctx->Light.ColorMaterialEnabled) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 846 | FLUSH_CURRENT( ctx, 0 ); |
| Brian Paul | 1930053 | 2000-10-29 19:02:23 +0000 | [diff] [blame] | 847 | gl_update_color_material( ctx, ctx->Current.Color ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 848 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
| 852 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 853 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 854 | |
| 855 | void |
| 856 | _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params ) |
| 857 | { |
| 858 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 859 | GLuint f; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 860 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 861 | |
| 862 | if (face==GL_FRONT) { |
| 863 | f = 0; |
| 864 | } |
| 865 | else if (face==GL_BACK) { |
| 866 | f = 1; |
| 867 | } |
| 868 | else { |
| 869 | gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" ); |
| 870 | return; |
| 871 | } |
| 872 | switch (pname) { |
| 873 | case GL_AMBIENT: |
| 874 | COPY_4FV( params, ctx->Light.Material[f].Ambient ); |
| 875 | break; |
| 876 | case GL_DIFFUSE: |
| 877 | COPY_4FV( params, ctx->Light.Material[f].Diffuse ); |
| 878 | break; |
| 879 | case GL_SPECULAR: |
| 880 | COPY_4FV( params, ctx->Light.Material[f].Specular ); |
| 881 | break; |
| 882 | case GL_EMISSION: |
| 883 | COPY_4FV( params, ctx->Light.Material[f].Emission ); |
| 884 | break; |
| 885 | case GL_SHININESS: |
| 886 | *params = ctx->Light.Material[f].Shininess; |
| 887 | break; |
| 888 | case GL_COLOR_INDEXES: |
| 889 | params[0] = ctx->Light.Material[f].AmbientIndex; |
| 890 | params[1] = ctx->Light.Material[f].DiffuseIndex; |
| 891 | params[2] = ctx->Light.Material[f].SpecularIndex; |
| 892 | break; |
| 893 | default: |
| 894 | gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | |
| 899 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 900 | void |
| 901 | _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 902 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 903 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 904 | GLuint f; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 905 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 906 | |
| 907 | if (face==GL_FRONT) { |
| 908 | f = 0; |
| 909 | } |
| 910 | else if (face==GL_BACK) { |
| 911 | f = 1; |
| 912 | } |
| 913 | else { |
| 914 | gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialiv(face)" ); |
| 915 | return; |
| 916 | } |
| 917 | switch (pname) { |
| 918 | case GL_AMBIENT: |
| 919 | params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[0] ); |
| 920 | params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[1] ); |
| 921 | params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[2] ); |
| 922 | params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[3] ); |
| 923 | break; |
| 924 | case GL_DIFFUSE: |
| 925 | params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[0] ); |
| 926 | params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[1] ); |
| 927 | params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[2] ); |
| 928 | params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[3] ); |
| 929 | break; |
| 930 | case GL_SPECULAR: |
| 931 | params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[0] ); |
| 932 | params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[1] ); |
| 933 | params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[2] ); |
| 934 | params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[3] ); |
| 935 | break; |
| 936 | case GL_EMISSION: |
| 937 | params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[0] ); |
| 938 | params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[1] ); |
| 939 | params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[2] ); |
| 940 | params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[3] ); |
| 941 | break; |
| 942 | case GL_SHININESS: |
| 943 | *params = ROUNDF( ctx->Light.Material[f].Shininess ); |
| 944 | break; |
| 945 | case GL_COLOR_INDEXES: |
| 946 | params[0] = ROUNDF( ctx->Light.Material[f].AmbientIndex ); |
| 947 | params[1] = ROUNDF( ctx->Light.Material[f].DiffuseIndex ); |
| 948 | params[2] = ROUNDF( ctx->Light.Material[f].SpecularIndex ); |
| 949 | break; |
| 950 | default: |
| 951 | gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | /**********************************************************************/ |
| 959 | /***** Lighting computation *****/ |
| 960 | /**********************************************************************/ |
| 961 | |
| 962 | |
| 963 | /* |
| 964 | * Notes: |
| 965 | * When two-sided lighting is enabled we compute the color (or index) |
| 966 | * for both the front and back side of the primitive. Then, when the |
| 967 | * orientation of the facet is later learned, we can determine which |
| 968 | * color (or index) to use for rendering. |
| 969 | * |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 970 | * KW: We now know orientation in advance and only shade for |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 971 | * the side or sides which are actually required. |
| 972 | * |
| 973 | * Variables: |
| 974 | * n = normal vector |
| 975 | * V = vertex position |
| 976 | * P = light source position |
| 977 | * Pe = (0,0,0,1) |
| 978 | * |
| 979 | * Precomputed: |
| 980 | * IF P[3]==0 THEN |
| 981 | * // light at infinity |
| 982 | * IF local_viewer THEN |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 983 | * _VP_inf_norm = unit vector from V to P // Precompute |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 984 | * ELSE |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 985 | * // eye at infinity |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 986 | * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 987 | * ENDIF |
| 988 | * ENDIF |
| 989 | * |
| 990 | * Functions: |
| 991 | * Normalize( v ) = normalized vector v |
| 992 | * Magnitude( v ) = length of vector v |
| 993 | */ |
| 994 | |
| 995 | |
| 996 | |
| 997 | /* |
| 998 | * Whenever the spotlight exponent for a light changes we must call |
| 999 | * this function to recompute the exponent lookup table. |
| 1000 | */ |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1001 | void |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1002 | gl_invalidate_spot_exp_table( struct gl_light *l ) |
| 1003 | { |
| 1004 | l->_SpotExpTable[0][0] = -1; |
| 1005 | } |
| 1006 | |
| 1007 | static void validate_spot_exp_table( struct gl_light *l ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1008 | { |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1009 | GLint i; |
| 1010 | GLdouble exponent = l->SpotExponent; |
| 1011 | GLdouble tmp = 0; |
| 1012 | GLint clamp = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1013 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1014 | l->_SpotExpTable[0][0] = 0.0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1015 | |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1016 | for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1017 | if (clamp == 0) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1018 | tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent); |
| 1019 | if (tmp < FLT_MIN * 100.0) { |
| 1020 | tmp = 0.0; |
| 1021 | clamp = 1; |
| 1022 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1023 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1024 | l->_SpotExpTable[i][0] = tmp; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1025 | } |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1026 | for (i = 0; i < EXP_TABLE_SIZE - 1; i++) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1027 | l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] - |
| 1028 | l->_SpotExpTable[i][0]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1029 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1030 | l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | /* Calculate a new shine table. Doing this here saves a branch in |
| 1037 | * lighting, and the cost of doing it early may be partially offset |
| 1038 | * by keeping a MRU cache of shine tables for various shine values. |
| 1039 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1040 | void |
| 1041 | gl_invalidate_shine_table( GLcontext *ctx, GLuint i ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1042 | { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1043 | if (ctx->_ShineTable[i]) |
| 1044 | ctx->_ShineTable[i]->refcount--; |
| 1045 | ctx->_ShineTable[i] = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1048 | static void validate_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1049 | { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1050 | struct gl_shine_tab *list = ctx->_ShineTabList; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1051 | struct gl_shine_tab *s; |
| 1052 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1053 | /* fprintf(stderr, "validate_shine_table %d, shininess %f\n", i, shininess); */ |
| 1054 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1055 | foreach(s, list) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1056 | if ( s->shininess == shininess ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1059 | if (s == list) { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1060 | GLint i; |
| 1061 | GLfloat *m; |
| 1062 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1063 | foreach(s, list) |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1064 | if (s->refcount == 0) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1065 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1066 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1067 | m = s->tab; |
| 1068 | m[0] = 0.0; |
| 1069 | if (shininess == 0.0) { |
| 1070 | for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) |
| 1071 | m[i] = 1.0; |
| 1072 | } |
| 1073 | else { |
| 1074 | for (i = 1 ; i < SHINE_TABLE_SIZE ; i++) { |
| 1075 | GLdouble t = pow(i / (GLfloat)(SHINE_TABLE_SIZE-1), shininess); |
| 1076 | if (t > 1e-20) |
| 1077 | m[i] = t; |
| 1078 | else |
| 1079 | m[i] = 0.0; |
| 1080 | } |
| 1081 | m[SHINE_TABLE_SIZE] = 1.0; |
| 1082 | } |
| 1083 | |
| 1084 | s->shininess = shininess; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1087 | if (ctx->_ShineTable[i]) |
| 1088 | ctx->_ShineTable[i]->refcount--; |
| 1089 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1090 | ctx->_ShineTable[i] = s; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1091 | move_to_tail( list, s ); |
| 1092 | s->refcount++; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | void |
| 1096 | gl_validate_all_lighting_tables( GLcontext *ctx ) |
| 1097 | { |
| 1098 | GLint i; |
| 1099 | GLfloat shininess; |
| 1100 | |
| 1101 | shininess = ctx->Light.Material[0].Shininess; |
| 1102 | if (!ctx->_ShineTable[0]) validate_shine_table( ctx, 0, shininess ); |
| 1103 | |
| 1104 | shininess = ctx->Light.Material[1].Shininess; |
| 1105 | if (!ctx->_ShineTable[1]) validate_shine_table( ctx, 1, shininess ); |
| 1106 | |
| 1107 | for (i = 0 ; i < MAX_LIGHTS ; i++) |
| 1108 | if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1) |
| 1109 | validate_spot_exp_table( &ctx->Light.Light[i] ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1114 | |
| 1115 | /* |
| 1116 | * Examine current lighting parameters to determine if the optimized lighting |
| 1117 | * function can be used. |
| 1118 | * Also, precompute some lighting values such as the products of light |
| 1119 | * source and material ambient, diffuse and specular coefficients. |
| 1120 | */ |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1121 | void |
| 1122 | gl_update_lighting( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1123 | { |
| 1124 | struct gl_light *light; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1125 | ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE; |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1126 | ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT; |
| 1127 | ctx->_NeedNormals &= ~NEED_NORMALS_LIGHT; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1128 | ctx->Light._Flags = 0; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1129 | |
| 1130 | if (!ctx->Light.Enabled) |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1131 | return; |
| 1132 | |
| 1133 | ctx->_NeedNormals |= NEED_NORMALS_LIGHT; |
| 1134 | |
| 1135 | if (ctx->Light.Model.TwoSide) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1136 | ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1137 | |
| 1138 | foreach(light, &ctx->Light.EnabledList) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1139 | ctx->Light._Flags |= light->_Flags; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1142 | ctx->Light._NeedVertices = |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1143 | ((ctx->Light._Flags & (LIGHT_POSITIONAL|LIGHT_SPOT)) || |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1144 | ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR || |
| 1145 | ctx->Light.Model.LocalViewer); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1146 | |
| 1147 | if ((ctx->Light._Flags & LIGHT_POSITIONAL) || |
| 1148 | ctx->Light.Model.LocalViewer) |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1149 | ctx->_NeedEyeCoords |= NEED_EYE_LIGHT; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1150 | |
| 1151 | |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1152 | /* XXX: This test is overkill & needs to be fixed both for software and |
| 1153 | * hardware t&l drivers. The above should be sufficient & should |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1154 | * be tested to verify this. |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1155 | */ |
| 1156 | if (ctx->Light._NeedVertices) |
| 1157 | ctx->_NeedEyeCoords |= NEED_EYE_LIGHT; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1158 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1159 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1160 | /* Precompute some shading values. Although we reference |
| 1161 | * Light.Material here, we can get away without flushing |
| 1162 | * FLUSH_UPDATE_CURRENT, as when any outstanding material changes |
| 1163 | * are flushed, they will update the derived state at that time. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1164 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1165 | if (ctx->Visual.RGBAflag) { |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1166 | GLuint sides = ctx->Light.Model.TwoSide ? 2 : 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1167 | GLuint side; |
| 1168 | for (side=0; side < sides; side++) { |
| 1169 | struct gl_material *mat = &ctx->Light.Material[side]; |
| Brian Paul | c535ba5 | 2000-06-29 04:56:30 +0000 | [diff] [blame] | 1170 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1171 | COPY_3V(ctx->Light._BaseColor[side], mat->Emission); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1172 | ACC_SCALE_3V(ctx->Light._BaseColor[side], |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1173 | ctx->Light.Model.Ambient, |
| 1174 | mat->Ambient); |
| 1175 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1176 | FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[side], |
| Brian Paul | c893a01 | 2000-10-28 20:41:13 +0000 | [diff] [blame] | 1177 | ctx->Light.Material[side].Diffuse[3] ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1178 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1179 | |
| 1180 | foreach (light, &ctx->Light.EnabledList) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1181 | for (side=0; side< sides; side++) { |
| Brian Paul | c535ba5 | 2000-06-29 04:56:30 +0000 | [diff] [blame] | 1182 | const struct gl_material *mat = &ctx->Light.Material[side]; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1183 | SCALE_3V( light->_MatDiffuse[side], light->Diffuse, mat->Diffuse ); |
| 1184 | SCALE_3V( light->_MatAmbient[side], light->Ambient, mat->Ambient ); |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1185 | SCALE_3V( light->_MatSpecular[side], light->Specular, |
| 1186 | mat->Specular); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1187 | } |
| 1188 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1189 | } |
| Brian Paul | c535ba5 | 2000-06-29 04:56:30 +0000 | [diff] [blame] | 1190 | else { |
| 1191 | static const GLfloat ci[3] = { .30, .59, .11 }; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1192 | foreach(light, &ctx->Light.EnabledList) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1193 | light->_dli = DOT3(ci, light->Diffuse); |
| 1194 | light->_sli = DOT3(ci, light->Specular); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| Brian Paul | c535ba5 | 2000-06-29 04:56:30 +0000 | [diff] [blame] | 1199 | |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1200 | /* _NEW_MODELVIEW |
| 1201 | * _NEW_LIGHT |
| 1202 | * _TNL_NEW_NEED_EYE_COORDS |
| 1203 | * |
| 1204 | * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled. |
| 1205 | * Also update on lighting space changes. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1206 | */ |
| Brian Paul | a0faa7f | 2000-07-18 16:55:56 +0000 | [diff] [blame] | 1207 | void |
| 1208 | gl_compute_light_positions( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1209 | { |
| 1210 | struct gl_light *light; |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1211 | static const GLfloat eye_z[3] = { 0, 0, 1 }; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1212 | |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1213 | if (!ctx->Light.Enabled) |
| 1214 | return; |
| 1215 | |
| 1216 | if (ctx->_NeedEyeCoords) { |
| 1217 | COPY_3V( ctx->_EyeZDir, eye_z ); |
| 1218 | } |
| 1219 | else { |
| 1220 | TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelView.m ); |
| 1221 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1222 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1223 | foreach (light, &ctx->Light.EnabledList) { |
| 1224 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1225 | if (ctx->_NeedEyeCoords) { |
| 1226 | COPY_4FV( light->_Position, light->EyePosition ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1227 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1228 | else { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1229 | TRANSFORM_POINT( light->_Position, ctx->ModelView.inv, |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1230 | light->EyePosition ); |
| 1231 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1232 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1233 | if (!(light->_Flags & LIGHT_POSITIONAL)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1234 | /* VP (VP) = Normalize( Position ) */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1235 | COPY_3V( light->_VP_inf_norm, light->_Position ); |
| 1236 | NORMALIZE_3FV( light->_VP_inf_norm ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1237 | |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1238 | if (!ctx->Light.Model.LocalViewer) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1239 | /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */ |
| 1240 | ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir); |
| 1241 | NORMALIZE_3FV( light->_h_inf_norm ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1242 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1243 | light->_VP_inf_spot_attenuation = 1.0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1244 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1245 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1246 | if (light->_Flags & LIGHT_SPOT) { |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1247 | if (ctx->_NeedEyeCoords) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1248 | COPY_3V( light->_NormDirection, light->EyeDirection ); |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1249 | } |
| 1250 | else { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1251 | TRANSFORM_NORMAL( light->_NormDirection, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1252 | light->EyeDirection, |
| 1253 | ctx->ModelView.m); |
| 1254 | } |
| 1255 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1256 | NORMALIZE_3FV( light->_NormDirection ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1257 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1258 | if (!(light->_Flags & LIGHT_POSITIONAL)) { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1259 | GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1260 | light->_NormDirection); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1261 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1262 | if (PV_dot_dir > light->_CosCutoff) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1263 | double x = PV_dot_dir * (EXP_TABLE_SIZE-1); |
| 1264 | int k = (int) x; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1265 | light->_VP_inf_spot_attenuation = |
| 1266 | (light->_SpotExpTable[k][0] + |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1267 | (x-k)*light->_SpotExpTable[k][1]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1268 | } |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1269 | else { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1270 | light->_VP_inf_spot_attenuation = 0; |
| Brian Paul | de82d06 | 2000-06-26 23:37:46 +0000 | [diff] [blame] | 1271 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | |