+ 0.125f, 0.125f, 0.125f, 0.125f,
+ 0.09375f, 0.09375f, 0.09375f, 0.09375f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 0.25f, 0.25f, 0.25f, 0.25f,
+
+ 0.125f, 0.125f, 0.125f, 0.125f,
+ 0.09375f, 0.09375f, 0.09375f, 0.09375f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 0.25f, 0.25f, 0.25f, 0.25f,
+ };
+ float out_data[4 * 16];
+ EffectChainTester tester(NULL, 4, 16, FORMAT_GRAYSCALE);
+
+ ImageFormat format;
+ format.color_space = COLORSPACE_sRGB;
+ format.gamma_curve = GAMMA_LINEAR;
+
+ NonMipmapCapableInput *input = new NonMipmapCapableInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 4, 16);
+ input->set_pixel_data(data);
+ tester.get_chain()->add_input(input);
+ tester.get_chain()->add_effect(new MipmapNeedingEffect());
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, 4, 16);
+}
+
+TEST(EffectChainTest, ResizeDownByFourThenUpByFour) {
+ float data[] = { // In 4x4 blocks.
+ 1.0f, 0.0f, 0.0f, 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, 0.0f,
+ 0.0f, 0.5f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f,
+
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+
+ 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f,
+ };
+ float expected_data[] = { // Repeated four times horizontaly, interpolated vertically.
+ 0.1250f, 0.1250f, 0.1250f, 0.1250f,
+ 0.1250f, 0.1250f, 0.1250f, 0.1250f,
+ 0.1211f, 0.1211f, 0.1211f, 0.1211f,
+ 0.1133f, 0.1133f, 0.1133f, 0.1133f,
+ 0.1055f, 0.1055f, 0.1055f, 0.1055f,
+ 0.0977f, 0.0977f, 0.0977f, 0.0977f,
+ 0.2070f, 0.2070f, 0.2070f, 0.2070f,
+ 0.4336f, 0.4336f, 0.4336f, 0.4336f,
+ 0.6602f, 0.6602f, 0.6602f, 0.6602f,
+ 0.8867f, 0.8867f, 0.8867f, 0.8867f,
+ 0.9062f, 0.9062f, 0.9062f, 0.9062f,
+ 0.7188f, 0.7188f, 0.7188f, 0.7188f,
+ 0.5312f, 0.5312f, 0.5312f, 0.5312f,
+ 0.3438f, 0.3438f, 0.3438f, 0.3438f,
+ 0.2500f, 0.2500f, 0.2500f, 0.2500f,
+ 0.2500f, 0.2500f, 0.2500f, 0.2500f,
+ };
+ float out_data[4 * 16];
+
+ ResizeEffect *downscale = new ResizeEffect();
+ ASSERT_TRUE(downscale->set_int("width", 1));
+ ASSERT_TRUE(downscale->set_int("height", 4));
+
+ ResizeEffect *upscale = new ResizeEffect();
+ ASSERT_TRUE(upscale->set_int("width", 4));
+ ASSERT_TRUE(upscale->set_int("height", 16));
+
+ EffectChainTester tester(data, 4, 16, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+ tester.get_chain()->add_effect(downscale);
+ tester.get_chain()->add_effect(upscale);
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, 4, 16);
+}
+
+// An effect that adds its two inputs together. Used below.
+class AddEffect : public Effect {
+public:
+ AddEffect() {}
+ virtual string effect_type_id() const { return "AddEffect"; }
+ string output_fragment_shader() { return read_file("add.frag"); }
+ virtual unsigned num_inputs() const { return 2; }
+ virtual AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; }
+};
+
+// Constructs the graph
+//
+// FlatInput |
+// / \ |
+// MultiplyEffect MultiplyEffect |
+// \ / |
+// AddEffect |
+//
+// and verifies that it gives the correct output.
+TEST(EffectChainTest, DiamondGraph) {
+ 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];
+
+ 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_vec4("factor", half));
+
+ MultiplyEffect *mul_two = new MultiplyEffect();
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
+
+ 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(new AddEffect(), mul_half, mul_two);
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ 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];
+
+ 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_vec4("factor", half));
+
+ MultiplyEffect *mul_two = new MultiplyEffect();
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
+
+ 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);
+}
+
+TEST(EffectChainTest, EffectUsedTwiceOnlyGetsOneGammaConversion) {
+ float data[] = {
+ 0.735f, 0.0f,
+ 0.735f, 0.0f,
+ };
+ float expected_data[] = {
+ 0.0f, 0.5f, // 0.5 and not 1.0, since AddEffect doesn't clamp alpha properly.
+ 0.0f, 0.5f,
+ };
+ float out_data[2 * 2];
+
+ EffectChainTester tester(NULL, 2, 2);
+ tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB);
+
+ // MirrorEffect does not get linear light, so the conversions will be
+ // inserted after it, not before.
+ RewritingEffect<MirrorEffect> *effect = new RewritingEffect<MirrorEffect>();
+ tester.get_chain()->add_effect(effect);
+
+ Effect *identity1 = tester.get_chain()->add_effect(new IdentityEffect(), effect);
+ Effect *identity2 = tester.get_chain()->add_effect(new IdentityEffect(), effect);
+ tester.get_chain()->add_effect(new AddEffect(), identity1, identity2);
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, 2, 2);
+
+ Node *node = effect->replaced_node;
+ ASSERT_EQ(1, node->incoming_links.size());
+ ASSERT_EQ(1, node->outgoing_links.size());
+ EXPECT_EQ("FlatInput", node->incoming_links[0]->effect->effect_type_id());
+ EXPECT_EQ("GammaExpansionEffect", node->outgoing_links[0]->effect->effect_type_id());
+}
+
+TEST(EffectChainTest, EffectUsedTwiceOnlyGetsOneColorspaceConversion) {
+ float data[] = {
+ 0.5f, 0.0f,
+ 0.5f, 0.0f,
+ };
+ float expected_data[] = {
+ 0.0f, 0.5f, // 0.5 and not 1.0, since AddEffect doesn't clamp alpha properly.
+ 0.0f, 0.5f,
+ };
+ float out_data[2 * 2];
+
+ EffectChainTester tester(NULL, 2, 2);
+ tester.add_input(data, FORMAT_GRAYSCALE, COLORSPACE_REC_601_625, GAMMA_LINEAR);
+
+ // MirrorEffect does not get linear light, so the conversions will be
+ // inserted after it, not before.
+ RewritingEffect<MirrorEffect> *effect = new RewritingEffect<MirrorEffect>();
+ tester.get_chain()->add_effect(effect);
+
+ Effect *identity1 = tester.get_chain()->add_effect(new IdentityEffect(), effect);
+ Effect *identity2 = tester.get_chain()->add_effect(new IdentityEffect(), effect);
+ tester.get_chain()->add_effect(new AddEffect(), identity1, identity2);
+ tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+ expect_equal(expected_data, out_data, 2, 2);
+
+ Node *node = effect->replaced_node;
+ ASSERT_EQ(1, node->incoming_links.size());
+ ASSERT_EQ(1, node->outgoing_links.size());
+ EXPECT_EQ("FlatInput", node->incoming_links[0]->effect->effect_type_id());
+ EXPECT_EQ("ColorspaceConversionEffect", node->outgoing_links[0]->effect->effect_type_id());
+}
+
+// An effect that does nothing, but requests texture bounce and stores
+// its input size.
+class SizeStoringEffect : public BouncingIdentityEffect {
+public:
+ SizeStoringEffect() : input_width(-1), input_height(-1) {}
+ virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height) {
+ assert(input_num == 0);
+ input_width = width;
+ input_height = height;