From: Steinar H. Gunderson Date: Sat, 20 Feb 2016 16:13:48 +0000 (+0100) Subject: Allow setting the intermediate texture format; useful for reducing bandwidth at the... X-Git-Tag: 1.4.0~21 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=d47ac1e362683896033f43ecd9aeb2f2330b5678 Allow setting the intermediate texture format; useful for reducing bandwidth at the expense of quality, and possibly future GLES2 support. --- diff --git a/effect_chain.cpp b/effect_chain.cpp index 19d89f8..fa7340d 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -32,12 +32,13 @@ using namespace std; namespace movit { -EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool) +EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool, GLenum intermediate_format) : aspect_nom(aspect_nom), aspect_denom(aspect_denom), output_color_rgba(false), output_color_ycbcr(false), dither_effect(NULL), + intermediate_format(intermediate_format), num_dither_bits(0), output_origin(OUTPUT_ORIGIN_BOTTOM_LEFT), finalized(false), @@ -1692,6 +1693,8 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height check_error(); glDisable(GL_DITHER); check_error(); + glEnable(GL_FRAMEBUFFER_SRGB); + check_error(); // Save original viewport. GLuint x = 0, y = 0; @@ -1853,7 +1856,7 @@ void EffectChain::execute_phase(Phase *phase, bool last_phase, if (!last_phase) { find_output_size(phase); - GLuint tex_num = resource_pool->create_2d_texture(GL_RGBA16F, phase->output_width, phase->output_height); + GLuint tex_num = resource_pool->create_2d_texture(intermediate_format, phase->output_width, phase->output_height); output_textures->insert(make_pair(phase, tex_num)); } diff --git a/effect_chain.h b/effect_chain.h index 22f0b96..718d5ff 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -194,7 +194,7 @@ public: // will create its own that is not shared with anything else. Does not take // ownership of the passed-in ResourcePool, but will naturally take ownership // of its own internal one if created. - EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool = NULL); + EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool = NULL, GLenum intermediate_format = GL_RGBA16F); ~EffectChain(); // User API: @@ -438,6 +438,7 @@ private: std::vector inputs; // Also contained in nodes. std::vector phases; + GLenum intermediate_format; unsigned num_dither_bits; OutputOrigin output_origin; bool finalized; diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 6ab874d..a8cb41f 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -1303,5 +1303,20 @@ TEST(EffectChainTest, StringStreamLocalesWork) { free(saved_locale); } +TEST(EffectChainTest, sRGBIntermediate) { + float data[] = { + 0.0f, 0.25f, 0.0f, 1.0f, + }; + float expected_data[] = { + 0.0f, 0.25048828125f, 0.0f, 1.0f, + }; + float out_data[4]; + EffectChainTester tester(data, 1, 1, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR, GL_RGBA16F_ARB, GL_SRGB8); + tester.get_chain()->add_effect(new IdentityEffect()); + tester.get_chain()->add_effect(new BouncingIdentityEffect()); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(expected_data, out_data, 4, 1, 1e-4); +} } // namespace movit diff --git a/init.h b/init.h index 3af6644..463c7fc 100644 --- a/init.h +++ b/init.h @@ -56,7 +56,12 @@ extern float movit_texel_subpixel_precision; // of errors are stored here. // // If this value is above 0, we will round off explicitly at the very end -// of the shader. +// of the shader. Note the following limitations: +// +// - The measurement is done on linear 8-bit, not any sRGB format, +// 10-bit output, or the likes. +// - This only covers the final pass; intermediates are not covered +// (only relevant if you use e.g. GL_SRGB8 intermediates). extern int movit_num_wrongly_rounded; // Whether the GPU in use supports GL_EXT_texture_sRGB. diff --git a/test_util.cpp b/test_util.cpp index ada84dc..b377309 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -46,8 +46,14 @@ void vertical_flip(T *data, unsigned width, unsigned height) EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve, - GLenum framebuffer_format) - : chain(width, height, get_static_pool()), width(width), height(height), framebuffer_format(framebuffer_format), output_added(false), finalized(false) + GLenum framebuffer_format, + GLenum intermediate_format) + : chain(width, height, get_static_pool(), intermediate_format), + width(width), + height(height), + framebuffer_format(framebuffer_format), + output_added(false), + finalized(false) { CHECK(init_movit(".", MOVIT_DEBUG_OFF)); diff --git a/test_util.h b/test_util.h index 1f9e47f..69efe35 100644 --- a/test_util.h +++ b/test_util.h @@ -15,7 +15,8 @@ public: MovitPixelFormat pixel_format = FORMAT_GRAYSCALE, Colorspace color_space = COLORSPACE_sRGB, GammaCurve gamma_curve = GAMMA_LINEAR, - GLenum framebuffer_format = GL_RGBA16F_ARB); + GLenum framebuffer_format = GL_RGBA16F_ARB, + GLenum intermediate_format = GL_RGBA16F_ARB); ~EffectChainTester(); EffectChain *get_chain() { return &chain; } diff --git a/version.h b/version.h index 556c4af..3a6600d 100644 --- a/version.h +++ b/version.h @@ -5,6 +5,6 @@ // changes, even within git versions. There is no specific version // documentation outside the regular changelogs, though. -#define MOVIT_VERSION 18 +#define MOVIT_VERSION 19 #endif // !defined(_MOVIT_VERSION_H)