1 #ifndef MSP_GL_TEXTURE3D_H_
2 #define MSP_GL_TEXTURE3D_H_
5 #include <msp/linal/vector.h>
6 #include "texture3d_backend.h"
12 Three-dimensional texture, consisting of a cuboid-shaped array of texels.
14 class Texture3D: public Texture3DBackend
16 friend Texture3DBackend;
19 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>
23 Loader(Texture3D &, Collection &);
27 void storage(PixelFormat, unsigned, unsigned, unsigned);
28 void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
39 Texture3D() = default;
41 /** Sets storage format and dimensions and allocates memory for the texture.
42 If lv is zero, a complete mipmap pyramid is automatically created. Storage
43 cannot be changed once set. */
44 void storage(PixelFormat, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
46 /** Replaces contents of an entire mipmap level. Allocated storage must
47 exist. The image data is interpreted according to the storage format and
48 must have size matching the selected mipmap level. */
49 void image(unsigned level, const void *);
51 /** Replaces a cuboid-shaped region of the texture. Allocated storage must
52 exist. The image data is interpreted according to the storage format and
53 the region must be fully inside the texture. */
54 void sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *);
56 /** Sets the texture's contents from an image. The image is treated as a
57 stack of square layers and its height must be divisible by its width. If
58 storage has not been allocated yet, it will be set to match the image.
59 Otherwise the image must be compatible with the existing storage. */
60 virtual void image(const Graphics::Image &, unsigned = 0);
62 unsigned get_width() const { return width; }
63 unsigned get_height() const { return height; }
64 unsigned get_depth() const { return depth; }
66 unsigned get_n_levels() const;
67 LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;