1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
5 #include <msp/graphics/image.h>
7 #include "pixelformat.h"
15 Two-dimensional texture. Consists of an array of texels in the shape of a
16 rectangle. Texture coordinate have a range of [0, 1]. Coordinates outside of
17 this range are subject to wrapping. This is the most common type of texture.
19 class Texture2D: public Texture
22 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
26 Loader(Texture2D &, Collection &);
30 void image_data(const std::string &);
31 void raw_data(const std::string &);
32 void storage(PixelFormat, unsigned, unsigned);
33 void storage_b(PixelFormat, unsigned, unsigned, unsigned);
45 Texture2D(ResourceManager * = 0);
47 /** Defines storage structure for the texture. Must be called before an
48 image can be uploaded. Once storage is defined, it can't be changed. */
49 void storage(PixelFormat fmt, unsigned wd, unsigned ht);
51 /** Allocates storage for the texture. The contents are initially
52 undefined. If storage has already been allocated, does nothing. */
53 void allocate(unsigned level);
55 /** Uploads an image to the texture. Storage must be defined beforehand.
56 The image data must have dimensions and format compatible with the defined
58 void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
60 /** Updates a rectangular region of the texture. Storage must be defined
61 and allocated beforehand. The update region must be fully inside the
63 void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
64 PixelFormat fmt, DataType type, const void *data);
66 /// Loads a Graphics::Image from a file and uploads it to the texture.
67 void load_image(const std::string &fn, bool srgb = false);
69 /** Uploads an image to the texture. If storage has not been defined, it
70 will be set to match the image. Otherwise the image must be compatible with
73 If srgb is true and storage is determined by this call, then an sRGB pixel
74 format will be used. */
75 void image(const Graphics::Image &, bool srgb = false);
78 void image(const Graphics::Image &, bool, bool);
81 unsigned get_width() const { return width; }
82 unsigned get_height() const { return height; }
85 void get_level_size(unsigned, unsigned &, unsigned &);
88 virtual Resource::AsyncLoader *load(IO::Seekable &);
89 virtual UInt64 get_data_size() const;
90 virtual void unload();