X-Git-Url: https://eleni.mutantstargoat.com/git/?a=blobdiff_plain;f=src%2Fshader.h;h=6e9509a141101de204910ee3d6d4b19dfcdd1139;hb=855c42d8e50fff743fd7b1be5e91cb0db18def77;hp=204d0538dab6fa523af925ef1caa84c37a1156e2;hpb=46cc932f7ddb0c81f352bc847973dae6b327ebeb;p=demo diff --git a/src/shader.h b/src/shader.h index 204d053..6e9509a 100644 --- a/src/shader.h +++ b/src/shader.h @@ -1,33 +1,81 @@ #ifndef SHADER_H_ #define SHADER_H_ +#include + +#include +#include + +#include + +/* + Shader class +*/ + enum SType { + SDR_UNKNOWN, SDR_VERTEX, SDR_FRAGMENT }; class Shader { -private: +protected: SType type; + std::string name; + + virtual bool create(char *buf, unsigned int bsz, const char *fname) = 0; public: + Shader(); - ~Shader(); + virtual ~Shader() = 0; virtual bool load(const char *fname, SType type); + virtual void destroy() = 0; + virtual SType get_type(); +}; + +/* Shader Program */ + +struct Uniform { + int location; + std::string name; + int state_idx; }; class ShaderProgram { -private: +protected: Shader *shaders[2]; + std::vector uniforms; public: ShaderProgram(); - virtual ~ShaderProgram() = 0; + virtual ~ShaderProgram(); + + virtual bool create() = 0; + virtual bool link() = 0; + virtual bool use() const = 0; + virtual void destroy() = 0; + virtual void attach_shader(Shader *shader) = 0; + + /* + THIS PART MIGHT NEED SEVERAL CHANGES: on vulkan we set the uniforms + using descriptor sets. The current design is suitable for OpenGL and + it *might* have to be rewritten to work with both APIs later + */ + virtual int get_uniform_location(const char *name) const = 0; + + virtual void set_uniformi(int location, int value) = 0; + virtual void set_uniformi(int location, int x, int y) = 0; + virtual void set_uniformi(int location, int x, int y, int z) = 0; + virtual void set_uniformi(int location, int x, int y, int z, int w) = 0; + + virtual void set_uniformf(int location, float value) = 0; + virtual void set_uniformf(int location, float x, float y) = 0; + virtual void set_uniformf(int location, float x, float y, float z) = 0; + virtual void set_uniformf(int location, float x, float y, float z, float w) = 0; - void add_shader(Shader *sdr, SType type); - bool link(); - void bind(); + virtual void set_uniform_matrix(int location, const Mat4 &mat) = 0; }; #endif // SHADER_H_