1 #include <msp/strings/format.h>
11 void Sampler::update() const
13 SamplerBackend::update(dirty_params);
17 void Sampler::set_min_filter(TextureFilter f)
20 dirty_params |= MIN_FILTER;
23 void Sampler::set_mag_filter(TextureFilter f)
26 throw invalid_argument("Sampler::set_mag_filter");
28 dirty_params |= MAG_FILTER;
31 void Sampler::set_filter(TextureFilter f)
34 set_mag_filter(f==NEAREST ? NEAREST : LINEAR);
37 void Sampler::set_max_anisotropy(float a)
40 throw invalid_argument("Sampler::set_max_anisotropy");
41 if(a>Device::get_current().get_info().limits.max_anisotropy)
42 throw out_of_range("Sampler::set_max_anisotropy");
43 bool supported = check_anisotropic(a>1.0f);
46 dirty_params |= MAX_ANISOTROPY;
49 void Sampler::set_wrap_s(TextureWrap w)
52 dirty_params |= WRAP_S;
55 void Sampler::set_wrap_t(TextureWrap w)
58 dirty_params |= WRAP_T;
61 void Sampler::set_wrap_r(TextureWrap w)
64 dirty_params |= WRAP_R;
67 void Sampler::set_wrap(TextureWrap w)
74 void Sampler::set_border_color(const Color &c)
77 dirty_params |= BORDER_COLOR;
80 void Sampler::disable_compare()
83 dirty_params |= COMPARE;
86 void Sampler::set_compare(Predicate f)
90 dirty_params |= COMPARE;
94 Sampler::Loader::Loader(Sampler &s):
95 DataFile::ObjectLoader<Sampler>(s)
97 add("border_color", &Loader::border_color);
98 add("compare", &Loader::compare);
99 add("filter", &Loader::filter);
100 add("mag_filter", &Loader::mag_filter);
101 add("max_anisotropy", &Loader::max_anisotropy);
102 add("min_filter", &Loader::min_filter);
103 add("wrap", &Loader::wrap);
104 add("wrap_r", &Loader::wrap_r);
105 add("wrap_s", &Loader::wrap_s);
106 add("wrap_t", &Loader::wrap_t);
109 void Sampler::Loader::border_color(float r, float g, float b, float a)
111 obj.set_border_color(Color(r, g, b, a));
114 void Sampler::Loader::compare(Predicate c)
119 void Sampler::Loader::filter(TextureFilter f)
124 void Sampler::Loader::mag_filter(TextureFilter f)
126 obj.set_mag_filter(f);
129 void Sampler::Loader::max_anisotropy(float a)
131 obj.set_max_anisotropy(a);
134 void Sampler::Loader::min_filter(TextureFilter f)
136 obj.set_min_filter(f);
139 void Sampler::Loader::wrap(TextureWrap w)
144 void Sampler::Loader::wrap_r(TextureWrap w)
149 void Sampler::Loader::wrap_s(TextureWrap w)
154 void Sampler::Loader::wrap_t(TextureWrap w)
160 bool is_mipmapped(TextureFilter filter)
162 return (filter==NEAREST_MIPMAP_NEAREST || filter==NEAREST_MIPMAP_LINEAR ||
163 filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
166 void operator>>(const LexicalConverter &c, TextureFilter &tf)
168 if(c.get()=="NEAREST")
170 else if(c.get()=="LINEAR")
172 else if(c.get()=="NEAREST_MIPMAP_NEAREST")
173 tf = NEAREST_MIPMAP_NEAREST;
174 else if(c.get()=="NEAREST_MIPMAP_LINEAR")
175 tf = NEAREST_MIPMAP_LINEAR;
176 else if(c.get()=="LINEAR_MIPMAP_NEAREST")
177 tf = LINEAR_MIPMAP_NEAREST;
178 else if(c.get()=="LINEAR_MIPMAP_LINEAR")
179 tf = LINEAR_MIPMAP_LINEAR;
181 throw lexical_error(format("conversion of '%s' to TextureFilter", c.get()));
184 void operator>>(const LexicalConverter &c, TextureWrap &tw)
186 if(c.get()=="REPEAT")
188 else if(c.get()=="CLAMP_TO_EDGE")
190 else if(c.get()=="CLAMP_TO_BORDER")
191 tw = CLAMP_TO_BORDER;
192 else if(c.get()=="MIRRORED_REPEAT")
193 tw = MIRRORED_REPEAT;
195 throw lexical_error(format("conversion of '%s' to TextureWrap", c.get()));