summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/shader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core/graphics/shader.cpp')
-rw-r--r--source/modules/asura-core/graphics/shader.cpp55
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;