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!=levels))
19 throw incompatible_data("Texture3D::storage");
22 if(wd==0 || ht==0 || dp==0)
23 throw invalid_argument("Texture3D::storage");
29 levels = get_n_levels();
31 levels = min(levels, lv);
36 void Texture3D::image(unsigned level, const void *data)
38 LinAl::Vector<unsigned, 3> size = get_level_size(level);
39 return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
42 void Texture3D::sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *data)
44 if(width==0 || height==0 || depth==0)
45 throw invalid_operation("Texture3D::sub_image");
46 if(level>=levels || x>width || x+wd>width || y>height || y+ht>height || z>depth || z+dp>depth)
47 throw out_of_range("Texture3D::sub_image");
49 Texture3DBackend::sub_image(level, x, y, z, wd, ht, dp, data);
52 void Texture3D::image(const Graphics::Image &img, unsigned lv)
54 unsigned w = img.get_width();
55 unsigned h = img.get_height();
58 throw incompatible_data("Texture3D::load_image");
62 storage(pixelformat_from_image(img, use_srgb_format), w, h, d, lv);
63 image(0, img.get_pixels());
66 unsigned Texture3D::get_n_levels() const
68 unsigned s = max(width, height);
72 for(; s; s>>=1, ++n) ;
76 LinAl::Vector<unsigned, 3> Texture3D::get_level_size(unsigned level) const
78 unsigned w = width>>level;
79 unsigned h = height>>level;
91 return LinAl::Vector<unsigned, 3>(w, h, d);
95 Texture3D::Loader::Loader(Texture3D &t):
96 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t)
101 Texture3D::Loader::Loader(Texture3D &t, Collection &c):
102 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t, c)
107 void Texture3D::Loader::init()
109 add("storage", &Loader::storage);
110 add("storage", &Loader::storage_levels);
113 void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
115 obj.storage(fmt, w, h, d);
118 void Texture3D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned d, unsigned l)
120 obj.storage(fmt, w, h, d, l);