From: Steinar H. Gunderson Date: Wed, 9 Jan 2013 19:21:13 +0000 (+0100) Subject: Allow data files to be fetched somewhere else than the current directory. X-Git-Tag: 1.0~194 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=5614a34b00bbcfdb3d0f5a7dc1fc4205e7088cdf Allow data files to be fetched somewhere else than the current directory. --- diff --git a/demo.cpp b/demo.cpp index 99fec55..f5434cc 100644 --- a/demo.cpp +++ b/demo.cpp @@ -155,7 +155,7 @@ int main(int argc, char **argv) SDL_SetVideoMode(WIDTH, HEIGHT, 0, SDL_OPENGL); SDL_WM_SetCaption("OpenGL window", NULL); - init_movit(); + init_movit("."); printf("GPU texture subpixel precision: about %.1f bits\n", log2(1.0f / movit_texel_subpixel_precision)); diff --git a/init.cpp b/init.cpp index a89028c..a70ae05 100644 --- a/init.cpp +++ b/init.cpp @@ -1,4 +1,5 @@ #include +#include #include "init.h" #include "util.h" @@ -7,6 +8,11 @@ bool movit_initialized = false; float movit_texel_subpixel_precision; bool movit_srgb_textures_supported; +// The rules for objects with nontrivial constructors in static scope +// are somewhat convoluted, and easy to mess up. We simply have a +// pointer instead (and never care to clean it up). +std::string *movit_data_directory = NULL; + namespace { void measure_texel_subpixel_precision() @@ -148,12 +154,14 @@ void check_extensions() } // namespace -void init_movit() +void init_movit(const std::string& data_directory) { if (movit_initialized) { return; } + movit_data_directory = new std::string(data_directory); + glewInit(); // geez diff --git a/init.h b/init.h index 9c371e0..e2b7f66 100644 --- a/init.h +++ b/init.h @@ -1,10 +1,17 @@ #ifndef _INIT_H #define _INIT_H +#include + // Initialize the library; in particular, will query the GPU for information // that is needed by various components. For instance, it verifies that // we have all the OpenGL extensions we need. -void init_movit(); +// +// The parameter gives which directory to read .frag files from. +// This is a temporary hack until we add something more solid. +// If you call init_movit() twice with different values for data_directory, +// only the first will count. +void init_movit(const std::string& data_directory); // GPU features. These are not intended for end-user use. diff --git a/test_util.cpp b/test_util.cpp index 9053c5e..2ddf665 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -29,7 +29,7 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned GLenum framebuffer_format) : chain(width, height), width(width), height(height), finalized(false) { - init_movit(); + init_movit("."); if (data != NULL) { add_input(data, pixel_format, color_space, gamma_curve); diff --git a/util.cpp b/util.cpp index 62e0efc..4e6a31c 100644 --- a/util.cpp +++ b/util.cpp @@ -7,6 +7,8 @@ #include "util.h" #include "init.h" +extern std::string *movit_data_directory; + void hsv2rgb(float h, float s, float v, float *r, float *g, float *b) { if (h < 0.0f) { @@ -65,10 +67,12 @@ void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b) std::string read_file(const std::string &filename) { + const std::string full_pathname = *movit_data_directory + "/" + filename; + static char buf[131072]; - FILE *fp = fopen(filename.c_str(), "r"); + FILE *fp = fopen(full_pathname.c_str(), "r"); if (fp == NULL) { - perror(filename.c_str()); + perror(full_pathname.c_str()); exit(1); }