- // Give the required parameters to all the effects.
- 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);
- check_error();
+ for (map<Phase *, GLuint>::const_iterator texture_it = output_textures.begin();
+ texture_it != output_textures.end();
+ ++texture_it) {
+ resource_pool->release_2d_texture(texture_it->second);
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ check_error();
+ glUseProgram(0);
+ check_error();
+
+ if (do_phase_timing) {
+ // Get back the timer queries.
+ for (unsigned phase_num = 0; phase_num < phases.size(); ++phase_num) {
+ Phase *phase = phases[phase_num];
+ GLint available = 0;
+ while (!available) {
+ glGetQueryObjectiv(phase->timer_query_object, GL_QUERY_RESULT_AVAILABLE, &available);
+ }
+ GLuint64 time_elapsed;
+ glGetQueryObjectui64v(phase->timer_query_object, GL_QUERY_RESULT, &time_elapsed);
+ phase->time_elapsed_ns += time_elapsed;
+ ++phase->num_measured_iterations;
+ }
+ }
+}
+
+void EffectChain::enable_phase_timing(bool enable)
+{
+ if (enable) {
+ assert(movit_timer_queries_supported);
+ }
+ this->do_phase_timing = enable;
+}
+
+void EffectChain::reset_phase_timing()
+{
+ for (unsigned phase_num = 0; phase_num < phases.size(); ++phase_num) {
+ Phase *phase = phases[phase_num];
+ phase->time_elapsed_ns = 0;
+ phase->num_measured_iterations = 0;
+ }
+}
+
+void EffectChain::print_phase_timing()
+{
+ double total_time_ms = 0.0;
+ for (unsigned phase_num = 0; phase_num < phases.size(); ++phase_num) {
+ Phase *phase = phases[phase_num];
+ double avg_time_ms = phase->time_elapsed_ns * 1e-6 / phase->num_measured_iterations;
+ printf("Phase %d: %5.1f ms [", phase_num, avg_time_ms);
+ for (unsigned effect_num = 0; effect_num < phase->effects.size(); ++effect_num) {
+ if (effect_num != 0) {
+ printf(", ");
+ }
+ printf("%s", phase->effects[effect_num]->effect->effect_type_id().c_str());