]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture3d.h
Remove remaining deprecated things from the core classes
[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 "texture.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
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].
14 */
15 class Texture3D: public Texture
16 {
17 public:
18         class Loader: public Msp::DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>
19         {
20         public:
21                 Loader(Texture3D &);
22                 Loader(Texture3D &, Collection &);
23         private:
24                 void init();
25
26                 void raw_data(const std::string &);
27                 void storage(PixelFormat, unsigned, unsigned, unsigned);
28                 void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
29         };
30
31 protected:
32         unsigned width;
33         unsigned height;
34         unsigned depth;
35         unsigned levels;
36         unsigned allocated;
37
38         Texture3D(GLenum);
39 public:
40         Texture3D();
41
42         /** Defines storage structure for the texture.  If lv is zero, the number
43         of mipmap levels is automatically determined from storage dimensions.
44
45         Must be called before an image can be uploaded.  Once storage is defined,
46         it can't be changed. */
47         void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
48
49         /** Allocates storage for the texture.  The contents are initially
50         undefined.  If storage has already been allocated, does nothing. */
51         void allocate(unsigned level);
52
53         /** Updates the contents of the entire texture.  Storage must be defined
54         beforehand.  The image data must have dimensions and format matching the
55         defined storage. */
56         void image(unsigned level, const void *data);
57
58         /** Updates a cuboid-shaped region of the texture.  Storage must be defined
59         beforehand.  The image data must be in a format mathing the defined storage
60         and the update region must be fully inside the texture. */
61         void sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data);
62
63         /** Updates the contents of the entire texture from an image.  If storage
64         has not been defined, it will be set to match the image.  In this case the
65         image will be treated as a stack of square layers and its height must be
66         divisible by its width.  Otherwise the image must match the defined
67         storage. */
68         virtual void image(const Graphics::Image &, unsigned = 0);
69
70         using Texture::image;
71
72         unsigned get_width() const { return width; }
73         unsigned get_height() const { return height; }
74         unsigned get_depth() const { return depth; }
75 protected:
76         unsigned get_n_levels() const;
77         LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;
78
79 public:
80         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
81         virtual std::uint64_t get_data_size() const;
82         virtual void unload() { }
83 };
84
85 } // namespace GL
86 } // namespace Msp
87
88 #endif