X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain.cpp;h=21c4a0d1d2cf84e8a2eb3f80153715557aab8d1c;hp=e4ab7199c8d23320c545d47c98b4c53dec39af3b;hb=d88ed3150376693000665b9016c0350d5d90e9e1;hpb=9b0bd744d606d9d92bd955e0e575c73aa505073d diff --git a/effect_chain.cpp b/effect_chain.cpp index e4ab719..21c4a0d 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -1,8 +1,7 @@ #define GL_GLEXT_PROTOTYPES 1 -#include +#include #include -#include #include #include #include @@ -53,15 +52,6 @@ EffectChain::~EffectChain() delete nodes[i]; } for (unsigned i = 0; i < phases.size(); ++i) { - glBindVertexArray(phases[i]->vao); - check_error(); - - cleanup_vertex_attribute(phases[i]->glsl_program_num, "position", phases[i]->position_vbo); - cleanup_vertex_attribute(phases[i]->glsl_program_num, "texcoord", phases[i]->texcoord_vbo); - - glBindVertexArray(0); - check_error(); - resource_pool->release_glsl_program(phases[i]->glsl_program_num); delete phases[i]; } @@ -238,7 +228,7 @@ string replace_prefix(const string &text, const string &prefix) void EffectChain::compile_glsl_program(Phase *phase) { - string frag_shader = read_file("header.frag"); + string frag_shader = read_version_dependent_file("header", "frag"); // Create functions for all the texture inputs that we need. for (unsigned i = 0; i < phase->inputs.size(); ++i) { @@ -249,7 +239,7 @@ void EffectChain::compile_glsl_program(Phase *phase) frag_shader += string("uniform sampler2D tex_") + effect_id + ";\n"; frag_shader += string("vec4 ") + effect_id + "(vec2 tc) {\n"; - frag_shader += "\treturn texture2D(tex_" + string(effect_id) + ", tc);\n"; + frag_shader += "\treturn tex2D(tex_" + string(effect_id) + ", tc);\n"; frag_shader += "}\n"; frag_shader += "\n"; } @@ -288,30 +278,10 @@ void EffectChain::compile_glsl_program(Phase *phase) frag_shader += "\n"; } frag_shader += string("#define INPUT ") + phase->effect_ids[phase->effects.back()] + "\n"; - frag_shader.append(read_file("footer.frag")); - - phase->glsl_program_num = resource_pool->compile_glsl_program(read_file("vs.vert"), frag_shader); - - // Prepare the geometry for the fullscreen quad used in this phase. - // (We have separate VAOs per shader, since the bindings can in theory - // be different.) - float vertices[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f - }; + frag_shader.append(read_version_dependent_file("footer", "frag")); - glGenVertexArrays(1, &phase->vao); - check_error(); - glBindVertexArray(phase->vao); - check_error(); - - phase->position_vbo = fill_vertex_attribute(phase->glsl_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices); - phase->texcoord_vbo = fill_vertex_attribute(phase->glsl_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices); // Same as vertices. - - glBindVertexArray(0); - check_error(); + string vert_shader = read_version_dependent_file("vs", "vert"); + phase->glsl_program_num = resource_pool->compile_glsl_program(vert_shader, frag_shader); } // Construct GLSL programs, starting at the given effect and following @@ -1359,10 +1329,6 @@ Node *EffectChain::find_output_node() void EffectChain::finalize() { - // Save the current locale, and set it to C, so that we can output decimal - // numbers with printf and be sure to get them in the format mandated by GLSL. - char *saved_locale = setlocale(LC_NUMERIC, "C"); - // Output the graph as it is before we do any conversions on it. output_dot("step0-start.dot"); @@ -1425,7 +1391,6 @@ void EffectChain::finalize() assert(phases[0]->inputs.empty()); finalized = true; - setlocale(LC_NUMERIC, saved_locale); } void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height) @@ -1484,8 +1449,6 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height glBindFramebuffer(GL_FRAMEBUFFER, 0); check_error(); - glBindVertexArray(0); - check_error(); glUseProgram(0); check_error(); } @@ -1525,8 +1488,7 @@ void EffectChain::execute_phase(Phase *phase, bool last_phase, mapcreate_fbo(context, (*output_textures)[phase]); + fbo = resource_pool->create_fbo((*output_textures)[phase]); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glViewport(0, 0, phase->output_width, phase->output_height); } @@ -1547,11 +1509,32 @@ void EffectChain::execute_phase(Phase *phase, bool last_phase, mapvao); + // Now draw! + 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(); + + 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. + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); check_error(); + cleanup_vertex_attribute(glsl_program_num, "position", position_vbo); + cleanup_vertex_attribute(glsl_program_num, "texcoord", texcoord_vbo); + + glUseProgram(0); + check_error(); + for (unsigned i = 0; i < phase->effects.size(); ++i) { Node *node = phase->effects[i]; node->effect->clear_gl_state(); @@ -1560,6 +1543,9 @@ void EffectChain::execute_phase(Phase *phase, bool last_phase, maprelease_fbo(fbo); } + + glDeleteVertexArrays(1, &vao); + check_error(); } void EffectChain::setup_rtt_sampler(GLuint glsl_program_num, int sampler_num, const string &effect_id, bool use_mipmaps)