]> git.sesse.net Git - movit/commitdiff
Allow changing pitch on YCbCrInput as we go.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Oct 2012 08:39:23 +0000 (10:39 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Oct 2012 08:39:23 +0000 (10:39 +0200)
ycbcr_input.cpp
ycbcr_input.h

index a625fe3474c70f712f14db97397fedd79682dfc0..a73518d4ad2797f274f2dad2cac6ebf6a281a0ff 100644 (file)
@@ -11,6 +11,7 @@ YCbCrInput::YCbCrInput(const ImageFormat &image_format,
        : image_format(image_format),
          ycbcr_format(ycbcr_format),
          needs_update(false),
+         needs_pbo_recreate(false),
          finalized(false),
          needs_mipmaps(false),
          width(width),
@@ -71,12 +72,20 @@ void YCbCrInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix
                glBindTexture(GL_TEXTURE_2D, texture_num[channel]);
                check_error();
 
-               if (needs_update) {
+               if (needs_update || needs_pbo_recreate) {
                        // Copy the pixel data into the PBO.
                        glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbos[channel]);
                        check_error();
+
+                       if (needs_pbo_recreate) {
+                               // The pitch has changed; we need to reallocate this PBO.
+                               glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, pitch[channel] * heights[channel], NULL, GL_STREAM_DRAW);
+                               check_error();
+                       }
+
                        void *mapped_pbo = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
                        memcpy(mapped_pbo, pixel_data[channel], pitch[channel] * heights[channel]);
+
                        glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
                        check_error();
 
@@ -103,6 +112,7 @@ void YCbCrInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix
 
        *sampler_num += 3;
        needs_update = false;
+       needs_pbo_recreate = false;
 }
 
 std::string YCbCrInput::output_fragment_shader()
index fd9db273d52ba1a049c0ff98411f507a97ccc723..d4cdf9ffe3e3f05cf2c3434a77c1308ed5fa9140 100644 (file)
@@ -69,9 +69,11 @@ public:
        }
 
        void set_pitch(unsigned channel, unsigned pitch) {
-               assert(!finalized);
                assert(channel >= 0 && channel < 3);
-               this->pitch[channel] = pitch;
+               if (this->pitch[channel] != pitch) {
+                       this->pitch[channel] = pitch;
+                       needs_pbo_recreate = true;
+               }
        }
 
        unsigned get_pitch(unsigned channel) {
@@ -83,7 +85,7 @@ private:
        ImageFormat image_format;
        YCbCrFormat ycbcr_format;
        GLuint pbos[3], texture_num[3];
-       bool needs_update, finalized;
+       bool needs_update, needs_pbo_recreate, finalized;
 
        int needs_mipmaps;