]> git.tdb.fi Git - libs/gl.git/blob - source/core/texturecube.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / texturecube.h
1 #ifndef MSP_GL_TEXTURECUBE_H_
2 #define MSP_GL_TEXTURECUBE_H_
3
4 #include <msp/graphics/image.h>
5 #include "texturecube_backend.h"
6 #include "vector.h"
7
8 namespace Msp {
9 namespace GL {
10
11 enum TextureCubeFace
12 {
13         POSITIVE_X = 0,
14         NEGATIVE_X = 1,
15         POSITIVE_Y = 2,
16         NEGATIVE_Y = 3,
17         POSITIVE_Z = 4,
18         NEGATIVE_Z = 5
19 };
20
21 /**
22 Cube map texture, consisting of six square faces.
23
24 A cube map texture is addressed by three-dimensional texture coordinates.  The
25 coordinate vector is projected on the unit cube, with the largest coordinate
26 selecting the face and the remaining two used to sample from the face image.
27 The images are oriented so that the cross product of the s and t axes will
28 point into the cube.
29 */
30 class TextureCube: public TextureCubeBackend
31 {
32         friend TextureCubeBackend;
33
34 public:
35         class Loader: public Msp::DataFile::DerivedObjectLoader<TextureCube, Texture::Loader>
36         {
37         public:
38                 Loader(TextureCube &);
39                 Loader(TextureCube &, Collection &);
40         private:
41                 void init();
42
43                 void external_image(TextureCubeFace, const std::string &);
44                 void image_data(TextureCubeFace, const std::string &);
45                 void raw_data(TextureCubeFace, const std::string &);
46                 void storage(PixelFormat, unsigned);
47                 void storage_levels(PixelFormat, unsigned, unsigned);
48         };
49
50 private:
51         unsigned size = 0;
52
53         static const Vector3 directions[6];
54         static const unsigned orientations[12];
55
56 public:
57         /** Sets storage format and dimensions and allocates memory for the texture.
58         If lv is zero, a complete mipmap pyramid is automatically created.  Storage
59         cannot be changed once set. */
60         void storage(PixelFormat, unsigned size, unsigned lv = 0);
61
62         virtual void image(unsigned, const void *);
63
64         /** Replaces contents of a single face.  Allocated storage must exist.  The
65         image data is interpreted according to the storage format and must have size
66         matching the selected mipmap level. */
67         void image(TextureCubeFace, unsigned level, const void *);
68
69         /** Replaces a rectangular region of a face.  Allocated storage must exist.
70         The image data is interpreted according to the storage format and the region
71         must be fully inside the face. */
72         void sub_image(TextureCubeFace, unsigned level, unsigned x, unsigned y, unsigned w, unsigned h, const void *);
73
74         void image(TextureCubeFace, const Graphics::Image &);
75
76         /** Sets the texture's contents from an image.  The image is treated as a
77         stack of square layers and its height must be six times its width.  If
78         storage has not been allocated yet, it will be set to match the image.
79         Otherwise the image must be compatible with the existing storage. */
80         virtual void image(const Graphics::Image &, unsigned = 0);
81
82         unsigned get_size() const { return size; }
83 private:
84         unsigned get_level_size(unsigned) const;
85
86 public:
87         /** Returns a vector pointing out of the face. */
88         static const Vector3 &get_face_direction(TextureCubeFace);
89
90         /** Returns a vector in the direction of the s axis of the face. */
91         static const Vector3 &get_s_direction(TextureCubeFace);
92
93         /** Returns a vector in the direction of the t axis of the face. */
94         static const Vector3 &get_t_direction(TextureCubeFace);
95
96         /** Returns a vector pointing to the center of a texel. */
97         Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned);
98 };
99
100 void operator>>(const LexicalConverter &, TextureCubeFace &);
101
102 } // namespace GL
103 } // namespace Msp
104
105 #endif