1 #include <msp/strings/format.h>
10 void Sampler::update() const
12 SamplerBackend::update(dirty_params);
16 void Sampler::set_min_filter(TextureFilter f)
19 dirty_params |= MIN_FILTER;
22 void Sampler::set_mag_filter(TextureFilter f)
25 dirty_params |= MAG_FILTER;
28 void Sampler::set_filter(TextureFilter f)
31 set_mag_filter(f==NEAREST ? NEAREST : LINEAR);
34 void Sampler::set_max_anisotropy(float a)
37 throw invalid_argument("Sampler::set_max_anisotropy");
38 bool supported = check_anisotropic(a>1.0f);
41 dirty_params |= MAX_ANISOTROPY;
44 void Sampler::set_wrap(TextureWrap w)
51 void Sampler::set_wrap_s(TextureWrap w)
54 dirty_params |= WRAP_S;
57 void Sampler::set_wrap_t(TextureWrap w)
60 dirty_params |= WRAP_T;
63 void Sampler::set_wrap_r(TextureWrap w)
66 dirty_params |= WRAP_R;
69 void Sampler::set_border_color(const Color &c)
72 dirty_params |= BORDER_COLOR;
75 void Sampler::disable_compare()
78 dirty_params |= COMPARE;
81 void Sampler::set_compare(Predicate f)
85 dirty_params |= COMPARE;
89 Sampler::Loader::Loader(Sampler &s):
90 DataFile::ObjectLoader<Sampler>(s)
92 add("border_color", &Loader::border_color);
93 add("compare", &Loader::compare);
94 add("filter", &Loader::filter);
95 add("mag_filter", &Loader::mag_filter);
96 add("max_anisotropy", &Loader::max_anisotropy);
97 add("min_filter", &Loader::min_filter);
98 add("wrap", &Loader::wrap);
99 add("wrap_r", &Loader::wrap_r);
100 add("wrap_s", &Loader::wrap_s);
101 add("wrap_t", &Loader::wrap_t);
104 void Sampler::Loader::border_color(float r, float g, float b, float a)
106 obj.set_border_color(Color(r, g, b, a));
109 void Sampler::Loader::compare(Predicate c)
114 void Sampler::Loader::filter(TextureFilter f)
119 void Sampler::Loader::mag_filter(TextureFilter f)
121 obj.set_mag_filter(f);
124 void Sampler::Loader::max_anisotropy(float a)
126 obj.set_max_anisotropy(a);
129 void Sampler::Loader::min_filter(TextureFilter f)
131 obj.set_min_filter(f);
134 void Sampler::Loader::wrap(TextureWrap w)
139 void Sampler::Loader::wrap_r(TextureWrap w)
144 void Sampler::Loader::wrap_s(TextureWrap w)
149 void Sampler::Loader::wrap_t(TextureWrap w)
155 bool is_mipmapped(TextureFilter filter)
157 return (filter==NEAREST_MIPMAP_NEAREST || filter==NEAREST_MIPMAP_LINEAR ||
158 filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
161 void operator>>(const LexicalConverter &c, TextureFilter &tf)
163 if(c.get()=="NEAREST")
165 else if(c.get()=="LINEAR")
167 else if(c.get()=="NEAREST_MIPMAP_NEAREST")
168 tf = NEAREST_MIPMAP_NEAREST;
169 else if(c.get()=="NEAREST_MIPMAP_LINEAR")
170 tf = NEAREST_MIPMAP_LINEAR;
171 else if(c.get()=="LINEAR_MIPMAP_NEAREST")
172 tf = LINEAR_MIPMAP_NEAREST;
173 else if(c.get()=="LINEAR_MIPMAP_LINEAR")
174 tf = LINEAR_MIPMAP_LINEAR;
176 throw lexical_error(format("conversion of '%s' to TextureFilter", c.get()));
179 void operator>>(const LexicalConverter &c, TextureWrap &tw)
181 if(c.get()=="REPEAT")
183 else if(c.get()=="CLAMP_TO_EDGE")
185 else if(c.get()=="CLAMP_TO_BORDER")
186 tw = CLAMP_TO_BORDER;
187 else if(c.get()=="MIRRORED_REPEAT")
188 tw = MIRRORED_REPEAT;
190 throw lexical_error(format("conversion of '%s' to TextureWrap", c.get()));