]> git.tdb.fi Git - libs/gl.git/blobdiff - source/lightunit.cpp
Rewrite light binding to match textures
[libs/gl.git] / source / lightunit.cpp
diff --git a/source/lightunit.cpp b/source/lightunit.cpp
new file mode 100644 (file)
index 0000000..58d42e6
--- /dev/null
@@ -0,0 +1,48 @@
+#include <stdexcept>
+#include "gl.h"
+#include "misc.h"
+#include "lightunit.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+vector<LightUnit> LightUnit::units;
+LightUnit *LightUnit::cur_unit = 0;
+
+LightUnit::LightUnit():
+       light(0)
+{ }
+
+bool LightUnit::set_light(const Light *l)
+{
+       bool result = (l!=light);
+       light = l;
+       return result;
+}
+
+unsigned LightUnit::get_n_units()
+{
+       static int count = get_i(GL_MAX_LIGHTS);
+       return count;
+}
+
+LightUnit &LightUnit::get_unit(unsigned n)
+{
+       if(n>=get_n_units())
+               throw out_of_range("LightUnit::get_unit");
+
+       if(units.size()<=n)
+       {
+               unsigned i = units.size();
+               units.resize(n+1, LightUnit());
+               for(; i<units.size(); ++i)
+                       units[i].index = i;
+       }
+
+       return units[n];
+}
+
+} // namespace GL
+} // namespace Msp