]> git.sesse.net Git - movit/commitdiff
Allow data files to be fetched somewhere else than the current directory.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 9 Jan 2013 19:21:13 +0000 (20:21 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 9 Jan 2013 19:21:13 +0000 (20:21 +0100)
demo.cpp
init.cpp
init.h
test_util.cpp
util.cpp

index 99fec55470cf31d7690ce9a372f58ec6f7b71a95..f5434cc1dd5d40f293bd9b9ec2d5c21534e9b812 100644 (file)
--- 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));
        
index a89028c645eb1504a203b0562948a4693ebfa614..a70ae058bbf39ddd0eb0b0ae2ee31b3cafef0be9 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -1,4 +1,5 @@
 #include <GL/glew.h>
+#include <string>
 
 #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 9c371e0316b4b6987a4a2e70ab995127d399e9d2..e2b7f6636989b8afe38bd2751144c38c4f02c9c7 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1,10 +1,17 @@
 #ifndef _INIT_H
 #define _INIT_H
 
+#include <string>
+
 // 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.
 
index 9053c5e6d6e9f003d34c45299bc8cf494e8990f5..2ddf6651ece97b115d4f7bc60dfa20dd658e3427 100644 (file)
@@ -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);
index 62e0efcc314250505ea3513a159425e4a5a81580..4e6a31c70502cba2687197cba2549b791f4da98c 100644 (file)
--- 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);
        }