10 Texture3D::Texture3D(unsigned t):
14 void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv)
18 if(fmt!=format || wd!=width || ht!=height || dp!=depth || (lv && lv!=n_levels))
19 throw incompatible_data("Texture3D::storage");
22 if(wd==0 || ht==0 || dp==0)
23 throw invalid_argument("Texture3D::storage");
29 unsigned size = max(width, height);
31 size = max(size, depth);
32 n_levels = count_levels(size);
34 n_levels = min(n_levels, lv);
39 void Texture3D::image(unsigned level, const void *data)
41 LinAl::Vector<unsigned, 3> size = get_level_size(level);
42 return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
45 void Texture3D::sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *data)
47 if(width==0 || height==0 || depth==0)
48 throw invalid_operation("Texture3D::sub_image");
49 if(level>=n_levels || x>width || x+wd>width || y>height || y+ht>height || z>depth || z+dp>depth)
50 throw out_of_range("Texture3D::sub_image");
52 Texture3DBackend::sub_image(level, x, y, z, wd, ht, dp, data);
55 void Texture3D::image(const Graphics::Image &img, unsigned lv)
57 unsigned w = img.get_width();
58 unsigned h = img.get_height();
61 throw incompatible_data("Texture3D::load_image");
65 storage(pixelformat_from_image(img, use_srgb_format), w, h, d, lv);
66 image(0, img.get_pixels());
69 LinAl::Vector<unsigned, 3> Texture3D::get_level_size(unsigned level) const
71 unsigned w = width>>level;
72 unsigned h = height>>level;
84 return LinAl::Vector<unsigned, 3>(w, h, d);
88 Texture3D::Loader::Loader(Texture3D &t):
89 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t)
94 Texture3D::Loader::Loader(Texture3D &t, Collection &c):
95 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t, c)
100 void Texture3D::Loader::init()
102 add("storage", &Loader::storage);
103 add("storage", &Loader::storage_levels);
106 void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
108 obj.storage(fmt, w, h, d);
111 void Texture3D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned d, unsigned l)
113 obj.storage(fmt, w, h, d, l);