+ void *mapped_pbo = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
+ memset(mapped_pbo, 0, width * height * bytes_per_pixel);
+ glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
+ check_error();
+
+ glGenTextures(1, &source_image_num);
+ check_error();
+ glBindTexture(GL_TEXTURE_2D, source_image_num);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ check_error();
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
+ check_error();
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ check_error();
+
+ finalized = true;
+}
+
+void EffectChain::render_to_screen(unsigned char *src)
+{
+ assert(finalized);
+
+ // Copy the pixel data into the PBO.
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 2);
+ check_error();
+ void *mapped_pbo = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
+ memcpy(mapped_pbo, src, width * height * bytes_per_pixel);
+ glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
+ check_error();
+
+ // Re-upload the texture from the PBO.
+ glActiveTexture(GL_TEXTURE0);
+ check_error();
+ glBindTexture(GL_TEXTURE_2D, source_image_num);
+ check_error();
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ check_error();
+
+ // Intel/Mesa seems to have a broken glGenerateMipmap() for non-FBO textures, so do it here.
+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, phases[0].input_needs_mipmaps ? GL_TRUE : GL_FALSE);
+ check_error();
+
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ check_error();