1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
5 #include <msp/graphics/image.h>
7 #include "pixelformat.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 Resource
25 class Loader: public DataFile::CollectionObjectLoader<Texture>
32 Loader(Texture &, Collection &);
36 virtual void finish();
39 void load_external_image(Graphics::Image &, const std::string &);
42 void external_image(const std::string &);
43 void external_image_srgb(const std::string &);
44 void external_image_common(const std::string &);
45 void generate_mipmap(bool);
46 void image_data(const std::string &);
47 void mipmap_levels(unsigned);
54 RG_TO_LUMINANCE_ALPHA,
61 PixelFormat storage_fmt;
62 FormatSwizzle swizzle;
65 std::string debug_name;
67 static const int swizzle_orders[];
68 static Texture *scratch_binding;
70 Texture(GLenum, ResourceManager * = 0);
71 Texture(const Texture &);
72 Texture &operator=(const Texture &);
78 void set_format(PixelFormat);
80 void set_parameter_i(GLenum, int) const;
83 PixelFormat get_format() const { return format; }
85 void generate_mipmap();
87 /// Loads a Graphics::Image from a file and uploads it to the texture.
88 virtual void load_image(const std::string &, unsigned = 0);
90 /** Uploads an image to the texture. If storage has not been defined, it
91 will be set to match the image. Otherwise the image must be compatible
92 with the defined storage. Semantics depend on the type of texture. */
93 virtual void image(const Graphics::Image &, unsigned = 0) = 0;
95 GLenum get_target() const { return target; }
96 unsigned get_id() const { return id; }
98 virtual std::uint64_t get_data_size() const { return 0; }
100 void set_debug_name(const std::string &);
105 static void unbind_scratch();