10 Texture3D::Texture3D(unsigned t):
17 Texture3D::Texture3D():
23 void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv)
27 if(fmt!=format || wd!=width || ht!=height || dp!=depth || (lv && lv!=levels))
28 throw incompatible_data("Texture3D::storage");
31 if(wd==0 || ht==0 || dp==0)
32 throw invalid_argument("Texture3D::storage");
38 levels = get_n_levels();
40 levels = min(levels, lv);
45 void Texture3D::image(unsigned level, const void *data)
47 LinAl::Vector<unsigned, 3> size = get_level_size(level);
48 return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
51 void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
53 if(width==0 || height==0 || depth==0)
54 throw invalid_operation("Texture3D::sub_image");
56 throw out_of_range("Texture3D::sub_image");
58 Texture3DBackend::sub_image(level, x, y, z, wd, ht, dp, data);
61 void Texture3D::image(const Graphics::Image &img, unsigned lv)
63 unsigned w = img.get_width();
64 unsigned h = img.get_height();
67 throw incompatible_data("Texture3D::load_image");
71 storage(pixelformat_from_image(img, use_srgb_format), w, h, d, lv);
72 image(0, img.get_pixels());
75 unsigned Texture3D::get_n_levels() const
77 unsigned s = max(width, height);
81 for(; s; s>>=1, ++n) ;
85 LinAl::Vector<unsigned, 3> Texture3D::get_level_size(unsigned level) const
87 unsigned w = width>>level;
88 unsigned h = height>>level;
100 return LinAl::Vector<unsigned, 3>(w, h, d);
103 uint64_t Texture3D::get_data_size() const
105 return id ? width*height*depth*get_pixel_size(storage_fmt) : 0;
109 Texture3D::Loader::Loader(Texture3D &t):
110 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t)
115 Texture3D::Loader::Loader(Texture3D &t, Collection &c):
116 DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t, c)
121 void Texture3D::Loader::init()
123 add("raw_data", &Loader::raw_data);
124 add("storage", &Loader::storage);
125 add("storage", &Loader::storage_levels);
128 void Texture3D::Loader::raw_data(const string &data)
130 obj.image(0, data.data());
133 void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
135 obj.storage(fmt, w, h, d);
138 void Texture3D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned d, unsigned l)
140 obj.storage(fmt, w, h, d, l);