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);
38 Texture3D() = default;
40 /** Sets storage format and dimensions and allocates memory for the texture.
41 If lv is zero, a complete mipmap pyramid is automatically created. Storage
42 cannot be changed once set. */
43 void storage(PixelFormat, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
45 /** Replaces contents of an entire mipmap level. Allocated storage must
46 exist. The image data is interpreted according to the storage format and
47 must have size matching the selected mipmap level. */
48 void image(unsigned level, const void *);
50 /** Replaces a cuboid-shaped region of the texture. Allocated storage must
51 exist. The image data is interpreted according to the storage format and
52 the region must be fully inside the texture. */
53 void sub_image(unsigned level, unsigned x, unsigned y, unsigned z, unsigned wd, unsigned ht, unsigned dp, const void *);
55 /** Sets the texture's contents from an image. The image is treated as a
56 stack of square layers and its height must be divisible by its width. If
57 storage has not been allocated yet, it will be set to match the image.
58 Otherwise the image must be compatible with the existing storage. */
59 virtual void image(const Graphics::Image &, unsigned = 0);
61 unsigned get_width() const { return width; }
62 unsigned get_height() const { return height; }
63 unsigned get_depth() const { return depth; }
65 LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;