- char buf[1024];
- sprintf(buf,
- "const mat3 %s = mat3(\n"
- " %.8f, %.8f, %.8f,\n"
- " %.8f, %.8f, %.8f,\n"
- " %.8f, %.8f, %.8f);\n\n",
- name.c_str(),
- m(0,0), m(1,0), m(2,0),
- m(0,1), m(1,1), m(2,1),
- m(0,2), m(1,2), m(2,2));
- return buf;
+ // Use stringstream to be independent of the current locale in a thread-safe manner.
+ stringstream ss;
+ ss.imbue(locale("C"));
+ ss.precision(8);
+ ss << scientific;
+ ss << "const mat3 " << name << " = mat3(\n";
+ ss << " " << m(0,0) << ", " << m(1,0) << ", " << m(2,0) << ",\n";
+ ss << " " << m(0,1) << ", " << m(1,1) << ", " << m(2,1) << ",\n";
+ ss << " " << m(0,2) << ", " << m(1,2) << ", " << m(2,2) << ");\n\n";
+ 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 << scientific;
+ 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.
+ stringstream ss;
+ ss.imbue(locale("C"));
+ ss.precision(8);
+ ss << scientific;
+ ss << "const vec2 " << name << " = vec2(" << x << ", " << y << ");\n";
+ return ss.str();
+}
+
+string output_glsl_vec3(const string &name, float x, float y, float z)
+{
+ // Use stringstream to be independent of the current locale in a thread-safe manner.
+ stringstream ss;
+ ss.imbue(locale("C"));
+ ss.precision(8);
+ ss << scientific;
+ ss << "const vec3 " << name << " = vec3(" << x << ", " << y << ", " << z << ");\n";
+ return ss.str();