From: Steinar H. Gunderson Date: Fri, 5 Oct 2012 22:39:21 +0000 (+0200) Subject: Generate PBOs on-the-fly instead of having hard-coded numbers. X-Git-Tag: 1.0~378 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=6a31570f6a85004d33a83bbe2f77642614361da6 Generate PBOs on-the-fly instead of having hard-coded numbers. --- diff --git a/input.cpp b/input.cpp index 1e460f0..453620c 100644 --- 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 dd80bb6..b3eb836 100644 --- 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; diff --git a/main.cpp b/main.cpp index 8693716..7e28993 100644 --- 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();