-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsh_matrix.cpp
More file actions
45 lines (36 loc) · 1.64 KB
/
sh_matrix.cpp
File metadata and controls
45 lines (36 loc) · 1.64 KB
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
#include "sh_matrix.h"
/**
* Sends a single 4x4 matrix of floats to the shader program
* @param programHandle, shader program handle
* @param uniformLable, null terminated string with the name of uniform in the shader program
* @param matrix, array of 16 floats to send to shader program
* @returns 0 for success, error otherwise
*/
int setUniformMatrix(unsigned int programHandle, const char *uniformLabel, float *matrix) {
// Get the uniform from the shader program
// All active uniforms can be found by name using this function
int uniformHandle = glGetUniformLocation(programHandle, uniformLabel);
if (uniformHandle == -1) {
std::cout << "Uniform: " << uniformLabel << " was not an active uniform label\n";
return 1;
}
// Set its value to the supplied matrix
// Note the function suffix *Matrix4fv, meaning a 4x4 matrix of floats
// There exists many forms of this function for sending different data-types/amounts
glUniformMatrix4fv( uniformHandle, 1, false, matrix );
return 0;
}
int setUniformMatrix3(unsigned int programHandle, const char *uniformLabel, float *matrix) {
// Get the uniform from the shader program
// All active uniforms can be found by name using this function
int uniformHandle = glGetUniformLocation(programHandle, uniformLabel);
if (uniformHandle == -1) {
std::cout << "Uniform: " << uniformLabel << " was not an active uniform label\n";
return 1;
}
// Set its value to the supplied matrix
// Note the function suffix *Matrix4fv, meaning a 4x4 matrix of floats
// There exists many forms of this function for sending different data-types/amounts
glUniformMatrix3fv( uniformHandle, 1, false, matrix );
return 0;
}