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
|
#pragma once
#include <GL/glew.h>
#include <string>
#include <vector>
#include "mathlib.h"
typedef GLuint Shader;
Shader loadShader(const GLchar* vertexShader, const GLchar* fragmentShader);
inline GLint getShaderUniform(const Shader& shader, const GLchar *name) {
GLint uid = glGetUniformLocation(shader, name);
if (uid < 0) {
return -1;
}
return uid;
}
inline GLint getShaderAttribute(const Shader& shader, const GLchar *name) {
printf("Getting attribute for shader, name: %d, %s\n", shader, name);
GLint uid = glGetAttribLocation(shader, name);
if (uid < 0) {
printf("Unable to get attribute %s for shader %d\n", name, shader);
return -1;
}
return uid;
}
inline void useShader(const Shader& shader) {
glUseProgram(shader);
}
inline void setShaderFloat(GLint location, GLfloat value) {
glUniform1f(location, value);
}
inline void setShaderInt(GLint location, GLint value) {
glUniform1i(location, value);
}
inline void setShaderUint(GLint location, GLuint value) {
glUniform1ui(location, value);
}
inline void setShaderVec2(GLint location, const Vector2& value) {
glUniform2f(location, value.x, value.y);
}
inline void setShaderMat4(GLint location, const Mat4x4& matrix) {
glUniformMatrix4fv(location, 1, GL_FALSE, matrix.m);
}
inline void setShaderBVec3(GLint location, bool first, bool second, bool third) {
glUniform3i(location, first, second, third);
}
inline void setShaderBVec4(GLint location, bool first, bool second, bool third, bool fourth) {
glUniform4i(location, first, second, third, fourth);
}
inline void setShaderBool(GLint location, bool value) {
glUniform1i(location, value);
}
|