fixed shader manager, added it
[demo] / src / shader.h
1 #ifndef SHADER_H_
2 #define SHADER_H_
3
4 #include <vector>
5 #include <string>
6
7 #include <gmath/gmath.h>
8
9 /*
10         Shader class
11 */
12
13 enum SType {
14         SDR_UNKNOWN,
15         SDR_VERTEX,
16         SDR_FRAGMENT
17 };
18
19 class Shader {
20 protected:
21         SType type;
22         std::string name;
23
24         virtual bool create(char *buf, unsigned int bsz, const char *fname) = 0;
25
26 public:
27
28         Shader();
29         virtual ~Shader() = 0;
30
31         virtual bool load(const char *fname, SType type);
32         virtual void destroy() = 0;
33 };
34
35 /* Shader Program */
36
37 struct Uniform {
38         int location;
39         std::string name;
40         int state_idx;
41 };
42
43 class ShaderProgram {
44 protected:
45         Shader *shaders[2];
46         std::vector<Uniform> uniforms;
47
48 public:
49         ShaderProgram();
50         virtual ~ShaderProgram();
51
52         virtual void cache_uniforms() = 0;
53
54         virtual bool create() = 0;
55         virtual bool link() = 0;
56         virtual bool use() = 0;
57         virtual void destroy() = 0;
58         virtual void attach_shader(Shader *shader) = 0;
59
60         /*
61                 THIS PART MIGHT NEED SEVERAL CHANGES: on vulkan we set the uniforms
62                 using descriptor sets. The current design is suitable for OpenGL and
63                 it *might* have to be rewritten to work with both APIs later
64         */
65
66         virtual void set_uniformi(int location, int value) = 0;
67         virtual void set_uniformi(int location, int x, int y) = 0;
68         virtual void set_uniformi(int location, int x, int y, int z) = 0;
69         virtual void set_uniformi(int location, int x, int y, int z, int w) = 0;
70
71         virtual void set_uniformf(int location, float value) = 0;
72         virtual void set_uniformf(int location, float x, float y) = 0;
73         virtual void set_uniformf(int location, float x, float y, float z) = 0;
74         virtual void set_uniformf(int location, float x, float y, float z, float w) = 0;
75
76         virtual void set_uniform_matrix(int location, const Mat4 &mat) = 0;
77 };
78
79 ShaderProgram *get_current_program();
80
81 #endif // SHADER_H_