1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
16 /// Bilinear filtering
19 /// Mipmapping without filtering
20 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
22 /// Linear filtering between two mipmap levels
23 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
25 /// Bilinear filtering on the closest mipmap level
26 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
28 /// Trilinear filtering between two mipmap levels
29 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
35 /// Tile the texture infinitely
38 /// Extend the texels at the edge of the texture to infinity
39 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
41 /// Tile the texture, with every other repetition mirrored
42 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
47 Base class for textures. This class only defines operations common for all
48 texture types and is not instantiable. For specifying images for textures, see
49 one of the dimensioned texture classes.
51 A texture is generally rendered at a size that's either smaller or larger than
52 its native size, so that the texture coordinates do not exactly correspond to
53 the texels of the texture. The kind of filtering used, if any, is determined
54 by the minification and magnification filter parameters. The default is LINEAR
55 for magnification and NEAREST_MIPMAP_LINEAR for minification.
57 When a mipmapped filter is in use, the texture consists of a stack of mipmap
58 images. Level 0 is the base image. Each level above 0 has half the size of
59 the previous level, rounded down and clamped to 1. The level with size 1 in
60 all dimensions is the last mipmap level. All levels must be allocated for the
63 If texture coordinates fall outside of the principal range of the texture,
64 wrapping is applied. The default for all directions is REPEAT.
69 class Loader: public DataFile::ObjectLoader<Texture>
74 void filter(TextureFilter);
75 void generate_mipmap(bool);
76 void mag_filter(TextureFilter);
77 void max_anisotropy(float);
78 void min_filter(TextureFilter);
79 void wrap(TextureWrap);
80 void wrap_r(TextureWrap);
81 void wrap_s(TextureWrap);
82 void wrap_t(TextureWrap);
100 TextureFilter min_filter;
101 TextureFilter mag_filter;
102 float max_anisotropy;
109 mutable int dirty_params;
112 Texture(const Texture &);
113 Texture &operator=(const Texture &);
118 void update_parameter(int) const;
120 void set_min_filter(TextureFilter);
121 void set_mag_filter(TextureFilter);
123 /** Sets filter for both minification and magnification. Since mipmapping
124 is not applicable to magnification, LINEAR is used instead. */
125 void set_filter(TextureFilter);
127 void set_max_anisotropy(float);
129 /** Sets the wrapping mode for all coordinates. */
130 void set_wrap(TextureWrap);
132 void set_wrap_s(TextureWrap);
133 void set_wrap_t(TextureWrap);
134 void set_wrap_r(TextureWrap);
136 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
137 when a texture image is uploaded. */
138 void set_generate_mipmap(bool);
140 /** Sets depth texture comparison. Has no effect on other formats. When
141 comparison is enabled, the third component of the texture coordinate is
142 compared against the texel value, and the result is returned as the texture
144 void set_compare_enabled(bool);
146 /** Sets the function to use for depth comparison. */
147 void set_compare_func(Predicate);
149 GLenum get_target() const { return target; }
150 unsigned get_id() const { return id; }
153 void bind_to(unsigned) const;
155 static const Texture *current();
156 static void unbind();
157 static void unbind_from(unsigned);