]> git.tdb.fi Git - libs/gl.git/blob - source/core/texturecube.h
Use default member initializers for simple types
[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.  All of the faces must be of
23 the same size.  A cube map texture is addressed by three-dimensional texture
24 coordinates, with a principal range of [-1, 1].  The face is first selected
25 according to the largest coordinate, and the remaining two coordinates are used
26 to sample the face image.  The images are oriented so that the cross product of
27 the s and t axes will point into the cube.
28
29 All faces of a cube map texture must be allocated for it to be usable.
30
31 Requires OpenGL version 1.3.
32 */
33 class TextureCube: public TextureCubeBackend
34 {
35         friend TextureCubeBackend;
36
37 public:
38         class Loader: public Msp::DataFile::DerivedObjectLoader<TextureCube, Texture::Loader>
39         {
40         public:
41                 Loader(TextureCube &);
42                 Loader(TextureCube &, Collection &);
43         private:
44                 void init();
45
46                 void external_image(TextureCubeFace, const std::string &);
47                 void image_data(TextureCubeFace, const std::string &);
48                 void raw_data(TextureCubeFace, const std::string &);
49                 void storage(PixelFormat, unsigned);
50                 void storage_levels(PixelFormat, unsigned, unsigned);
51         };
52
53 private:
54         unsigned size = 0;
55         unsigned levels = 0;
56
57         static const Vector3 directions[6];
58         static const unsigned orientations[12];
59
60 public:
61         /** Defines storage structure for the texture.  If lv is zero, the number
62         of mipmap levels is automatically determined from storage dimensions.
63
64         Must be called before an image can be uploaded.  Once storage is defined,
65         it can't be changed. */
66         void storage(PixelFormat fmt, unsigned size, unsigned lv = 0);
67
68         /** Updates the contents of a face.  Storage must be defined beforehand.
69         The image data must have dimensions and format matching the defined
70         storage. */
71         void image(TextureCubeFace face, unsigned level, const void *data);
72
73         /** Updates a rectangular region of a face.  Storage must be defined
74         beforehand.  The image data must be in a format mathing the defined storage
75         and the update region must be fully inside the face. */
76         void sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned w, unsigned h, const void *data);
77
78         void image(TextureCubeFace, const Graphics::Image &);
79
80         virtual void image(const Graphics::Image &, unsigned = 0);
81         using Texture::image;
82
83         unsigned get_size() const { return size; }
84 private:
85         unsigned get_n_levels() const;
86         unsigned get_level_size(unsigned) const;
87
88 public:
89         /** Returns a vector pointing out of the face. */
90         static const Vector3 &get_face_direction(TextureCubeFace);
91
92         /** Returns a vector in the direction of the s axis of the face. */
93         static const Vector3 &get_s_direction(TextureCubeFace);
94
95         /** Returns a vector in the direction of the t axis of the face. */
96         static const Vector3 &get_t_direction(TextureCubeFace);
97
98         /** Returns a vector pointing to the center a texel. */
99         Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned);
100
101         virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
102         virtual std::uint64_t get_data_size() const;
103         virtual void unload() { }
104 };
105
106 void operator>>(const LexicalConverter &, TextureCubeFace &);
107
108 } // namespace GL
109 } // namespace Msp
110
111 #endif