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>
37 Loader(Texture &, Collection &);
41 unsigned get_levels() const;
43 void external_image(const std::string &);
44 void filter(TextureFilter);
45 void generate_mipmap(bool);
46 void image_data(const std::string &);
47 void mag_filter(TextureFilter);
48 void max_anisotropy(float);
49 void min_filter(TextureFilter);
50 void mipmap_levels(unsigned);
52 void wrap(TextureWrap);
53 void wrap_r(TextureWrap);
54 void wrap_s(TextureWrap);
55 void wrap_t(TextureWrap);
73 FormatSwizzle swizzle;
75 Sampler default_sampler;
77 static int swizzle_orders[];
79 Texture(GLenum, ResourceManager * = 0);
80 Texture(const Texture &);
81 Texture &operator=(const Texture &);
86 void set_internal_format(PixelFormat);
87 PixelComponents get_upload_components(PixelComponents) const;
89 void set_parameter_i(GLenum, int) const;
92 Sampler &get_default_sampler() { return default_sampler; }
93 const Sampler &get_default_sampler() const { return default_sampler; }
95 DEPRECATED void set_min_filter(TextureFilter);
96 DEPRECATED void set_mag_filter(TextureFilter);
98 /** Sets filter for both minification and magnification. Since mipmapping
99 is not applicable to magnification, LINEAR is used instead. */
100 DEPRECATED void set_filter(TextureFilter);
102 DEPRECATED void set_mipmap_levels(unsigned) { }
104 DEPRECATED void set_max_anisotropy(float);
106 /** Sets the wrapping mode for all coordinates. */
107 DEPRECATED void set_wrap(TextureWrap);
109 DEPRECATED void set_wrap_s(TextureWrap);
110 DEPRECATED void set_wrap_t(TextureWrap);
111 DEPRECATED void set_wrap_r(TextureWrap);
113 static bool can_generate_mipmap();
115 void generate_mipmap();
117 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
118 when a texture image is uploaded. */
119 void set_auto_generate_mipmap(bool);
121 /// Deprecated. Use set_auto_generate_mipmap instead.
122 DEPRECATED void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
124 /** Sets depth texture comparison. Has no effect on other formats. When
125 comparison is enabled, the third component of the texture coordinate is
126 compared against the texel value, and the result is returned as the texture
128 DEPRECATED void set_compare_enabled(bool);
130 /** Sets the function to use for depth comparison. */
131 DEPRECATED void set_compare_func(Predicate);
133 /// Loads a Graphics::Image from a file and uploads it to the texture.
134 virtual void load_image(const std::string &, bool srgb = false);
136 virtual void load_image(const std::string &, unsigned, bool srgb = false);
138 /** Uploads an image to the texture. If storage has not been defined, it
139 will be set to match the image. Otherwise the image must be compatible
140 with the defined storage. Semantics depend on the type of texture.
142 If srgb is true and storage is determined by this call, then an sRGB pixel
143 format will be used. */
144 virtual void image(const Graphics::Image &, bool srgb = false);
146 virtual void image(const Graphics::Image &, unsigned, bool srgb = false) = 0;
148 GLenum get_target() const { return target; }
149 unsigned get_id() const { return id; }
151 void bind() const { bind_to(0); }
152 void bind_to(unsigned) const;
154 static const Texture *current(unsigned = 0);
155 static void unbind() { unbind_from(0); }
156 static void unbind_from(unsigned);
158 virtual UInt64 get_data_size() const { return 0; }