From ff4daae11db0ab811cac66e262d289a4107bba4a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 27 Dec 2017 23:48:41 +0100 Subject: Add uniform (shader global variable) --- include/RenderBackend/OpenGL/ShaderVec.hpp | 56 +++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'include/RenderBackend/OpenGL/ShaderVec.hpp') diff --git a/include/RenderBackend/OpenGL/ShaderVec.hpp b/include/RenderBackend/OpenGL/ShaderVec.hpp index a5163ba..7c14af1 100644 --- a/include/RenderBackend/OpenGL/ShaderVec.hpp +++ b/include/RenderBackend/OpenGL/ShaderVec.hpp @@ -8,15 +8,60 @@ namespace amalgine { class VertexShader; class PixelShader; + class ShaderProgram; enum class AttributeType { NONE, - VEC2 + VEC2, + VEC3, + VEC4 }; AttributeType getAttributeTypeByName(const char *attributeName); + class ShaderGlobalVec + { + friend class VertexShader; + friend class PixelShader; + friend class ShaderGlobalVec3; + public: + ShaderGlobalVec() : attributeType(AttributeType::NONE) {} + const std::string& getName() const { return name; } + AttributeType getAttributeType() const { return attributeType; } + protected: + ShaderGlobalVec(const std::string &_name, AttributeType _attributeType) : name(_name), attributeType(_attributeType) {} + private: + std::string name; + AttributeType attributeType; + }; + + class ShaderGlobalVec3 + { + friend class VertexShader; + friend class PixelShader; + public: + const std::string& getName() const { return globalVec.getName(); } + AttributeType getAttributeType() const { return globalVec.getAttributeType(); } + ShaderGlobalVec getVecObject() const { return globalVec; } + private: + ShaderGlobalVec3(const std::string &_name) : globalVec(_name, AttributeType::VEC3) {} + private: + ShaderGlobalVec globalVec; + }; + + class ShaderProgramGlobalVec3 + { + friend class ShaderProgram; + public: + void set(f32 x = 0.0f, f32 y = 0.0f, f32 z = 0.0f); + private: + ShaderProgramGlobalVec3(ShaderProgram *_shaderProgram, i32 _uniformId) : shaderProgram(_shaderProgram), uniformId(_uniformId){} + private: + ShaderProgram *shaderProgram; + i32 uniformId; + }; + class ShaderInputVec2 { friend class VertexShader; @@ -62,6 +107,15 @@ namespace amalgine result += ")"; } + ShaderVec4(const ShaderGlobalVec3 &vec3, f32 w = 0.0f) + { + result = "vec4("; + result += vec3.getName(); + result += ", "; + result += std::to_string(w); + result += ")"; + } + const std::string& getOutput() const { return result; -- cgit v1.2.3