1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
5 #include <msp/linal/vector.h>
6 #include "texture2d_backend.h"
12 Two-dimensional texture, consisting of a rectangular array of texels.
14 class Texture2D: public Texture2DBackend
16 friend Texture2DBackend;
19 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
23 Loader(Texture2D &, Collection &);
27 void storage(PixelFormat, unsigned, unsigned);
28 void storage_levels(PixelFormat, unsigned, unsigned, unsigned);
32 An RAII handle for asynchronously writing texel data into a texture.
34 class AsyncTransfer: public Texture2DBackend::AsyncTransfer
36 friend Texture2DBackend;
37 friend class Texture2D;
38 friend class Texture2DBackend::AsyncTransfer;
41 Texture2D *texture = 0;
47 std::size_t data_size = 0;
50 AsyncTransfer(Texture2D &, unsigned, unsigned, unsigned, unsigned, unsigned);
52 AsyncTransfer() = default;
53 AsyncTransfer(AsyncTransfer &&);
54 AsyncTransfer &operator=(AsyncTransfer &&);
58 /** Returns an address for writing the texel data. It should not be used
59 beyond the lifetime of the object. */
60 void *get_address() { return dest_addr; }
70 Texture2D() = default;
71 Texture2D(Texture2D &&) = default;
74 /** Sets storage format and dimensions and allocates memory for the texture.
75 If lv is zero, a complete mipmap pyramid is automatically created. Storage
76 cannot be changed once set. */
77 void storage(PixelFormat, unsigned wd, unsigned ht, unsigned lv = 0);
79 void image(unsigned level, const void *) override;
81 /** Replaces a rectangular region of the texture. Allocated storage must
82 exist. The image data is interpreted according to the storage format and
83 the region must be fully inside the selected mipmap level. */
84 void sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht, const void *);
86 AsyncTransfer sub_image_async(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht);
88 virtual void image(const Graphics::Image &, unsigned = 0);
90 unsigned get_width() const { return width; }
91 unsigned get_height() const { return height; }
94 unsigned get_n_levels() const;
95 LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
98 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);