#include "embedded_files.h"
#include "gpu_timers.h"
+#include "shared/read_file.h"
#include "util.h"
#include <algorithm>
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;
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);
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);
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);
: 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,