X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Flighting.cpp;h=d8e5400626ae43eb26221ebd92bd748bb8043972;hp=699aabc02c7daa8679d60b2ab6fd8eaf8d99723b;hb=HEAD;hpb=3ac3a51c623271da815c8ee60c484445871753bf diff --git a/source/materials/lighting.cpp b/source/materials/lighting.cpp index 699aabc0..d8e54006 100644 --- a/source/materials/lighting.cpp +++ b/source/materials/lighting.cpp @@ -1,25 +1,31 @@ #include #include #include +#include #include -#include "error.h" +#include #include "light.h" #include "lighting.h" -#include "matrix.h" -#include "misc.h" using namespace std; namespace Msp { namespace GL { -Lighting::Lighting(): - zenith_direction(0, 0, 1), - horizon_angle(Geometry::Angle::zero()) +Lighting::Lighting() { set_ambient(0.2f); set_fog_color(Color(0.0f, 0.0f, 0.0f, 0.0f)); set_fog_density(0.0f); + + for(unsigned i=0; i<6; ++i) + { + string base = format("light_sources[%d]", i); + shdata.uniform(base+".position", Vector4(0, 0, 1, 0)); + shdata.uniform(base+".color", 0.0f, 0.0f, 0.0f); + shdata.uniform(base+".type", 0); + shdata.uniform(base+".attenuation", 1.0f, 0.0f, 0.0f); + } } void Lighting::set_ambient(const Color &a) @@ -28,24 +34,6 @@ void Lighting::set_ambient(const Color &a) shdata.uniform("ambient_color", ambient); } -void Lighting::set_sky_color(const Color &s) -{ - sky_color = s; - shdata.uniform("sky_color", sky_color); -} - -void Lighting::set_zenith_direction(const Vector3 &d) -{ - zenith_direction = d; - shdata.uniform("world_zenith_dir", zenith_direction); -} - -void Lighting::set_horizon_angle(const Geometry::Angle &a) -{ - horizon_angle = a; - shdata.uniform("horizon_limit", horizon_angle.radians()); -} - void Lighting::set_fog_color(const Color &c) { fog_color = c; @@ -74,36 +62,18 @@ void Lighting::attach(const Light &l) void Lighting::detach(const Light &l) { - vector::iterator i = find_member(lights, &l, &AttachedLight::light); + auto i = find_member(lights, &l, &AttachedLight::light); if(i!=lights.end()) + { lights.erase(i); + shdata.uniform(format("light_sources[%d].enabled", lights.size()), 0); + } } -void Lighting::detach(unsigned i) -{ - if(i>=lights.size()) - return; - - detach(*lights[i].light); -} - -const Light *Lighting::get_attached_light(unsigned i) const +int Lighting::find_light_index(const Light &l) const { - return iupdate_shader_data(sd, i); + auto i = find_member(lights, &l, &AttachedLight::light); + return (i!=lights.end() ? i-lights.begin() : -1); } const ProgramData &Lighting::get_shader_data() const @@ -130,12 +100,6 @@ void Lighting::set_debug_name(const string &name) DataFile::Loader::ActionMap Lighting::Loader::shared_actions; -Lighting::Loader::Loader(Lighting &l): - CollectionObjectLoader(l, 0) -{ - set_actions(shared_actions); -} - Lighting::Loader::Loader(Lighting &l, Collection &c): CollectionObjectLoader(l, &c) { @@ -150,12 +114,6 @@ void Lighting::Loader::init_actions() add("fog_half_distance", &Loader::fog_half_distance); add("light", &Loader::light); add("light", &Loader::light_inline); - - // Deprecated - add("horizon_angle", &Loader::horizon_angle); - add("light", &Loader::light_inline_index); - add("sky_color", &Loader::sky_color); - add("zenith_direction", &Loader::zenith_direction); } void Lighting::Loader::ambient(float r, float g, float b) @@ -178,14 +136,6 @@ void Lighting::Loader::fog_half_distance(float d) obj.set_fog_half_distance(d); } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -void Lighting::Loader::horizon_angle(float a) -{ - obj.set_horizon_angle(Geometry::Angle::from_degrees(a)); -} -#pragma GCC diagnostic pop - void Lighting::Loader::light(const string &name) { obj.attach(get_collection().get(name)); @@ -193,29 +143,11 @@ void Lighting::Loader::light(const string &name) void Lighting::Loader::light_inline() { - RefPtr lgt = new Light; - load_sub(*lgt); - get_collection().add(format("%s/%d.light", FS::basename(get_source()), obj.lights.size()), lgt.get()); - obj.attach(*lgt.release()); -} - -void Lighting::Loader::light_inline_index(unsigned) -{ - light_inline(); -} - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -void Lighting::Loader::sky_color(float r, float g, float b) -{ - obj.set_sky_color(Color(r, g, b)); -} - -void Lighting::Loader::zenith_direction(float x, float y, float z) -{ - obj.set_zenith_direction(Vector3(x, y, z)); + Light::GenericLoader ldr(get_collection()); + load_sub_with(ldr); + Light *lgt = ldr.store_object(get_collection(), format("%s/%d.light", FS::basename(get_source()), obj.lights.size())); + obj.attach(*lgt); } -#pragma GCC diagnostic pop } // namespace GL } // namespace Msp