]> git.tdb.fi Git - libs/gl.git/blob - source/texture2d.h
Remove alignment where it doesn't belong
[libs/gl.git] / source / texture2d.h
1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
3
4 #include <string>
5 #include <msp/graphics/image.h>
6 #include "datatype.h"
7 #include "pixelformat.h"
8 #include "texture.h"
9
10 namespace Msp {
11 namespace GL {
12
13 /**
14 Two-dimensional texture.  Consists of an array of texels in the shape of a
15 rectangle.  Texture coordinate have a principal range of [0, 1].  This is the
16 most common type of texture.
17 */
18 class Texture2D: public Texture
19 {
20 public:
21         class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
22         {
23         public:
24                 Loader(Texture2D &);
25         private:
26                 void image_data(const std::string &);
27                 void raw_data(const std::string &);
28                 void storage(PixelFormat, unsigned, unsigned);
29                 void storage_b(PixelFormat, unsigned, unsigned, unsigned);
30         };
31
32 private:
33         PixelFormat ifmt;
34         unsigned width;
35         unsigned height;
36         unsigned allocated;
37
38 public:
39         Texture2D();
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 wd, unsigned ht);
44
45         /** Allocates storage for the texture.  The contents are initially
46         undefined.  If storage has already been allocated, does nothing. */
47         void allocate(unsigned level);
48         
49         /** Uploads an image to the texture.  Storage must be defined beforehand.
50         The image data must have dimensions and format compatible with the defined
51         storage. */
52         void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
53
54         /** Updates a rectangular region of the texture.  Storage must be defined
55         and allocated beforehand.  The update region must be fully inside the
56         texture. */
57         void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
58                 PixelFormat fmt, DataType type, const void *data);
59
60         /** Loads an image from a file and uploads it to the texture.  If storage
61         has not been defined, it will be set to match the loaded image.  Otherwise
62         the image must be compatible with the defined storage. */
63         void load_image(const std::string &fn);
64
65 private:
66         void image(const Graphics::Image &);
67
68 public:
69         unsigned get_width() const { return width; }
70         unsigned get_height() const { return height; }
71
72 private:
73         void get_level_size(unsigned, unsigned &, unsigned &);
74 };
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif