1 #ifndef MSP_GL_SAMPLER_H_
2 #define MSP_GL_SAMPLER_H_
4 #include <msp/datafile/objectloader.h>
17 /// Bilinear filtering
20 /// Mipmapping without filtering
21 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
23 /// Linear filtering between two mipmap levels
24 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
26 /// Bilinear filtering on the closest mipmap level
27 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
29 /// Trilinear filtering between two mipmap levels
30 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
36 /// Tile the texture infinitely
39 /// Extend the texels at the edge of the texture to infinity
40 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
42 /// Sampling outside the texture will return border color
43 CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER,
45 /// Tile the texture, with every other repetition mirrored
46 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
53 Samplers are used to access texture data in shaders. To use a sampler with a
54 texture, bind it to the same texture unit. Each texture has a default sampler
55 which is used if no external sampler is bound.
57 A texture is generally rendered at a size that's either smaller or larger than
58 its native size, so that the texture coordinates do not exactly correspond to
59 the texels of the texture. The kind of filtering used, if any, is determined
60 by the minification and magnification filter parameters. The default is LINEAR
61 for magnification and NEAREST_MIPMAP_LINEAR for minification.
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<Sampler>
76 void border_color(float, float, float, float);
77 void compare(Predicate);
78 void filter(TextureFilter);
79 void mag_filter(TextureFilter);
80 void max_anisotropy(float);
81 void min_filter(TextureFilter);
82 void wrap(TextureWrap);
83 void wrap_r(TextureWrap);
84 void wrap_s(TextureWrap);
85 void wrap_t(TextureWrap);
102 TextureFilter min_filter;
103 TextureFilter mag_filter;
104 float max_anisotropy;
111 mutable int dirty_params;
118 void set_parameter_i(unsigned, int) const;
119 void set_parameter_f(unsigned, float) const;
120 void set_parameter_fv(unsigned, const float *) const;
123 void set_min_filter(TextureFilter);
124 void set_mag_filter(TextureFilter);
126 /** Sets filter for both minification and magnification. If a mipmapping
127 filter is specified, LINEAR is used for magnification. */
128 void set_filter(TextureFilter);
130 TextureFilter get_min_filter() const { return min_filter; }
131 TextureFilter get_mag_filter() const { return mag_filter; }
133 void set_max_anisotropy(float);
134 float get_max_anisotropy() const { return max_anisotropy; }
136 /** Sets the wrapping mode for all coordinates. */
137 void set_wrap(TextureWrap);
139 void set_wrap_s(TextureWrap);
140 void set_wrap_t(TextureWrap);
141 void set_wrap_r(TextureWrap);
143 void set_border_color(const Color &);
144 const Color &get_border_color() const { return border_color; }
146 /** Disables depth comparison. */
147 void disable_compare();
149 /** Enables depth comparison and sets the compare function. Only has an
150 effect when used with a depth texture. When depth comparison is enabled,
151 the third component of the texture coordinate is compared against the texel
152 value, and the result is returned as the texture sample.*/
153 void set_compare(Predicate);
155 bool is_compare_enabled() const { return compare; }
156 Predicate get_compare_function() const { return cmp_func; }
158 void refresh() const { if(dirty_params) update(); }
160 unsigned get_id() const { return id; }
162 void set_debug_name(const std::string &);
166 bool is_mipmapped(TextureFilter);
168 void operator>>(const LexicalConverter &, TextureFilter &);
169 void operator>>(const LexicalConverter &, TextureWrap &);