1 #include <msp/strings/format.h>
11 min_filter(NEAREST_MIPMAP_LINEAR),
17 border_color(Color(0.0f, 0.0f, 0.0f, 0.0f)),
23 void Sampler::update() const
25 SamplerBackend::update(dirty_params);
29 void Sampler::set_min_filter(TextureFilter f)
32 dirty_params |= MIN_FILTER;
35 void Sampler::set_mag_filter(TextureFilter f)
38 dirty_params |= MAG_FILTER;
41 void Sampler::set_filter(TextureFilter f)
44 set_mag_filter(f==NEAREST ? NEAREST : LINEAR);
47 void Sampler::set_max_anisotropy(float a)
50 throw invalid_argument("Sampler::set_max_anisotropy");
51 bool supported = check_anisotropic(a>1.0f);
54 dirty_params |= MAX_ANISOTROPY;
57 void Sampler::set_wrap(TextureWrap w)
64 void Sampler::set_wrap_s(TextureWrap w)
67 dirty_params |= WRAP_S;
70 void Sampler::set_wrap_t(TextureWrap w)
73 dirty_params |= WRAP_T;
76 void Sampler::set_wrap_r(TextureWrap w)
79 dirty_params |= WRAP_R;
82 void Sampler::set_border_color(const Color &c)
85 dirty_params |= BORDER_COLOR;
88 void Sampler::disable_compare()
91 dirty_params |= COMPARE;
94 void Sampler::set_compare(Predicate f)
98 dirty_params |= COMPARE;
102 Sampler::Loader::Loader(Sampler &s):
103 DataFile::ObjectLoader<Sampler>(s)
105 add("border_color", &Loader::border_color);
106 add("compare", &Loader::compare);
107 add("filter", &Loader::filter);
108 add("mag_filter", &Loader::mag_filter);
109 add("max_anisotropy", &Loader::max_anisotropy);
110 add("min_filter", &Loader::min_filter);
111 add("wrap", &Loader::wrap);
112 add("wrap_r", &Loader::wrap_r);
113 add("wrap_s", &Loader::wrap_s);
114 add("wrap_t", &Loader::wrap_t);
117 void Sampler::Loader::border_color(float r, float g, float b, float a)
119 obj.set_border_color(Color(r, g, b, a));
122 void Sampler::Loader::compare(Predicate c)
127 void Sampler::Loader::filter(TextureFilter f)
132 void Sampler::Loader::mag_filter(TextureFilter f)
134 obj.set_mag_filter(f);
137 void Sampler::Loader::max_anisotropy(float a)
139 obj.set_max_anisotropy(a);
142 void Sampler::Loader::min_filter(TextureFilter f)
144 obj.set_min_filter(f);
147 void Sampler::Loader::wrap(TextureWrap w)
152 void Sampler::Loader::wrap_r(TextureWrap w)
157 void Sampler::Loader::wrap_s(TextureWrap w)
162 void Sampler::Loader::wrap_t(TextureWrap w)
168 bool is_mipmapped(TextureFilter filter)
170 return (filter==NEAREST_MIPMAP_NEAREST || filter==NEAREST_MIPMAP_LINEAR ||
171 filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
174 void operator>>(const LexicalConverter &c, TextureFilter &tf)
176 if(c.get()=="NEAREST")
178 else if(c.get()=="LINEAR")
180 else if(c.get()=="NEAREST_MIPMAP_NEAREST")
181 tf = NEAREST_MIPMAP_NEAREST;
182 else if(c.get()=="NEAREST_MIPMAP_LINEAR")
183 tf = NEAREST_MIPMAP_LINEAR;
184 else if(c.get()=="LINEAR_MIPMAP_NEAREST")
185 tf = LINEAR_MIPMAP_NEAREST;
186 else if(c.get()=="LINEAR_MIPMAP_LINEAR")
187 tf = LINEAR_MIPMAP_LINEAR;
189 throw lexical_error(format("conversion of '%s' to TextureFilter", c.get()));
192 void operator>>(const LexicalConverter &c, TextureWrap &tw)
194 if(c.get()=="REPEAT")
196 else if(c.get()=="CLAMP_TO_EDGE")
198 else if(c.get()=="CLAMP_TO_BORDER")
199 tw = CLAMP_TO_BORDER;
200 else if(c.get()=="MIRRORED_REPEAT")
201 tw = MIRRORED_REPEAT;
203 throw lexical_error(format("conversion of '%s' to TextureWrap", c.get()));