]> git.tdb.fi Git - libs/gl.git/blob - source/texture2d.h
Remove the obsolete storage statement with border
[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 "resource.h"
7 #include "texture.h"
8
9 namespace Msp {
10 namespace GL {
11
12 /**
13 Two-dimensional texture.  Consists of an array of texels in the shape of a
14 rectangle.  Texture coordinate have a range of [0, 1].  Coordinates outside of
15 this range are subject to wrapping.  This is the most common type of texture.
16 */
17 class Texture2D: public Texture
18 {
19 public:
20         class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
21         {
22         public:
23                 Loader(Texture2D &);
24                 Loader(Texture2D &, Collection &);
25         private:
26                 void init();
27
28                 void raw_data(const std::string &);
29                 void storage(PixelFormat, unsigned, unsigned);
30         };
31
32 private:
33         class AsyncLoader;
34
35         PixelFormat ifmt;
36         unsigned width;
37         unsigned height;
38         unsigned allocated;
39
40 public:
41         Texture2D(ResourceManager * = 0);
42         virtual ~Texture2D();
43
44         /** Defines storage structure for the texture.  Must be called before an
45         image can be uploaded.  Once storage is defined, it can't be changed. */
46         void storage(PixelFormat fmt, unsigned wd, unsigned ht);
47
48         /** Allocates storage for the texture.  The contents are initially
49         undefined.  If storage has already been allocated, does nothing. */
50         void allocate(unsigned level);
51
52         /** Uploads an image to the texture.  Storage must be defined beforehand.
53         The image data must have dimensions and format compatible with the defined
54         storage. */
55         void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
56
57         /** Updates a rectangular region of the texture.  Storage must be defined
58         and allocated beforehand.  The update region must be fully inside the
59         texture. */
60         void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
61                 PixelFormat fmt, DataType type, const void *data);
62
63         /** Uploads an image to the texture.  If storage has not been defined, it
64         will be set to match the image.  Otherwise the image must be compatible with
65         the defined storage.
66
67         If srgb is true and storage is determined by this call, then an sRGB pixel
68         format will be used. */
69         virtual void image(const Graphics::Image &, bool srgb = false);
70
71 private:
72         void image(const Graphics::Image &, bool, bool);
73
74 public:
75         unsigned get_width() const { return width; }
76         unsigned get_height() const { return height; }
77
78 private:
79         void get_level_size(unsigned, unsigned &, unsigned &);
80
81 public:
82         virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
83         virtual UInt64 get_data_size() const;
84         virtual void unload();
85 };
86
87 } // namespace GL
88 } // namespace Msp
89
90 #endif