From: Steinar H. Gunderson Date: Thu, 10 Jan 2013 17:48:07 +0000 (+0100) Subject: Change the .dot/.frag writing to be dependent on an init_movit() parameter instead... X-Git-Tag: 1.0~192 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=49ef2523611e215b327cd26f7bf698d1516edd46 Change the .dot/.frag writing to be dependent on an init_movit() parameter instead of being bound to assertion checking. --- diff --git a/demo.cpp b/demo.cpp index f5434cc..02c923c 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(".", MOVIT_DEBUG_ON); printf("GPU texture subpixel precision: about %.1f bits\n", log2(1.0f / movit_texel_subpixel_precision)); diff --git a/effect_chain.cpp b/effect_chain.cpp index 84b5c4e..dd7a652 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -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) { diff --git a/init.cpp b/init.cpp index a70ae05..e0302d3 100644 --- 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 e2b7f66..7cee858 100644 --- a/init.h +++ b/init.h @@ -3,21 +3,34 @@ #include +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. diff --git a/test_util.cpp b/test_util.cpp index 2ddf665..68e0b93 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(".", MOVIT_DEBUG_ON); if (data != NULL) { add_input(data, pixel_format, color_space, gamma_curve);