{
// The first blur pass will forward resolution information to us.
hpass = new SingleBlurPassEffect(this);
- hpass->set_int("direction", SingleBlurPassEffect::HORIZONTAL);
+ CHECK(hpass->set_int("direction", SingleBlurPassEffect::HORIZONTAL));
vpass = new SingleBlurPassEffect(NULL);
- vpass->set_int("direction", SingleBlurPassEffect::VERTICAL);
+ CHECK(vpass->set_int("direction", SingleBlurPassEffect::VERTICAL));
update_radius();
}
//vignette_effect->set_float("inner_radius", inner_radius);
//vignette_effect->set_vec2("center", (float[]){ 0.7f, 0.5f });
- diffusion_effect->set_float("radius", blur_radius);
- diffusion_effect->set_float("blurred_mix_amount", blurred_mix_amount);
+ CHECK(diffusion_effect->set_float("radius", blur_radius));
+ CHECK(diffusion_effect->set_float("blurred_mix_amount", blurred_mix_amount));
input->set_pixel_data(src_img);
chain.render_to_screen();
// Set a parameter; intended to be called from user code.
// Neither of these take ownership of the pointer.
- virtual bool set_int(const std::string&, int value);
- virtual bool set_float(const std::string &key, float value);
- virtual bool set_vec2(const std::string &key, const float *values);
- virtual bool set_vec3(const std::string &key, const float *values);
+ virtual bool set_int(const std::string&, int value) MUST_CHECK_RESULT;
+ virtual bool set_float(const std::string &key, float value) MUST_CHECK_RESULT;
+ virtual bool set_vec2(const std::string &key, const float *values) MUST_CHECK_RESULT;
+ virtual bool set_vec3(const std::string &key, const float *values) MUST_CHECK_RESULT;
protected:
// Register a parameter. Whenever set_*() is called with the same key,
for (unsigned i = 0; i < effects.size(); ++i) {
Node *node = effects[i];
if (node->effect->num_inputs() == 0) {
- node->effect->set_int("needs_mipmaps", input_needs_mipmaps);
+ CHECK(node->effect->set_int("needs_mipmaps", input_needs_mipmaps));
}
}
frag_shader += std::string("#define INPUT ") + effects.back()->effect_id + "\n";
continue;
}
Node *conversion = add_node(new ColorspaceConversionEffect());
- conversion->effect->set_int("source_space", input->output_color_space);
- conversion->effect->set_int("destination_space", COLORSPACE_sRGB);
+ CHECK(conversion->effect->set_int("source_space", input->output_color_space));
+ CHECK(conversion->effect->set_int("destination_space", COLORSPACE_sRGB));
conversion->output_color_space = COLORSPACE_sRGB;
insert_node_between(input, conversion, node);
}
Node *output = find_output_node();
if (output->output_color_space != output_format.color_space) {
Node *conversion = add_node(new ColorspaceConversionEffect());
- conversion->effect->set_int("source_space", output->output_color_space);
- conversion->effect->set_int("destination_space", output_format.color_space);
+ CHECK(conversion->effect->set_int("source_space", output->output_color_space));
+ CHECK(conversion->effect->set_int("destination_space", output_format.color_space));
conversion->output_color_space = output_format.color_space;
connect_nodes(output, conversion);
propagate_gamma_and_color_space();
}
for (unsigned i = 0; i < nonlinear_inputs.size(); ++i) {
- nonlinear_inputs[i]->effect->set_int("output_linear_gamma", 1);
+ CHECK(nonlinear_inputs[i]->effect->set_int("output_linear_gamma", 1));
nonlinear_inputs[i]->output_gamma_curve = GAMMA_LINEAR;
}
if (node->incoming_links.empty()) {
assert(node->outgoing_links.empty());
Node *conversion = add_node(new GammaExpansionEffect());
- conversion->effect->set_int("source_curve", node->output_gamma_curve);
+ CHECK(conversion->effect->set_int("source_curve", node->output_gamma_curve));
conversion->output_gamma_curve = GAMMA_LINEAR;
connect_nodes(node, conversion);
}
continue;
}
Node *conversion = add_node(new GammaExpansionEffect());
- conversion->effect->set_int("source_curve", input->output_gamma_curve);
+ CHECK(conversion->effect->set_int("source_curve", input->output_gamma_curve));
conversion->output_gamma_curve = GAMMA_LINEAR;
insert_node_between(input, conversion, node);
}
Node *output = find_output_node();
if (output->output_gamma_curve != output_format.gamma_curve) {
Node *conversion = add_node(new GammaCompressionEffect());
- conversion->effect->set_int("destination_curve", output_format.gamma_curve);
+ CHECK(conversion->effect->set_int("destination_curve", output_format.gamma_curve));
conversion->output_gamma_curve = output_format.gamma_curve;
connect_nodes(output, conversion);
}
cutoff(new HighlightCutoffEffect),
mix(new MixEffect)
{
- blur->set_float("radius", 20.0f);
- mix->set_float("strength_first", 1.0f);
- mix->set_float("strength_second", 1.0f);
- cutoff->set_float("cutoff", 0.2f);
+ CHECK(blur->set_float("radius", 20.0f));
+ CHECK(mix->set_float("strength_first", 1.0f));
+ CHECK(mix->set_float("strength_second", 1.0f));
+ CHECK(cutoff->set_float("cutoff", 0.2f));
}
void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
// The first blur pass will forward resolution information to us.
hpass = new SingleResamplePassEffect(this);
- hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL);
+ CHECK(hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL));
vpass = new SingleResamplePassEffect(NULL);
- vpass->set_int("direction", SingleResamplePassEffect::VERTICAL);
+ CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL));
update_size();
}
: blur(new BlurEffect),
mix(new MixEffect)
{
- mix->set_float("strength_first", 1.0f);
- mix->set_float("strength_second", -0.3f);
+ CHECK(mix->set_float("strength_first", 1.0f));
+ CHECK(mix->set_float("strength_second", -0.3f));
}
void UnsharpMaskEffect::rewrite_graph(EffectChain *graph, Node *self)
#define check_error() { int err = glGetError(); if (err != GL_NO_ERROR) { printf("GL error 0x%x at %s:%d\n", err, __FILE__, __LINE__); exit(1); } }
#endif
+#ifdef __GNUC__
+#define MUST_CHECK_RESULT __attribute__((warn_unused_result))
+#else
+#define MUST_CHECK_RESULT
+#endif
+
+// CHECK() is like assert(), but retains any side effects no matter the compilation mode.
+#ifdef NDEBUG
+#define CHECK(x) (void)(x)
+#else
+#define CHECK(x) do { bool ok = x; if (!ok) { fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #x); abort(); } } while (false)
+#endif
+
#endif // !defined(_UTIL_H)