1 #include <msp/io/memory.h>
3 #include "resourcemanager.h"
11 Texture::Texture(unsigned t):
13 format(NO_PIXELFORMAT),
16 use_srgb_format(false),
17 auto_gen_mipmap(false)
20 void Texture::set_format(PixelFormat fmt)
22 PixelComponents comp = get_components(fmt);
23 PixelComponents st_comp = comp;
24 FormatSwizzle swiz = NO_SWIZZLE;
29 swiz = R_TO_LUMINANCE;
33 swiz = RG_TO_LUMINANCE_ALPHA;
46 PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt));
47 require_pixelformat(st_fmt);
56 void Texture::load_image(const string &fn, unsigned lv)
65 Texture::Loader::Loader(Texture &t, Collection *c):
66 CollectionObjectLoader<Texture>(t, c),
69 add("external_image", &Loader::external_image);
70 add("external_image_srgb", &Loader::external_image_srgb);
71 add("generate_mipmap", &Loader::generate_mipmap);
72 add("image_data", &Loader::image_data);
73 add("mipmap_levels", &Loader::mipmap_levels);
76 void Texture::Loader::finish()
78 if(obj.auto_gen_mipmap)
79 obj.generate_mipmap();
82 void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
84 RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
86 throw IO::file_not_found(fn);
90 void Texture::Loader::external_image(const string &fn)
92 obj.use_srgb_format = false;
93 external_image_common(fn);
96 void Texture::Loader::external_image_srgb(const string &fn)
98 obj.use_srgb_format = true;
99 external_image_common(fn);
102 void Texture::Loader::external_image_common(const string &fn)
105 obj.manager->set_resource_location(obj, get_collection(), fn);
109 load_external_image(img, fn);
110 obj.image(img, levels);
114 void Texture::Loader::generate_mipmap(bool gm)
116 obj.auto_gen_mipmap = gm;
119 void Texture::Loader::image_data(const string &data)
125 IO::Memory mem(data.data(), data.size());
128 obj.image(img, levels);
131 void Texture::Loader::mipmap_levels(unsigned l)