]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resources.cpp
Split Module into a base class and format-specific class
[libs/gl.git] / source / resources / resources.cpp
index ef8b93255fca8927104d35e4434e4a68cf5ee1bf..bb3243f6fde4601d0f452901dfe4b6a4d3c02625 100644 (file)
@@ -132,20 +132,23 @@ Texture2D *Resources::create_texture2d(const string &name)
 
        if(RefPtr<IO::Seekable> io = open_raw(name))
        {
-               Graphics::Image image;
-               if(!resource_manager)
-                       image.load_io(*io);
-
-               RefPtr<Texture2D> tex = new Texture2D(resource_manager);
+               RefPtr<Texture2D> 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);
+
+                       tex = new Texture2D(resource_manager);
                        Sampler &samp = tex->get_default_sampler();
                        if(is_mipmapped(default_tex_filter))
                        {
@@ -156,12 +159,13 @@ Texture2D *Resources::create_texture2d(const string &name)
                                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);
+                       else
+                               tex->image(image);
                }
 
-               if(resource_manager)
-                       resource_manager->set_resource_location(*tex, *this, name);
-               else
-                       tex->image(image);
                return tex.release();
        }
 
@@ -170,11 +174,18 @@ Texture2D *Resources::create_texture2d(const string &name)
 
 Module *Resources::create_module(const string &name)
 {
+       string ext = FS::extpart(name);
+       if(ext!=".glsl")
+               return 0;
+
        if(RefPtr<IO::Seekable> io = open_raw(name))
        {
-               RefPtr<Module> module = new Module;
-               module->load_source(*io, this, name);
-               return module.release();
+               if(ext==".glsl")
+               {
+                       RefPtr<GlslModule> module = new GlslModule;
+                       module->load_source(*io, this, name);
+                       return module.release();
+               }
        }
 
        return 0;