X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flighting.cpp;h=f5fbca6ac7ac954c5a2c63cd75590557e4245660;hb=f159ebc4120fb057c9d59efb0e5c7c36bff6f40a;hp=0af2416c14729788d411e747b91e8bcedfa0303c;hpb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;p=libs%2Fgl.git diff --git a/source/lighting.cpp b/source/lighting.cpp index 0af2416c..f5fbca6a 100644 --- a/source/lighting.cpp +++ b/source/lighting.cpp @@ -1,7 +1,11 @@ +#include #include "light.h" #include "lighting.h" +#include "lightunit.h" #include "misc.h" +using namespace std; + namespace Msp { namespace GL { @@ -16,10 +20,15 @@ void Lighting::set_ambient(const Color &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); lights[i] = &l; + if(current()==this) + l.bind_to(i); } void Lighting::detach(unsigned i) @@ -28,6 +37,16 @@ void Lighting::detach(unsigned i) return; lights[i] = 0; + if(current()==this) + Light::unbind_from(i); +} + +void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const +{ + shdata.uniform("ambient_color", ambient); + for(unsigned i=0; iupdate_shader_data(shdata, view_matrix, i); } void Lighting::bind() const