X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=63a72404339435329206acc68f5b9df515fb7dc0;hb=e087bfd5a9a850db30c399e95ef3fd8ab48005d1;hp=62bdabf60594e796439833b110e512bcd3544b24;hpb=b7f46931a9878b2fd7ec863d520dc22ac89c0baf;p=libs%2Fgl.git diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index 62bdabf6..63a72404 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -43,39 +43,43 @@ Resources::Resources(bool set_as_global): add_type().suffix(".anim").keyword("animation"); add_type().suffix(".arma").keyword("armature"); add_type().keyword("camera") - .notify(&Resources::set_debug_name); + .notify(&set_debug_name); 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); + .notify(&set_debug_name); add_type().suffix(".mat") - .creator(&Resources::create_material).notify(&Resources::set_debug_name); + .creator([this](const string &n){ return create_generic(n); }) + .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().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); + .notify(&set_debug_name); add_type().suffix(".scene") - .creator(&Resources::create_scene); + .creator([this](const string &n){ return create_generic(n); }); 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_source(get_builtins()); @@ -121,14 +125,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(); + return ldr.get_object(); } return 0; @@ -149,19 +154,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); @@ -269,7 +261,7 @@ void Resources::Loader::scene(const string &name) { Scene::GenericLoader ldr(obj); load_sub_with(ldr); - obj.add(name, ldr.get_scene()); + obj.add(name, ldr.get_object()); } } // namespace GL