]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture2d.h
Remove support for array size specialization from the engine as well
[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/linal/vector.h>
6 #include "texture2d_backend.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Two-dimensional texture, consisting of a rectangular array of texels.
13 */
14 class Texture2D: public Texture2DBackend
15 {
16         friend Texture2DBackend;
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 storage(PixelFormat, unsigned, unsigned);
28                 void storage_levels(PixelFormat, unsigned, unsigned, unsigned);
29         };
30
31 private:
32         unsigned width = 0;
33         unsigned height = 0;
34         unsigned levels = 0;
35
36 public:
37         virtual ~Texture2D();
38
39         /** Sets storage format and dimensions and allocates memory for the texture.
40         If lv is zero, a complete mipmap pyramid is automatically created.  Storage
41         cannot be changed once set. */
42         void storage(PixelFormat, unsigned wd, unsigned ht, unsigned lv = 0);
43
44         void image(unsigned level, const void *) override;
45
46         /** Replaces a rectangular region of the texture.  Allocated storage must
47         exist.  The image data is interpreted according to the storage format and
48         the region must be fully inside the selected mipmap level. */
49         void sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *);
50
51         virtual void image(const Graphics::Image &, unsigned = 0);
52
53         unsigned get_width() const { return width; }
54         unsigned get_height() const { return height; }
55
56 private:
57         unsigned get_n_levels() const;
58         LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
59
60 public:
61         virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
62         virtual std::size_t get_data_size() const;
63         using Texture2DBackend::unload;
64 };
65
66 } // namespace GL
67 } // namespace Msp
68
69 #endif