1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
5 #include <msp/graphics/image.h>
6 #include <msp/linal/vector.h>
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.
17 class Texture2D: public Texture
20 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
24 Loader(Texture2D &, Collection &);
28 void raw_data(const std::string &);
29 void storage(PixelFormat, unsigned, unsigned);
30 void storage_levels(PixelFormat, unsigned, unsigned, unsigned);
41 Texture2D(ResourceManager * = 0);
44 /** Defines storage structure for the texture. If lv is zero, the number
45 of mipmap levels is automatically determined from storage dimensions.
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);
51 /** Updates the contents of the entire texture. Storage must be defined
52 beforehand. The image data must have dimensions and format matching the
54 virtual void image(unsigned level, const void *data);
56 /** Updates a rectangular region of the texture. Storage must be defined
57 beforehand. The image data must be in a format mathing the defined storage
58 and the update region must be fully inside the texture. */
59 void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data);
61 /** Updates the contents of the entire texture from an image. If storage
62 has not been defined, it will be set to match the image. Otherwise the
63 image must match the defined storage. */
64 virtual void image(const Graphics::Image &, unsigned lv = 0);
69 void image(const Graphics::Image &, unsigned, bool);
72 unsigned get_width() const { return width; }
73 unsigned get_height() const { return height; }
76 unsigned get_n_levels() const;
77 LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
80 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
81 virtual std::uint64_t get_data_size() const;
82 virtual void unload();