1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
5 #include <msp/graphics/image.h>
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.
16 class Texture2D: public Texture
19 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
23 Loader(Texture2D &, Collection &);
27 void raw_data(const std::string &);
28 void storage(PixelFormat, unsigned, unsigned);
40 Texture2D(ResourceManager * = 0);
43 /** Defines storage structure for the texture. Must be called before an
44 image can be uploaded. Once storage is defined, it can't be changed. */
45 void storage(PixelFormat fmt, unsigned wd, unsigned ht);
47 /** Allocates storage for the texture. The contents are initially
48 undefined. If storage has already been allocated, does nothing. */
49 void allocate(unsigned level);
51 /** Uploads an image to the texture. Storage must be defined beforehand.
52 The image data must have dimensions and format compatible with the defined
54 void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
56 /** Updates a rectangular region of the texture. Storage must be defined
57 and allocated beforehand. The update region must be fully inside the
59 void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
60 PixelFormat fmt, DataType type, const void *data);
62 /** Uploads an image to the texture. If storage has not been defined, it
63 will be set to match the image. Otherwise the image must be compatible with
66 If srgb is true and storage is determined by this call, then an sRGB pixel
67 format will be used. */
68 virtual void image(const Graphics::Image &, bool srgb = false);
71 void image(const Graphics::Image &, bool, bool);
74 unsigned get_width() const { return width; }
75 unsigned get_height() const { return height; }
78 void get_level_size(unsigned, unsigned &, unsigned &);
81 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
82 virtual UInt64 get_data_size() const;
83 virtual void unload();