From: Mikko Rasa Date: Thu, 8 May 2014 17:55:53 +0000 (+0300) Subject: Don't store ProgramData in Lighting X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ce657d3b7783db9f3450162fbf07210ea1c8c661;p=libs%2Fgl.git Don't store ProgramData in Lighting 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). --- diff --git a/source/lighting.cpp b/source/lighting.cpp index 515733a6..f5fbca6a 100644 --- a/source/lighting.cpp +++ b/source/lighting.cpp @@ -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 private: Color ambient; std::vector 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(); diff --git a/source/renderer.cpp b/source/renderer.cpp index af0d0873..606dd341 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -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(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();