-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShader.h
99 lines (74 loc) · 2.58 KB
/
Shader.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
#ifndef _SHADER_H
#define _SHADER_H
#include <string>
#include <list>
#include <memory>
#include "math/common.h"
#include "GfxAPI.h"
class Shader
{
public:
enum eType {
NO_TYPE = 0,
FRAGMENT,
VERTEX,
GEOMETRY
};
protected:
unsigned int m_ID;
eType m_Type;
public:
Shader();
Shader(std::string fn, eType type, unsigned int flags = 0);
virtual ~Shader();
void nullify();
//enum {
// L_COMPILE = BIT(1)
//};
bool load(std::string fn, eType type, unsigned int flags = 0);
//bool compile();
void unload();
bool good() const { return m_ID!=0; }
bool bad() const { return m_ID==0; }
unsigned int id() const { return m_ID; }
};
class Program
{
public:
typedef int UniformID;
static bool isValidUniformID(UniformID u) { return (int)u >= 0; }
protected:
unsigned int m_ID;
std::list<std::shared_ptr<Shader>> m_Shaders;
public:
Program();
virtual ~Program();
bool attach(std::unique_ptr<Shader>&& shader);
bool link();
bool use();
void unload();
bool good() const { return m_ID!=0; }
bool bad() const { return m_ID==0; }
void nullify();
unsigned int id() const { return m_ID; }
void attribute(unsigned int index, std::string name) {
glBindAttribLocation(m_ID, index, name.c_str());
}
UniformID uniform(std::string n);
static void uniform(UniformID uid, float v);
static void uniform(UniformID uid, float v, float v2);
static void uniform(UniformID uid, float v, float v2, float v3);
static void uniform(UniformID uid, float v, float v2, float v3, float v4);
static void uniform(UniformID uid, int v);
static void uniform(UniformID uid, int v, int v2);
static void uniform(UniformID uid, int v, int v2, int v3);
static void uniform(UniformID uid, int v, int v2, int v3, int v4);
static void uniform(UniformID uid, glm::mat4& matrix);
static void uniform(UniformID uid, glm::vec3& vec);
static void uniform(UniformID uid, glm::vec4& vec);
// glUniform{size}{f|i}({uid},{count},{v})
static void uniform(UniformID uid, unsigned int size, unsigned int count, const int* v);
static void uniform(UniformID uid, unsigned int size, unsigned int count, const float* v);
static void unuseAll() { glUseProgram(0); }
};
#endif