]> git.sesse.net Git - movit/blobdiff - input.cpp
Add missing file image_format.h, and add grayscale support.
[movit] / input.cpp
index 1e460f09606d89bcb15064ed36b535b869806146..cf0210c8fcfca822ff1d5b8d463ed9069dabf369 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -41,12 +41,17 @@ void Input::finalize()
        } else if (image_format.pixel_format == FORMAT_BGRA) {
                format = GL_BGRA;
                bytes_per_pixel = 4;
+       } else if (image_format.pixel_format == FORMAT_GRAYSCALE) {
+               format = GL_LUMINANCE;
+               bytes_per_pixel = 1;
        } else {
                assert(false);
        }
 
        // Create PBO to hold the texture holding the input image, and then the texture itself.
-       glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 2);
+       glGenBuffers(1, &pbo);
+       check_error();
+       glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
        check_error();
        glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * bytes_per_pixel, NULL, GL_STREAM_DRAW);
        check_error();
@@ -73,7 +78,7 @@ void Input::set_gl_state(GLuint glsl_program_num, const std::string& prefix, uns
 {
        if (needs_update) {
                // Copy the pixel data into the PBO.
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 2);
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
                check_error();
                void *mapped_pbo = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
                memcpy(mapped_pbo, pixel_data, width * height * bytes_per_pixel);