namespace GL {
Texture3D::Texture3D(unsigned t):
- Texture3DBackend(t),
- width(0),
- height(0),
- depth(0)
-{ }
-
-Texture3D::Texture3D():
- width(0),
- height(0),
- depth(0)
+ Texture3DBackend(t)
{ }
void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv)
{
if(width>0)
{
- if(fmt!=format || wd!=width || ht!=height || dp!=depth || (lv && lv!=levels))
+ if(fmt!=format || wd!=width || ht!=height || dp!=depth || (lv && lv!=n_levels))
throw incompatible_data("Texture3D::storage");
return;
}
width = wd;
height = ht;
depth = dp;
- levels = get_n_levels();
+ unsigned size = max(width, height);
+ if(!is_array())
+ size = max(size, depth);
+ n_levels = count_levels(size);
if(lv>0)
- levels = min(levels, lv);
+ n_levels = min(n_levels, lv);
allocate();
}
return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
}
-void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
+void Texture3D::sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *data)
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::sub_image");
- if(level>=levels)
+ if(level>=n_levels || x>width || x+wd>width || y>height || y+ht>height || z>depth || z+dp>depth)
throw out_of_range("Texture3D::sub_image");
Texture3DBackend::sub_image(level, x, y, z, wd, ht, dp, data);
image(0, img.get_pixels());
}
-unsigned Texture3D::get_n_levels() const
-{
- unsigned s = max(width, height);
- if(!is_array())
- s = max(s, depth);
- unsigned n = 0;
- for(; s; s>>=1, ++n) ;
- return n;
-}
-
LinAl::Vector<unsigned, 3> Texture3D::get_level_size(unsigned level) const
{
unsigned w = width>>level;
return LinAl::Vector<unsigned, 3>(w, h, d);
}
-uint64_t Texture3D::get_data_size() const
-{
- return id ? width*height*depth*get_pixel_size(storage_fmt) : 0;
-}
-
Texture3D::Loader::Loader(Texture3D &t):
DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>(t)
void Texture3D::Loader::init()
{
- add("raw_data", &Loader::raw_data);
add("storage", &Loader::storage);
add("storage", &Loader::storage_levels);
}
-void Texture3D::Loader::raw_data(const string &data)
-{
- obj.image(0, data.data());
-}
-
void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
{
obj.storage(fmt, w, h, d);