1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/core/attributes.h>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/graphics/image.h>
9 #include "pixelformat.h"
10 #include "predicate.h"
18 Base class for textures. This class only defines operations common for all
19 texture types and is not instantiable. For specifying images for textures,
20 see one of the dimensioned texture classes.
22 A texture can consinst of a stack of images, called a mipmap. The dimensions
23 of each mipmap level are half that of the previous level. The mipmap stack
24 can be used for texture minification; see the Sampler class for details.
26 class Texture: public Resource
29 class Loader: public DataFile::CollectionObjectLoader<Texture>
36 Loader(Texture &, Collection &);
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,
63 PixelFormat storage_fmt;
64 FormatSwizzle swizzle;
67 std::string debug_name;
69 static int swizzle_orders[];
71 Texture(GLenum, ResourceManager * = 0);
72 Texture(const Texture &);
73 Texture &operator=(const Texture &);
79 void set_format(PixelFormat);
81 void set_parameter_i(GLenum, int) const;
84 PixelFormat get_format() const { return format; }
86 static bool can_generate_mipmap();
88 void generate_mipmap();
90 void generate_mipmap_();
93 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
94 when a texture image is uploaded. */
95 void set_auto_generate_mipmap(bool);
97 /// Deprecated. Use set_auto_generate_mipmap instead.
98 DEPRECATED void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
100 /// Loads a Graphics::Image from a file and uploads it to the texture.
101 virtual void load_image(const std::string &, unsigned = 0);
103 DEPRECATED void load_image(const std::string &, bool srgb);
105 /** Uploads an image to the texture. If storage has not been defined, it
106 will be set to match the image. Otherwise the image must be compatible
107 with the defined storage. Semantics depend on the type of texture. */
108 virtual void image(const Graphics::Image &, unsigned = 0) = 0;
110 DEPRECATED void image(const Graphics::Image &, bool srgb);
112 GLenum get_target() const { return target; }
113 unsigned get_id() const { return id; }
115 virtual UInt64 get_data_size() const { return 0; }
117 void set_debug_name(const std::string &);