X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=flat_input_test.cpp;h=f01bab82bee0392ed781525b6770d617bf196922;hp=397cae3c26d788f7abe5ed10ba064f23b60d2cbd;hb=8cd14c3d54e817f9ad83966409dd672bcbfb7555;hpb=7ea0b3a5be9bafaa2d1fa5a17ce285a725ce132b diff --git a/flat_input_test.cpp b/flat_input_test.cpp index 397cae3..f01bab8 100644 --- a/flat_input_test.cpp +++ b/flat_input_test.cpp @@ -6,6 +6,7 @@ #include "effect_chain.h" #include "flat_input.h" #include "gtest/gtest.h" +#include "resource_pool.h" #include "test_util.h" #include "util.h" @@ -108,7 +109,7 @@ TEST(FlatInput, AlphaIsNotModifiedBySRGBConversion) { }; float out_data[4 * size]; - EffectChainTester tester(NULL, 1, size); + EffectChainTester tester(nullptr, 1, size); tester.add_input(data, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_sRGB); tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); @@ -184,7 +185,7 @@ TEST(FlatInput, Pitch) { }; float out_data[4 * width * height]; - EffectChainTester tester(NULL, width, height); + EffectChainTester tester(nullptr, width, height); ImageFormat format; format.color_space = COLORSPACE_sRGB; @@ -211,7 +212,7 @@ TEST(FlatInput, UpdatedData) { }; float out_data[width * height]; - EffectChainTester tester(NULL, width, height); + EffectChainTester tester(nullptr, width, height); ImageFormat format; format.color_space = COLORSPACE_sRGB; @@ -251,7 +252,7 @@ TEST(FlatInput, PBO) { glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * sizeof(float), data, GL_STREAM_DRAW); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); - EffectChainTester tester(NULL, width, height); + EffectChainTester tester(nullptr, width, height); ImageFormat format; format.color_space = COLORSPACE_sRGB; @@ -267,4 +268,76 @@ TEST(FlatInput, PBO) { glDeleteBuffers(1, &pbo); } +TEST(FlatInput, ExternalTexture) { + const int size = 5; + + float data[3 * size] = { + 0.0, 0.0, 0.0, + 0.5, 0.0, 0.0, + 0.0, 0.5, 0.0, + 0.0, 0.0, 0.7, + 0.0, 0.3, 0.7, + }; + float expected_data[4 * size] = { + 0.0, 0.0, 0.0, 1.0, + 0.5, 0.0, 0.0, 1.0, + 0.0, 0.5, 0.0, 1.0, + 0.0, 0.0, 0.7, 1.0, + 0.0, 0.3, 0.7, 1.0, + }; + float out_data[4 * size]; + + EffectChainTester tester(nullptr, 1, size, FORMAT_RGB, COLORSPACE_sRGB, GAMMA_LINEAR); + + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_LINEAR; + + ResourcePool pool; + GLuint tex = pool.create_2d_texture(GL_RGB8, 1, size); + check_error(); + glBindTexture(GL_TEXTURE_2D, tex); + check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + check_error(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + check_error(); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, size, GL_RGB, GL_FLOAT, data); + check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + check_error(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_error(); + + FlatInput *input = new FlatInput(format, FORMAT_RGB, GL_FLOAT, 1, size); + input->set_texture_num(tex); + tester.get_chain()->add_input(input); + + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + pool.release_2d_texture(tex); + + expect_equal(expected_data, out_data, 4, size); +} + +TEST(FlatInput, NoData) { + const int width = 2; + const int height = 4; + + float out_data[width * height]; + + EffectChainTester tester(nullptr, width, height); + + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_LINEAR; + + FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height); + tester.get_chain()->add_input(input); + + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + // Don't care what the output was, just that it does not crash. +} + } // namespace movit