-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.hpp
73 lines (55 loc) · 1.88 KB
/
shader.hpp
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
#ifndef SHADER_H
#define SHADER_H
#include <map>
#include <string>
#include <iostream>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <conf.hpp>
#define SHADER_SSO(size,stride,offset) \
(((size)&0x1f) | (((stride)&0x1f) << 5) | (((offset)&0x1f) << 10))
#define SHADER_SSO_SIZE(sso) ((sso)&0x1f)
#define SHADER_SSO_STRIDE(sso) (((sso) >> 5)&0x1f)
#define SHADER_SSO_OFFSET(sso) (((sso) >> 10)&0x1f)
class Shader;
class GLEntity {
public:
virtual void bind(Shader *shader) = 0;
};
class Object;
class Shader {
public:
Shader();
Shader(std::string src);
Shader(std::string vSrc, std::string fSrc);
Shader(const ShaderConf& conf);
virtual ~Shader();
void requireAttr(std::string name);
void requireAttr(std::string name, int loc);
void requireUniform(std::string name);
void requireUniform(std::string name, int loc);
void bind(GLEntity *entity);
void setVertShader(std::string src);
void setFragShader(std::string src);
void setUniform(std::string name, const glm::vec3& v);
void setUniform(std::string name, float x, float y, float z);
void setUniform(std::string name, bool v);
void setUniform(std::string name, int v);
void setUniform(std::string name, const glm::mat4& m);
void bindVertexData(std::string name, unsigned int vbo);
void bindVertexData(std::string name, unsigned int vbo, int sso);
void bindIndexData(unsigned int vbo);
void unbindVertexData(std::string name);
virtual void draw(Object *obj);
protected:
int resolveUniform(std::string name);
int resolveAttribute(std::string name);
void recompile();
void use();
bool hasVert, hasFrag, hasProgram;
GLuint shadVert, shadFrag, program;
std::map<std::string,unsigned int> uMap;
std::map<std::string,unsigned int> aMap;
static Shader *inUse;
};
#endif /* SHADER_H */