+ hpass = new SingleBlurPassEffect();
+ hpass->set_int("direction", SingleBlurPassEffect::HORIZONTAL);
+ vpass = new SingleBlurPassEffect();
+ vpass->set_int("direction", SingleBlurPassEffect::VERTICAL);
+
+ update_radius();
+}
+
+void BlurEffect::rewrite_graph(EffectChain *graph, Node *self)
+{
+ Node *hpass_node = graph->add_node(hpass);
+ Node *vpass_node = graph->add_node(vpass);
+ graph->connect_nodes(hpass_node, vpass_node);
+ graph->replace_receiver(self, hpass_node);
+ graph->replace_sender(self, vpass_node);
+ self->disabled = true;
+}
+
+void BlurEffect::update_radius()
+{
+ // We only have 16 taps to work with on each side, and we want that to
+ // reach out to about 2.5*sigma. Bump up the mipmap levels (giving us
+ // box blurs) until we have what we need.
+ //
+ // TODO: Consider the actual width and height (they influence mipmap
+ // sizes subtly).
+ unsigned base_mipmap_level = 0;
+ float adjusted_radius = radius;
+ while (adjusted_radius * 1.5f > NUM_TAPS / 2) {
+ ++base_mipmap_level;
+ adjusted_radius /= 2.0f;
+ }
+
+ bool ok = hpass->set_float("radius", adjusted_radius);
+ ok |= hpass->set_int("width", 1280 / (1 << base_mipmap_level)); // FIXME
+ ok |= hpass->set_int("height", 720 / (1 << base_mipmap_level)); // FIXME
+
+ ok |= vpass->set_float("radius", adjusted_radius);
+ ok |= vpass->set_int("width", 1280 / (1 << base_mipmap_level)); // FIXME
+ ok |= vpass->set_int("height", 720 / (1 << base_mipmap_level)); // FIXME
+
+ assert(ok);
+}
+
+bool BlurEffect::set_float(const std::string &key, float value) {
+ if (key == "radius") {
+ radius = value;
+ update_radius();
+ return true;
+ }
+ return false;
+}
+
+SingleBlurPassEffect::SingleBlurPassEffect()
+ : radius(3.0f),
+ direction(HORIZONTAL),
+ width(1280),
+ height(720)
+{
+ register_float("radius", &radius);
+ register_int("direction", (int *)&direction);
+ register_int("width", &width);
+ register_int("height", &height);