-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2008 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <stdexcept>
#include "light.h"
#include "lighting.h"
+#include "lightunit.h"
#include "misc.h"
+using namespace std;
+
namespace Msp {
namespace GL {
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)
return;
lights[i] = 0;
+ if(current()==this)
+ Light::unbind_from(i);
+}
+
+void Lighting::update_shader_data(const Matrix &view_matrix)
+{
+ shdata.uniform("ambient_color", ambient);
+ for(unsigned i=0; i<lights.size(); ++i)
+ if(lights[i])
+ lights[i]->update_shader_data(shdata, view_matrix, i);
}
void Lighting::bind() const