Lines Matching refs:light
32 #include "light.h"
47 if (ctx->Light.ShadeModel == mode)
56 ctx->Light.ShadeModel = mode;
85 if (ctx->Light.ProvokingVertex == mode)
89 ctx->Light.ProvokingVertex = mode;
95 * per-light state.
103 struct gl_light *light;
106 light = &ctx->Light.Light[lnum];
110 if (TEST_EQ_4V(light->Ambient, params))
113 COPY_4V( light->Ambient, params );
116 if (TEST_EQ_4V(light->Diffuse, params))
119 COPY_4V( light->Diffuse, params );
122 if (TEST_EQ_4V(light->Specular, params))
125 COPY_4V( light->Specular, params );
129 if (TEST_EQ_4V(light->EyePosition, params))
132 COPY_4V(light->EyePosition, params);
133 if (light->EyePosition[3] != 0.0F)
134 light->_Flags |= LIGHT_POSITIONAL;
136 light->_Flags &= ~LIGHT_POSITIONAL;
140 if (TEST_EQ_3V(light->SpotDirection, params))
143 COPY_3V(light->SpotDirection, params);
148 if (light->SpotExponent == params[0])
151 light->SpotExponent = params[0];
155 if (light->SpotCutoff == params[0])
158 light->SpotCutoff = params[0];
159 light->_CosCutoff = (cosf(light->SpotCutoff * M_PI / 180.0));
160 if (light->_CosCutoff < 0)
161 light->_CosCutoff = 0;
162 if (light->SpotCutoff != 180.0F)
163 light->_Flags |= LIGHT_SPOT;
165 light->_Flags &= ~LIGHT_SPOT;
169 if (light->ConstantAttenuation == params[0])
172 light->ConstantAttenuation = params[0];
176 if (light->LinearAttenuation == params[0])
179 light->LinearAttenuation = params[0];
183 if (light->QuadraticAttenuation == params[0])
186 light->QuadraticAttenuation = params[0];
199 _mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
204 _mesa_Lightfv( light, pname, fparam );
209 _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
212 GLint i = (GLint) (light - GL_LIGHT0);
216 _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
270 _mesa_Lighti( GLenum light, GLenum pname, GLint param )
275 _mesa_Lightiv( light, pname, iparam );
280 _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
316 _mesa_Lightfv( light, pname, fparam );
322 _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
325 GLint l = (GLint) (light - GL_LIGHT0);
334 COPY_4V( params, ctx->Light.Light[l].Ambient );
337 COPY_4V( params, ctx->Light.Light[l].Diffuse );
340 COPY_4V( params, ctx->Light.Light[l].Specular );
343 COPY_4V( params, ctx->Light.Light[l].EyePosition );
346 COPY_3V( params, ctx->Light.Light[l].SpotDirection );
349 params[0] = ctx->Light.Light[l].SpotExponent;
352 params[0] = ctx->Light.Light[l].SpotCutoff;
355 params[0] = ctx->Light.Light[l].ConstantAttenuation;
358 params[0] = ctx->Light.Light[l].LinearAttenuation;
361 params[0] = ctx->Light.Light[l].QuadraticAttenuation;
371 _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
374 GLint l = (GLint) (light - GL_LIGHT0);
383 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
384 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
385 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
386 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
389 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
390 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
391 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
392 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
395 params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
396 params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
397 params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
398 params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
401 params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
402 params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
403 params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
404 params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
407 params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
408 params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
409 params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
412 params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
415 params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
418 params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
421 params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
424 params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
435 /*** Light Model ***/
448 if (TEST_EQ_4V( ctx->Light.Model.Ambient, params ))
451 COPY_4V( ctx->Light.Model.Ambient, params );
457 if (ctx->Light.Model.LocalViewer == newbool)
460 ctx->Light.Model.LocalViewer = newbool;
464 if (ctx->Light.Model.TwoSide == newbool)
467 ctx->Light.Model.TwoSide = newbool;
481 if (ctx->Light.Model.ColorControl == newenum)
484 ctx->Light.Model.ColorControl = newenum;
610 /* Update derived values following a change in ctx->Light.Material
615 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
625 GLbitfield mask = ctx->Light._EnabledLights;
628 struct gl_light *light = &ctx->Light.Light[i];
629 SCALE_3V( light->_MatAmbient[0], light->Ambient,
635 GLbitfield mask = ctx->Light._EnabledLights;
638 struct gl_light *light = &ctx->Light.Light[i];
639 SCALE_3V( light->_MatAmbient[1], light->Ambient,
646 COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
647 ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
648 ctx->Light.Model.Ambient );
652 COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
653 ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
654 ctx->Light.Model.Ambient );
659 GLbitfield mask = ctx->Light._EnabledLights;
662 struct gl_light *light = &ctx->Light.Light[i];
663 SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
669 GLbitfield mask = ctx->Light._EnabledLights;
672 struct gl_light *light = &ctx->Light.Light[i];
673 SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
680 GLbitfield mask = ctx->Light._EnabledLights;
683 struct gl_light *light = &ctx->Light.Light[i];
684 SCALE_3V( light->_MatSpecular[0], light->Specular,
690 GLbitfield mask = ctx->Light._EnabledLights;
693 struct gl_light *light = &ctx->Light.Light[i];
694 SCALE_3V( light->_MatSpecular[1], light->Specular,
709 GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
710 struct gl_material *mat = &ctx->Light.Material;
741 if (ctx->Light._ColorMaterialBitmask == bitmask &&
742 ctx->Light.ColorMaterialFace == face &&
743 ctx->Light.ColorMaterialMode == mode)
747 ctx->Light._ColorMaterialBitmask = bitmask;
748 ctx->Light.ColorMaterialFace = face;
749 ctx->Light.ColorMaterialMode = mode;
751 if (ctx->Light.ColorMaterialEnabled) {
766 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
769 FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
818 GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
823 FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
878 * Also, precompute some lighting values such as the products of light
885 ctx->Light._NeedEyeCoords = GL_FALSE;
887 if (!ctx->Light.Enabled)
890 GLbitfield mask = ctx->Light._EnabledLights;
893 struct gl_light *light = &ctx->Light.Light[i];
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.
951 if (!ctx->Light.Enabled)
961 GLbitfield mask = ctx->Light._EnabledLights;
964 struct gl_light *light = &ctx->Light.Light[i];
968 COPY_4FV( light->_Position, light->EyePosition );
972 TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
973 light->EyePosition );
976 if (!(light->_Flags & LIGHT_POSITIONAL)) {
978 COPY_3V( light->_VP_inf_norm, light->_Position );
979 NORMALIZE_3FV( light->_VP_inf_norm );
981 if (!ctx->Light.Model.LocalViewer) {
983 ADD_3V( light->_h_inf_norm, light->_VP_inf_norm, ctx->_EyeZDir);
984 NORMALIZE_3FV( light->_h_inf_norm );
986 light->_VP_inf_spot_attenuation = 1.0;
989 /* positional light w/ homogeneous coordinate, divide by W */
990 GLfloat wInv = 1.0F / light->_Position[3];
991 light->_Position[0] *= wInv;
992 light->_Position[1] *= wInv;
993 light->_Position[2] *= wInv;
996 if (light->_Flags & LIGHT_SPOT) {
1000 COPY_3V( light->_NormSpotDirection, light->SpotDirection );
1001 NORMALIZE_3FV( light->_NormSpotDirection );
1005 COPY_3V(spotDir, light->SpotDirection);
1007 TRANSFORM_NORMAL( light->_NormSpotDirection,
1012 NORMALIZE_3FV( light->_NormSpotDirection );
1014 if (!(light->_Flags & LIGHT_POSITIONAL)) {
1015 GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
1016 light->_NormSpotDirection);
1018 if (PV_dot_dir > light->_CosCutoff) {
1019 light->_VP_inf_spot_attenuation =
1020 powf(PV_dot_dir, light->SpotExponent);
1023 light->_VP_inf_spot_attenuation = 0;
1062 ctx->Light._NeedEyeCoords)
1065 if (ctx->Light.Enabled &&
1098 * light-in-modelspace optimization. It's also useful for debugging.
1116 * Initialize the n-th light data structure.
1119 * \param n number of the light.
1120 * \note The defaults for light 0 are different than the other lights.
1147 * Initialize the light model data structure.
1194 ctx->Light._EnabledLights = 0;
1196 init_light( &ctx->Light.Light[i], i );
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 = ctx->API == API_OPENGL_COMPAT;
1213 ctx->Light._ClampVertexColor = ctx->API == API_OPENGL_COMPAT;
1216 ctx->Light._NeedEyeCoords = GL_FALSE;