1 #ifndef MSP_GL_TEXTURE2D_H_
2 #define MSP_GL_TEXTURE2D_H_
5 #include <msp/graphics/image.h>
7 #include "pixelformat.h"
14 Two-dimensional texture. Consists of an array of texels in the shape of a
15 rectangle. Texture coordinate have a principal range of [0, 1]. This is the
16 most common type of texture.
18 class Texture2D: public Texture
21 class Loader: public Msp::DataFile::DerivedObjectLoader<Texture2D, Texture::Loader>
26 void image_data(const std::string &);
27 void raw_data(const std::string &);
28 void storage(PixelFormat, unsigned, unsigned);
29 void storage_b(PixelFormat, unsigned, unsigned, unsigned);
41 /** Defines storage structure for the texture. Must be called before an
42 image can be uploaded. Once storage is defined, it can't be changed. */
43 void storage(PixelFormat fmt, unsigned wd, unsigned ht);
45 /** Allocates storage for the texture. The contents are initially
46 undefined. If storage has already been allocated, does nothing. */
47 void allocate(unsigned level);
49 /** Uploads an image to the texture. Storage must be defined beforehand.
50 The image data must have dimensions and format compatible with the defined
52 void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
54 /** Updates a rectangular region of the texture. Storage must be defined
55 and allocated beforehand. The update region must be fully inside the
57 void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
58 PixelFormat fmt, DataType type, const void *data);
60 /** Loads an image from a file and uploads it to the texture. If storage
61 has not been defined, it will be set to match the loaded image. Otherwise
62 the image must be compatible with the defined storage. */
63 void load_image(const std::string &fn);
65 /** Uploads an image to the texture. If storage has not been defined, it
66 will be set to match the image. Otherwise the image must be compatible with
67 the defined storage. */
68 void image(const Graphics::Image &);
70 unsigned get_width() const { return width; }
71 unsigned get_height() const { return height; }
74 void get_level_size(unsigned, unsigned &, unsigned &);