X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=75491030b05b66f27fef22a17ca8e5f7ccf66dcd;hp=ce3870a5b166caca74ccfa589d013805f7e28f8b;hb=8e37939a9bc1c902d0929dfae70e8d515de6e684;hpb=f6ccf310656ba0c218574654fbf8e794041efeaf diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index ce3870a..7549103 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -51,6 +51,7 @@ public: virtual std::string effect_type_id() const { return "IdentityEffect"; } std::string output_fragment_shader() { return read_file("identity.frag"); } bool needs_texture_bounce() const { return true; } + AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; } }; TEST(EffectChainTest, TextureBouncePreservesIdentity) { @@ -101,7 +102,7 @@ public: template class RewritingEffect : public Effect { public: - RewritingEffect() : effect(new T()) {} + RewritingEffect() : effect(new T()), replaced_node(NULL) {} virtual std::string effect_type_id() const { return "RewritingEffect[" + effect->effect_type_id() + "]"; } std::string output_fragment_shader() { EXPECT_TRUE(false); return read_file("identity.frag"); } virtual void rewrite_graph(EffectChain *graph, Node *self) { @@ -640,3 +641,52 @@ TEST(EffectChainTest, DiamondGraph) { expect_equal(expected_data, out_data, 2, 2); } + +// Constructs the graph +// +// FlatInput | +// / \ | +// MultiplyEffect MultiplyEffect | +// \ | | +// \ BouncingIdentityEffect | +// \ / | +// AddEffect | +// +// and verifies that it gives the correct output. +TEST(EffectChainTest, DiamondGraphWithOneInputUsedInTwoPhases) { + float data[] = { + 1.0f, 1.0f, + 1.0f, 0.0f, + }; + float expected_data[] = { + 2.5f, 2.5f, + 2.5f, 0.0f, + }; + float out_data[2 * 2]; + + MultiplyEffect *mul_half = new MultiplyEffect(); + ASSERT_TRUE(mul_half->set_float("factor", 0.5f)); + + MultiplyEffect *mul_two = new MultiplyEffect(); + ASSERT_TRUE(mul_two->set_float("factor", 2.0f)); + + BouncingIdentityEffect *bounce = new BouncingIdentityEffect(); + + EffectChainTester tester(NULL, 2, 2); + + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_LINEAR; + + FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 2, 2); + input->set_pixel_data(data); + + tester.get_chain()->add_input(input); + tester.get_chain()->add_effect(mul_half, input); + tester.get_chain()->add_effect(mul_two, input); + tester.get_chain()->add_effect(bounce, mul_two); + tester.get_chain()->add_effect(new AddEffect(), mul_half, bounce); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(expected_data, out_data, 2, 2); +}