Remove the finalize() member function from Input.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 26 Jan 2014 23:44:44 +0000 (00:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 26 Jan 2014 23:53:39 +0000 (00:53 +0100)
It is no longer needed now that the texture is not created once,
but rather fetched on-demand from the ResourcePool.

effect_chain.cpp
flat_input.cpp
flat_input.h
input.h
ycbcr_input.cpp
ycbcr_input.h

index 114670c..ec64b83 100644 (file)
@@ -1413,10 +1413,6 @@ void EffectChain::finalize()
 
        output_dot("step19-split-to-phases.dot");
 
-       for (unsigned i = 0; i < inputs.size(); ++i) {
-               inputs[i]->finalize();
-       }
-
        assert(phases[0]->inputs.empty());
        
        finalized = true;
index 70cc109..d19cd4e 100644 (file)
@@ -15,7 +15,6 @@ FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format, GL
          type(type),
          pbo(0),
          texture_num(0),
-         finalized(false),
          output_linear_gamma(false),
          needs_mipmaps(false),
          width(width),
@@ -35,43 +34,40 @@ FlatInput::~FlatInput()
        }
 }
 
-void FlatInput::finalize()
-{
-       // Translate the input format to OpenGL's enums.
-       if (type == GL_FLOAT) {
-               internal_format = GL_RGBA32F_ARB;
-       } else if (output_linear_gamma) {
-               assert(type == GL_UNSIGNED_BYTE);
-               internal_format = GL_SRGB8_ALPHA8;
-       } else {
-               assert(type == GL_UNSIGNED_BYTE);
-               internal_format = GL_RGBA8;
-       }
-       if (pixel_format == FORMAT_RGB) {
-               format = GL_RGB;
-       } else if (pixel_format == FORMAT_RGBA_PREMULTIPLIED_ALPHA ||
-                  pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) {
-               format = GL_RGBA;
-       } else if (pixel_format == FORMAT_BGR) {
-               format = GL_BGR;
-       } else if (pixel_format == FORMAT_BGRA_PREMULTIPLIED_ALPHA ||
-                  pixel_format == FORMAT_BGRA_POSTMULTIPLIED_ALPHA) {
-               format = GL_BGRA;
-       } else if (pixel_format == FORMAT_GRAYSCALE) {
-               format = GL_LUMINANCE;
-       } else {
-               assert(false);
-       }
-
-       finalized = true;
-}
-       
 void FlatInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
 {
        glActiveTexture(GL_TEXTURE0 + *sampler_num);
        check_error();
 
        if (texture_num == 0) {
+               // Translate the input format to OpenGL's enums.
+               GLint internal_format;
+               GLenum format;
+               if (type == GL_FLOAT) {
+                       internal_format = GL_RGBA32F_ARB;
+               } else if (output_linear_gamma) {
+                       assert(type == GL_UNSIGNED_BYTE);
+                       internal_format = GL_SRGB8_ALPHA8;
+               } else {
+                       assert(type == GL_UNSIGNED_BYTE);
+                       internal_format = GL_RGBA8;
+               }
+               if (pixel_format == FORMAT_RGB) {
+                       format = GL_RGB;
+               } else if (pixel_format == FORMAT_RGBA_PREMULTIPLIED_ALPHA ||
+                          pixel_format == FORMAT_RGBA_POSTMULTIPLIED_ALPHA) {
+                       format = GL_RGBA;
+               } else if (pixel_format == FORMAT_BGR) {
+                       format = GL_BGR;
+               } else if (pixel_format == FORMAT_BGRA_PREMULTIPLIED_ALPHA ||
+                          pixel_format == FORMAT_BGRA_POSTMULTIPLIED_ALPHA) {
+                       format = GL_BGRA;
+               } else if (pixel_format == FORMAT_GRAYSCALE) {
+                       format = GL_LUMINANCE;
+               } else {
+                       assert(false);
+               }
+
                // (Re-)upload the texture.
                texture_num = resource_pool->create_2d_texture(internal_format, width, height);
                glBindTexture(GL_TEXTURE_2D, texture_num);
index 7875e2c..57f6f5a 100644 (file)
@@ -22,11 +22,6 @@ public:
 
        virtual std::string effect_type_id() const { return "FlatInput"; }
 
-       // Create the texture itself. We cannot do this in the constructor,
-       // because we don't necessarily know all the settings (sRGB texture,
-       // mipmap generation) at that point.
-       void finalize();
-
        virtual bool can_output_linear_gamma() const {
                return (movit_srgb_textures_supported &&
                        type == GL_UNSIGNED_BYTE &&
@@ -89,8 +84,8 @@ public:
        void invalidate_pixel_data();
 
        void set_pitch(unsigned pitch) {
-               assert(!finalized);
                this->pitch = pitch;
+               invalidate_pixel_data();
        }
 
        virtual void inform_added(EffectChain *chain)
@@ -101,9 +96,8 @@ public:
 private:
        ImageFormat image_format;
        MovitPixelFormat pixel_format;
-       GLenum internal_format, format, type;
+       GLenum type;
        GLuint pbo, texture_num;
-       bool finalized;
        int output_linear_gamma, needs_mipmaps;
        unsigned width, height, pitch;
        const void *pixel_data;
diff --git a/input.h b/input.h
index da5b1fb..e0febb1 100644 (file)
--- a/input.h
+++ b/input.h
@@ -7,9 +7,7 @@
 #include "image_format.h"
 
 // An input is a degenerate case of an effect; it represents the picture data
-// that comes from the user. As such, it has zero “inputs” itself. Also, it
-// has an extra operation called finalize(), which runs when the effect chain
-// is finalized.
+// that comes from the user. As such, it has zero “inputs” itself.
 //
 // An input is, like any other effect, required to be able to output a GLSL
 // fragment giving a RGBA value (although that GLSL fragment will have zero
@@ -19,11 +17,6 @@ class Input : public Effect {
 public:
        virtual unsigned num_inputs() const { return 0; }
 
-       // Create the texture itself. We cannot do this in the constructor,
-       // because we don't necessarily know all the settings (sRGB texture,
-       // mipmap generation) at that point.
-       virtual void finalize() = 0;
-
        // Whether this input can deliver linear gamma directly if it's
        // asked to. (If so, set the parameter “output_linear_gamma”
        // to activate it.)
index 6e73d3e..476f083 100644 (file)
@@ -63,7 +63,6 @@ YCbCrInput::YCbCrInput(const ImageFormat &image_format,
                        unsigned width, unsigned height)
        : image_format(image_format),
          ycbcr_format(ycbcr_format),
-         finalized(false),
          needs_mipmaps(false),
          width(width),
          height(height),
@@ -96,11 +95,6 @@ YCbCrInput::~YCbCrInput()
        }
 }
 
-void YCbCrInput::finalize()
-{
-       finalized = true;
-}
-       
 void YCbCrInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
 {
        for (unsigned channel = 0; channel < 3; ++channel) {
index 9f4e320..997eb48 100644 (file)
@@ -44,11 +44,6 @@ public:
 
        virtual std::string effect_type_id() const { return "YCbCrInput"; }
 
-       // Create the texture itself. We cannot do this in the constructor,
-       // because we don't necessarily know all the settings (sRGB texture,
-       // mipmap generation) at that point.
-       void finalize();
-
        virtual bool can_output_linear_gamma() const { return false; }
        virtual AlphaHandling alpha_handling() const { return OUTPUT_BLANK_ALPHA; }
 
@@ -85,6 +80,7 @@ public:
        void set_pitch(unsigned channel, unsigned pitch) {
                assert(channel >= 0 && channel < 3);
                this->pitch[channel] = pitch;
+               invalidate_pixel_data();
        }
 
        virtual void inform_added(EffectChain *chain)
@@ -96,7 +92,6 @@ private:
        ImageFormat image_format;
        YCbCrFormat ycbcr_format;
        GLuint pbos[3], texture_num[3];
-       bool finalized;
 
        int needs_mipmaps;