]> git.sesse.net Git - nageru/blobdiff - futatabi/flow.cpp
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / flow.cpp
index 5125d26b53a5d2f09bde21132136d2a6ec333b5c..8ae7bfc259fcfd9ddc3c4ea2b52cf11787b43ddf 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "embedded_files.h"
 #include "gpu_timers.h"
+#include "shared/read_file.h"
 #include "util.h"
 
 #include <algorithm>
@@ -42,7 +43,7 @@ GLuint vertex_vbo;
 int find_num_levels(int width, int height)
 {
        int levels = 1;
-       for (int w = width, h = height; w > 1 || h > 1; ) {
+       for (int w = width, h = height; w > 1 || h > 1;) {
                w >>= 1;
                h >>= 1;
                ++levels;
@@ -50,53 +51,6 @@ int find_num_levels(int width, int height)
        return levels;
 }
 
-string read_file(const string &filename, const unsigned char *start = nullptr, const size_t size = 0)
-{
-       FILE *fp = fopen(filename.c_str(), "r");
-       if (fp == nullptr) {
-               // Fall back to the version we compiled in. (We prefer disk if we can,
-               // since that makes it possible to work on shaders without recompiling
-               // all the time.)
-               if (start != nullptr) {
-                       return string(reinterpret_cast<const char *>(start),
-                               reinterpret_cast<const char *>(start) + size);
-               }
-
-               perror(filename.c_str());
-               exit(1);
-       }
-
-       int ret = fseek(fp, 0, SEEK_END);
-       if (ret == -1) {
-               perror("fseek(SEEK_END)");
-               exit(1);
-       }
-
-       int disk_size = ftell(fp);
-
-       ret = fseek(fp, 0, SEEK_SET);
-       if (ret == -1) {
-               perror("fseek(SEEK_SET)");
-               exit(1);
-       }
-
-       string str;
-       str.resize(disk_size);
-       ret = fread(&str[0], disk_size, 1, fp);
-       if (ret == -1) {
-               perror("fread");
-               exit(1);
-       }
-       if (ret == 0) {
-               fprintf(stderr, "Short read when trying to read %d bytes from %s\n",
-                       disk_size, filename.c_str());
-               exit(1);
-       }
-       fclose(fp);
-
-       return str;
-}
-
 GLuint compile_shader(const string &shader_src, GLenum type)
 {
        GLuint obj = glCreateShader(type);
@@ -129,7 +83,7 @@ GLuint compile_shader(const string &shader_src, GLenum type)
                }
 
                fprintf(stderr, "Failed to compile shader:\n%s\n", src_with_lines.c_str());
-               exit(1);
+               abort();
        }
 
        return obj;
@@ -144,10 +98,10 @@ GLuint link_program(GLuint vs_obj, GLuint fs_obj)
        GLint success;
        glGetProgramiv(program, GL_LINK_STATUS, &success);
        if (success == GL_FALSE) {
-               GLchar error_log[1024] = {0};
+               GLchar error_log[1024] = { 0 };
                glGetProgramInfoLog(program, 1024, nullptr, error_log);
                fprintf(stderr, "Error linking program: %s\n", error_log);
-               exit(1);
+               abort();
        }
        return program;
 }
@@ -315,8 +269,8 @@ void Densify::exec(GLuint tex_view, GLuint flow_tex, GLuint dense_flow_tex, int
        bind_sampler(densify_program, uniform_flow_tex, 1, flow_tex, nearest_sampler);
 
        glProgramUniform2f(densify_program, uniform_patch_size,
-               float(op.patch_size_pixels) / level_width,
-               float(op.patch_size_pixels) / level_height);
+                          float(op.patch_size_pixels) / level_width,
+                          float(op.patch_size_pixels) / level_height);
 
        glViewport(0, 0, level_width, level_height);
        glEnable(GL_BLEND);
@@ -965,7 +919,8 @@ Interpolate::Interpolate(const OperatingPoint &op, bool split_ycbcr_output)
        : flow_level(op.finest_level),
          split_ycbcr_output(split_ycbcr_output),
          splat(op),
-         blend(split_ycbcr_output) {
+         blend(split_ycbcr_output)
+{
        // Set up the vertex data that will be shared between all passes.
        float vertices[] = {
                0.0f, 1.0f,