]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't store ProgramData in Lighting
authorMikko Rasa <tdb@tdb.fi>
Thu, 8 May 2014 17:55:53 +0000 (20:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 8 May 2014 17:55:53 +0000 (20:55 +0300)
It can't be kept up to date automatically, as Lighting can't track the
individual Lights' state.  It's also hard to make optimize out unnecessary
updates.  It's typically computed very few times per frame anyway, so the
performance hit is negligible (as opposed to something like Material,
which might get used hundreds or thousands of times per frame).

source/lighting.cpp
source/lighting.h
source/renderer.cpp

index 515733a6b253e13a69f2b8a117680a73f487e6cf..f5fbca6ac7ac954c5a2c63cd75590557e4245660 100644 (file)
@@ -41,7 +41,7 @@ void Lighting::detach(unsigned i)
                Light::unbind_from(i);
 }
 
-void Lighting::update_shader_data(const Matrix &view_matrix)
+void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
 {
        shdata.uniform("ambient_color", ambient);
        for(unsigned i=0; i<lights.size(); ++i)
index 7c7dc454c14f027e1fed3c17f62ec5b6b9b3c608..593d8039fe5c8365269b757f963173b14289cd51 100644 (file)
@@ -20,7 +20,6 @@ class Lighting: public Bindable<Lighting>
 private:
        Color ambient;
        std::vector<const Light *> lights;
-       ProgramData shdata;
 
 public:
        Lighting();
@@ -31,8 +30,7 @@ public:
        void attach(unsigned, const Light &);
        void detach(unsigned);
 
-       void update_shader_data(const Matrix &);
-       const ProgramData &get_shader_data() const { return shdata; }
+       void update_shader_data(ProgramData &, const Matrix &) const;
        void bind() const;
 
        static void unbind();
index af0d087398da9010816a0cce0f8bf563dc1f69d0..606dd341336fcbc8668bc8724e38898f9fe084bb 100644 (file)
@@ -90,9 +90,7 @@ void Renderer::set_lighting(const Lighting *l)
        state->lighting = l;
        state->lighting_matrix = mtx_stack.top();
        if(l)
-               /* XXX I'm not happy with this, but can't come up with anything better
-               right now. */
-               const_cast<Lighting *>(l)->update_shader_data(mtx_stack.top());
+               l->update_shader_data(standard_shdata, mtx_stack.top());
        lighting_changed = true;
 }
 
@@ -246,8 +244,6 @@ void Renderer::apply_state()
                                        nm(i, j) = m(i, j);
                        nm = transpose(invert(nm));
                        standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
-                       if(state->lighting)
-                               state->lighting->get_shader_data().apply();
                        if(state->material)
                                state->material->get_shader_data().apply();
                        standard_shdata.apply();