3dphotoshoot

view src/shader.h @ 27:3d082c566b53

fixed all the bugs, pc version works
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 18 Jun 2015 04:32:25 +0300
parents 4ca4e3c5a754
children
line source
1 #ifndef SHADER_H_
2 #define SHADER_H_
4 #include <vector>
5 #include "vmath/vmath.h"
7 enum SdrDefaultAttrib {
8 SDR_ATTR_VERTEX,
9 SDR_ATTR_NORMAL,
10 SDR_ATTR_TEXCOORD,
11 SDR_ATTR_COLOR,
12 SDR_ATTR_TANGENT
13 };
16 class SdrProg {
17 private:
18 std::vector<unsigned int> priv_sdr;
19 unsigned int prog;
20 mutable bool valid;
22 public:
23 static const SdrProg *active;
25 SdrProg();
26 ~SdrProg();
28 void create();
29 void destroy();
31 bool attach_shader(unsigned int sdr);
33 bool create(unsigned int vsdr, unsigned int psdr);
34 bool create(const char *vsrc, const char *psrc);
35 bool load(const char *vfname, const char *pfname);
37 bool link() const;
39 int get_uniform(const char *name) const;
40 int get_attrib(const char *name) const;
41 bool bind_attrib(const char *name, int loc) const;
42 void bind_default_attribs() const;
44 bool bind() const;
46 // helper functions for setting uniforms
47 void set_uniform(const char *name, int count, const int *val) const;
48 void set_uniform(const char *name, int count, const float *val) const;
49 void set_uniform(const char *name, const Vector4 &v) const;
51 void set_uniform1i(const char *name, int x) const;
52 void set_uniform2i(const char *name, int x, int y) const;
53 void set_uniform3i(const char *name, int x, int y, int z) const;
54 void set_uniform4i(const char *name, int x, int y, int z, int w) const;
56 void set_uniform1f(const char *name, float x) const;
57 void set_uniform2f(const char *name, float x, float y) const;
58 void set_uniform3f(const char *name, float x, float y, float z) const;
59 void set_uniform4f(const char *name, float x, float y, float z, float w) const;
61 void set_uniform_matrix(const char *name, const float *m) const;
62 void set_uniform_matrix(const char *name, const Matrix4x4 &m) const;
65 unsigned int get_globj() const { return prog; }
66 };
68 unsigned int get_shader(const char *name, unsigned int type);
70 SdrProg *get_sdrprog(const char *vfile, const char *pfile);
72 #endif /* SHADER_H_ */