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 compare(Predicate);
73 void filter(TextureFilter);
74 void mag_filter(TextureFilter);
75 void max_anisotropy(float);
76 void min_filter(TextureFilter);
77 void wrap(TextureWrap);
78 void wrap_r(TextureWrap);
79 void wrap_s(TextureWrap);
80 void wrap_t(TextureWrap);
97 TextureFilter min_filter;
98 TextureFilter mag_filter;
105 mutable int dirty_params;
109 Sampler(const Texture &);
113 void update_parameter(int) const;
114 void set_parameter_i(unsigned, int) const;
115 void set_parameter_f(unsigned, float) const;
118 void set_min_filter(TextureFilter);
119 void set_mag_filter(TextureFilter);
121 /** Sets filter for both minification and magnification. If a mipmapping
122 filter is specified, LINEAR is used for magnification. */
123 void set_filter(TextureFilter);
125 TextureFilter get_min_filter() const { return min_filter; }
126 TextureFilter get_mag_filter() const { return mag_filter; }
128 void set_max_anisotropy(float);
129 float get_max_anisotropy() const { return max_anisotropy; }
131 /** Sets the wrapping mode for all coordinates. */
132 void set_wrap(TextureWrap);
134 void set_wrap_s(TextureWrap);
135 void set_wrap_t(TextureWrap);
136 void set_wrap_r(TextureWrap);
138 /** Disables depth comparison. */
139 void disable_compare();
141 /** Enables depth comparison and sets the compare function. Only has an
142 effect when used with a depth texture. When depth comparison is enabled,
143 the third component of the texture coordinate is compared against the texel
144 value, and the result is returned as the texture sample.*/
145 void set_compare(Predicate);
147 bool is_compare_enabled() const { return compare; }
148 Predicate get_compare_function() const { return cmp_func; }
150 void bind() const { bind_to(0); }
151 void bind_to(unsigned) const;
153 static const Sampler *current(unsigned = 0);
154 static void unbind() { unbind_from(0); }
155 static void unbind_from(unsigned);
161 bool is_mipmapped(TextureFilter);
163 void operator>>(const LexicalConverter &, TextureFilter &);
164 void operator>>(const LexicalConverter &, TextureWrap &);