From: Steinar H. Gunderson Date: Sat, 22 Mar 2014 14:34:07 +0000 (+0100) Subject: Factor out RTT sampler setting in its own function. X-Git-Tag: 1.1~25 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;ds=sidebyside;h=83614ac8a2b9ef69ff65b452d2ea27723afc33cf;p=movit Factor out RTT sampler setting in its own function. --- diff --git a/effect_chain.cpp b/effect_chain.cpp index ca6a777..e754412 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -1484,22 +1484,12 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height input->output_node->bound_sampler_num = sampler; glBindTexture(GL_TEXTURE_2D, output_textures[input]); check_error(); - if (phase->input_needs_mipmaps) { - if (generated_mipmaps.count(input) == 0) { - glGenerateMipmap(GL_TEXTURE_2D); - check_error(); - generated_mipmaps.insert(input); - } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - check_error(); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (phase->input_needs_mipmaps && generated_mipmaps->count(input) == 0) { + glGenerateMipmap(GL_TEXTURE_2D); check_error(); + generated_mipmaps->insert(input); } - 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(); + setup_rtt_sampler(glsl_program_num, sampler, phase->effect_ids[input->output_node], phase->input_needs_mipmaps); string texture_name = string("tex_") + phase->effect_ids[input->output_node]; glUniform1i(glGetUniformLocation(glsl_program_num, texture_name.c_str()), sampler); @@ -1568,4 +1558,25 @@ void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height check_error(); } +void EffectChain::setup_rtt_sampler(GLuint glsl_program_num, int sampler_num, const string &effect_id, bool use_mipmaps) +{ + glActiveTexture(GL_TEXTURE0 + sampler_num); + check_error(); + if (use_mipmaps) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + check_error(); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + 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(); + + string texture_name = string("tex_") + effect_id; + glUniform1i(glGetUniformLocation(glsl_program_num, texture_name.c_str()), sampler_num); + check_error(); +} + } // namespace movit diff --git a/effect_chain.h b/effect_chain.h index 6ce2332..704c20c 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -235,6 +235,10 @@ private: // as the last effect. Also pushes all phases in order onto . Phase *construct_phase(Node *output, std::map *completed_effects); + // Set up the given sampler number for sampling from an RTT texture, + // and bind it to "tex_" plus the given GLSL variable. + void setup_rtt_sampler(GLuint glsl_program_num, int sampler_num, const std::string &effect_id, bool use_mipmaps); + // Output the current graph to the given file in a Graphviz-compatible format; // only useful for debugging. void output_dot(const char *filename);