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).
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)
private:
Color ambient;
std::vector<const Light *> lights;
- ProgramData shdata;
public:
Lighting();
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();
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;
}
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();