]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources.cpp
Move texture sampler state to a separate object
[libs/gl.git] / source / resources.cpp
index b8eec774387ea94233c6aa0223095199042ea12e..dd9a3c68c3543b549f425a863a842ad2d35bcc04 100644 (file)
@@ -30,6 +30,7 @@ void init_shaderlib(DataFile::BuiltinSource &);
 
 Resources::Resources():
        default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
+       default_tex_anisotropy(1.0f),
        srgb_conversion(false),
        resource_manager(0)
 {
@@ -39,7 +40,7 @@ Resources::Resources():
        add_type<Font>().keyword("font");
        add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
        add_type<Lighting>().suffix(".lightn").keyword("lighting");
-       add_type<Material>().suffix(".mat").keyword("material");
+       add_type<Material>().suffix(".mat").creator(&Resources::create_material);
        add_type<Mesh>().keyword("mesh").creator(&Resources::create_mesh);
        add_type<Object>().keyword("object");
        add_type<PipelineTemplate>().suffix(".pipe").keyword("pipeline");
@@ -74,6 +75,11 @@ 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;
@@ -84,12 +90,25 @@ void Resources::set_resource_manager(ResourceManager *m)
        resource_manager = m;
 }
 
+Material *Resources::create_material(const string &name)
+{
+       if(RefPtr<IO::Seekable> io = open_raw(name))
+       {
+               DataFile::Parser parser(*io, name);
+               Material::GenericLoader ldr(this);
+               ldr.load(parser);
+               return ldr.get_material();
+       }
+
+       return 0;
+}
+
 Mesh *Resources::create_mesh(const string &name)
 {
        if(!resource_manager)
                return 0;
 
-       if(RefPtr<IO::Seekable> io = open_from_sources(name))
+       if(RefPtr<IO::Seekable> io = open_raw(name))
        {
                RefPtr<Mesh> mesh = new Mesh(resource_manager);
                resource_manager->set_resource_location(*mesh, *this, name);
@@ -105,7 +124,7 @@ Texture2D *Resources::create_texture2d(const string &name)
        if(ext==".tex2d")
                return 0;
 
-       if(RefPtr<IO::Seekable> io = open_from_sources(name))
+       if(RefPtr<IO::Seekable> io = open_raw(name))
        {
                Graphics::Image image;
                if(!resource_manager)
@@ -113,14 +132,16 @@ Texture2D *Resources::create_texture2d(const string &name)
 
                RefPtr<Texture2D> tex = new Texture2D(resource_manager);
 
+               Sampler &samp = tex->get_default_sampler();
                if(is_mipmapped(default_tex_filter))
                {
-                       tex->set_generate_mipmap(true);
-                       tex->set_mag_filter(LINEAR);
+                       tex->set_auto_generate_mipmap(true);
+                       samp.set_mag_filter(LINEAR);
                }
                else
-                       tex->set_mag_filter(default_tex_filter);
-               tex->set_min_filter(default_tex_filter);
+                       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);
@@ -138,7 +159,7 @@ Program *Resources::create_program(const string &name)
        if(ext==".shader")
                return 0;
 
-       if(RefPtr<IO::Seekable> io = open_from_sources(name))
+       if(RefPtr<IO::Seekable> io = open_raw(name))
        {
                ProgramCompiler compiler;
                compiler.compile(*io, this, name);