-
Notifications
You must be signed in to change notification settings - Fork 1
/
Shaders.h
99 lines (76 loc) · 2.09 KB
/
Shaders.h
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
#ifndef SHADERS_H
#define SHADERS_H
#include <OpenGL/GL.h>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <vector>
// Basically, create a shader program by calling
// ShaderProgram(vert_shader_filename, frag_shader_filename)
// and then when you want it to be active, call Use()
// on it. To go back to the default shader, call
// glUseProgram(0).
class Shader
{
protected:
GLuint m_object;
char *m_source;
public:
Shader();
virtual ~Shader();
std::string m_filename;
int Load(char *filename);
void Compile();
void Attach(GLuint program);
static Shader *Create(std::string filename);
static Shader *LoadAgnostic(char *filename);
friend class ShaderProgram;
};
class glVertexShader: public Shader
{
public:
glVertexShader();
glVertexShader(char *filename);
~glVertexShader();
};
class glGeometryShader: public Shader
{
public:
glGeometryShader();
glGeometryShader(char *filename);
~glGeometryShader();
};
class glFragmentShader: public Shader
{
public:
glFragmentShader();
glFragmentShader(char *filename);
~glFragmentShader();
};
//-----
class ShaderProgram
{
protected:
std::vector<Shader *> m_shaders;
GLuint m_object;
public:
ShaderProgram();
ShaderProgram(std::string vertex, std::string fragment);
ShaderProgram(Shader *vertex, Shader *fragment);
~ShaderProgram();
std::string m_filename;
GLuint GetObject();
void AddShader(std::string filename);
void AddShader(Shader *s);
void Link();
void Use();
void setUniform1f(GLuint u, GLfloat value);
void setUniform3f(GLuint u, GLfloat val1, GLfloat val2, GLfloat val3);
void setUniform4f(GLuint u, GLfloat val1, GLfloat val2, GLfloat val3, GLfloat val4);
void setUniform4fv(GLuint u, GLsizei count, GLfloat *value);
void setUniform1i(GLuint u, GLuint value);
void setUniformMatrix4fv(GLuint u, GLsizei count, GLboolean transpose, GLfloat *value);
GLuint getUniform(std::string name);
GLuint getAttribute(std::string name);
};
#endif