1 #include <msp/fs/utils.h>
2 #include <msp/gl/extensions/sgis_generate_mipmap.h>
12 #include "resourcemanager.h"
13 #include "resources.h"
14 #include "technique.h"
15 #include "texture2d.h"
16 #include "texturecube.h"
23 Resources::Resources():
24 default_tex_filter(SGIS_generate_mipmap ? LINEAR_MIPMAP_LINEAR : LINEAR),
25 srgb_conversion(false),
28 add_type<Animation>().suffix(".anim").keyword("animation");
29 add_type<Armature>().suffix(".arma").keyword("armature");
30 add_type<Font>().keyword("font");
31 add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
32 add_type<Material>().suffix(".mat").keyword("material");
33 add_type<Mesh>().keyword("mesh").creator(&Resources::create_mesh);
34 add_type<Object>().keyword("object");
35 add_type<Pose>().keyword("pose");
36 add_type<Program>().keyword("shader");
37 add_type<Technique>().suffix(".tech").keyword("technique");
38 add_type<Texture2D>().base<Texture>().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d);
39 add_type<TextureCube>().base<Texture>().suffix(".texcb").keyword("texture_cube");
42 void Resources::set_default_texture_filter(TextureFilter tf)
44 default_tex_filter = tf;
47 void Resources::set_srgb_conversion(bool c)
52 void Resources::set_resource_manager(ResourceManager *m)
57 Mesh *Resources::create_mesh(const string &name)
62 if(RefPtr<IO::Seekable> io = open_from_sources(name))
64 RefPtr<GL::Mesh> mesh = new GL::Mesh(resource_manager);
65 resource_manager->set_resource_location(*mesh, *this, name);
66 return mesh.release();
72 Texture2D *Resources::create_texture2d(const string &name)
74 string ext = FS::extpart(name);
78 if(RefPtr<IO::Seekable> io = open_from_sources(name))
80 Graphics::Image image;
84 RefPtr<GL::Texture2D> tex = new GL::Texture2D(resource_manager);
86 if(default_tex_filter==NEAREST_MIPMAP_NEAREST || default_tex_filter==NEAREST_MIPMAP_LINEAR ||
87 default_tex_filter==LINEAR_MIPMAP_NEAREST || default_tex_filter==LINEAR_MIPMAP_LINEAR)
89 tex->set_generate_mipmap(true);
90 tex->set_mag_filter(LINEAR);
93 tex->set_mag_filter(default_tex_filter);
94 tex->set_min_filter(default_tex_filter);
97 resource_manager->set_resource_location(*tex, *this, name);
99 tex->image(image, srgb_conversion);
100 return tex.release();