]> git.tdb.fi Git - libs/gl.git/commitdiff
Some fixes to lighting management
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Aug 2016 20:39:33 +0000 (23:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Aug 2016 20:39:33 +0000 (23:39 +0300)
source/lighting.cpp
source/lightunit.cpp
source/lightunit.h

index 5cda4f4c6a4e005a5ad71c22427ddc0c5d0d69c7..ce522ac06a11e77151a5c7fbe0967347674f2aa3 100644 (file)
@@ -104,14 +104,25 @@ void Lighting::bind() const
        if(lights.size()>LightUnit::get_n_units())
                throw invalid_operation("Lighting::bind");
 
+       const Lighting *old = current();
        if(!set_current(this))
                return;
 
        enable(GL_LIGHTING);
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r);
        for(unsigned i=0; i<lights.size(); ++i)
+       {
                if(lights[i])
                        lights[i]->bind_to(i);
+               else
+                       Light::unbind_from(i);
+       }
+
+       if(old)
+       {
+               for(unsigned i=lights.size(); i<old->lights.size(); ++i)
+                       Light::unbind_from(i);
+       }
 
        if(fog_density)
        {
index 3eb32929859fe8bc51bfb4d5572e6b3d2b389372..e7cf7419c1672961ad4eb85280b30e834ea8a0b7 100644 (file)
@@ -10,7 +10,6 @@ namespace Msp {
 namespace GL {
 
 vector<LightUnit> LightUnit::units;
-LightUnit *LightUnit::cur_unit = 0;
 
 LightUnit::LightUnit():
        light(0)
index 658712df1bd092b62c3ab2498cdfc6f2c71c2882..bc200ea4aa7283bab9beec8b15d0585c09178944 100644 (file)
@@ -15,7 +15,6 @@ private:
        const Light *light;
 
        static std::vector<LightUnit> units;
-       static LightUnit *cur_unit;
 
        LightUnit();