From 084623519e95f0ab0cf4bc328b5fa736d679c5bd Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 31 Jul 2019 21:35:12 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-core/graphics/shader.h | 152 ++++++++++++++-------------- 1 file changed, 75 insertions(+), 77 deletions(-) (limited to 'source/modules/asura-core/graphics/shader.h') diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index dc8dbe0..c535570 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -20,100 +20,98 @@ #include "vertex_buffer.h" #include "index_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 uniforms和use着色 +/// 器的方法。编辑器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material +/// 设置。 +/// +class Shader ASURA_FINAL + : public Scripting::Portable + , public AEIO::Renewable { - namespace Graphics - { - - /// - /// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 uniforms和use着色 - /// 器的方法。编辑器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material - /// 设置。 - /// - class Shader ASURA_FINAL - : public Scripting::Portable - , public AEIO::Renewable - { - public: - - Shader(); - - ~Shader(); - - static void SetActive(Shader* shader); - static Shader* GetActive(); - - bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); - - // 使用SetActive切换shader时调用 - void OnEnable(); - void OnDisable(); - // Draw call之后调用 - void OnUsed(); +public: + + Shader(); + + ~Shader(); + + static void SetActive(Shader* shader); + static Shader* GetActive(); + + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); + + // 使用SetActive切换shader时调用 + void OnEnable(); + void OnDisable(); + // Draw call之后调用 + void OnUsed(); - void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); - int GetAttributeLocation(const std::string& attribute); - void DisableAttribute(int loc); + void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); + int GetAttributeLocation(const std::string& attribute); + void DisableAttribute(int loc); - bool HasUniform(const std::string& uniform); - uint GetUniformLocation(const std::string& uniform); - void SetUniformFloat(uint loc, float value); - void SetUniformVector2(uint loc, const Math::Vector2f& vec2); - void SetUniformVector3(uint loc, const Math::Vector3f& vec3); - void SetUniformVector4(uint loc, const Math::Vector4f& vec4); - void SetUniformColor(uint loc, const Color& color); - void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); - bool SetUniformTexture(uint loc, const Texture& texture); + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); + void SetUniformFloat(uint loc, float value); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); - float GetUniformFloat(uint loc); - AEMath::Vector2f GetUniformVector2(uint loc); - AEMath::Vector3f GetUniformVector3(uint loc); - AEMath::Vector4f GetUniformVector4s(uint loc); - AEMath::Matrix44 GetUniformMatrix44(uint loc); + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); - GLuint GetGLProgram(); + GLuint GetGLProgram(); - static uint GetGLTextureUnitCount(); + static uint GetGLTextureUnitCount(); - private: +private: - bool CompileVertexShader(const std::string& vert, std::string& outError); - bool CompileFragementShader(const std::string& frag, std::string& outError); + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); - std::string GetProgramWarnings(); - std::string GetShaderWarnings(GLuint shader); + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); - GLuint m_Program; - GLuint m_VertShader; - GLuint m_FragShader; + GLuint m_Program; + GLuint m_VertShader; + GLuint m_FragShader; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Shader); + LUAX_DECL_FACTORY(Shader); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Update); - LUAX_DECL_METHOD(_HasUniform); - LUAX_DECL_METHOD(_GetUniformLocation); - LUAX_DECL_METHOD(_SetUniformFloat); - LUAX_DECL_METHOD(_SetUniformTexture); - LUAX_DECL_METHOD(_SetUniformVector2); - LUAX_DECL_METHOD(_SetUniformVector3); - LUAX_DECL_METHOD(_SetUniformVector4); - LUAX_DECL_METHOD(_SetUniformColor); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); - LUAX_DECL_METHOD(_GetAttributeLocation); - LUAX_DECL_METHOD(_SetAttribute); - LUAX_DECL_METHOD(_DisableAttribute); + LUAX_DECL_METHOD(_GetAttributeLocation); + LUAX_DECL_METHOD(_SetAttribute); + LUAX_DECL_METHOD(_DisableAttribute); - LUAX_DECL_METHOD(_SetBuiltInUniforms); + LUAX_DECL_METHOD(_SetBuiltInUniforms); - }; +}; - typedef Shader GpuProgram; +typedef Shader GpuProgram; - } -} +namespace_end +namespace_end #endif \ No newline at end of file -- cgit v1.1-26-g67d0