X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flighting.cpp;h=517530a2f128854f964f673411f11eedfc97df87;hb=f136af6873d7409daffe262b14f632af986bd7dc;hp=44a01a5e6ab6ade990bd324d0ea7a0f97a5c8e85;hpb=42ace9ac1350d3ae009bdd2fb335ac1e57d1b36b;p=libs%2Fgl.git diff --git a/source/lighting.cpp b/source/lighting.cpp index 44a01a5e..517530a2 100644 --- a/source/lighting.cpp +++ b/source/lighting.cpp @@ -1,14 +1,11 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include #include "light.h" #include "lighting.h" +#include "lightunit.h" #include "misc.h" +using namespace std; + namespace Msp { namespace GL { @@ -23,10 +20,15 @@ void Lighting::set_ambient(const Color &a) 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) @@ -35,6 +37,8 @@ void Lighting::detach(unsigned i) return; lights[i] = 0; + if(current()==this) + Light::unbind_from(i); } void Lighting::bind() const @@ -42,7 +46,7 @@ void Lighting::bind() const if(!set_current(this)) return; - enable(LIGHTING); + enable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &ambient.r); for(unsigned i=0; ilights.size(); ++i) if(old->lights[i]) - { - Light::activate(i); - Light::unbind(); - } - disable(LIGHTING); + Light::unbind_from(i); + + disable(GL_LIGHTING); } } // namespace GL