#include "gtest/gtest.h"
#include "input.h"
#include "mirror_effect.h"
+#include "multiply_effect.h"
#include "resize_effect.h"
#include "test_util.h"
#include "util.h"
expect_equal(expected_data, out_data, 4, 16);
}
-// An effect that multiplies with a constant. Used below.
-class MultiplyEffect : public Effect {
-public:
- MultiplyEffect() { register_float("factor", &factor); }
- virtual std::string effect_type_id() const { return "MultiplyEffect"; }
- std::string output_fragment_shader() { return read_file("multiply.frag"); }
- virtual AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; }
-
-private:
- float factor;
-};
-
// An effect that adds its two inputs together. Used below.
class AddEffect : public Effect {
public:
};
float out_data[2 * 2];
+ const float half[] = { 0.5f, 0.5f, 0.5f, 0.5f };
+ const float two[] = { 2.0f, 2.0f, 2.0f, 0.5f };
+
MultiplyEffect *mul_half = new MultiplyEffect();
- ASSERT_TRUE(mul_half->set_float("factor", 0.5f));
+ ASSERT_TRUE(mul_half->set_vec4("factor", half));
MultiplyEffect *mul_two = new MultiplyEffect();
- ASSERT_TRUE(mul_two->set_float("factor", 2.0f));
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
EffectChainTester tester(NULL, 2, 2);
};
float out_data[2 * 2];
+ const float half[] = { 0.5f, 0.5f, 0.5f, 0.5f };
+ const float two[] = { 2.0f, 2.0f, 2.0f, 0.5f };
+
MultiplyEffect *mul_half = new MultiplyEffect();
- ASSERT_TRUE(mul_half->set_float("factor", 0.5f));
+ ASSERT_TRUE(mul_half->set_vec4("factor", half));
MultiplyEffect *mul_two = new MultiplyEffect();
- ASSERT_TRUE(mul_two->set_float("factor", 2.0f));
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
BouncingIdentityEffect *bounce = new BouncingIdentityEffect();
--- /dev/null
+#include <GL/glew.h>
+
+#include "multiply_effect.h"
+#include "util.h"
+
+MultiplyEffect::MultiplyEffect()
+ : factor(1.0f, 1.0f, 1.0f, 1.0f)
+{
+ register_vec4("factor", (float *)&factor);
+}
+
+std::string MultiplyEffect::output_fragment_shader()
+{
+ return read_file("multiply_effect.frag");
+}
--- /dev/null
+#ifndef _MOVIT_MULTIPLY_EFFECT_H
+#define _MOVIT_MULTIPLY_EFFECT_H 1
+
+// An effect that multiplies every pixel by a constant (separate for each of
+// R, G, B, A). A common use would be to reduce the alpha of an overlay before
+// sending it through OverlayEffect, e.g. with R=G=B=A=0.3 to get 30% alpha
+// (remember, alpha is premultiplied).
+
+#include <GL/glew.h>
+#include <string>
+
+#include "effect.h"
+
+class MultiplyEffect : public Effect {
+public:
+ MultiplyEffect();
+ virtual std::string effect_type_id() const { return "MultiplyEffect"; }
+ std::string output_fragment_shader();
+
+private:
+ RGBATuple factor;
+};
+
+#endif // !defined(_MOVIT_MULTIPLY_EFFECT_H)