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