diff options
author | chai <chaifix@163.com> | 2019-06-21 22:47:36 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-06-21 22:47:36 +0800 |
commit | 7894c2971626f9560b4ec77a1ce5a9a64a4f3810 (patch) | |
tree | c7bd04fbf4b8e21b48c4d6902c4bd910987e7560 /source/modules/asura-core/graphics/shader.cpp | |
parent | 8ee3f7453bf7b0db5c7358e697e91714d825c87d (diff) |
*格式化代码
Diffstat (limited to 'source/modules/asura-core/graphics/shader.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/shader.cpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index afd10b0..22b9ee3 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -10,10 +10,8 @@ namespace AsuraEngine namespace Graphics { - /// - /// texture unit - /// - static int _texture_unit; + // texture unit + static uint8 texUnit = 0; Shader::Shader() { @@ -26,6 +24,16 @@ namespace AsuraEngine if(mProgram) glDeleteProgram(mProgram); } + void Shader::SetActive(Shader* shader) + { + gfx.SetActiveShader(shader); + } + + Shader* Shader::GetActive() + { + return gfx.GetActiveShader(); + } + bool Shader::Load(const string& vert, const string& frag) { string warnning = ""; @@ -117,14 +125,19 @@ namespace AsuraEngine return true; } - void Shader::OnUse() + void Shader::OnEnable() { - _texture_unit = 0; + texUnit = 0; } - void Shader::OnUnuse() + void Shader::OnDisable() { - _texture_unit; + texUnit = 0; + } + + void Shader::OnUsed() + { + texUnit = 0; } uint Shader::GetUniformLocation(const std::string& uniform) @@ -146,65 +159,59 @@ namespace AsuraEngine void Shader::SetUniformFloat(uint loc, float value) { - if(gfx.state.shader == this) + if(gfx.GetActiveShader() == this) glUniform1f(loc, value); } bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (gfx.state.shader != this) + if (gfx.GetActiveShader() != this) return false; gfx.WipeError(); - glActiveTexture(GL_TEXTURE0 + _texture_unit); + glActiveTexture(GL_TEXTURE0 + texUnit); if (gfx.HasError()) return false; GLint tex = texture.GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); if (gfx.HasError()) return false; - glUniform1i(loc, _texture_unit); + glUniform1i(loc, texUnit); if (gfx.HasError()) return false; - ++_texture_unit; + ++texUnit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform3f(loc, vec3.x, vec3.y, vec3.z); } void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } void Shader::SetUniformColor(uint loc, const Color& color) { - if (gfx.state.shader == this) + if (gfx.GetActiveShader() == this) glUniform4f(loc, color.r, color.g, color.b, color.a); } - //void Shader::GetUniform() - //{ - // //if(gfx.state.shader == this) - // // glGetUniformfv() - //} - uint Shader::GetGLTextureUnitCount() { GLint maxTextureUnits; |