- 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;
-}
-
-void combine_two_samples(float w1, float w2, float *offset, float *total_weight, float *sum_sq_error)
-{
- assert(movit_initialized);
- assert(w1 * w2 >= 0.0f); // Should not have differing signs.
- float z; // Just a shorter name for offset.
- if (fabs(w1 + w2) < 1e-6) {
- z = 0.5f;
- } else {
- z = w2 / (w1 + w2);
+ // 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();
+}
+
+GLuint generate_vbo(GLint size, GLenum type, GLsizeiptr data_size, const GLvoid *data)
+{
+ GLuint vbo;
+ glGenBuffers(1, &vbo);
+ check_error();
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ check_error();
+ glBufferData(GL_ARRAY_BUFFER, data_size, data, GL_STATIC_DRAW);
+ check_error();
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ check_error();
+
+ return vbo;
+}
+
+GLuint fill_vertex_attribute(GLuint glsl_program_num, const string &attribute_name, GLint size, GLenum type, GLsizeiptr data_size, const GLvoid *data)
+{
+ int attrib = glGetAttribLocation(glsl_program_num, attribute_name.c_str());
+ if (attrib == -1) {
+ return -1;