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);
29 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 DEPRECATED void storage(PixelComponents cm, unsigned wd, unsigned ht, unsigned lv = 0)
52 { storage(make_pixelformat(cm, UNSIGNED_BYTE), wd, ht, lv); }
54 /** Allocates storage for the texture. The contents are initially
55 undefined. If storage has already been allocated, does nothing. */
56 void allocate(unsigned level);
58 /** Updates the contents of the entire texture. Storage must be defined
59 beforehand. The image data must have dimensions and format matching the
61 virtual void image(unsigned level, const void *data);
63 DEPRECATED void image(unsigned level, PixelComponents fmt, DataType type, const void *data);
65 /** Updates a rectangular region of the texture. Storage must be defined
66 beforehand. The image data must be in a format mathing the defined storage
67 and the update region must be fully inside the texture. */
68 void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data);
70 DEPRECATED void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
71 PixelComponents fmt, DataType type, const void *data);
73 /** Updates the contents of the entire texture from an image. If storage
74 has not been defined, it will be set to match the image. Otherwise the
75 image must match the defined storage. */
76 virtual void image(const Graphics::Image &, unsigned lv = 0);
81 void image(const Graphics::Image &, unsigned, bool);
84 unsigned get_width() const { return width; }
85 unsigned get_height() const { return height; }
88 unsigned get_n_levels() const;
89 void get_level_size(unsigned, unsigned &, unsigned &) const;
92 virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
93 virtual UInt64 get_data_size() const;
94 virtual void unload();