1 #ifndef MSP_GL_TEXTURECUBE_H_
2 #define MSP_GL_TEXTURECUBE_H_
4 #include <msp/graphics/image.h>
5 #include "texturecube_backend.h"
22 Cube map texture, consisting of six square faces.
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
30 class TextureCube: public TextureCubeBackend
32 friend TextureCubeBackend;
35 class Loader: public Msp::DataFile::DerivedObjectLoader<TextureCube, Texture::Loader>
38 Loader(TextureCube &);
39 Loader(TextureCube &, Collection &);
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);
54 static const Vector3 directions[6];
55 static const unsigned orientations[12];
58 /** Sets storage format and dimensions and allocates memory for the texture.
59 If lv is zero, a complete mipmap pyramid is automatically created. Storage
60 cannot be changed once set. */
61 void storage(PixelFormat, unsigned size, unsigned lv = 0);
63 virtual void image(unsigned, const void *);
65 /** Replaces contents of a single face. Allocated storage must exist. The
66 image data is interpreted according to the storage format and must have size
67 matching the selected mipmap level. */
68 void image(TextureCubeFace, unsigned level, const void *);
70 /** Replaces a rectangular region of a face. Allocated storage must exist.
71 The image data is interpreted according to the storage format and the region
72 must be fully inside the face. */
73 void sub_image(TextureCubeFace, unsigned level, unsigned x, unsigned y, unsigned w, unsigned h, const void *);
75 void image(TextureCubeFace, const Graphics::Image &);
77 /** Sets the texture's contents from an image. The image is treated as a
78 stack of square layers and its height must be six times its width. If
79 storage has not been allocated yet, it will be set to match the image.
80 Otherwise the image must be compatible with the existing storage. */
81 virtual void image(const Graphics::Image &, unsigned = 0);
83 unsigned get_size() const { return size; }
85 unsigned get_n_levels() const;
86 unsigned get_level_size(unsigned) const;
89 /** Returns a vector pointing out of the face. */
90 static const Vector3 &get_face_direction(TextureCubeFace);
92 /** Returns a vector in the direction of the s axis of the face. */
93 static const Vector3 &get_s_direction(TextureCubeFace);
95 /** Returns a vector in the direction of the t axis of the face. */
96 static const Vector3 &get_t_direction(TextureCubeFace);
98 /** Returns a vector pointing to the center of a texel. */
99 Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned);
101 virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
102 virtual std::size_t get_data_size() const;
103 virtual void unload() { }
106 void operator>>(const LexicalConverter &, TextureCubeFace &);