1 #include <msp/fs/utils.h>
2 #include <msp/gl/extensions/sgis_generate_mipmap.h>
12 #include "programcompiler.h"
13 #include "resourcemanager.h"
14 #include "resources.h"
15 #include "technique.h"
16 #include "texture1d.h"
17 #include "texture2d.h"
18 #include "texture2darray.h"
19 #include "texturecube.h"
26 Resources::Resources():
27 default_tex_filter(SGIS_generate_mipmap ? LINEAR_MIPMAP_LINEAR : LINEAR),
28 srgb_conversion(false),
31 add_type<Animation>().suffix(".anim").keyword("animation");
32 add_type<Armature>().suffix(".arma").keyword("armature");
33 add_type<Font>().keyword("font");
34 add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
35 add_type<Material>().suffix(".mat").keyword("material");
36 add_type<Mesh>().keyword("mesh").creator(&Resources::create_mesh);
37 add_type<Object>().keyword("object");
38 add_type<Pose>().keyword("pose");
39 add_type<Program>().keyword("shader").suffix(".glsl").creator(&Resources::create_program);
40 add_type<Technique>().suffix(".tech").keyword("technique");
41 add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d");
42 add_type<Texture2D>().base<Texture>().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d);
43 add_type<Texture3D>().base<Texture>().suffix(".tex3d").keyword("texture3d");
44 add_type<TextureCube>().base<Texture>().suffix(".texcb").keyword("texture_cube");
45 add_type<Texture2DArray>().base<Texture>().suffix(".tex2da").keyword("texture2d_array");
48 void Resources::set_default_texture_filter(TextureFilter tf)
50 default_tex_filter = tf;
53 void Resources::set_srgb_conversion(bool c)
58 void Resources::set_resource_manager(ResourceManager *m)
63 Mesh *Resources::create_mesh(const string &name)
68 if(RefPtr<IO::Seekable> io = open_from_sources(name))
70 RefPtr<GL::Mesh> mesh = new GL::Mesh(resource_manager);
71 resource_manager->set_resource_location(*mesh, *this, name);
72 return mesh.release();
78 Texture2D *Resources::create_texture2d(const string &name)
80 string ext = FS::extpart(name);
84 if(RefPtr<IO::Seekable> io = open_from_sources(name))
86 Graphics::Image image;
90 RefPtr<GL::Texture2D> tex = new GL::Texture2D(resource_manager);
92 if(is_mipmapped(default_tex_filter))
94 tex->set_generate_mipmap(true);
95 tex->set_mag_filter(LINEAR);
98 tex->set_mag_filter(default_tex_filter);
99 tex->set_min_filter(default_tex_filter);
102 resource_manager->set_resource_location(*tex, *this, name);
104 tex->image(image, srgb_conversion);
105 return tex.release();
111 Program *Resources::create_program(const string &name)
113 string ext = FS::extpart(name);
117 if(RefPtr<IO::Seekable> io = open_from_sources(name))
119 ProgramCompiler compiler;
120 compiler.compile(*io);
121 RefPtr<Program> program = new Program;
122 compiler.add_shaders(*program);
124 return program.release();