]> git.sesse.net Git - movit/commitdiff
Allow setting the intermediate texture format; useful for reducing bandwidth at the...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Feb 2016 16:13:48 +0000 (17:13 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Feb 2016 16:26:04 +0000 (17:26 +0100)
effect_chain.cpp
effect_chain.h
effect_chain_test.cpp
init.h
test_util.cpp
test_util.h
version.h

index 19d89f823c313b6faca3bcdd3c1aef505f762f8d..fa7340d7a456839f7ef2563d76c5a872182491ff 100644 (file)
@@ -32,12 +32,13 @@ using namespace std;
 
 namespace movit {
 
 
 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),
        : 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),
          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();
        check_error();
        glDisable(GL_DITHER);
        check_error();
+       glEnable(GL_FRAMEBUFFER_SRGB);
+       check_error();
 
        // Save original viewport.
        GLuint x = 0, y = 0;
 
        // 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);
 
        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));
        }
 
                output_textures->insert(make_pair(phase, tex_num));
        }
 
index 22f0b96c6e4eabc807c8bf57a75b70516c3a8cda..718d5ff7830cde86c7fb192b77417278dd68f7cf 100644 (file)
@@ -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.
        // 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:
        ~EffectChain();
 
        // User API:
@@ -438,6 +438,7 @@ private:
        std::vector<Input *> inputs;  // Also contained in nodes.
        std::vector<Phase *> phases;
 
        std::vector<Input *> inputs;  // Also contained in nodes.
        std::vector<Phase *> phases;
 
+       GLenum intermediate_format;
        unsigned num_dither_bits;
        OutputOrigin output_origin;
        bool finalized;
        unsigned num_dither_bits;
        OutputOrigin output_origin;
        bool finalized;
index 6ab874d2e4e32507beb5cc9eeb546fac69e9f546..a8cb41f044d1fa9b6070fb32b676abc3f373a195 100644 (file)
@@ -1303,5 +1303,20 @@ TEST(EffectChainTest, StringStreamLocalesWork) {
        free(saved_locale);
 }
 
        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
 
 }  // namespace movit
diff --git a/init.h b/init.h
index 3af6644facf740b073c94337e86c885483644b4f..463c7fc3286d8b12b29846b1c80f6c07dd9dcabb 100644 (file)
--- 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 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.
 extern int movit_num_wrongly_rounded;
 
 // Whether the GPU in use supports GL_EXT_texture_sRGB.
index ada84dca8832f24513c40a05d58fae7f6de97869..b377309638114057f2d99a56c852ee010bebb18f 100644 (file)
@@ -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,
 
 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));
 
 {
        CHECK(init_movit(".", MOVIT_DEBUG_OFF));
 
index 1f9e47fa207725bb944f59ffdd3406ab174d7fe0..69efe358b10d60b0e0556751b7d1d6ea313cee1f 100644 (file)
@@ -15,7 +15,8 @@ public:
                          MovitPixelFormat pixel_format = FORMAT_GRAYSCALE,
                          Colorspace color_space = COLORSPACE_sRGB,
                          GammaCurve gamma_curve = GAMMA_LINEAR,
                          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; }
        ~EffectChainTester();
        
        EffectChain *get_chain() { return &chain; }
index 556c4af878f272f225172b9cd210714f02eff784..3a6600daaf6c67ef5e6d21c007b4b0778b6e8ce4 100644 (file)
--- 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.
 
 // 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)
 
 #endif // !defined(_MOVIT_VERSION_H)