]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture3d.h
Always set uniform array size to at least one
[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         unsigned levels = 0;
36
37         Texture3D(unsigned);
38 public:
39         Texture3D() = default;
40
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);
45
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 *);
50
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 *);
55
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);
61
62         unsigned get_width() const { return width; }
63         unsigned get_height() const { return height; }
64         unsigned get_depth() const { return depth; }
65 protected:
66         unsigned get_n_levels() const;
67         LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;
68
69 public:
70         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
71         virtual std::size_t get_data_size() const;
72         virtual void unload() { }
73 };
74
75 } // namespace GL
76 } // namespace Msp
77
78 #endif