- DISComputeFlow compute_flow(width1, height1);
- GLuint final_tex = compute_flow.exec(tex0, tex1);
-
- schedule_read(final_tex, width1, height1, filename0, filename1, flow_filename, "flow.ppm");
- compute_flow.release_texture(final_tex);
-
- // See if there are more flows on the command line (ie., more than three arguments),
- // and if so, process them.
- int num_flows = (argc - optind) / 3;
- for (int i = 1; i < num_flows; ++i) {
- const char *filename0 = argv[optind + i * 3 + 0];
- const char *filename1 = argv[optind + i * 3 + 1];
- const char *flow_filename = argv[optind + i * 3 + 2];
- GLuint width, height;
- GLuint tex0 = load_texture(filename0, &width, &height);
- if (width != width1 || height != height1) {
- fprintf(stderr, "%s: Image dimensions don't match (%dx%d versus %dx%d)\n",
- filename0, width, height, width1, height1);
- exit(1);
+ GLint position_attrib = 0; // Hard-coded in every vertex shader.
+ glEnableVertexArrayAttrib(vao, position_attrib);
+ glVertexAttribPointer(position_attrib, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
+}
+
+pair<GLuint, GLuint> Interpolate::exec(GLuint image_tex, GLuint gray_tex, GLuint bidirectional_flow_tex, GLuint width, GLuint height, float alpha)
+{
+ GPUTimers timers;
+
+ ScopedTimer total_timer("Interpolate", &timers);
+
+ glBindVertexArray(vao);
+ glDisable(GL_DITHER);
+
+ // Pick out the right level to test splatting results on.
+ GLuint tex_view;
+ glGenTextures(1, &tex_view);
+ glTextureView(tex_view, GL_TEXTURE_2D_ARRAY, gray_tex, GL_R8, flow_level, 1, 0, 2);
+
+ int flow_width = width >> flow_level;
+ int flow_height = height >> flow_level;
+
+ GLuint flow_tex = pool.get_texture(GL_RG16F, flow_width, flow_height);
+ GLuint depth_rb = pool.get_renderbuffer(GL_DEPTH_COMPONENT16, flow_width, flow_height); // Used for ranking flows.
+
+ {
+ ScopedTimer timer("Splat", &total_timer);
+ splat.exec(tex_view, bidirectional_flow_tex, flow_tex, depth_rb, flow_width, flow_height, alpha);
+ }
+ glDeleteTextures(1, &tex_view);
+
+ GLuint temp_tex[3];
+ temp_tex[0] = pool.get_texture(GL_RG16F, flow_width, flow_height);
+ temp_tex[1] = pool.get_texture(GL_RG16F, flow_width, flow_height);
+ temp_tex[2] = pool.get_texture(GL_RG16F, flow_width, flow_height);
+
+ {
+ ScopedTimer timer("Fill holes", &total_timer);
+ hole_fill.exec(flow_tex, depth_rb, temp_tex, flow_width, flow_height);
+ hole_blend.exec(flow_tex, depth_rb, temp_tex, flow_width, flow_height);
+ }
+
+ pool.release_texture(temp_tex[0]);
+ pool.release_texture(temp_tex[1]);
+ pool.release_texture(temp_tex[2]);
+ pool.release_renderbuffer(depth_rb);
+
+ GLuint output_tex, output2_tex = 0;
+ if (split_ycbcr_output) {
+ output_tex = pool.get_texture(GL_R8, width, height);
+ output2_tex = pool.get_texture(GL_RG8, width, height);
+ {
+ ScopedTimer timer("Blend", &total_timer);
+ blend.exec(image_tex, flow_tex, output_tex, output2_tex, width, height, alpha);
+ }
+ } else {
+ output_tex = pool.get_texture(GL_RGBA8, width, height);
+ {
+ ScopedTimer timer("Blend", &total_timer);
+ blend.exec(image_tex, flow_tex, output_tex, 0, width, height, alpha);
+ }
+ }
+ pool.release_texture(flow_tex);
+ total_timer.end();
+ if (!in_warmup) {
+ timers.print();
+ }
+
+ return make_pair(output_tex, output2_tex);
+}
+
+GLuint TexturePool::get_texture(GLenum format, GLuint width, GLuint height, GLuint num_layers)
+{
+ {
+ lock_guard<mutex> lock(mu);
+ for (Texture &tex : textures) {
+ if (!tex.in_use && !tex.is_renderbuffer && tex.format == format &&
+ tex.width == width && tex.height == height && tex.num_layers == num_layers) {
+ tex.in_use = true;
+ return tex.tex_num;
+ }