X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain.cpp;h=7d19ac3eb0df29861b5a19012d81d3f6d2810bde;hp=d80c4f82a28b33c39c983b38f02894ad514979e1;hb=6cb5e1fe7bc64c156da45b7646e2e52bf473e253;hpb=85f9719bf3519b1f1942738d11601584f5d38725 diff --git a/effect_chain.cpp b/effect_chain.cpp index d80c4f8..7d19ac3 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "alpha_division_effect.h" @@ -28,6 +29,8 @@ using namespace std; +namespace movit { + EffectChain::EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool) : aspect_nom(aspect_nom), aspect_denom(aspect_denom), @@ -1412,10 +1415,6 @@ void EffectChain::finalize() output_dot("step19-split-to-phases.dot"); - for (unsigned i = 0; i < inputs.size(); ++i) { - inputs[i]->finalize(); - } - assert(phases[0]->inputs.empty()); finalized = true; @@ -1447,13 +1446,6 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height 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(); - if (phases.size() > 1) { glGenFramebuffers(1, &fbo); check_error(); @@ -1477,7 +1469,9 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height output_textures.insert(make_pair(phases[phase], tex_num)); } - glUseProgram(phases[phase]->glsl_program_num); + const GLuint glsl_program_num = phases[phase]->glsl_program_num; + check_error(); + glUseProgram(glsl_program_num); check_error(); // Set up RTT inputs for this phase. @@ -1504,7 +1498,7 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height check_error(); string texture_name = string("tex_") + phases[phase]->effect_ids[input]; - glUniform1i(glGetUniformLocation(phases[phase]->glsl_program_num, texture_name.c_str()), sampler); + glUniform1i(glGetUniformLocation(glsl_program_num, texture_name.c_str()), sampler); check_error(); } @@ -1537,32 +1531,43 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height unsigned sampler_num = phases[phase]->inputs.size(); for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) { Node *node = phases[phase]->effects[i]; - node->effect->set_gl_state(phases[phase]->glsl_program_num, phases[phase]->effect_ids[node], &sampler_num); + node->effect->set_gl_state(glsl_program_num, phases[phase]->effect_ids[node], &sampler_num); check_error(); } // Now draw! - glBegin(GL_QUADS); - - glTexCoord2f(0.0f, 0.0f); - glVertex2f(0.0f, 0.0f); + float vertices[] = { + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f + }; + + GLuint vao; + glGenVertexArrays(1, &vao); + check_error(); + glBindVertexArray(vao); + check_error(); - glTexCoord2f(1.0f, 0.0f); - glVertex2f(1.0f, 0.0f); + GLuint position_vbo = fill_vertex_attribute(glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices); + GLuint texcoord_vbo = fill_vertex_attribute(glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices); // Same as vertices. - glTexCoord2f(1.0f, 1.0f); - glVertex2f(1.0f, 1.0f); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + check_error(); - glTexCoord2f(0.0f, 1.0f); - glVertex2f(0.0f, 1.0f); + cleanup_vertex_attribute(glsl_program_num, "position", position_vbo); + cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo); - glEnd(); + glUseProgram(0); check_error(); for (unsigned i = 0; i < phases[phase]->effects.size(); ++i) { Node *node = phases[phase]->effects[i]; node->effect->clear_gl_state(); } + + glDeleteVertexArrays(1, &vao); + check_error(); } for (map::const_iterator texture_it = output_textures.begin(); @@ -1579,3 +1584,5 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height check_error(); } } + +} // namespace movit