backup
[demo] / src / shader.h
1 #ifndef SHADER_H_
2 #define SHADER_H_
3
4 #include <vulkan/vulkan.h>
5
6 #include <vector>
7 #include <string>
8
9 #include <gmath/gmath.h>
10
11 /*
12         Shader class
13 */
14
15 enum SType {
16         SDR_UNKNOWN,
17         SDR_VERTEX,
18         SDR_FRAGMENT
19 };
20
21 class Shader {
22 protected:
23         SType type;
24         std::string name;
25
26         virtual bool create(char *buf, unsigned int bsz, const char *fname) = 0;
27
28 public:
29
30         Shader();
31         virtual ~Shader() = 0;
32
33         virtual bool load(const char *fname, SType type);
34         virtual void destroy() = 0;
35         virtual SType get_type();
36 };
37
38 /* Shader Program */
39
40 struct Uniform {
41         int location;
42         std::string name;
43         int state_idx;
44 };
45
46 class ShaderProgram {
47 protected:
48         Shader *shaders[2];
49         std::vector<Uniform> uniforms;
50
51 public:
52         ShaderProgram();
53         virtual ~ShaderProgram();
54
55         virtual bool create() = 0;
56         virtual bool link() = 0;
57         virtual bool use() const = 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         virtual int get_uniform_location(const char *name) const = 0;
67
68         virtual void set_uniformi(int location, int value) = 0;
69         virtual void set_uniformi(int location, int x, int y) = 0;
70         virtual void set_uniformi(int location, int x, int y, int z) = 0;
71         virtual void set_uniformi(int location, int x, int y, int z, int w) = 0;
72
73         virtual void set_uniformf(int location, float value) = 0;
74         virtual void set_uniformf(int location, float x, float y) = 0;
75         virtual void set_uniformf(int location, float x, float y, float z) = 0;
76         virtual void set_uniformf(int location, float x, float y, float z, float w) = 0;
77
78         virtual void set_uniform_matrix(int location, const Mat4 &mat) = 0;
79 };
80
81 #endif // SHADER_H_