9 Texture2D::~Texture2D()
14 void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
18 if(fmt!=format || wd!=width || ht!=height || (lv && lv!=n_levels))
19 throw incompatible_data("Texture2D::storage");
23 throw invalid_argument("Texture2D::storage");
28 n_levels = count_levels(max(width, height));
30 n_levels = min(n_levels, lv);
35 void Texture2D::image(unsigned level, const void *data)
37 LinAl::Vector<unsigned, 2> size = get_level_size(level);
38 return sub_image(level, 0, 0, size.x, size.y, data);
41 void Texture2D::sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *data)
43 if(width==0 || height==0)
44 throw invalid_operation("Texture2D::sub_image");
45 if(level>=n_levels || x>width || x+wd>width || y>height || y+ht>height)
46 throw out_of_range("Texture2D::sub_image");
48 Texture2DBackend::sub_image(level, x, y, wd, ht, data);
51 void Texture2D::image(const Graphics::Image &img, unsigned lv)
53 storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv);
54 image(0, img.get_pixels());
57 LinAl::Vector<unsigned, 2> Texture2D::get_level_size(unsigned level) const
59 unsigned w = width>>level;
60 unsigned h = height>>level;
67 return LinAl::Vector<unsigned, 2>(w, h);
71 Texture2D::Loader::Loader(Texture2D &t):
72 DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>(t)
77 Texture2D::Loader::Loader(Texture2D &t, Collection &c):
78 DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>(t, c)
83 void Texture2D::Loader::init()
85 add("storage", &Loader::storage);
86 add("storage", &Loader::storage_levels);
89 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
91 obj.storage(fmt, w, h);
94 void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned l)
96 obj.storage(fmt, w, h, l);