1 #include <msp/datafile/rawdata.h>
2 #include <msp/io/memory.h>
4 #include "resourcemanager.h"
8 #include "texture2darray.h"
10 #include "texturecube.h"
17 Texture::Texture(unsigned t):
21 void Texture::set_format(PixelFormat fmt)
23 PixelComponents comp = get_components(fmt);
24 ComponentSwizzle swiz = get_required_swizzle(comp);
25 PixelComponents st_comp = unswizzle_components(comp, swiz);
27 PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt));
28 require_pixelformat(st_fmt);
37 void Texture::load_image(const string &fn, unsigned lv)
45 Texture::GenericLoader::TypeRegistry &Texture::get_texture_registry()
47 static GenericLoader::TypeRegistry registry;
48 static bool initialized = false;
52 registry.register_type<Texture1D>("1d");
53 registry.register_type<Texture2D>("2d");
54 registry.register_type<Texture3D>("3d");
55 registry.register_type<Texture2DArray>("2d_array");
56 registry.register_type<TextureCube>("cube");
62 Texture::Loader::Loader(Texture &t, Collection *c):
63 CollectionObjectLoader<Texture>(t, c),
66 add("external_data", &Loader::external_data);
67 add("external_image", &Loader::external_image, false);
68 add("external_image_srgb", &Loader::external_image, true);
69 add("generate_mipmap", &Loader::generate_mipmap);
70 add("image_data", &Loader::image_data);
71 add("mipmap_levels", &Loader::mipmap_levels);
72 add("raw_data", &Loader::raw_data);
75 void Texture::Loader::finish()
77 if(obj.auto_gen_mipmap)
78 obj.generate_mipmap();
81 void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
83 RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
85 throw IO::file_not_found(fn);
89 void Texture::Loader::external_data(const string &fn)
92 obj.manager->set_resource_location(obj, get_collection(), fn);
96 rd.open_file(get_collection(), fn);
98 obj.image(0, rd.get_data());
102 void Texture::Loader::external_image(bool srgb, const string &fn)
104 obj.use_srgb_format = srgb;
106 obj.manager->set_resource_location(obj, get_collection(), fn);
110 load_external_image(img, fn);
111 obj.image(img, levels);
115 void Texture::Loader::generate_mipmap(bool gm)
117 obj.auto_gen_mipmap = gm;
120 void Texture::Loader::image_data(const string &data)
126 IO::Memory mem(data.data(), data.size());
129 obj.image(img, levels);
132 void Texture::Loader::mipmap_levels(unsigned l)
137 void Texture::Loader::raw_data(const string &data)
142 obj.image(0, data.data());