- // Compute the interpolated frame.
- qf.flow_tex = compute_flow->exec(resources->gray_tex, DISComputeFlow::FORWARD_AND_BACKWARD, DISComputeFlow::DO_NOT_RESIZE_FLOW);
- check_error();
+ GLuint flow_tex;
+ if (last_flow_tex != 0 && frame1 == last_frame1 && frame2 == last_frame2) {
+ // Reuse the flow from previous computation. This frequently happens
+ // if we slow down by more than 2x, so that there are multiple interpolated
+ // frames between each original.
+ flow_tex = last_flow_tex;
+ qf.flow_tex = 0;
+ } else {
+ // Cache miss, so release last_flow_tex.
+ qf.flow_tex = last_flow_tex;
+
+ // Compute the flow.
+ flow_tex = compute_flow->exec(resources->gray_tex, DISComputeFlow::FORWARD_AND_BACKWARD, DISComputeFlow::DO_NOT_RESIZE_FLOW);
+ check_error();
+
+ // Store the flow texture for possible reuse next frame.
+ last_flow_tex = flow_tex;
+ last_frame1 = frame1;
+ last_frame2 = frame2;
+ }