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. Consists of an array of texels in the shape of a
13 right cuboid. Texture coordinates have a principal range of [0, 1].
15 class Texture3D: public Texture3DBackend
17 friend Texture3DBackend;
20 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>
24 Loader(Texture3D &, Collection &);
28 void raw_data(const std::string &);
29 void storage(PixelFormat, unsigned, unsigned, unsigned);
30 void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
41 Texture3D() = default;
43 /** Defines storage structure for the texture. If lv is zero, the number
44 of mipmap levels is automatically determined from storage dimensions.
46 Must be called before an image can be uploaded. Once storage is defined,
47 it can't be changed. */
48 void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
50 /** Updates the contents of the entire texture. Storage must be defined
51 beforehand. The image data must have dimensions and format matching the
53 void image(unsigned level, const void *data);
55 /** Updates a cuboid-shaped region of the texture. Storage must be defined
56 beforehand. The image data must be in a format mathing the defined storage
57 and the update region must be fully inside the texture. */
58 void sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data);
60 /** Updates the contents of the entire texture from an image. If storage
61 has not been defined, it will be set to match the image. In this case the
62 image will be treated as a stack of square layers and its height must be
63 divisible by its width. Otherwise the image must match the defined
65 virtual void image(const Graphics::Image &, unsigned = 0);
69 unsigned get_width() const { return width; }
70 unsigned get_height() const { return height; }
71 unsigned get_depth() const { return depth; }
73 unsigned get_n_levels() const;
74 LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;
77 virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
78 virtual std::uint64_t get_data_size() const;
79 virtual void unload() { }