1 #ifndef MSP_GL_SAMPLER_H_
2 #define MSP_GL_SAMPLER_H_
4 #include <msp/datafile/objectloader.h>
7 #include "sampler_backend.h"
17 /// Bilinear filtering
20 /// Mipmapping without filtering
21 NEAREST_MIPMAP_NEAREST,
23 /// Linear filtering between two mipmap levels
24 NEAREST_MIPMAP_LINEAR,
26 /// Bilinear filtering on the closest mipmap level
27 LINEAR_MIPMAP_NEAREST,
29 /// Trilinear filtering between two mipmap levels
36 /// Tile the texture infinitely
39 /// Extend the texels at the edge of the texture to infinity
42 /// Sampling outside the texture will return border color
45 /// Tile the texture, with every other repetition mirrored
51 Samplers are used to access texture data in shaders. To use a sampler with a
52 texture, bind it to the same texture unit. Each texture has a default sampler
53 which is used if no external sampler is bound.
55 A texture is generally rendered at a size that's either smaller or larger than
56 its native size, so that the texture coordinates do not exactly correspond to
57 the texels of the texture. The kind of filtering used, if any, is determined
58 by the minification and magnification filter parameters. The default is LINEAR
59 for magnification and NEAREST_MIPMAP_LINEAR for minification.
61 If texture coordinates fall outside of the principal range of the texture,
62 wrapping is applied. The default for all directions is REPEAT.
64 class Sampler: public SamplerBackend
66 friend SamplerBackend;
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);
101 TextureFilter min_filter = NEAREST_MIPMAP_LINEAR;
102 TextureFilter mag_filter = LINEAR;
103 float max_anisotropy = 1.0f;
104 TextureWrap wrap_s = REPEAT;
105 TextureWrap wrap_t = REPEAT;
106 TextureWrap wrap_r = REPEAT;
107 Color border_color = { 0.0f, 0.0f, 0.0f, 0.0f };
108 bool compare = false;
109 Predicate cmp_func = LEQUAL;
110 mutable int dirty_params = 0;
115 void set_min_filter(TextureFilter);
116 void set_mag_filter(TextureFilter);
118 /** Sets filter for both minification and magnification. If a mipmapping
119 filter is specified, LINEAR is used for magnification. */
120 void set_filter(TextureFilter);
122 TextureFilter get_min_filter() const { return min_filter; }
123 TextureFilter get_mag_filter() const { return mag_filter; }
125 void set_max_anisotropy(float);
126 float get_max_anisotropy() const { return max_anisotropy; }
128 /** Sets the wrapping mode for all coordinates. */
129 void set_wrap(TextureWrap);
131 void set_wrap_s(TextureWrap);
132 void set_wrap_t(TextureWrap);
133 void set_wrap_r(TextureWrap);
135 void set_border_color(const Color &);
136 const Color &get_border_color() const { return border_color; }
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 refresh() const { if(dirty_params) update(); }
152 using SamplerBackend::set_debug_name;
156 bool is_mipmapped(TextureFilter);
158 void operator>>(const LexicalConverter &, TextureFilter &);
159 void operator>>(const LexicalConverter &, TextureWrap &);