]> git.sesse.net Git - movit/blobdiff - effect_chain.cpp
Properly restore the LC_NUMERIC locale after finalizing.
[movit] / effect_chain.cpp
index c6f1e89af7b2cbef25919ff922f9bc6c1bc2258c..a5c3bbdcb08fc29700119c1625892519da73b39a 100644 (file)
@@ -1,6 +1,6 @@
 #define GL_GLEXT_PROTOTYPES 1
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <assert.h>
 #include <locale.h>
 #include <math.h>
@@ -229,7 +229,7 @@ string replace_prefix(const string &text, const string &prefix)
 
 void EffectChain::compile_glsl_program(Phase *phase)
 {
-       string frag_shader = read_file("header.frag");
+       string frag_shader = read_version_dependent_file("header", "frag");
 
        // Create functions for all the texture inputs that we need.
        for (unsigned i = 0; i < phase->inputs.size(); ++i) {
@@ -240,7 +240,7 @@ void EffectChain::compile_glsl_program(Phase *phase)
        
                frag_shader += string("uniform sampler2D tex_") + effect_id + ";\n";
                frag_shader += string("vec4 ") + effect_id + "(vec2 tc) {\n";
-               frag_shader += "\treturn texture2D(tex_" + string(effect_id) + ", tc);\n";
+               frag_shader += "\treturn tex2D(tex_" + string(effect_id) + ", tc);\n";
                frag_shader += "}\n";
                frag_shader += "\n";
        }
@@ -279,9 +279,10 @@ void EffectChain::compile_glsl_program(Phase *phase)
                frag_shader += "\n";
        }
        frag_shader += string("#define INPUT ") + phase->effect_ids[phase->effects.back()] + "\n";
-       frag_shader.append(read_file("footer.frag"));
+       frag_shader.append(read_version_dependent_file("footer", "frag"));
 
-       phase->glsl_program_num = resource_pool->compile_glsl_program(read_file("vs.vert"), frag_shader);
+       string vert_shader = read_version_dependent_file("vs", "vert");
+       phase->glsl_program_num = resource_pool->compile_glsl_program(vert_shader, frag_shader);
 }
 
 // Construct GLSL programs, starting at the given effect and following
@@ -1331,7 +1332,11 @@ void EffectChain::finalize()
 {
        // Save the current locale, and set it to C, so that we can output decimal
        // numbers with printf and be sure to get them in the format mandated by GLSL.
-       char *saved_locale = setlocale(LC_NUMERIC, "C");
+       // Note that the OpenGL driver might call setlocale() behind-the-scenes,
+       // and that might corrupt the returned pointer, so we need to take our own
+       // copy of it here.
+       char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL));
+       setlocale(LC_NUMERIC, "C");
 
        // Output the graph as it is before we do any conversions on it.
        output_dot("step0-start.dot");
@@ -1396,6 +1401,7 @@ void EffectChain::finalize()
        
        finalized = true;
        setlocale(LC_NUMERIC, saved_locale);
+       free(saved_locale);
 }
 
 void EffectChain::render_to_fbo(GLuint dest_fbo, unsigned width, unsigned height)