1 #ifndef MSP_GL_SAMPLER_H_
2 #define MSP_GL_SAMPLER_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
49 Samplers are used to access texture data in shaders. To use a sampler with a
50 texture, bind it to the same texture unit. Each texture has a default sampler
51 which is used if no external sampler is bound.
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 If texture coordinates fall outside of the principal range of the texture,
60 wrapping is applied. The default for all directions is REPEAT.
65 class Loader: public DataFile::ObjectLoader<Sampler>
72 void filter(TextureFilter);
73 void mag_filter(TextureFilter);
74 void max_anisotropy(float);
75 void min_filter(TextureFilter);
76 void wrap(TextureWrap);
77 void wrap_r(TextureWrap);
78 void wrap_s(TextureWrap);
79 void wrap_t(TextureWrap);
96 TextureFilter min_filter;
97 TextureFilter mag_filter;
104 mutable int dirty_params;
108 Sampler(const Texture &);
112 void update_parameter(int) const;
113 void set_parameter_i(unsigned, int) const;
114 void set_parameter_f(unsigned, float) const;
117 void set_min_filter(TextureFilter);
118 void set_mag_filter(TextureFilter);
120 /** Sets filter for both minification and magnification. If a mipmapping
121 filter is specified, LINEAR is used for magnification. */
122 void set_filter(TextureFilter);
124 TextureFilter get_min_filter() const { return min_filter; }
125 TextureFilter get_mag_filter() const { return mag_filter; }
127 void set_max_anisotropy(float);
128 float get_max_anisotropy() const { return max_anisotropy; }
130 /** Sets the wrapping mode for all coordinates. */
131 void set_wrap(TextureWrap);
133 void set_wrap_s(TextureWrap);
134 void set_wrap_t(TextureWrap);
135 void set_wrap_r(TextureWrap);
137 /** Disables depth comparison. */
138 void disable_compare();
140 /** Enables depth comparison and sets the compare function. Only has an
141 effect when used with a depth texture. When depth comparison is enabled,
142 the third component of the texture coordinate is compared against the texel
143 value, and the result is returned as the texture sample.*/
144 void set_compare(Predicate);
146 bool is_compare_enabled() const { return compare; }
147 Predicate get_compare_function() const { return cmp_func; }
149 void bind() const { bind_to(0); }
150 void bind_to(unsigned) const;
156 bool is_mipmapped(TextureFilter);
158 void operator>>(const LexicalConverter &, TextureFilter &);
159 void operator>>(const LexicalConverter &, TextureWrap &);