]> git.sesse.net Git - movit/commitdiff
Generate PBOs on-the-fly instead of having hard-coded numbers.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 5 Oct 2012 22:39:21 +0000 (00:39 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 5 Oct 2012 22:39:21 +0000 (00:39 +0200)
input.cpp
input.h
main.cpp

index 1e460f09606d89bcb15064ed36b535b869806146..453620c41df023353fc943c920cd117673c0f1b2 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -46,7 +46,9 @@ void Input::finalize()
        }
 
        // 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 +75,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);
diff --git a/input.h b/input.h
index dd80bb61ca6f82b3822300239d993aed6368231a..b3eb836a26a8f9d4e1754ddc3574e866763dce2a 100644 (file)
--- a/input.h
+++ b/input.h
@@ -46,7 +46,7 @@ public:
 private:
        ImageFormat image_format;
        GLenum format;
-       GLuint texture_num;
+       GLuint pbo, texture_num;
        bool needs_update;
        int use_srgb_texture_format, needs_mipmaps;
        unsigned width, height, bytes_per_pixel;
index 869371626882eb506cf4cd9f617de4f9c17fb977..7e289935abf29745a4a7a6aee2271097e9d82295 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -177,7 +177,9 @@ int main(int argc, char **argv)
 
        // generate a PDO to hold the data we read back with glReadPixels()
        // (Intel/DRI goes into a slow path if we don't read to PDO)
-       glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);
+       GLuint pbo;
+       glGenBuffers(1, &pbo);
+       glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo);
        glBufferData(GL_PIXEL_PACK_BUFFER_ARB, WIDTH * HEIGHT * 4, NULL, GL_STREAM_READ);
 
        make_hsv_wheel_texture();
@@ -220,7 +222,7 @@ int main(int argc, char **argv)
                input->set_pixel_data(src_img);
                chain.render_to_screen();
                
-               glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);
+               glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo);
                check_error();
                glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, BUFFER_OFFSET(0));
                check_error();
@@ -242,7 +244,7 @@ int main(int argc, char **argv)
                SDL_GL_SwapBuffers();
                check_error();
 
-               glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);
+               glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo);
                check_error();
                unsigned char *screenbuf = (unsigned char *)glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
                check_error();