diff options
Diffstat (limited to 'Source/Asura.Engine/Graphics/Shader.h')
-rw-r--r-- | Source/Asura.Engine/Graphics/Shader.h | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h index 02d9f46..2cc482b 100644 --- a/Source/Asura.Engine/Graphics/Shader.h +++ b/Source/Asura.Engine/Graphics/Shader.h @@ -4,16 +4,18 @@ #include <map> #include <string> -#include "luax/luax.h" +#include "Scripting/Luax.hpp" +#include "Math/Vector2.h" +#include "Math/Vector3.h" +#include "Math/Vector4.h" +#include "Math/Matrix44.h" #include "StringMap.hpp" #include "Object.h" #include "Color.h" #include "Manager.hpp" #include "Texture.h" -#include "Math/Vector2.h" -#include "Math/Vector3.h" -#include "Math/Vector4.h" #include "GL.h" +#include "SimClass.h" namespace AsuraEngine { @@ -21,10 +23,10 @@ namespace AsuraEngine { /// - /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ÿ - /// shaderͨshaderҵuniforms¶frameworkmaterialá + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ + /// ÿshaderͨshaderҵuniforms¶frameworkmaterialá /// - class Shader : virtual public Object + class Shader final : virtual public Object, public SimClass { public: @@ -32,9 +34,10 @@ namespace AsuraEngine ~Shader(); /// - /// ӴshaderʱȼǷϴλuniforms location map + /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ + /// ɫ /// - void Load(const std::string& vertexShader, const std::string& fragmentShader); + bool Load(const std::string& vertexShader, const std::string& fragmentShader); /// /// shaderΪ @@ -44,16 +47,7 @@ namespace AsuraEngine /// /// shaderΪǻ /// - void UnUse(); - - /// - /// һϵuniformsķ - /// - void SetUniformFloat(const std::string& uniform, float value); - void SetUniformTexture(const std::string& uniform, const Texture& texture); - void SetUniformVector2(const std::string& uniform, const Math::Vector2& vec2); - void SetUniformVector3(const std::string& uniform, const Math::Vector3& vec3); - void SetUniformVector4(const std::string& uniform, const Math::Vector4& vec4); + void Unuse(); /// /// Ѿ֪uniform location£ֵ @@ -63,46 +57,58 @@ namespace AsuraEngine void SetUniformVector2(uint loc, const Math::Vector2& vec2); void SetUniformVector3(uint loc, const Math::Vector3& vec3); void SetUniformVector4(uint loc, const Math::Vector4& vec4); - -/* - /// - /// עܷframeworkʵ֣㣬shadereditorҲõ - /// ջunifrom location±shaderµuniform location - /// - void ClearUniformLocation(); -*/ - /// - /// program id - /// - GLint GetNativeHandle(); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); uint GetUniformLocation(const std::string& uniform); - private: + bool HasUniform(const std::string& uniform); + + GLuint GetGLProgramHandle(); /// - /// ñ - /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ - /// vec2 Asura_RenderTargetSize RTĴСΪλ - /// Texture Asura_MainTexture + /// texture unitһΪ16 /// - void SetBuiltInUniforms(); - - // OpenGLɫʶprogram id - GLuint mPID; - //// Uniformlocations - //StringMap<uint> mUniformLocation; + static uint GetGLTextureUnitCount(); - //////////////////////////////////////////////////////////////////////////////////////////////////////////// + //---------------------------------------------------------------------------------------------------------- LUAX_DECL_FACTORY(SimShader); + LUAX_DECL_METHOD(l_Use); + LUAX_DECL_METHOD(l_Unuse); + LUAX_DECL_METHOD(l_Load); + LUAX_DECL_METHOD(l_HasUniform); + LUAX_DECL_METHOD(l_GetUniformLocation); LUAX_DECL_METHOD(l_SetBuiltInUniforms); LUAX_DECL_METHOD(l_SetUniformFloat); LUAX_DECL_METHOD(l_SetUniformTexture); LUAX_DECL_METHOD(l_SetUniformVector2); LUAX_DECL_METHOD(l_SetUniformVector3); LUAX_DECL_METHOD(l_SetUniformVector4); + LUAX_DECL_METHOD(l_SetUniformColor); + + //---------------------------------------------------------------------------------------------------------- + + private: + + /// + /// ǰshader + /// + static Shader* mCurrentShader; + + /// + /// ñ + /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ + /// vec2 Asura_RenderTargetSize RTĴСΪλ + /// Texture Asura_MainTexture + /// + void SetBuiltInUniforms(); + + /// + /// OpenGL shader program handle. + /// + GLuint mProgramHandle; }; |