]> git.sesse.net Git - movit/commitdiff
Change the .dot/.frag writing to be dependent on an init_movit() parameter instead...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 10 Jan 2013 17:48:07 +0000 (18:48 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 10 Jan 2013 17:48:07 +0000 (18:48 +0100)
demo.cpp
effect_chain.cpp
init.cpp
init.h
test_util.cpp

index f5434cc1dd5d40f293bd9b9ec2d5c21534e9b812..02c923c4dba60c6a814ca9a990e56b270705e4eb 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(".", MOVIT_DEBUG_ON);
        printf("GPU texture subpixel precision: about %.1f bits\n",
                log2(1.0f / movit_texel_subpixel_precision));
        
index 84b5c4e74f3f3a1cf7bbfd32beb89c165c79a8c2..dd7a652804b4fc119019545fcd45744999a7ffd3 100644 (file)
@@ -18,6 +18,7 @@
 #include "colorspace_conversion_effect.h"
 #include "dither_effect.h"
 #include "input.h"
+#include "init.h"
 
 EffectChain::EffectChain(float aspect_nom, float aspect_denom)
        : aspect_nom(aspect_nom),
@@ -268,19 +269,19 @@ Phase *EffectChain::compile_glsl_program(
        frag_shader += std::string("#define INPUT ") + effects.back()->effect_id + "\n";
        frag_shader.append(read_file("footer.frag"));
 
-#ifndef NDEBUG
-       // Output shader to a temporary file, for easier debugging.
-       static int compiled_shader_num = 0;
-       char filename[256];
-       sprintf(filename, "chain-%03d.frag", compiled_shader_num++);
-       FILE *fp = fopen(filename, "w");
-       if (fp == NULL) {
-               perror(filename);
-               exit(1);
+       if (movit_debug_level == MOVIT_DEBUG_ON) {
+               // Output shader to a temporary file, for easier debugging.
+               static int compiled_shader_num = 0;
+               char filename[256];
+               sprintf(filename, "chain-%03d.frag", compiled_shader_num++);
+               FILE *fp = fopen(filename, "w");
+               if (fp == NULL) {
+                       perror(filename);
+                       exit(1);
+               }
+               fprintf(fp, "%s\n", frag_shader.c_str());
+               fclose(fp);
        }
-       fprintf(fp, "%s\n", frag_shader.c_str());
-       fclose(fp);
-#endif
        
        GLuint glsl_program_num = glCreateProgram();
        GLuint vs_obj = compile_shader(read_file("vs.vert"), GL_VERTEX_SHADER);
@@ -429,9 +430,9 @@ void EffectChain::construct_glsl_programs(Node *output)
 
 void EffectChain::output_dot(const char *filename)
 {
-#ifdef NDEBUG
-       return;
-#endif
+       if (movit_debug_level != MOVIT_DEBUG_ON) {
+               return;
+       }
 
        FILE *fp = fopen(filename, "w");
        if (fp == NULL) {
index a70ae058bbf39ddd0eb0b0ae2ee31b3cafef0be9..e0302d378a416421f97c8ceb158d52ad3f7d5d2d 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -5,6 +5,7 @@
 #include "util.h"
 
 bool movit_initialized = false;
+MovitDebugLevel movit_debug_level = MOVIT_DEBUG_ON;
 float movit_texel_subpixel_precision;
 bool movit_srgb_textures_supported;
 
@@ -154,13 +155,14 @@ void check_extensions()
 
 }  // namespace
 
-void init_movit(const std::string& data_directory)
+void init_movit(const std::string& data_directory, MovitDebugLevel debug_level)
 {
        if (movit_initialized) {
                return;
        }
 
        movit_data_directory = new std::string(data_directory);
+       movit_debug_level = debug_level;
 
        glewInit();
 
diff --git a/init.h b/init.h
index e2b7f6636989b8afe38bd2751144c38c4f02c9c7..7cee8587758331566d1b5b7e57db20e6f25aa2ab 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3,21 +3,34 @@
 
 #include <string>
 
+enum MovitDebugLevel {
+       MOVIT_DEBUG_OFF = 0,
+       MOVIT_DEBUG_ON = 1,
+};
+
 // 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.
 //
-// The parameter gives which directory to read .frag files from.
+// The first 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,
+//
+// The second parameter specifies whether debugging is on or off.
+// If it is on, Movit will write intermediate graphs and the final
+// generated shaders to the current directory.
+//
+// If you call init_movit() twice with different parameters,
 // only the first will count.
-void init_movit(const std::string& data_directory);
+void init_movit(const std::string& data_directory, MovitDebugLevel debug_level);
 
 // GPU features. These are not intended for end-user use.
 
 // Whether init_movit() has been called.
 extern bool movit_initialized;
 
+// The current debug level.
+extern MovitDebugLevel movit_debug_level;
+
 // An estimate on the smallest values the linear texture interpolation
 // of the GPU can distinguish between, i.e., for a GPU with N-bit
 // texture subpixel precision, this value will be 2^-N.
index 2ddf6651ece97b115d4f7bc60dfa20dd658e3427..68e0b93e3dd51e4aca8e07bb99bb5976ee719485 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(".", MOVIT_DEBUG_ON);
 
        if (data != NULL) {
                add_input(data, pixel_format, color_space, gamma_curve);