X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=12448a901fc436ce1059b7a92bc834b57f0d6166;hb=6880f2eceaab2cec7882b0791dd982fe9d9c5068;hp=62bdabf60594e796439833b110e512bcd3544b24;hpb=b7f46931a9878b2fd7ec863d520dc22ac89c0baf;p=libs%2Fgl.git diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index 62bdabf6..12448a90 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -2,28 +2,34 @@ #include #include "animation.h" #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 "material.h" #include "mesh.h" #include "module.h" #include "object.h" +#include "occludedscene.h" +#include "orderedscene.h" +#include "pbrmaterial.h" #include "sequencetemplate.h" +#include "pointlight.h" #include "pose.h" #include "program.h" #include "resourcemanager.h" #include "resources.h" #include "sampler.h" -#include "scene.h" +#include "simplescene.h" #include "technique.h" #include "texture1d.h" #include "texture2d.h" #include "texture2darray.h" #include "texturecube.h" +#include "unlitmaterial.h" +#include "zsortedscene.h" #include "glsl/compiler.h" using namespace std; @@ -42,40 +48,59 @@ Resources::Resources(bool set_as_global): { add_type().suffix(".anim").keyword("animation"); add_type().suffix(".arma").keyword("armature"); + add_type().base().suffix(".mat") + .creator([this](const string &n) -> BasicMaterial * { create_generic(n); return 0; }) + .notify(&set_debug_name); add_type().keyword("camera") - .notify(&Resources::set_debug_name); + .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(&Resources::set_debug_name); - add_type().suffix(".mat") - .creator(&Resources::create_material).notify(&Resources::set_debug_name); + .notify(&set_debug_name); add_type().keyword("mesh") - .creator(&Resources::create_mesh).notify(&Resources::set_debug_name); + .creator([this](const string &n){ return create_mesh(n); }) + .notify(&set_debug_name); add_type().suffix(".glsl").suffix(".spv") - .creator(&Resources::create_module); + .creator([this](const string &n){ return create_module(n); }); add_type().keyword("object"); + add_type().base().suffix(".scene") + .creator([this](const string &n) -> OccludedScene * { create_generic(n); return 0; }); + add_type().base().suffix(".scene") + .creator([this](const string &n) -> OrderedScene * { create_generic(n); return 0; }); + 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") - .creator(&Resources::create_program).notify(&Resources::set_debug_name); + .creator([this](const string &n){ return create_program(n); }) + .notify(&set_debug_name); add_type().suffix(".samp").keyword("sampler") - .notify(&Resources::set_debug_name); - add_type().suffix(".scene") - .creator(&Resources::create_scene); + .notify(&set_debug_name); + add_type().base().suffix(".scene") + .creator([this](const string &n) -> SimpleScene * { create_generic(n); return 0; }); add_type().suffix(".tech").keyword("technique") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); add_type().base().suffix(".tex1d").keyword("texture1d") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); add_type().base().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d") - .creator(&Resources::create_texture2d).notify(&Resources::set_debug_name); + .creator([this](const string &n){ return create_texture2d(n); }) + .notify(&set_debug_name); add_type().base().suffix(".tex3d").keyword("texture3d") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); add_type().base().suffix(".texcb").keyword("texture_cube") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); add_type().base().suffix(".tex2da").keyword("texture2d_array") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); + add_type().base().suffix(".mat") + .creator([this](const string &n) -> UnlitMaterial * { create_generic(n); return 0; }) + .notify(&set_debug_name); + add_type().base().suffix(".scene") + .creator([this](const string &n) -> ZSortedScene * { create_generic(n); return 0; }); add_source(get_builtins()); @@ -121,14 +146,15 @@ void Resources::set_resource_manager(ResourceManager *m) resource_manager = m; } -Material *Resources::create_material(const string &name) +template +T *Resources::create_generic(const string &name) { if(RefPtr io = open_raw(name)) { DataFile::Parser parser(*io, name); - Material::GenericLoader ldr(this); + typename T::GenericLoader ldr(*this); ldr.load(parser); - return ldr.get_material(); + ldr.store_object(*this, name); } return 0; @@ -141,7 +167,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(); } @@ -149,19 +176,6 @@ Mesh *Resources::create_mesh(const string &name) return 0; } -Scene *Resources::create_scene(const string &name) -{ - if(RefPtr io = open_raw(name)) - { - DataFile::Parser parser(*io, name); - Scene::GenericLoader ldr(*this); - ldr.load(parser); - return ldr.get_scene(); - } - - return 0; -} - Texture2D *Resources::create_texture2d(const string &name) { string ext = FS::extpart(name); @@ -174,7 +188,8 @@ Texture2D *Resources::create_texture2d(const string &name) if(ext==".tex2d") { - tex = new Texture2D(resource_manager); + tex = new Texture2D; + tex->set_manager(resource_manager); DataFile::Parser parser(*io, name); Texture2D::Loader ldr(*tex, *this); ldr.load(parser); @@ -262,14 +277,17 @@ 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); } -void Resources::Loader::scene(const string &name) +template +void Resources::Loader::generic(const string &name) { - Scene::GenericLoader ldr(obj); + typename T::GenericLoader ldr(obj); load_sub_with(ldr); - obj.add(name, ldr.get_scene()); + ldr.store_object(obj, name); } } // namespace GL