]> git.tdb.fi Git - libs/gl.git/blob - source/texturecube.h
Add support for cube map textures
[libs/gl.git] / source / texturecube.h
1 #ifndef MSP_GL_TEXTURECUBE_H_
2 #define MSP_GL_TEXTURECUBE_H_
3
4 #include "datatype.h"
5 #include "pixelformat.h"
6 #include "texture.h"
7
8 namespace Msp {
9 namespace GL {
10
11 enum TextureCubeFace
12 {
13         POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X,
14         NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
15         POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
16         NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
17         POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
18         NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
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.  The face is first selected according to the largest coordinate,
25 and the remaining two coordinates are used to sample the face image.
26
27 All faces of a cube map texture must be allocated for it to be usable.
28
29 Requires OpenGL version 1.3.
30 */
31 class TextureCube: public Texture
32 {
33 private:
34         PixelFormat ifmt;
35         unsigned size;
36         unsigned allocated;
37
38 public:
39         TextureCube();
40
41         /** Defines storage structure for the texture.  Must be called before an
42         image can be uploaded.  Once storage is defined, it can't be changed. */
43         void storage(PixelFormat fmt, unsigned size);
44
45         /** Allocates storage for the cube faces.  The contents are initially
46         undefined.  If storage has already been allocated, does nothing. */
47         void allocate(unsigned level);
48
49         /** Uploads image data to a face.  Storage must be defined beforehand.  The
50         image data must have dimensions and format compatible with the defined
51         storage. */
52         void image(TextureCubeFace face, unsigned level,
53                 PixelFormat fmt, DataType type, const void *data);
54
55         /** Updates a rectangular region of a face.  Storage must be defined and
56         allocated beforehand.  The update region must be fully inside the texture.
57         The data format must be compatible with the defined storage. */
58         void sub_image(TextureCubeFace face, unsigned level,
59                 int x, int y, unsigned w, unsigned h,
60                 PixelFormat fmt, DataType type, const void *data);
61
62         unsigned get_size() const { return size; }
63 private:
64         unsigned get_level_size(unsigned);
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif