quick backup
[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 bool create() = 0;
53         virtual bool link() = 0;
54         virtual bool use() const = 0;
55         virtual void destroy() = 0;
56         virtual void attach_shader(Shader *shader) = 0;
57
58         /*
59                 THIS PART MIGHT NEED SEVERAL CHANGES: on vulkan we set the uniforms
60                 using descriptor sets. The current design is suitable for OpenGL and
61                 it *might* have to be rewritten to work with both APIs later
62         */
63         virtual int get_uniform_location(const char *name) const = 0;
64
65         virtual void set_uniformi(int location, int value) = 0;
66         virtual void set_uniformi(int location, int x, int y) = 0;
67         virtual void set_uniformi(int location, int x, int y, int z) = 0;
68         virtual void set_uniformi(int location, int x, int y, int z, int w) = 0;
69
70         virtual void set_uniformf(int location, float value) = 0;
71         virtual void set_uniformf(int location, float x, float y) = 0;
72         virtual void set_uniformf(int location, float x, float y, float z) = 0;
73         virtual void set_uniformf(int location, float x, float y, float z, float w) = 0;
74
75         virtual void set_uniform_matrix(int location, const Mat4 &mat) = 0;
76 };
77
78 #endif // SHADER_H_