1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/dynamicobjectloader.h>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/graphics/image.h>
7 #include "pixelformat.h"
9 #include "texture_backend.h"
15 Base class for textures. This class only defines operations common for all
16 texture types and is not instantiable. For specifying images for textures,
17 see one of the dimensioned texture classes.
19 A texture can consinst of a stack of images, called a mipmap. The dimensions
20 of each mipmap level are half that of the previous level. The mipmap stack
21 can be used for texture minification; see the Sampler class for details.
23 class Texture: public TextureBackend, public Resource
25 friend TextureBackend;
28 class Loader: public DataFile::CollectionObjectLoader<Texture>
34 Loader(Texture &t): Loader(t, 0) { }
35 Loader(Texture &t, Collection &c): Loader(t, &c) { }
37 Loader(Texture &, Collection *);
39 virtual void finish();
42 void load_external_image(Graphics::Image &, const std::string &);
45 void external_image(const std::string &);
46 void external_image_srgb(const std::string &);
47 void external_image_common(const std::string &);
48 void generate_mipmap(bool);
49 void image_data(const std::string &);
50 void mipmap_levels(unsigned);
54 class GenericLoader: public DataFile::DynamicObjectLoader<Texture>
59 GenericLoader(Collection &c): DynamicObjectLoader<Texture>(&c) { }
62 virtual const TypeRegistry &get_type_registry() const { return get_texture_registry(); }
70 RG_TO_LUMINANCE_ALPHA,
75 PixelFormat storage_fmt;
76 FormatSwizzle swizzle;
82 void set_format(PixelFormat);
85 PixelFormat get_format() const { return format; }
87 using TextureBackend::generate_mipmap;
89 /// Loads a Graphics::Image from a file and uploads it to the texture.
90 virtual void load_image(const std::string &, unsigned = 0);
92 /** Uploads an image to the texture. If storage has not been defined, it
93 will be set to match the image. Otherwise the image must be compatible
94 with the defined storage. Semantics depend on the type of texture. */
95 virtual void image(const Graphics::Image &, unsigned = 0) = 0;
97 virtual std::uint64_t get_data_size() const { return 0; }
99 using TextureBackend::set_debug_name;
102 static GenericLoader::TypeRegistry &get_texture_registry();