]> git.tdb.fi Git - libs/gl.git/blobdiff - source/lighting.cpp
Tweak buffer logic a bit in Batch::draw
[libs/gl.git] / source / lighting.cpp
index 0af2416c14729788d411e747b91e8bcedfa0303c..517530a2f128854f964f673411f11eedfc97df87 100644 (file)
@@ -1,7 +1,11 @@
+#include <stdexcept>
 #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,8 @@ void Lighting::detach(unsigned i)
                return;
 
        lights[i] = 0;
+       if(current()==this)
+               Light::unbind_from(i);
 }
 
 void Lighting::bind() const