X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=a85fb365798fc945c77e7c856605e5bb333c7583;hp=c8fd946e6717fdd523048e58005b5f68e73d0d75;hb=b2da076fe497ab3cbaa01c1e5230210e8a2cf228;hpb=8eb4f2233b58dd11d276de2db44a8841224e15f5 diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index c8fd946..a85fb36 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -1,8 +1,10 @@ // Unit tests for EffectChain. +// +// Note that this also contains the tests for some of the simpler effects. #include "effect_chain.h" #include "flat_input.h" -#include "sandbox_effect.h" +#include "mirror_effect.h" #include "opengl.h" #include "gtest/gtest.h" @@ -96,6 +98,26 @@ void expect_equal(const float *ref, const float *result, unsigned width, unsigne } } +TEST(EffectChainTest, EmptyChain) { + float data[] = { + 0.0f, 0.25f, 0.3f, + 0.75f, 1.0f, 1.0f, + }; + float out_data[6]; + EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(data, out_data, 3, 2); +} + +// An effect that does nothing. +class IdentityEffect : public Effect { +public: + IdentityEffect() {} + virtual std::string effect_type_id() const { return "IdentityEffect"; } + std::string output_fragment_shader() { return read_file("identity.frag"); } +}; + TEST(EffectChainTest, Identity) { float data[] = { 0.0f, 0.25f, 0.3f, @@ -103,7 +125,47 @@ TEST(EffectChainTest, Identity) { }; float out_data[6]; EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(new IdentityEffect()); tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); expect_equal(data, out_data, 3, 2); } + +// An effect that does nothing, but requests texture bounce. +class BouncingIdentityEffect : public Effect { +public: + BouncingIdentityEffect() {} + 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; } +}; + +TEST(EffectChainTest, TextureBouncePreservesIdentity) { + float data[] = { + 0.0f, 0.25f, 0.3f, + 0.75f, 1.0f, 1.0f, + }; + float out_data[6]; + EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(new BouncingIdentityEffect()); + tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(data, out_data, 3, 2); +} + +TEST(MirrorTest, BasicTest) { + float data[] = { + 0.0f, 0.25f, 0.3f, + 0.75f, 1.0f, 1.0f, + }; + float expected_data[6] = { + 0.3f, 0.25f, 0.0f, + 1.0f, 1.0f, 0.75f, + }; + float out_data[6]; + EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(new MirrorEffect()); + tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(expected_data, out_data, 3, 2); +}