]> git.tdb.fi Git - libs/gl.git/blob - source/texture3d.h
Use a type registry to manage postprocessor types for pipeline templates
[libs/gl.git] / source / texture3d.h
1 #ifndef MSP_GL_TEXTURE3D_H_
2 #define MSP_GL_TEXTURE3D_H_
3
4 #include <string>
5 #include "texture.h"
6
7 namespace Msp {
8 namespace GL {
9
10 /**
11 Three-dimensional texture.  Consists of an array of texels in the shape of a
12 right cuboid.  Texture coordinates have a principal range of [0, 1].
13 */
14 class Texture3D: public Texture
15 {
16 public:
17         class Loader: public Msp::DataFile::DerivedObjectLoader<Texture3D, Texture::Loader>
18         {
19         public:
20                 Loader(Texture3D &);
21                 Loader(Texture3D &, Collection &);
22         private:
23                 void init();
24
25                 void raw_data(const std::string &);
26                 void storage(PixelFormat, unsigned, unsigned, unsigned);
27         };
28
29 private:
30         unsigned width;
31         unsigned height;
32         unsigned depth;
33         unsigned levels;
34         unsigned allocated;
35
36 protected:
37         Texture3D(GLenum);
38 public:
39         Texture3D();
40
41         /** Defines storage structure for the texture.  If lv is zero, the number
42         of mipmap levels is automatically determined from storage dimensions.
43
44         Must be called before an image can be uploaded.  Once storage is defined,
45         it can't be changed. */
46         void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
47
48         /** Allocates storage for the texture.  The contents are initially
49         undefined.  If storage has already been allocated, does nothing. */
50         void allocate(unsigned level);
51
52         /** Uploads an image to the texture.  Storage must be defined beforehand.
53         The image data must have dimensions and format compatible with the defined
54         storage. */
55         void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
56
57         /** Updates a cuboid-shaped region of the texture.  Storage must be defined
58         and allocated beforehand.  The update region must be fully inside the
59         texture. */
60         void sub_image(unsigned level,
61                 int x, int y, int z, unsigned wd, unsigned ht, unsigned dp,
62                 PixelFormat fmt, DataType type, const void *data);
63
64         /** Loads an image from a file and uploads it to the texture.  If storage
65         has not been defined, it will be set to match the loaded image.  To
66         construct a three-dimensional texture from a two-dimensional image, the
67         image is interpreted as an array of consecutive images.  If dp is -1, the
68         texture's width and height are equal.  If dp is -2, the texture's height and
69         depth are equal.  Otherwise, dp must be positive and determines the
70         texture's depth.  In all cases, the image's height must equal the texture's
71         height times its depth.
72         
73         Deprecated in favor of the base class version.*/
74         void load_image(const std::string &fn, int dp = -1);
75
76         using Texture::load_image;
77
78         /** Uploads an image to the texture.  If storage has not been defined, it
79         will be set to match the image.  In this case the image will be treated as
80         a stack of square layers and its height must be divisible by its width.
81         Otherwise the image must be compatible with the defined storage.
82
83         If srgb is true and storage is determined by this call, then an sRGB pixel
84         format will be used. */
85         virtual void image(const Graphics::Image &, bool = false);
86
87         unsigned get_width() const { return width; }
88         unsigned get_height() const { return height; }
89         unsigned get_depth() const { return depth; }
90 protected:
91         unsigned get_n_levels() const;
92         void get_level_size(unsigned, unsigned &, unsigned &, unsigned &) const;
93
94 public:
95         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
96         virtual UInt64 get_data_size() const;
97         virtual void unload() { }
98 };
99
100 } // namespace GL
101 } // namespace Msp
102
103 #endif