]> git.sesse.net Git - movit/blob - util.h
Make a pow() call unambiguous.
[movit] / util.h
1 #ifndef _MOVIT_UTIL_H
2 #define _MOVIT_UTIL_H 1
3
4 // Various utilities.
5
6 #include <GL/glew.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <Eigen/Core>
10 #include <string>
11
12 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
13
14 // Converts a HSV color to RGB. Assumes h in [0, 2pi> or [-pi, pi>
15 void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
16
17 // Converts a HSV color to RGB, but keeps luminance constant
18 // (ie. color luminance is as if S=0).
19 void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b);
20
21 // Read a file from disk and return its contents.
22 // Dies if the file does not exist.
23 std::string read_file(const std::string &filename);
24
25 // Compile the given GLSL shader (typically a vertex or fragment shader)
26 // and return the object number.
27 GLuint compile_shader(const std::string &shader_src, GLenum type);
28
29 // Print a 3x3 matrix to standard output. Useful for debugging.
30 void print_3x3_matrix(const Eigen::Matrix3d &m);
31
32 // Output a GLSL 3x3 matrix declaration.
33 std::string output_glsl_mat3(const std::string &name, const Eigen::Matrix3d &m);
34
35 // Calculate where to sample, and with what weight, if one wants to use
36 // the GPU's bilinear hardware to sample w1 * x[0] + w2 * x[1].
37 //
38 // Note that since the GPU might have limited precision in its linear
39 // interpolation, the effective weights might be different from the ones you
40 // asked for. sum_sq_error, if not NULL, will contain the sum of the
41 // (estimated) squared errors of the two weights.
42 void combine_two_samples(float w1, float w2, float *offset, float *total_weight, float *sum_sq_error);
43
44 #ifdef NDEBUG
45 #define check_error()
46 #else
47 #define check_error() { int err = glGetError(); if (err != GL_NO_ERROR) { printf("GL error 0x%x at %s:%d\n", err, __FILE__, __LINE__); exit(1); } }
48 #endif
49
50 // CHECK() is like assert(), but retains any side effects no matter the compilation mode.
51 #ifdef NDEBUG
52 #define CHECK(x) (void)(x)
53 #else
54 #define CHECK(x) do { bool ok = x; if (!ok) { fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #x); abort(); } } while (false)
55 #endif
56
57 #endif // !defined(_MOVIT_UTIL_H)