X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=a37496b93771190add82369f87cea33fa6b0ce2c;hb=be92396630a2065e43c21d9d1904e97014844cff;hp=32f59d93d6e5a85f0bea998fd6bc446deb3fe88f;hpb=e6e6f0fe81a2f92985e65ae0de708974194d81a3;p=libs%2Fgl.git diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index 32f59d93..a37496b9 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -4,10 +4,10 @@ #include "armature.h" #include "basicmaterial.h" #include "camera.h" +#include "directionallight.h" #include "error.h" #include "font.h" #include "keyframe.h" -#include "light.h" #include "lighting.h" #include "mesh.h" #include "module.h" @@ -16,6 +16,7 @@ #include "orderedscene.h" #include "pbrmaterial.h" #include "sequencetemplate.h" +#include "pointlight.h" #include "pose.h" #include "program.h" #include "resourcemanager.h" @@ -52,9 +53,10 @@ Resources::Resources(bool set_as_global): .notify(&set_debug_name); add_type().keyword("camera") .notify(&set_debug_name); + add_type().base().suffix(".light") + .creator([this](const string &n) -> DirectionalLight * { create_generic(n); return 0; }); add_type().keyword("font"); add_type().suffix(".kframe").keyword("keyframe"); - add_type().keyword("light"); add_type().suffix(".lightn").keyword("lighting") .notify(&set_debug_name); add_type().keyword("mesh") @@ -70,6 +72,8 @@ Resources::Resources(bool set_as_global): add_type().base().suffix(".mat") .creator([this](const string &n) -> PbrMaterial * { create_generic(n); return 0; }) .notify(&set_debug_name); + add_type().base().suffix(".light") + .creator([this](const string &n) -> PointLight * { create_generic(n); return 0; }); add_type().suffix(".seq").keyword("sequence"); add_type().keyword("pose"); add_type().keyword("shader") @@ -81,16 +85,20 @@ Resources::Resources(bool set_as_global): .creator([this](const string &n) -> SimpleScene * { create_generic(n); return 0; }); add_type().suffix(".tech").keyword("technique") .notify(&set_debug_name); - add_type().base().suffix(".tex1d").keyword("texture1d") + add_type().base().suffix(".tex") + .creator([this](const string &n) -> Texture1D * { create_texture(n); return 0; }) .notify(&set_debug_name); - add_type().base().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d") - .creator([this](const string &n){ return create_texture2d(n); }) + add_type().base().suffix(".tex").suffix(".png").suffix(".jpg") + .creator([this](const string &n) -> Texture2D * { create_texture(n); return 0; }) .notify(&set_debug_name); - add_type().base().suffix(".tex3d").keyword("texture3d") + add_type().base().suffix(".tex") + .creator([this](const string &n) -> Texture3D * { create_texture(n); return 0; }) .notify(&set_debug_name); - add_type().base().suffix(".texcb").keyword("texture_cube") + add_type().base().suffix(".tex") + .creator([this](const string &n) -> TextureCube * { create_texture(n); return 0; }) .notify(&set_debug_name); - add_type().base().suffix(".tex2da").keyword("texture2d_array") + add_type().base().suffix(".tex") + .creator([this](const string &n) -> Texture2DArray * { create_texture(n); return 0; }) .notify(&set_debug_name); add_type().base().suffix(".mat") .creator([this](const string &n) -> UnlitMaterial * { create_generic(n); return 0; }) @@ -142,13 +150,13 @@ void Resources::set_resource_manager(ResourceManager *m) resource_manager = m; } -template +template T *Resources::create_generic(const string &name) { if(RefPtr io = open_raw(name)) { DataFile::Parser parser(*io, name); - typename T::GenericLoader ldr(*this); + L ldr(*this); ldr.load(parser); ldr.store_object(*this, name); } @@ -163,7 +171,8 @@ Mesh *Resources::create_mesh(const string &name) if(RefPtr io = open_raw(name)) { - RefPtr mesh = new Mesh(resource_manager); + RefPtr mesh = new Mesh; + mesh->set_manager(resource_manager); resource_manager->set_resource_location(*mesh, *this, name); return mesh.release(); } @@ -171,39 +180,31 @@ Mesh *Resources::create_mesh(const string &name) return 0; } -Texture2D *Resources::create_texture2d(const string &name) +Texture *Resources::create_texture(const string &name) { string ext = FS::extpart(name); - if(ext==".tex2d" && !resource_manager) - return 0; + if(ext==".tex") + return create_generic>(name); if(RefPtr io = open_raw(name)) { RefPtr tex; - if(ext==".tex2d") - { - tex = new Texture2D(resource_manager); - DataFile::Parser parser(*io, name); - Texture2D::Loader ldr(*tex, *this); - ldr.load(parser); - } - else - { - // Verify that the image is loadable - Graphics::Image image; - if(!resource_manager) - image.load_io(*io); + // Verify that the image is loadable + Graphics::Image image; + if(!resource_manager) + image.load_io(*io); - tex = new Texture2D(resource_manager); + tex = new Texture2D; + tex->set_manager(resource_manager); - if(resource_manager) - resource_manager->set_resource_location(*tex, *this, name); - else - tex->image(image); - } + if(resource_manager) + resource_manager->set_resource_location(*tex, *this, name); + else + tex->image(image); - return tex.release(); + add(name, tex.get()); + tex.release(); } return 0; @@ -271,14 +272,26 @@ void Resources::set_debug_name(const string &name, T &item) Resources::Loader::Loader(Resources &r): DerivedObjectLoader(r) { - add("scene", &Loader::scene); + add("light", &Loader::generic); + add("material", &Loader::generic); + add("scene", &Loader::generic); + add("texture", &Loader::generic>); } -void Resources::Loader::scene(const string &name) +template +void Resources::Loader::generic(const string &name) { - Scene::GenericLoader ldr(obj); + L ldr(obj); load_sub_with(ldr); - obj.add(name, ldr.get_object()); + ldr.store_object(obj, name); +} + + +template +void Resources::GenericResourceLoader::type(const DataFile::Symbol &t) +{ + T::GenericLoader::type(t); + this->object->set_manager(resources.resource_manager); } } // namespace GL