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         virtual bool create(char *buf, unsigned int bsz, const char *fname) = 0;
22
23 public:
24         SType type;
25
26         Shader();
27         virtual ~Shader() = 0;
28
29         virtual bool load(const char *fname, SType type);
30         virtual void destroy() = 0;
31 };
32
33 /* Shader Program */
34
35 struct Uniform {
36         int location;
37         std::string name;
38         int state_idx;
39 };
40
41 class ShaderProgram {
42 protected:
43         Shader *shaders[2];
44         std::vector<Uniform> uniforms;
45
46 public:
47         ShaderProgram();
48         virtual ~ShaderProgram();
49
50         virtual void cache_uniforms() = 0;
51
52         virtual void add_shader(Shader *sdr);
53         virtual void delete_shaders() = 0;
54
55         virtual bool create() = 0;
56         virtual bool link() = 0;
57         virtual bool use() = 0;
58         virtual void destroy() = 0;
59         virtual void attach_shader(Shader *shader) = 0;
60
61         /*
62                 THIS PART MIGHT NEED SEVERAL CHANGES: on vulkan we set the uniforms
63                 using descriptor sets. The current design is suitable for OpenGL and
64                 it *might* have to be rewritten to work with both APIs later
65         */
66
67         virtual void set_uniformi(int location, int value) = 0;
68         virtual void set_uniformi(int location, int x, int y) = 0;
69         virtual void set_uniformi(int location, int x, int y, int z) = 0;
70         virtual void set_uniformi(int location, int x, int y, int z, int w) = 0;
71
72         virtual void set_uniformf(int location, float value) = 0;
73         virtual void set_uniformf(int location, float x, float y) = 0;
74         virtual void set_uniformf(int location, float x, float y, float z) = 0;
75         virtual void set_uniformf(int location, float x, float y, float z, float w) = 0;
76
77         virtual void set_uniform_matrix(int location, const Mat4 &mat) = 0;
78 };
79
80 ShaderProgram *get_current_program();
81
82 #endif // SHADER_H_