]> git.tdb.fi Git - libs/gl.git/blob - source/texture3d.h
Use UNSIGNED_SHORT for allocating DEPTH_COMPONENT textures
[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 private:
17         PixelFormat ifmt;
18         unsigned width;
19         unsigned height;
20         unsigned depth;
21         unsigned allocated;
22
23 public:
24         Texture3D();
25
26         /** Defines storage structure for the texture.  Must be called before an
27         image can be uploaded.  Once storage is defined, it can't be changed. */
28         void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp);
29
30         /** Allocates storage for the texture.  The contents are initially
31         undefined.  If storage has already been allocated, does nothing. */
32         void allocate(unsigned level);
33
34         /** Uploads an image to the texture.  Storage must be defined beforehand.
35         The image data must have dimensions and format compatible with the defined
36         storage. */
37         void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
38
39         /** Updates a cuboid-shaped region of the texture.  Storage must be defined
40         and allocated beforehand.  The update region must be fully inside the
41         texture. */
42         void sub_image(unsigned level,
43                 int x, int y, int z, unsigned wd, unsigned ht, unsigned dp,
44                 PixelFormat fmt, DataType type, const void *data);
45
46         /** Loads an image from a file and uploads it to the texture.  If storage
47         has not been defined, it will be set to match the loaded image.  To
48         construct a three-dimensional texture from a two-dimensional image, the
49         image is interpreted as an array of consecutive images.  If dp is -1, the
50         texture's width and height are equal.  If dp is -2, the texture's height and
51         depth are equal.  Otherwise, dp must be positive and determines the
52         texture's depth.  In all cases, the image's height must equal the texture's
53         height times its depth. */
54         void load_image(const std::string &fn, int dp = -1);
55
56         unsigned get_width() const { return width; }
57         unsigned get_height() const { return height; }
58         unsigned get_depth() const { return depth; }
59 private:
60         void get_level_size(unsigned, unsigned &, unsigned &, unsigned &);
61
62 public:
63         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
64         virtual UInt64 get_data_size() const;
65         virtual void unload() { }
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif