]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resources.cpp
Unify the loader wrappers for Material and Scene
[libs/gl.git] / source / resources / resources.cpp
index 79c95932b6c52b03f45c669d58a68f71d5e2bbeb..80a19e7c9bdd6aa3ed30f037930613defc39182b 100644 (file)
@@ -37,20 +37,20 @@ void init_builtin_data(DataFile::BuiltinSource &);
 Resources *Resources::global_resources = 0;
 
 Resources::Resources(bool set_as_global):
-       default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
-       default_tex_anisotropy(1.0f),
        srgb_conversion(false),
        resource_manager(0)
 {
        add_type<Animation>().suffix(".anim").keyword("animation");
        add_type<Armature>().suffix(".arma").keyword("armature");
-       add_type<Camera>().keyword("camera");
+       add_type<Camera>().keyword("camera")
+               .notify(&Resources::set_debug_name<Camera>);
        add_type<Font>().keyword("font");
        add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
        add_type<Light>().keyword("light");
-       add_type<Lighting>().suffix(".lightn").keyword("lighting");
+       add_type<Lighting>().suffix(".lightn").keyword("lighting")
+               .notify(&Resources::set_debug_name<Lighting>);
        add_type<Material>().suffix(".mat")
-               .creator(&Resources::create_material).notify(&Resources::set_debug_name<Material>);
+               .creator(&Resources::create_generic<Material>).notify(&Resources::set_debug_name<Material>);
        add_type<Mesh>().keyword("mesh")
                .creator(&Resources::create_mesh).notify(&Resources::set_debug_name<Mesh>);
        add_type<Module>().suffix(".glsl").suffix(".spv")
@@ -63,7 +63,7 @@ Resources::Resources(bool set_as_global):
        add_type<Sampler>().suffix(".samp").keyword("sampler")
                .notify(&Resources::set_debug_name<Sampler>);
        add_type<Scene>().suffix(".scene")
-               .creator(&Resources::create_scene);
+               .creator(&Resources::create_generic<Scene>);
        add_type<Technique>().suffix(".tech").keyword("technique")
                .notify(&Resources::set_debug_name<Technique>);
        add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d")
@@ -111,16 +111,6 @@ const DataFile::CollectionSource &Resources::get_builtins()
        return builtins;
 }
 
-void Resources::set_default_texture_filter(TextureFilter tf)
-{
-       default_tex_filter = tf;
-}
-
-void Resources::set_default_texture_anisotropy(float a)
-{
-       default_tex_anisotropy = a;
-}
-
 void Resources::set_srgb_conversion(bool c)
 {
        srgb_conversion = c;
@@ -131,14 +121,15 @@ void Resources::set_resource_manager(ResourceManager *m)
        resource_manager = m;
 }
 
-Material *Resources::create_material(const string &name)
+template<typename T>
+T *Resources::create_generic(const string &name)
 {
        if(RefPtr<IO::Seekable> 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;
@@ -159,19 +150,6 @@ Mesh *Resources::create_mesh(const string &name)
        return 0;
 }
 
-Scene *Resources::create_scene(const string &name)
-{
-       if(RefPtr<IO::Seekable> 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);
@@ -197,16 +175,6 @@ Texture2D *Resources::create_texture2d(const string &name)
                                image.load_io(*io);
 
                        tex = new Texture2D(resource_manager);
-                       Sampler &samp = tex->get_default_sampler();
-                       if(is_mipmapped(default_tex_filter))
-                       {
-                               tex->set_auto_generate_mipmap(true);
-                               samp.set_mag_filter(LINEAR);
-                       }
-                       else
-                               samp.set_mag_filter(default_tex_filter);
-                       samp.set_min_filter(default_tex_filter);
-                       samp.set_max_anisotropy(default_tex_anisotropy);
 
                        if(resource_manager)
                                resource_manager->set_resource_location(*tex, *this, name);
@@ -264,7 +232,6 @@ Program *Resources::create_program(const string &name)
                Module &module = get<Module>(base);
                RefPtr<Program> shprog = new Program;
                shprog->add_stages(module);
-               shprog->link();
                return shprog.release();
        }
 
@@ -290,7 +257,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