File: effect_util.cpp

package info (click to toggle)
movit 1.7.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,248 kB
  • sloc: cpp: 16,677; sh: 3,940; makefile: 167
file content (114 lines) | stat: -rw-r--r-- 2,929 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <epoxy/gl.h>
#include <Eigen/Core>
#include <stddef.h>
#include <string>
#include "util.h"

using namespace std;

namespace movit {

GLint get_uniform_location(GLuint glsl_program_num, const string &prefix, const string &key)
{
	string name = prefix + "_" + key;
	return glGetUniformLocation(glsl_program_num, name.c_str());
}

void set_uniform_int(GLuint glsl_program_num, const string &prefix, const string &key, int value)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform1i(location, value);
	check_error();
}

void set_uniform_float(GLuint glsl_program_num, const string &prefix, const string &key, float value)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform1f(location, value);
	check_error();
}

void set_uniform_vec2(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform2fv(location, 1, values);
	check_error();
}

void set_uniform_vec3(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform3fv(location, 1, values);
	check_error();
}

void set_uniform_vec4(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform4fv(location, 1, values);
	check_error();
}

void set_uniform_vec2_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform2fv(location, num_values, values);
	check_error();
}

void set_uniform_vec4_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();
	glUniform4fv(location, num_values, values);
	check_error();
}

void set_uniform_mat3(GLuint glsl_program_num, const string &prefix, const string &key, const Eigen::Matrix3d& matrix)
{
	GLint location = get_uniform_location(glsl_program_num, prefix, key);
	if (location == -1) {
		return;
	}
	check_error();

	// Convert to float (GLSL has no double matrices).
	float matrixf[9];
	for (unsigned y = 0; y < 3; ++y) {
		for (unsigned x = 0; x < 3; ++x) {
			matrixf[y + x * 3] = matrix(y, x);
		}
	}

	glUniformMatrix3fv(location, 1, GL_FALSE, matrixf);
	check_error();
}

}  // namespace movit