+void Light::set_spot_exponent(float e)
+{
+ if(e<0)
+ throw invalid_argument("Light::set_spot_exponent");
+
+ spot_exp = e;
+ update_parameter(SPOT_EXP);
+}
+
+void Light::set_spot_cutoff(float c)
+{
+ set_spot_cutoff(Geometry::Angle<float>::from_degrees(c));
+}
+
+void Light::set_spot_cutoff(const Geometry::Angle<float> &c)
+{
+ if(c<Geometry::Angle<float>::zero() || (c>Geometry::Angle<float>::right() && c!=Geometry::Angle<float>::straight()))
+ throw invalid_argument("Light::set_spot_cutoff");
+
+ spot_cutoff = c;
+ update_parameter(SPOT_CUTOFF);
+}
+
+void Light::disable_spot_cutoff()
+{
+ set_spot_cutoff(Geometry::Angle<float>::straight());
+}
+
+void Light::set_attenuation(float c, float l, float q)
+{
+ attenuation[0] = c;
+ attenuation[1] = l;
+ attenuation[2] = q;
+ update_parameter(ATTENUATION);
+}
+
+void Light::update_shader_data(ProgramData &shdata, const Matrix &view_matrix, unsigned i) const
+{
+ string base = format("light_sources[%d]", i);
+ shdata.uniform(base+".position", view_matrix*position);
+ shdata.uniform(base+".diffuse", diffuse);
+ shdata.uniform(base+".specular", specular);
+}
+
+void Light::bind_to(unsigned i) const
+{
+ static Require _req(MSP_legacy_features);
+
+ LightUnit &unit = LightUnit::get_unit(i);
+ if(unit.set_light(this))
+ {
+ enable(GL_LIGHT0+unit.get_index());
+ update_parameter(-1, unit.get_index());
+ }
+}
+
+const Light *Light::current(unsigned i)
+{
+ return LightUnit::get_unit(i).get_light();
+}
+
+void Light::unbind_from(unsigned i)
+{
+ LightUnit &unit = LightUnit::get_unit(i);
+ if(unit.set_light(0))
+ disable(GL_LIGHT0+unit.get_index());
+}