Lines Matching refs:Light
31 #include "light.h"
52 if (ctx->Light.ShadeModel == mode)
56 ctx->Light.ShadeModel = mode;
86 if (ctx->Light.ProvokingVertex == mode)
90 ctx->Light.ProvokingVertex = mode;
96 * per-light state.
104 struct gl_light *light;
107 light = &ctx->Light.Light[lnum];
111 if (TEST_EQ_4V(light->Ambient, params))
114 COPY_4V( light->Ambient, params );
117 if (TEST_EQ_4V(light->Diffuse, params))
120 COPY_4V( light->Diffuse, params );
123 if (TEST_EQ_4V(light->Specular, params))
126 COPY_4V( light->Specular, params );
130 if (TEST_EQ_4V(light->EyePosition, params))
133 COPY_4V(light->EyePosition, params);
134 if (light->EyePosition[3] != 0.0F)
135 light->_Flags |= LIGHT_POSITIONAL;
137 light->_Flags &= ~LIGHT_POSITIONAL;
141 if (TEST_EQ_3V(light->SpotDirection, params))
144 COPY_3V(light->SpotDirection, params);
149 if (light->SpotExponent == params[0])
152 light->SpotExponent = params[0];
156 if (light->SpotCutoff == params[0])
159 light->SpotCutoff = params[0];
160 light->_CosCutoff = (GLfloat) (cos(light->SpotCutoff * DEG2RAD));
161 if (light->_CosCutoff < 0)
162 light->_CosCutoff = 0;
163 if (light->SpotCutoff != 180.0F)
164 light->_Flags |= LIGHT_SPOT;
166 light->_Flags &= ~LIGHT_SPOT;
170 if (light->ConstantAttenuation == params[0])
173 light->ConstantAttenuation = params[0];
177 if (light->LinearAttenuation == params[0])
180 light->LinearAttenuation = params[0];
184 if (light->QuadraticAttenuation == params[0])
187 light->QuadraticAttenuation = params[0];
200 _mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
205 _mesa_Lightfv( light, pname, fparam );
210 _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
213 GLint i = (GLint) (light - GL_LIGHT0);
218 _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
282 _mesa_Lighti( GLenum light, GLenum pname, GLint param )
287 _mesa_Lightiv( light, pname, iparam );
292 _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
328 _mesa_Lightfv( light, pname, fparam );
334 _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
337 GLint l = (GLint) (light - GL_LIGHT0);
347 COPY_4V( params, ctx->Light.Light[l].Ambient );
350 COPY_4V( params, ctx->Light.Light[l].Diffuse );
353 COPY_4V( params, ctx->Light.Light[l].Specular );
356 COPY_4V( params, ctx->Light.Light[l].EyePosition );
359 COPY_3V( params, ctx->Light.Light[l].SpotDirection );
362 params[0] = ctx->Light.Light[l].SpotExponent;
365 params[0] = ctx->Light.Light[l].SpotCutoff;
368 params[0] = ctx->Light.Light[l].ConstantAttenuation;
371 params[0] = ctx->Light.Light[l].LinearAttenuation;
374 params[0] = ctx->Light.Light[l].QuadraticAttenuation;
384 _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
387 GLint l = (GLint) (light - GL_LIGHT0);
397 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
398 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
399 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
400 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
403 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
404 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
405 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
406 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
409 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
410 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
411 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
412 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
415 params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
416 params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
417 params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
418 params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
421 params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
422 params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
423 params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
426 params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
429 params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
432 params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
435 params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
438 params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
449 /*** Light Model ***/
463 if (TEST_EQ_4V( ctx->Light.Model.Ambient, params ))
466 COPY_4V( ctx->Light.Model.Ambient, params );
472 if (ctx->Light.Model.LocalViewer == newbool)
475 ctx->Light.Model.LocalViewer = newbool;
479 if (ctx->Light.Model.TwoSide == newbool)
482 ctx->Light.Model.TwoSide = newbool;
483 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
500 if (ctx->Light.Model.ColorControl == newenum)
503 ctx->Light.Model.ColorControl = newenum;
629 /* Update derived values following a change in ctx->Light.Material
634 struct gl_light *light, *list = &ctx->Light.EnabledList;
635 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
645 foreach (light, list) {
646 SCALE_3V( light->_MatAmbient[0], light->Ambient,
652 foreach (light, list) {
653 SCALE_3V( light->_MatAmbient[1], light->Ambient,
660 COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
661 ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
662 ctx->Light.Model.Ambient );
666 COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
667 ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
668 ctx->Light.Model.Ambient );
673 foreach (light, list) {
674 SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
680 foreach (light, list) {
681 SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
688 foreach (light, list) {
689 SCALE_3V( light->_MatSpecular[0], light->Specular,
695 foreach (light, list) {
696 SCALE_3V( light->_MatSpecular[1], light->Specular,
711 const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
712 struct gl_material *mat = &ctx->Light.Material;
743 if (ctx->Light._ColorMaterialBitmask == bitmask &&
744 ctx->Light.ColorMaterialFace == face &&
745 ctx->Light.ColorMaterialMode == mode)
749 ctx->Light._ColorMaterialBitmask = bitmask;
750 ctx->Light.ColorMaterialFace = face;
751 ctx->Light.ColorMaterialMode = mode;
753 if (ctx->Light.ColorMaterialEnabled) {
768 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
771 FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
820 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
825 FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
880 * Also, precompute some lighting values such as the products of light
887 struct gl_light *light;
888 ctx->Light._NeedEyeCoords = GL_FALSE;
890 if (!ctx->Light.Enabled)
893 foreach(light, &ctx->Light.EnabledList) {
894 flags |= light->_Flags;
897 ctx->Light._NeedVertices =
899 ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ||
900 ctx->Light.Model.LocalViewer);
902 ctx->Light._NeedEyeCoords = ((flags & LIGHT_POSITIONAL) ||
903 ctx->Light.Model.LocalViewer);
909 if (ctx->Light._NeedVertices)
910 ctx->Light._NeedEyeCoords = GL_TRUE;
913 * Light.Material here, we can get away without flushing
917 if (ctx->Light.Model.TwoSide)
937 * Update state derived from light position, spot direction.
949 struct gl_light *light;
952 if (!ctx->Light.Enabled)
962 foreach (light, &ctx->Light.EnabledList) {
966 COPY_4FV( light->_Position, light->EyePosition );
970 TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
971 light->EyePosition );
974 if (!(light->_Flags & LIGHT_POSITIONAL)) {
976 COPY_3V( light->_VP_inf_norm, light->_Position );
977 NORMALIZE_3FV( light->_VP_inf_norm );
979 if (!ctx->Light.Model.LocalViewer) {
981 ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir);
982 NORMALIZE_3FV( light->_h_inf_norm );
984 light->_VP_inf_spot_attenuation = 1.0;
987 /* positional light w/ homogeneous coordinate, divide by W */
988 GLfloat wInv = (GLfloat)1.0 / light->_Position[3];
989 light->_Position[0] *= wInv;
990 light->_Position[1] *= wInv;
991 light->_Position[2] *= wInv;
994 if (light->_Flags & LIGHT_SPOT) {
998 COPY_3V( light->_NormSpotDirection, light->SpotDirection );
999 NORMALIZE_3FV( light->_NormSpotDirection );
1003 COPY_3V(spotDir, light->SpotDirection);
1005 TRANSFORM_NORMAL( light->_NormSpotDirection,
1010 NORMALIZE_3FV( light->_NormSpotDirection );
1012 if (!(light->_Flags & LIGHT_POSITIONAL)) {
1013 GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
1014 light->_NormSpotDirection);
1016 if (PV_dot_dir > light->_CosCutoff) {
1017 light->_VP_inf_spot_attenuation =
1018 powf(PV_dot_dir, light->SpotExponent);
1021 light->_VP_inf_spot_attenuation = 0;
1060 ctx->Light._NeedEyeCoords)
1063 if (ctx->Light.Enabled &&
1096 * light-in-modelspace optimization. It's also useful for debugging.
1114 * Initialize the n-th light data structure.
1117 * \param n number of the light.
1118 * \note The defaults for light 0 are different than the other lights.
1147 * Initialize the light model data structure.
1195 init_light( &ctx->Light.Light[i], i );
1197 make_empty_list( &ctx->Light.EnabledList );
1199 init_lightmodel( &ctx->Light.Model );
1200 init_material( &ctx->Light.Material );
1201 ctx->Light.ShadeModel = GL_SMOOTH;
1202 ctx->Light.ProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT;
1203 ctx->Light.Enabled = GL_FALSE;
1204 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1205 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1206 ctx->Light._ColorMaterialBitmask = _mesa_material_bitmask( ctx,
1211 ctx->Light.ColorMaterialEnabled = GL_FALSE;
1212 ctx->Light.ClampVertexColor = GL_TRUE;
1215 ctx->Light._NeedEyeCoords = GL_FALSE;