X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=effect_chain_test.cpp;fp=effect_chain_test.cpp;h=ecf0b6919cdcce0afbc93b91b73c5f5dd06ea0ff;hb=f5e3256da7d8e3a56c002da47bedf8ec1a2133f4;hp=3a3811da156539c25b853756efa76b5c6d6d30ff;hpb=f8e5ddc082f2267198292ea9e53d4a8b45f7b3b1;p=movit diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 3a3811d..ecf0b69 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -154,7 +154,8 @@ public: template class RewritingEffect : public Effect { public: - RewritingEffect() : effect(new T()), replaced_node(nullptr) {} + template + RewritingEffect(Args &&... args) : effect(new T(std::forward(args)...)), replaced_node(nullptr) {} string effect_type_id() const override { return "RewritingEffect[" + effect->effect_type_id() + "]"; } string output_fragment_shader() override { EXPECT_TRUE(false); return read_file("identity.frag"); } void rewrite_graph(EffectChain *graph, Node *self) override { @@ -565,7 +566,7 @@ TEST(EffectChainTest, AlphaConversionsWithNonBlankAlphaPreservingEffect) { class MipmapNeedingEffect : public Effect { public: MipmapNeedingEffect() {} - bool needs_mipmaps() const override { return true; } + MipmapRequirements needs_mipmaps() const override { return NEEDS_MIPMAPS; } // To be allowed to mess with the sampler state. bool needs_texture_bounce() const override { return true; } @@ -773,6 +774,74 @@ TEST(EffectChainTest, ResizeDownByFourThenUpByFour) { expect_equal(expected_data, out_data, 4, 16); } +// An effect to verify that you can turn off mipmaps; it downscales by two, +// which gives blur with mipmaps and aliasing (picks out every other pixel) +// without. +class Downscale2xEffect : public Effect { +public: + explicit Downscale2xEffect(MipmapRequirements mipmap_requirements) + : mipmap_requirements(mipmap_requirements) + { + register_vec2("offset", offset); + } + MipmapRequirements needs_mipmaps() const override { return mipmap_requirements; } + + string effect_type_id() const override { return "Downscale2xEffect"; } + string output_fragment_shader() override { return read_file("downscale2x.frag"); } + +private: + const MipmapRequirements mipmap_requirements; + EffectChain *chain; + float offset[2] { 0.0f, 0.0f }; +}; + +TEST(EffectChainTest, MipmapChainGetsSplit) { + float data[] = { + 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 1.0f, 0.0f, + }; + + // The intermediate result after the first step looks like this, + // assuming there are no mipmaps (the zeros are due to border behavior): + // + // 0 0 0 0 + // 0 0 0 0 + // 1 1 0 0 + // 1 1 0 0 + // + // so another 2x downscale towards the bottom left will give + // + // 0 0 + // 1 0 + // + // with yet more zeros coming in on the top and the right from the border. + float expected_data[] = { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.0f, + }; + float out_data[4 * 4]; + + float offset[] = { -0.5f / 4.0f, -0.5f / 4.0f }; + RewritingEffect *pick_out_top_left = new RewritingEffect(Effect::CANNOT_ACCEPT_MIPMAPS); + ASSERT_TRUE(pick_out_top_left->effect->set_vec2("offset", offset)); + + RewritingEffect *downscale2x = new RewritingEffect(Effect::NEEDS_MIPMAPS); + + EffectChainTester tester(data, 4, 4, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(pick_out_top_left); + tester.get_chain()->add_effect(downscale2x); + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + EXPECT_NE(pick_out_top_left->replaced_node->containing_phase, + downscale2x->replaced_node->containing_phase); + + expect_equal(expected_data, out_data, 4, 4); +} + // An effect that adds its two inputs together. Used below. class AddEffect : public Effect { public: