1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
18 /// Bilinear filtering
21 /// Mipmapping without filtering
22 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
24 /// Linear filtering between two mipmap levels
25 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
27 /// Bilinear filtering on the closest mipmap level
28 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
30 /// Trilinear filtering between two mipmap levels
31 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
37 /// Tile the texture infinitely
40 /// Extend the texels at the edge of the texture to infinity
41 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
43 /// Tile the texture, with every other repetition mirrored
44 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
49 Base class for textures. This class only defines operations common for all
50 texture types and is not instantiable. For specifying images for textures, see
51 one of the dimensioned texture classes.
53 A texture is generally rendered at a size that's either smaller or larger than
54 its native size, so that the texture coordinates do not exactly correspond to
55 the texels of the texture. The kind of filtering used, if any, is determined
56 by the minification and magnification filter parameters. The default is LINEAR
57 for magnification and NEAREST_MIPMAP_LINEAR for minification.
59 When a mipmapped filter is in use, the texture consists of a stack of mipmap
60 images. Level 0 is the base image. Each level above 0 has half the size of
61 the previous level, rounded down and clamped to 1. The level with size 1 in
62 all dimensions is the last mipmap level. All levels must be allocated for the
65 If texture coordinates fall outside of the principal range of the texture,
66 wrapping is applied. The default for all directions is REPEAT.
71 class Loader: public DataFile::CollectionObjectLoader<Texture>
78 Loader(Texture &, Collection &);
82 void filter(TextureFilter);
83 void generate_mipmap(bool);
84 void mag_filter(TextureFilter);
85 void max_anisotropy(float);
86 void min_filter(TextureFilter);
87 void wrap(TextureWrap);
88 void wrap_r(TextureWrap);
89 void wrap_s(TextureWrap);
90 void wrap_t(TextureWrap);
100 GENERATE_MIPMAP = 32,
108 TextureFilter min_filter;
109 TextureFilter mag_filter;
110 float max_anisotropy;
117 mutable int dirty_params;
120 Texture(const Texture &);
121 Texture &operator=(const Texture &);
126 void update_parameter(int) const;
128 void set_min_filter(TextureFilter);
129 void set_mag_filter(TextureFilter);
131 /** Sets filter for both minification and magnification. Since mipmapping
132 is not applicable to magnification, LINEAR is used instead. */
133 void set_filter(TextureFilter);
135 void set_max_anisotropy(float);
137 /** Sets the wrapping mode for all coordinates. */
138 void set_wrap(TextureWrap);
140 void set_wrap_s(TextureWrap);
141 void set_wrap_t(TextureWrap);
142 void set_wrap_r(TextureWrap);
144 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
145 when a texture image is uploaded. */
146 void set_generate_mipmap(bool);
148 /** Sets depth texture comparison. Has no effect on other formats. When
149 comparison is enabled, the third component of the texture coordinate is
150 compared against the texel value, and the result is returned as the texture
152 void set_compare_enabled(bool);
154 /** Sets the function to use for depth comparison. */
155 void set_compare_func(Predicate);
157 GLenum get_target() const { return target; }
158 unsigned get_id() const { return id; }
160 void bind() const { bind_to(0); }
161 void bind_to(unsigned) const;
163 static const Texture *current(unsigned = 0);
164 static void unbind() { unbind_from(0); }
165 static void unbind_from(unsigned);