+
+// Effectively scales down its input linearly by 4x (and repeating it),
+// which is not attainable without mipmaps.
+class MipmapNeedingEffect : public Effect {
+public:
+ MipmapNeedingEffect() {}
+ virtual bool needs_mipmaps() const { return true; }
+ virtual std::string effect_type_id() const { return "MipmapNeedingEffect"; }
+ std::string output_fragment_shader() { return read_file("mipmap_needing_effect.frag"); }
+ void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
+ {
+ glActiveTexture(GL_TEXTURE0);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ check_error();
+ }
+};
+
+TEST(EffectChainTest, MipmapGenerationWorks) {
+ 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 each way.
+ 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,
+
+ 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(data, 4, 16, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+ 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);
+}