bloboland
diff src/shaders.h @ 1:cfe68befb7cc
some progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 15 Dec 2012 23:43:03 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/shaders.h Sat Dec 15 23:43:03 2012 +0200 1.3 @@ -0,0 +1,67 @@ 1.4 +#ifndef SDR_H_ 1.5 +#define SDR_H_ 1.6 + 1.7 +#include <vector> 1.8 +#include "vmath/vmath.h" 1.9 + 1.10 +class Shader { 1.11 +private: 1.12 + bool compiled; 1.13 + 1.14 +public: 1.15 + unsigned int sdr; 1.16 + 1.17 + Shader(unsigned int type); 1.18 + ~Shader(); 1.19 + 1.20 + void set_source(const char *src); 1.21 + 1.22 + bool compile(); 1.23 + bool is_compiled() const; 1.24 + 1.25 + bool load(const char *fname); 1.26 +}; 1.27 + 1.28 + 1.29 +// public shader manager interface 1.30 +Shader *get_shader(const char *fname, unsigned int type); 1.31 + 1.32 + 1.33 +class SdrProg { 1.34 +private: 1.35 + // SdrProg does not own the shader objects 1.36 + std::vector<Shader*> shaders; 1.37 + bool linked; 1.38 + 1.39 +public: 1.40 + unsigned int prog; 1.41 + 1.42 + SdrProg(); 1.43 + ~SdrProg(); 1.44 + 1.45 + void add_shader(Shader *sdr); 1.46 + bool link(); 1.47 + 1.48 + bool load(const char *vsfname, const char *psfname); 1.49 + 1.50 + int get_uniform_location(const char *name); 1.51 + int get_attribute_location(const char *name); 1.52 + 1.53 + void set_uniform(const char *name, int val); 1.54 + void set_uniform(const char *name, float val); 1.55 + void set_uniform(const char *name, const Vector2 &v); 1.56 + void set_uniform(const char *name, const Vector3 &v); 1.57 + void set_uniform(const char *name, const Vector4 &v); 1.58 + void set_uniform(const char *name, const Matrix4x4 &mat); 1.59 + 1.60 + void set_uniform(int loc, int val); 1.61 + void set_uniform(int loc, float val); 1.62 + void set_uniform(int loc, const Vector2 &v); 1.63 + void set_uniform(int loc, const Vector3 &v); 1.64 + void set_uniform(int loc, const Vector4 &v); 1.65 + void set_uniform(int loc, const Matrix4x4 &mat); 1.66 +}; 1.67 + 1.68 +bool bind_program(const SdrProg *prog); 1.69 + 1.70 +#endif /* SDR_H_ */