]> git.tdb.fi Git - libs/gl.git/blob - source/texture2d.h
Drop Id tags and copyright notices from files
[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/gbase/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 class.  This is the most common type of texture.
15 */
16 class Texture2D: public Texture
17 {
18 public:
19         class Loader: public Texture::Loader
20         {
21         public:
22                 Loader(Texture2D &);
23         private:
24                 void image_data(const std::string &);
25                 void raw_data(const std::string &);
26                 void storage(PixelFormat, unsigned, unsigned);
27                 void storage_b(PixelFormat, unsigned, unsigned, unsigned);
28         };
29
30 private:
31         PixelFormat ifmt;
32         unsigned width;
33         unsigned height;
34         unsigned allocated;
35
36 public:
37         Texture2D();
38
39         /**
40         Defines the texture storage.  This function may only be successfully called
41         once.
42         */
43         void storage(PixelFormat fmt, unsigned wd, unsigned ht);
44
45         /** Allocates texture storage.  If storage has already been allocated, this
46         function does nothing. */
47         void allocate(unsigned level);
48         
49         /** Uploads an image to the texture.  storage() must have been called prior to
50         this, and the image must have dimensions conforming to the specified
51         storage.  For level>0, mipmapping rules apply to the image dimensions. */
52         void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
53
54         /**
55         Uploads a sub-image into the texture.  Unlike full image upload, there are
56         no constraints on the size of the sub-image.
57         */
58         void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data);
59
60         /**
61         Loads an image from a file and uploads it to the texture.  If storage() has
62         not been called, the storage format will be set to match the loaded image.
63         */
64         void load_image(const std::string &fn);
65
66         unsigned get_width() const  { return width; }
67         unsigned get_height() const { return height; }
68
69 private:
70         void image(const Graphics::Image &);
71         void require_storage();
72         void get_level_size(unsigned, unsigned &, unsigned &);
73 };
74
75 } // namespace GL
76 } // namespace Msp
77
78 #endif