+void EffectChain::render_to_screen(unsigned char *src)
+{
+ assert(finalized);
+
+ check_error();
+ glUseProgram(glsl_program_num);
+ check_error();
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, SOURCE_IMAGE);
+
+ GLenum format, internal_format;
+ if (use_srgb_texture_format) {
+ internal_format = GL_SRGB8;
+ } else {
+ internal_format = GL_RGBA8;
+ }
+ if (input_format.pixel_format == FORMAT_RGB) {
+ format = GL_RGB;
+ } else if (input_format.pixel_format == FORMAT_RGBA) {
+ format = GL_RGBA;
+ } else if (input_format.pixel_format == FORMAT_BGR) {
+ format = GL_BGR;
+ } else if (input_format.pixel_format == FORMAT_BGRA) {
+ format = GL_BGRA;
+ } else {
+ assert(false);
+ }
+
+ static bool first = true;
+ if (first) {
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, src);
+ } else {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, src);
+ }
+ check_error();
+ glUniform1i(glGetUniformLocation(glsl_program_num, "input_tex"), 0);
+
+ for (unsigned i = 0; i < effects.size(); ++i) {
+ char effect_id[256];
+ sprintf(effect_id, "eff%d", i);
+ effects[i]->set_uniforms(glsl_program_num, effect_id);
+ }
+
+ glDisable(GL_BLEND);
+ check_error();
+ glDisable(GL_DEPTH_TEST);
+ check_error();
+ glDepthMask(GL_FALSE);
+ check_error();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glBegin(GL_QUADS);
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex2f(0.0f, 0.0f);
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex2f(1.0f, 0.0f);
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex2f(1.0f, 1.0f);
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex2f(0.0f, 1.0f);
+
+ glEnd();
+ check_error();
+}