]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture2d.h
Fix reflection of image types from Spir-V modules
[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         Texture2D() = default;
38         Texture2D(Texture2D &&) = default;
39         virtual ~Texture2D();
40
41         /** Sets storage format and dimensions and allocates memory for the texture.
42         If lv is zero, a complete mipmap pyramid is automatically created.  Storage
43         cannot be changed once set. */
44         void storage(PixelFormat, unsigned wd, unsigned ht, unsigned lv = 0);
45
46         void image(unsigned level, const void *) override;
47
48         /** Replaces a rectangular region of the texture.  Allocated storage must
49         exist.  The image data is interpreted according to the storage format and
50         the region must be fully inside the selected mipmap level. */
51         void sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *);
52
53         virtual void image(const Graphics::Image &, unsigned = 0);
54
55         unsigned get_width() const { return width; }
56         unsigned get_height() const { return height; }
57
58 private:
59         unsigned get_n_levels() const;
60         LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
61 };
62
63 } // namespace GL
64 } // namespace Msp
65
66 #endif