]> git.tdb.fi Git - libs/gl.git/blobdiff - source/lighting.cpp
Always update program uniforms if uniform names have changed
[libs/gl.git] / source / lighting.cpp
index 2ba1edc5560e00889ecd31fa01592f121a68a993..239bdc19d0d03fdb9d0bcfaf58902d4c12abf4f6 100644 (file)
@@ -1,4 +1,6 @@
 #include <stdexcept>
+#include <msp/gl/extensions/msp_legacy_features.h>
+#include "error.h"
 #include "light.h"
 #include "lighting.h"
 #include "lightunit.h"
@@ -38,9 +40,6 @@ void Lighting::set_horizon_angle(const Geometry::Angle<float> &a)
 
 void Lighting::attach(unsigned i, const Light &l)
 {
-       if(i>=LightUnit::get_n_units())
-               throw out_of_range("Lighting::attach");
-
        if(i>=lights.size())
                lights.resize(i+1);
 
@@ -63,7 +62,7 @@ void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix
 {
        shdata.uniform("ambient_color", ambient);
        shdata.uniform("sky_color", sky_color);
-       shdata.uniform("eye_sky_dir", Vector3(view_matrix*Vector4(sky_direction, 0.0f)));
+       shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*sky_direction);
        shdata.uniform("horizon_limit", horizon_angle.radians());
 
        for(unsigned i=0; i<lights.size(); ++i)
@@ -73,6 +72,10 @@ void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix
 
 void Lighting::bind() const
 {
+       static Require _req(MSP_legacy_features);
+       if(lights.size()>LightUnit::get_n_units())
+               throw invalid_operation("Lighting::bind");
+
        if(!set_current(this))
                return;