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