5 #include <gmath/gmath.h>
12 void bind_shader(const ShaderProg *sdr);
13 const ShaderProg *get_current_shader();
26 unsigned int get_id() const;
27 unsigned int get_type() const;
29 void set_name(const char *name);
30 const char *get_name() const;
32 void set_source(const char *src);
33 const char *get_source() const;
35 bool create(const char *src, unsigned int type);
38 bool load(const char *fname, unsigned int type);
40 friend bool load_shader(Shader*, const char*, unsigned int);
43 #define VSDR(s) s, GL_VERTEX_SHADER
44 #define FSDR(s) s, GL_FRAGMENT_SHADER
45 #define PSDR(s) FSDR(s)
46 #define GSDR(s) s, GL_GEOMETRY_SHADER
47 #define TCSDR(s) s, GL_TESS_CONTROL_SHADER
48 #define TESDR(s) s, GL_TESS_EVALUATION_SHADER
53 mutable bool must_link;
54 std::vector<Shader*> shaders;
56 struct StateLocCache { int sidx, loc; };
57 /** a cache of all st_ prefixed uniform locations and their corresponding
58 * index in the global uniform state vector (see unistate.h)
60 mutable std::vector<StateLocCache> stloc_cache;
62 void cache_state_uniforms() const;
63 void setup_state_uniforms() const;
66 static ShaderProg *current;
71 /// returns the OpenGL object id for this shader program
72 unsigned int get_id() const;
74 /** takes a series of shaders, and constructs a program object by linking
75 * them together. Terminate with a null pointer (don't use 0!) */
76 bool create(Shader *sdr, ...);
77 /// same as above, but with a va_list instead of variable arguments.
78 bool create(Shader *sdr, va_list ap);
79 /** takes two shaders (vertex and pixel) and constructs a program object by
80 * linking them together. Either one can be null. */
81 bool create(Shader *vsdr, Shader *psdr);
83 /** takes a series of shader source/shader type pairs and constructs a program
84 * object by linking them together. Terminate with a null pointer (don't use 0!)
85 * You can use the VSDR, PSDR, GSDR, TCSDR, TESDR convenience macros for passing
87 * Example: create(VSDR(vsrc0), VSDR(vsrc1), PSDR(psrc), NULL);
89 bool create(const char *src, unsigned int type, ...);
90 /// same as above, but with a va_list instead of variable arguments.
91 bool create(const char *src, unsigned int type, va_list ap);
92 /** takes two shaders source strings (vertex and pixel) and constructs
93 * a program object by linking them together. Either one can be null. */
94 bool create(const char *vsrc, const char *psrc);
98 /** takes a series of shader filename/shader type pairs, loads the shaders and
99 * constructs a program object by linking them together. Terminate with a null
100 * pointer (don't use 0!). You can use the VSDR, PSDR, GSDR, TCSDR, TESDR convenience
101 * macros for passing the pairs.
102 * Example: load(VSDR("vsdr1.glsl"), VSDR("vsdr2.glsl"), PSDR("pixel.glsl"), NULL);
104 bool load(const char *fname, unsigned int type, ...);
105 /// same as above, but with a va_list instead of variable arguments.
106 bool load(const char *fname, unsigned int type, va_list ap);
107 /** takes the filenames of two shader files (vertex and pixel), loads them and
108 * constructs a program object by linking them together. Either one can be null */
109 bool load(const char *vsrc, const char *psrc);
111 void add_shader(Shader *sdr);
116 int get_attrib_location(const char *name) const;
117 void set_attrib_location(const char *name, int loc) const;
119 int get_uniform_location(const char *name) const;
121 bool set_uniform(int loc, int val) const;
122 bool set_uniform(int loc, float val) const;
123 bool set_uniform(int loc, const Vec2 &v) const;
124 bool set_uniform(int loc, const Vec3 &v) const;
125 bool set_uniform(int loc, const Vec4 &v) const;
126 bool set_uniform(int loc, const Mat3 &m) const;
127 bool set_uniform(int loc, const Mat4 &m) const;
129 bool set_uniform(const char *name, int val) const;
130 bool set_uniform(const char *name, float val) const;
131 bool set_uniform(const char *name, const Vec2 &v) const;
132 bool set_uniform(const char *name, const Vec3 &v) const;
133 bool set_uniform(const char *name, const Vec4 &v) const;
134 bool set_uniform(const char *name, const Mat3 &m) const;
135 bool set_uniform(const char *name, const Mat4 &m) const;
137 friend void setup_unistate(const ShaderProg*);
140 class ShaderSet : public DataSet<Shader*> {
145 ShaderSet(unsigned int type);