1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
5 #include <msp/graphics/image.h>
6 #include "pixelformat.h"
8 #include "texture_backend.h"
14 Base class for textures. This class only defines operations common for all
15 texture types and is not instantiable. For specifying images for textures,
16 see one of the dimensioned texture classes.
18 A texture can consinst of a stack of images, called a mipmap. The dimensions
19 of each mipmap level are half that of the previous level. The mipmap stack
20 can be used for texture minification; see the Sampler class for details.
22 class Texture: public TextureBackend, public Resource
24 friend TextureBackend;
27 class Loader: public DataFile::CollectionObjectLoader<Texture>
33 Loader(Texture &t): Loader(t, 0) { }
34 Loader(Texture &t, Collection &c): Loader(t, &c) { }
36 Loader(Texture &, Collection *);
38 virtual void finish();
41 void load_external_image(Graphics::Image &, const std::string &);
44 void external_image(const std::string &);
45 void external_image_srgb(const std::string &);
46 void external_image_common(const std::string &);
47 void generate_mipmap(bool);
48 void image_data(const std::string &);
49 void mipmap_levels(unsigned);
56 RG_TO_LUMINANCE_ALPHA,
61 PixelFormat storage_fmt;
62 FormatSwizzle swizzle;
66 Texture(unsigned, ResourceManager * = 0);
68 void set_format(PixelFormat);
71 PixelFormat get_format() const { return format; }
73 using TextureBackend::generate_mipmap;
75 /// Loads a Graphics::Image from a file and uploads it to the texture.
76 virtual void load_image(const std::string &, unsigned = 0);
78 /** Uploads an image to the texture. If storage has not been defined, it
79 will be set to match the image. Otherwise the image must be compatible
80 with the defined storage. Semantics depend on the type of texture. */
81 virtual void image(const Graphics::Image &, unsigned = 0) = 0;
83 virtual std::uint64_t get_data_size() const { return 0; }
85 using TextureBackend::set_debug_name;