]> git.sesse.net Git - movit/blobdiff - util.cpp
If a shader fails to compile, output it for easier debugging.
[movit] / util.cpp
index 3ebf162d31a0558ddfb54d3a8520706035ee45e6..0a294e65ca7a8ab07a77ab1438286038848ea7a2 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -156,6 +156,7 @@ GLuint compile_shader(const string &shader_src, GLenum type)
        GLint status;
        glGetShaderiv(obj, GL_COMPILE_STATUS, &status);
        if (status == GL_FALSE) {
+               fprintf(stderr, "Failed to compile shader: %s\n", shader_src.c_str());
                exit(1);
        }
 
@@ -183,6 +184,16 @@ string output_glsl_mat3(const string &name, const Eigen::Matrix3d &m)
        return ss.str();
 }
 
+string output_glsl_float(const string &name, float x)
+{
+       // Use stringstream to be independent of the current locale in a thread-safe manner.
+       stringstream ss;
+       ss.imbue(locale("C"));
+       ss.precision(8);
+       ss << "const float " << name << " = " << x << ";\n";
+       return ss.str();
+}
+
 string output_glsl_vec2(const string &name, float x, float y)
 {
        // Use stringstream to be independent of the current locale in a thread-safe manner.