]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture3d.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / texture3d.h
1 #ifndef MSP_GL_TEXTURE3D_H_
2 #define MSP_GL_TEXTURE3D_H_
3
4 #include <string>
5 #include <msp/linal/vector.h>
6 #include "texture3d_backend.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Three-dimensional texture, consisting of a cuboid-shaped array of texels.
13 */
14 class Texture3D: public Texture3DBackend
15 {
16         friend Texture3DBackend;
17
18 public:
19         class Loader: public Msp::DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>
20         {
21         public:
22                 Loader(Texture3D &);
23                 Loader(Texture3D &, Collection &);
24         private:
25                 void init();
26
27                 void storage(PixelFormat, unsigned, unsigned, unsigned);
28                 void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
29         };
30
31 protected:
32         unsigned width = 0;
33         unsigned height = 0;
34         unsigned depth = 0;
35
36         Texture3D(unsigned);
37 public:
38         Texture3D() = default;
39
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);
44
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 *);
49
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 *);
54
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);
60
61         unsigned get_width() const { return width; }
62         unsigned get_height() const { return height; }
63         unsigned get_depth() const { return depth; }
64 protected:
65         LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif