]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture3d.h
Rearrange soucre files into subdirectories
[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 "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                 void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
28         };
29
30 private:
31         unsigned width;
32         unsigned height;
33         unsigned depth;
34         unsigned levels;
35         unsigned allocated;
36
37 protected:
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         DEPRECATED void storage(PixelComponents c, unsigned w, unsigned h, unsigned d, unsigned l = 0)
50         { storage(make_pixelformat(c, UNSIGNED_BYTE), w, h, d, l); }
51
52         /** Allocates storage for the texture.  The contents are initially
53         undefined.  If storage has already been allocated, does nothing. */
54         void allocate(unsigned level);
55
56         /** Updates the contents of the entire texture.  Storage must be defined
57         beforehand.  The image data must have dimensions and format matching the
58         defined storage. */
59         void image(unsigned level, const void *data);
60
61         DEPRECATED void image(unsigned level, PixelComponents comp, DataType type, const void *data);
62
63         /** Updates a cuboid-shaped region of the texture.  Storage must be defined
64         beforehand.  The image data must be in a format mathing the defined storage
65         and the update region must be fully inside the texture. */
66         void sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data);
67
68         DEPRECATED void sub_image(unsigned level,
69                 int x, int y, int z, unsigned wd, unsigned ht, unsigned dp,
70                 PixelComponents comp, DataType type, const void *data);
71
72         /** Updates the contents of the entire texture from an image.  If storage
73         has not been defined, it will be set to match the image.  In this case the
74         image will be treated as a stack of square layers and its height must be
75         divisible by its width.  Otherwise the image must match the defined
76         storage. */
77         virtual void image(const Graphics::Image &, unsigned = 0);
78
79         using Texture::image;
80
81         unsigned get_width() const { return width; }
82         unsigned get_height() const { return height; }
83         unsigned get_depth() const { return depth; }
84 protected:
85         unsigned get_n_levels() const;
86         void get_level_size(unsigned, unsigned &, unsigned &, unsigned &) const;
87
88 public:
89         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
90         virtual UInt64 get_data_size() const;
91         virtual void unload() { }
92 };
93
94 } // namespace GL
95 } // namespace Msp
96
97 #endif