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);
53 static const Vector3 directions[6];
54 static const unsigned orientations[12];
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);
62 virtual void image(unsigned, const void *);
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 *);
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 *);
74 void image(TextureCubeFace, const Graphics::Image &);
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);
82 unsigned get_size() const { return size; }
84 unsigned get_level_size(unsigned) const;
87 /** Returns a vector pointing out of the face. */
88 static const Vector3 &get_face_direction(TextureCubeFace);
90 /** Returns a vector in the direction of the s axis of the face. */
91 static const Vector3 &get_s_direction(TextureCubeFace);
93 /** Returns a vector in the direction of the t axis of the face. */
94 static const Vector3 &get_t_direction(TextureCubeFace);
96 /** Returns a vector pointing to the center of a texel. */
97 Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned);
100 void operator>>(const LexicalConverter &, TextureCubeFace &);