Changeset 3598 for trunk/src/opengl/mesa/light.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/light.c
r2962 r3598 1 /* $Id: light.c,v 1. 2 2000-03-01 18:49:31jeroen Exp $ */1 /* $Id: light.c,v 1.3 2000-05-23 20:40:39 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 32 32 #include "all.h" 33 33 #else 34 #include <float.h> 35 #ifndef XFree86Server 36 #include <assert.h> 37 #include <float.h> 38 #include <math.h> 39 #include <stdlib.h> 40 #include <stdio.h> 41 #else 42 #include "GL/xf86glx.h" 43 #endif 34 #include "glheader.h" 44 35 #include "types.h" 45 36 #include "context.h" … … 52 43 #include "vb.h" 53 44 #include "xform.h" 45 #include "mem.h" 54 46 #endif 55 47 56 57 58 void gl_ShadeModel( GLcontext *ctx, GLenum mode ) 59 { 48 /* XXX this is a bit of a hack needed for compilation within XFree86 */ 49 #ifndef FLT_MIN 50 #define FLT_MIN 1e-37 51 #endif 52 53 54 void 55 _mesa_ShadeModel( GLenum mode ) 56 { 57 GET_CURRENT_CONTEXT(ctx); 60 58 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glShadeModel"); 61 59 … … 65 63 if (mode == GL_FLAT || mode == GL_SMOOTH) { 66 64 if (ctx->Light.ShadeModel != mode) { 67 65 ctx->Light.ShadeModel = mode; 68 66 if (ctx->Light.ShadeModel == GL_FLAT) 69 ctx->TriangleCaps |= DD_FLATSHADE;67 SET_BITS(ctx->TriangleCaps, DD_FLATSHADE); 70 68 else 71 ctx->TriangleCaps &= ~DD_FLATSHADE;72 69 CLEAR_BITS(ctx->TriangleCaps, DD_FLATSHADE); 70 ctx->NewState |= NEW_RASTER_OPS; 73 71 if (ctx->Driver.ShadeModel) 74 72 (*ctx->Driver.ShadeModel)( ctx, mode ); … … 82 80 83 81 84 void gl_Lightfv( GLcontext *ctx, 85 GLenum light, GLenum pname, const GLfloat *params, 86 GLint nparams ) 87 { 82 void 83 _mesa_Lightf( GLenum light, GLenum pname, GLfloat param ) 84 { 85 _mesa_Lightfv( light, pname, ¶m ); 86 } 87 88 89 void 90 _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params ) 91 { 92 GET_CURRENT_CONTEXT(ctx); 88 93 GLint l; 89 90 (void) nparams; 94 GLint nParams; 91 95 92 96 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLight"); … … 94 98 l = (GLint) (light - GL_LIGHT0); 95 99 96 if (l <0 || l>=MAX_LIGHTS) {100 if (l < 0 || l >= MAX_LIGHTS) { 97 101 gl_error( ctx, GL_INVALID_ENUM, "glLight" ); 98 102 return; … … 102 106 case GL_AMBIENT: 103 107 COPY_4V( ctx->Light.Light[l].Ambient, params ); 108 nParams = 4; 104 109 break; 105 110 case GL_DIFFUSE: 106 111 COPY_4V( ctx->Light.Light[l].Diffuse, params ); 112 nParams = 4; 107 113 break; 108 114 case GL_SPECULAR: 109 115 COPY_4V( ctx->Light.Light[l].Specular, params ); 116 nParams = 4; 110 117 break; 111 118 case GL_POSITION: 112 113 114 119 /* transform position by ModelView matrix */ 120 TRANSFORM_POINT( ctx->Light.Light[l].EyePosition, 121 ctx->ModelView.m, 115 122 params ); 123 nParams = 4; 116 124 break; 117 125 case GL_SPOT_DIRECTION: 118 /* transform direction by inverse modelview */ 119 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) { 120 gl_matrix_analyze( &ctx->ModelView ); 121 } 122 TRANSFORM_NORMAL( ctx->Light.Light[l].EyeDirection, 123 params, 124 ctx->ModelView.inv ); 126 /* transform direction by inverse modelview */ 127 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) { 128 gl_matrix_analyze( &ctx->ModelView ); 129 } 130 TRANSFORM_NORMAL( ctx->Light.Light[l].EyeDirection, 131 params, 132 ctx->ModelView.inv ); 133 nParams = 3; 125 134 break; 126 135 case GL_SPOT_EXPONENT: … … 133 142 gl_compute_spot_exp_table( &ctx->Light.Light[l] ); 134 143 } 144 nParams = 1; 135 145 break; 136 146 case GL_SPOT_CUTOFF: … … 142 152 ctx->Light.Light[l].CosCutoff = cos(params[0]*DEG2RAD); 143 153 if (ctx->Light.Light[l].CosCutoff < 0) 144 ctx->Light.Light[l].CosCutoff = 0; 154 ctx->Light.Light[l].CosCutoff = 0; 155 nParams = 1; 145 156 break; 146 157 case GL_CONSTANT_ATTENUATION: … … 150 161 } 151 162 ctx->Light.Light[l].ConstantAttenuation = params[0]; 163 nParams = 1; 152 164 break; 153 165 case GL_LINEAR_ATTENUATION: … … 157 169 } 158 170 ctx->Light.Light[l].LinearAttenuation = params[0]; 171 nParams = 1; 159 172 break; 160 173 case GL_QUADRATIC_ATTENUATION: … … 164 177 } 165 178 ctx->Light.Light[l].QuadraticAttenuation = params[0]; 179 nParams = 1; 166 180 break; 167 181 default: 168 182 gl_error( ctx, GL_INVALID_ENUM, "glLight" ); 169 break;183 return; 170 184 } 171 185 172 186 if (ctx->Driver.Lightfv) 173 ctx->Driver.Lightfv( ctx, light, pname, params, n params );187 ctx->Driver.Lightfv( ctx, light, pname, params, nParams ); 174 188 175 189 ctx->NewState |= NEW_LIGHTING; 176 190 } 177 191 178 179 180 void gl_GetLightfv( GLcontext *ctx, 181 GLenum light, GLenum pname, GLfloat *params ) 182 { 192 void 193 _mesa_Lighti( GLenum light, GLenum pname, GLint param ) 194 { 195 _mesa_Lightiv( light, pname, ¶m ); 196 } 197 198 199 void 200 _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params ) 201 { 202 GLfloat fparam[4]; 203 204 switch (pname) { 205 case GL_AMBIENT: 206 case GL_DIFFUSE: 207 case GL_SPECULAR: 208 fparam[0] = INT_TO_FLOAT( params[0] ); 209 fparam[1] = INT_TO_FLOAT( params[1] ); 210 fparam[2] = INT_TO_FLOAT( params[2] ); 211 fparam[3] = INT_TO_FLOAT( params[3] ); 212 break; 213 case GL_POSITION: 214 fparam[0] = (GLfloat) params[0]; 215 fparam[1] = (GLfloat) params[1]; 216 fparam[2] = (GLfloat) params[2]; 217 fparam[3] = (GLfloat) params[3]; 218 break; 219 case GL_SPOT_DIRECTION: 220 fparam[0] = (GLfloat) params[0]; 221 fparam[1] = (GLfloat) params[1]; 222 fparam[2] = (GLfloat) params[2]; 223 break; 224 case GL_SPOT_EXPONENT: 225 case GL_SPOT_CUTOFF: 226 case GL_CONSTANT_ATTENUATION: 227 case GL_LINEAR_ATTENUATION: 228 case GL_QUADRATIC_ATTENUATION: 229 fparam[0] = (GLfloat) params[0]; 230 break; 231 default: 232 /* error will be caught later in gl_Lightfv */ 233 ; 234 } 235 236 _mesa_Lightfv( light, pname, fparam ); 237 } 238 239 240 241 void 242 _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params ) 243 { 244 GET_CURRENT_CONTEXT(ctx); 183 245 GLint l = (GLint) (light - GL_LIGHT0); 184 246 … … 229 291 230 292 231 void gl_GetLightiv( GLcontext *ctx, GLenum light, GLenum pname, GLint *params ) 232 { 293 void 294 _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params ) 295 { 296 GET_CURRENT_CONTEXT(ctx); 233 297 GLint l = (GLint) (light - GL_LIGHT0); 234 298 … … 298 362 299 363 300 void gl_LightModelfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) 301 { 302 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModel"); 364 void 365 _mesa_LightModelfv( GLenum pname, const GLfloat *params ) 366 { 367 GET_CURRENT_CONTEXT(ctx); 368 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModelfv"); 303 369 304 370 switch (pname) { … … 321 387 if (params[0] == (GLfloat) GL_SINGLE_COLOR) { 322 388 ctx->Light.Model.ColorControl = GL_SINGLE_COLOR; 323 ctx->TriangleCaps &= ~DD_SEPERATE_SPECULAR;389 CLEAR_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR); 324 390 } 325 391 else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR) { 326 392 ctx->Light.Model.ColorControl = GL_SEPARATE_SPECULAR_COLOR; 327 ctx->TriangleCaps |= DD_SEPERATE_SPECULAR;328 393 SET_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR); 394 } 329 395 else { 330 396 gl_error( ctx, GL_INVALID_ENUM, "glLightModel(param)" ); 331 397 } 332 398 ctx->NewState |= NEW_RASTER_OPS; 333 399 break; 334 400 default: … … 343 409 } 344 410 411 412 void 413 _mesa_LightModeliv( GLenum pname, const GLint *params ) 414 { 415 GLfloat fparam[4]; 416 GET_CURRENT_CONTEXT(ctx); 417 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModeliv"); 418 419 switch (pname) { 420 case GL_LIGHT_MODEL_AMBIENT: 421 fparam[0] = INT_TO_FLOAT( params[0] ); 422 fparam[1] = INT_TO_FLOAT( params[1] ); 423 fparam[2] = INT_TO_FLOAT( params[2] ); 424 fparam[3] = INT_TO_FLOAT( params[3] ); 425 break; 426 case GL_LIGHT_MODEL_LOCAL_VIEWER: 427 case GL_LIGHT_MODEL_TWO_SIDE: 428 case GL_LIGHT_MODEL_COLOR_CONTROL: 429 fparam[0] = (GLfloat) params[0]; 430 break; 431 default: 432 /* Error will be caught later in gl_LightModelfv */ 433 ; 434 } 435 _mesa_LightModelfv( pname, fparam ); 436 } 437 438 439 void 440 _mesa_LightModeli( GLenum pname, GLint param ) 441 { 442 _mesa_LightModeliv( pname, ¶m ); 443 } 444 445 446 void 447 _mesa_LightModelf( GLenum pname, GLfloat param ) 448 { 449 _mesa_LightModelfv( pname, ¶m ); 450 } 345 451 346 452 … … 354 460 */ 355 461 GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname, 356 357 462 GLuint legal, 463 const char *where ) 358 464 { 359 465 GLuint bitmask = 0; … … 426 532 */ 427 533 void gl_update_material( GLcontext *ctx, 428 429 534 struct gl_material *src, 535 GLuint bitmask ) 430 536 { 431 537 struct gl_light *light, *list = &ctx->Light.EnabledList; … … 446 552 ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp); 447 553 foreach (light, list) { 448 554 ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); 449 555 } 450 556 COPY_4FV( mat->Ambient, src[0].Ambient ); … … 455 561 ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp); 456 562 foreach (light, list) { 457 563 ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); 458 564 } 459 565 COPY_4FV( mat->Ambient, src[1].Ambient ); … … 463 569 SUB_3V( tmp, src[0].Diffuse, mat->Diffuse ); 464 570 foreach (light, list) { 465 571 ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp ); 466 572 } 467 573 COPY_4FV( mat->Diffuse, src[0].Diffuse ); … … 472 578 SUB_3V( tmp, src[1].Diffuse, mat->Diffuse ); 473 579 foreach (light, list) { 474 580 ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp ); 475 581 } 476 582 COPY_4FV( mat->Diffuse, src[1].Diffuse ); … … 481 587 SUB_3V( tmp, src[0].Specular, mat->Specular ); 482 588 foreach (light, list) { 483 484 485 486 487 589 if (light->Flags & LIGHT_SPECULAR) { 590 ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp ); 591 light->IsMatSpecular[0] = 592 (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16); 593 } 488 594 } 489 595 COPY_4FV( mat->Specular, src[0].Specular ); … … 493 599 SUB_3V( tmp, src[1].Specular, mat->Specular ); 494 600 foreach (light, list) { 495 496 497 498 499 601 if (light->Flags & LIGHT_SPECULAR) { 602 ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp ); 603 light->IsMatSpecular[1] = 604 (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16); 605 } 500 606 } 501 607 COPY_4FV( mat->Specular, src[1].Specular ); … … 538 644 struct gl_material *mat = &ctx->Light.Material[0]; 539 645 fprintf(stderr, "update_mat emission : %f %f %f\n", 540 541 542 646 mat->Emission[0], 647 mat->Emission[1], 648 mat->Emission[2]); 543 649 fprintf(stderr, "update_mat specular : %f %f %f\n", 544 545 546 650 mat->Specular[0], 651 mat->Specular[1], 652 mat->Specular[2]); 547 653 fprintf(stderr, "update_mat diffuse : %f %f %f\n", 548 549 550 654 mat->Diffuse[0], 655 mat->Diffuse[1], 656 mat->Diffuse[2]); 551 657 fprintf(stderr, "update_mat ambient : %f %f %f\n", 552 553 554 658 mat->Ambient[0], 659 mat->Ambient[1], 660 mat->Ambient[2]); 555 661 } 556 662 } … … 562 668 563 669 void gl_update_color_material( GLcontext *ctx, 564 670 const GLubyte rgba[4] ) 565 671 { 566 672 struct gl_light *light, *list = &ctx->Light.EnabledList; … … 579 685 ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp); 580 686 foreach (light, list) { 581 687 ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); 582 688 } 583 689 COPY_4FV( mat->Ambient, color ); … … 589 695 ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp); 590 696 foreach (light, list) { 591 697 ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); 592 698 } 593 699 COPY_4FV( mat->Ambient, color ); … … 598 704 SUB_3V( tmp, color, mat->Diffuse ); 599 705 foreach (light, list) { 600 706 ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp ); 601 707 } 602 708 COPY_4FV( mat->Diffuse, color ); … … 608 714 SUB_3V( tmp, color, mat->Diffuse ); 609 715 foreach (light, list) { 610 716 ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp ); 611 717 } 612 718 COPY_4FV( mat->Diffuse, color ); … … 618 724 SUB_3V( tmp, color, mat->Specular ); 619 725 foreach (light, list) { 620 621 622 623 624 726 if (light->Flags & LIGHT_SPECULAR) { 727 ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp ); 728 light->IsMatSpecular[0] = 729 (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16); 730 } 625 731 } 626 732 COPY_4FV( mat->Specular, color ); … … 630 736 SUB_3V( tmp, color, mat->Specular ); 631 737 foreach (light, list) { 632 633 634 635 636 738 if (light->Flags & LIGHT_SPECULAR) { 739 ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp ); 740 light->IsMatSpecular[1] = 741 (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16); 742 } 637 743 } 638 744 COPY_4FV( mat->Specular, color ); … … 655 761 struct gl_material *mat = &ctx->Light.Material[0]; 656 762 fprintf(stderr, "update_color_mat emission : %f %f %f\n", 657 658 659 763 mat->Emission[0], 764 mat->Emission[1], 765 mat->Emission[2]); 660 766 fprintf(stderr, "update_color_mat specular : %f %f %f\n", 661 662 663 767 mat->Specular[0], 768 mat->Specular[1], 769 mat->Specular[2]); 664 770 fprintf(stderr, "update_color_mat diffuse : %f %f %f\n", 665 666 667 771 mat->Diffuse[0], 772 mat->Diffuse[1], 773 mat->Diffuse[2]); 668 774 fprintf(stderr, "update_color_mat ambient : %f %f %f\n", 669 mat->Ambient[0], 670 mat->Ambient[1], 671 mat->Ambient[2]); 672 } 673 } 674 675 676 677 678 void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) 679 { 775 mat->Ambient[0], 776 mat->Ambient[1], 777 mat->Ambient[2]); 778 } 779 } 780 781 782 783 784 void 785 _mesa_ColorMaterial( GLenum face, GLenum mode ) 786 { 787 GET_CURRENT_CONTEXT(ctx); 680 788 GLuint bitmask; 681 789 GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT | 682 683 684 790 FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT | 791 FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT | 792 FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT); 685 793 686 794 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorMaterial"); … … 688 796 if (MESA_VERBOSE&VERBOSE_API) 689 797 fprintf(stderr, "glColorMaterial %s %s\n", 690 691 798 gl_lookup_enum_by_nr(face), 799 gl_lookup_enum_by_nr(mode)); 692 800 693 801 bitmask = gl_material_bitmask( ctx, face, mode, legal, "glColorMaterial" ); … … 705 813 706 814 815 816 void 817 _mesa_Materialf( GLenum face, GLenum pname, GLfloat param ) 818 { 819 _mesa_Materialfv( face, pname, ¶m ); 820 } 821 822 707 823 /* KW: This is now called directly (ie by name) from the glMaterial* 708 824 * API functions. 709 825 */ 710 void gl_Materialfv( GLcontext *ctx, 711 GLenum face, GLenum pname, const GLfloat *params ) 712 { 826 void 827 _mesa_Materialfv( GLenum face, GLenum pname, const GLfloat *params ) 828 { 829 GET_CURRENT_CONTEXT(ctx); 713 830 struct immediate *IM; 714 831 struct gl_material *mat; … … 725 842 if (!IM->Material) { 726 843 IM->Material = 727 728 844 (struct gl_material (*)[2]) MALLOC( sizeof(struct gl_material) * 845 VB_SIZE * 2 ); 729 846 IM->MaterialMask = (GLuint *) MALLOC( sizeof(GLuint) * VB_SIZE ); 730 847 } … … 735 852 IM->MaterialMask[count] = 0; 736 853 } 854 737 855 738 856 IM->MaterialMask[count] |= bitmask; … … 784 902 785 903 786 787 788 void gl_GetMaterialfv( GLcontext *ctx, 789 GLenum face, GLenum pname, GLfloat *params ) 790 { 904 void 905 _mesa_Materiali(GLenum face, GLenum pname, GLint param ) 906 { 907 _mesa_Materialiv(face, pname, ¶m); 908 } 909 910 911 void 912 _mesa_Materialiv(GLenum face, GLenum pname, const GLint *params ) 913 { 914 GLfloat fparam[4]; 915 switch (pname) { 916 case GL_AMBIENT: 917 case GL_DIFFUSE: 918 case GL_SPECULAR: 919 case GL_EMISSION: 920 case GL_AMBIENT_AND_DIFFUSE: 921 fparam[0] = INT_TO_FLOAT( params[0] ); 922 fparam[1] = INT_TO_FLOAT( params[1] ); 923 fparam[2] = INT_TO_FLOAT( params[2] ); 924 fparam[3] = INT_TO_FLOAT( params[3] ); 925 break; 926 case GL_SHININESS: 927 fparam[0] = (GLfloat) params[0]; 928 break; 929 case GL_COLOR_INDEXES: 930 fparam[0] = (GLfloat) params[0]; 931 fparam[1] = (GLfloat) params[1]; 932 fparam[2] = (GLfloat) params[2]; 933 break; 934 default: 935 /* Error will be caught later in gl_Materialfv */ 936 ; 937 } 938 _mesa_Materialfv(face, pname, fparam); 939 } 940 941 942 void 943 _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params ) 944 { 945 GET_CURRENT_CONTEXT(ctx); 791 946 GLuint f; 792 947 … … 809 964 case GL_DIFFUSE: 810 965 COPY_4FV( params, ctx->Light.Material[f].Diffuse ); 811 966 break; 812 967 case GL_SPECULAR: 813 968 COPY_4FV( params, ctx->Light.Material[f].Specular ); 814 969 break; 815 970 case GL_EMISSION: 816 817 971 COPY_4FV( params, ctx->Light.Material[f].Emission ); 972 break; 818 973 case GL_SHININESS: 819 820 974 *params = ctx->Light.Material[f].Shininess; 975 break; 821 976 case GL_COLOR_INDEXES: 822 823 824 825 977 params[0] = ctx->Light.Material[f].AmbientIndex; 978 params[1] = ctx->Light.Material[f].DiffuseIndex; 979 params[2] = ctx->Light.Material[f].SpecularIndex; 980 break; 826 981 default: 827 982 gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); … … 831 986 832 987 833 void gl_GetMaterialiv( GLcontext *ctx, 834 GLenum face, GLenum pname, GLint *params ) 835 { 988 void 989 _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) 990 { 991 GET_CURRENT_CONTEXT(ctx); 836 992 GLuint f; 837 993 … … 860 1016 params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[2] ); 861 1017 params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[3] ); 862 1018 break; 863 1019 case GL_SPECULAR: 864 1020 params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[0] ); … … 866 1022 params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[2] ); 867 1023 params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[3] ); 868 1024 break; 869 1025 case GL_EMISSION: 870 1026 params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[0] ); … … 872 1028 params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[2] ); 873 1029 params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[3] ); 874 1030 break; 875 1031 case GL_SHININESS: 876 1032 *params = ROUNDF( ctx->Light.Material[f].Shininess ); 877 1033 break; 878 1034 case GL_COLOR_INDEXES: 879 880 881 882 1035 params[0] = ROUNDF( ctx->Light.Material[f].AmbientIndex ); 1036 params[1] = ROUNDF( ctx->Light.Material[f].DiffuseIndex ); 1037 params[2] = ROUNDF( ctx->Light.Material[f].SpecularIndex ); 1038 break; 883 1039 default: 884 1040 gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); … … 972 1128 if (shininess == 0) { 973 1129 for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) 974 1130 m[i] = 1; 975 1131 } else { 976 1132 for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) { 977 978 979 1133 double t = pow( i/(GLfloat)SHINE_TABLE_SIZE, shininess ); 1134 m[i] = 0; 1135 if (t > 1e-20) m[i] = t; 980 1136 } 981 1137 } … … 993 1149 foreach(s, list) 994 1150 if ( DISTSQR(s->shininess, shininess) < 1e-4 ) 995 1151 break; 996 1152 997 1153 if (s == list) 998 1154 { 999 1155 foreach(s, list) 1000 1156 if (s->refcount == 0) break; 1001 1157 1002 1158 compute_shine_table( s, shininess ); … … 1011 1167 1012 1168 1013 1014 void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l )1169 #if 0 1170 static void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) 1015 1171 { 1016 1172 GLuint i; … … 1029 1185 for (i = 0 ; i < MAX_LIGHTS ; i++) { 1030 1186 if (l->Light[i].Enabled) 1031 1032 } 1033 } 1034 1187 insert_at_tail( &l->EnabledList, &l->Light[i] ); 1188 } 1189 } 1190 #endif 1035 1191 1036 1192 … … 1052 1208 1053 1209 if (light->EyePosition[3] != 0.0F) 1054 1210 light->Flags |= LIGHT_POSITIONAL; 1055 1211 1056 1212 if (LEN_SQUARED_3FV(light->Specular) > 1e-16) 1057 1213 light->Flags |= LIGHT_SPECULAR; 1058 1214 1059 1215 if (light->SpotCutoff != 180.0F) 1060 1216 light->Flags |= LIGHT_SPOT; 1061 1217 1062 1218 ctx->Light.Flags |= light->Flags; … … 1076 1232 GLuint side; 1077 1233 for (side=0; side < sides; side++) { 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 } 1088 1089 foreach (light, &ctx->Light.EnabledList) { 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1234 struct gl_material *mat = &ctx->Light.Material[side]; 1235 1236 COPY_3V(ctx->Light.BaseColor[side], mat->Emission); 1237 ACC_SCALE_3V(ctx->Light.BaseColor[side], 1238 ctx->Light.Model.Ambient, 1239 mat->Ambient); 1240 1241 FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[side], 1242 ctx->Light.Material[side].Diffuse[3] ); 1243 } 1244 1245 foreach (light, &ctx->Light.EnabledList) { 1246 for (side=0; side< sides; side++) { 1247 struct gl_material *mat = &ctx->Light.Material[side]; 1248 SCALE_3V( light->MatDiffuse[side], light->Diffuse, mat->Diffuse ); 1249 SCALE_3V( light->MatAmbient[side], light->Ambient, mat->Ambient ); 1250 ACC_3V( ctx->Light.BaseColor[side], light->MatAmbient[side] ); 1251 if (light->Flags & LIGHT_SPECULAR) 1252 { 1253 SCALE_3V( light->MatSpecular[side], light->Specular, 1254 mat->Specular); 1255 light->IsMatSpecular[side] = 1256 (LEN_SQUARED_3FV(light->MatSpecular[side]) > 1e-16); 1257 } 1258 else 1259 light->IsMatSpecular[side] = 0; 1260 } 1105 1261 } 1106 1262 } … … 1110 1266 1111 1267 foreach(light, &ctx->Light.EnabledList) { 1112 1113 1268 light->dli = DOT3(ci, light->Diffuse); 1269 light->sli = DOT3(ci, light->Specular); 1114 1270 } 1115 1271 } … … 1126 1282 GLfloat eye_z[3] = { 0, 0, 1 }; 1127 1283 if (!ctx->NeedEyeCoords) { 1128 1284 TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m ); 1129 1285 } else { 1130 1286 COPY_3V( ctx->EyeZDir, eye_z ); 1131 1287 } 1132 1288 } … … 1135 1291 1136 1292 if (!ctx->NeedEyeCoords) { 1137 1138 1293 TRANSFORM_POINT( light->Position, ctx->ModelView.inv, 1294 light->EyePosition ); 1139 1295 } else { 1140 1296 COPY_4FV( light->Position, light->EyePosition ); 1141 1297 } 1142 1298 1143 1299 if (!(light->Flags & LIGHT_POSITIONAL)) 1144 1300 { 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1301 /* VP (VP) = Normalize( Position ) */ 1302 COPY_3V( light->VP_inf_norm, light->Position ); 1303 NORMALIZE_3FV( light->VP_inf_norm ); 1304 1305 if (!ctx->Light.Model.LocalViewer) 1306 { 1307 /* h_inf_norm = Normalize( V_to_P + <0,0,1> ) */ 1308 ADD_3V( light->h_inf_norm, light->VP_inf_norm, ctx->EyeZDir); 1309 NORMALIZE_3FV( light->h_inf_norm ); 1310 } 1311 1312 light->VP_inf_spot_attenuation = 1.0; 1157 1313 } 1158 1314 1159 1315 if (light->Flags & LIGHT_SPOT) 1160 1316 { 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1317 if (ctx->NeedEyeNormals) { 1318 COPY_3V( light->NormDirection, light->EyeDirection ); 1319 } else { 1320 TRANSFORM_NORMAL( light->NormDirection, 1321 light->EyeDirection, 1322 ctx->ModelView.m); 1323 } 1324 1325 NORMALIZE_3FV( light->NormDirection ); 1326 1327 1328 /* Unlikely occurrance? 1329 */ 1330 if (!(light->Flags & LIGHT_POSITIONAL)) { 1331 GLfloat PV_dot_dir = - DOT3(light->VP_inf_norm, 1332 light->NormDirection); 1333 1334 if (PV_dot_dir > light->CosCutoff) { 1335 double x = PV_dot_dir * (EXP_TABLE_SIZE-1); 1336 int k = (int) x; 1337 light->VP_inf_spot_attenuation = 1338 (light->SpotExpTable[k][0] + 1339 (x-k)*light->SpotExpTable[k][1]); 1340 } 1341 else 1342 light->VP_inf_spot_attenuation = 0; 1343 } 1188 1344 } 1189 1345 } … … 1203 1359 if (ctx->NeedEyeCoords) { 1204 1360 if (ctx->NeedNormals) { 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1361 GLuint transform = NORM_TRANSFORM_NO_ROT; 1362 1363 if (ctx->ModelView.flags & (MAT_FLAG_GENERAL | 1364 MAT_FLAG_ROTATION | 1365 MAT_FLAG_GENERAL_3D | 1366 MAT_FLAG_PERSPECTIVE)) 1367 transform = NORM_TRANSFORM; 1368 1369 1370 new_flag = ctx->NewState & NEW_MODELVIEW; 1371 ctx->vb_rescale_factor = ctx->rescale_factor; 1372 1373 if (ctx->Transform.Normalize) 1374 { 1375 ctx->NormalTransform = gl_normal_tab[transform | NORM_NORMALIZE]; 1376 } 1377 else if (ctx->Transform.RescaleNormals && 1378 ctx->rescale_factor != 1.0) 1379 { 1380 ctx->NormalTransform = gl_normal_tab[transform | NORM_RESCALE]; 1381 } 1382 else 1383 { 1384 ctx->NormalTransform = gl_normal_tab[transform]; 1385 } 1230 1386 } else { 1231 1387 ctx->NormalTransform = 0; 1232 1388 } 1233 1389 } 1234 1390 else { 1235 1391 if (ctx->NeedNormals) { 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1392 ctx->vb_rescale_factor = 1.0/ctx->rescale_factor; 1393 1394 if (ctx->Transform.Normalize) 1395 { 1396 ctx->NormalTransform = gl_normal_tab[NORM_NORMALIZE]; 1397 } 1398 else if (!ctx->Transform.RescaleNormals && 1399 ctx->rescale_factor != 1.0) 1400 { 1401 ctx->NormalTransform = gl_normal_tab[NORM_RESCALE]; 1402 } 1403 else 1404 { 1405 ctx->NormalTransform = 0; 1406 } 1251 1407 } else { 1252 1408 ctx->NormalTransform = 0; 1253 1409 } 1254 1410 }
Note:
See TracChangeset
for help on using the changeset viewer.