summaryrefslogtreecommitdiff
path: root/source/modules
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules')
-rw-r--r--source/modules/asura-core/graphics/binding/_shader.cpp104
-rw-r--r--source/modules/asura-core/graphics/gl.cpp28
-rw-r--r--source/modules/asura-core/graphics/gl.h13
-rw-r--r--source/modules/asura-core/graphics/shader.cpp31
-rw-r--r--source/modules/asura-core/graphics/shader.h19
-rw-r--r--source/modules/asura-utils/math/matrix44.cpp1
6 files changed, 155 insertions, 41 deletions
diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp
index 71f4e28..34bc98b 100644
--- a/source/modules/asura-core/graphics/binding/_shader.cpp
+++ b/source/modules/asura-core/graphics/binding/_shader.cpp
@@ -11,19 +11,25 @@ namespace AsuraEngine
LUAX_REGISTRY(Shader)
{
LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "Load", _Load },
- { "Update", _Update },
- { "HasUniform", _HasUniform },
- { "GetUniformLocation", _GetUniformLocation },
- { "SetBuiltInUniforms", _SetBuiltInUniforms },
- { "SetUniformFloat", _SetUniformFloat },
- { "SetUniformTexture", _SetUniformTexture },
- { "SetUniformVector2", _SetUniformVector2 },
- { "SetUniformVector3", _SetUniformVector3 },
- { "SetUniformVector4", _SetUniformVector4 },
- { "SetUniformColor", _SetUniformColor },
- { "SetBuiltInUniforms", _SetBuiltInUniforms }
+ { "New", _New },
+ { "Load", _Load },
+ { "Update", _Update },
+ { "HasUniform", _HasUniform },
+ { "GetUniformLocation", _GetUniformLocation },
+ { "SetUniformFloat", _SetUniformFloat },
+ { "SetUniformTexture", _SetUniformTexture },
+ { "SetUniformVector2", _SetUniformVector2 },
+ { "SetUniformVector3", _SetUniformVector3 },
+ { "SetUniformVector4", _SetUniformVector4 },
+ { "SetUniformColor", _SetUniformColor },
+ { "GetAttributeLocation", _GetAttributeLocation },
+ { "SetAttribute", _SetAttribute },
+ { "DisableAttribute", _DisableAttribute },
+ { "SetBuiltInModelMatrix", _SetBuiltInModelMatrix },
+ { "SetBuiltInViewMatrix", _SetBuiltInViewMatrix },
+ { "SetBuiltInProjectionMatrix", _SetBuiltInProjectionMatrix },
+ { "SetBuiltInMVPMatrix", _SetBuiltInMVPMatrix },
+ { "SetBuiltInDrawColor", _SetBuiltInDrawColor }
);
}
@@ -72,14 +78,6 @@ namespace AsuraEngine
return 0;
}
- // shader:SetBuiltInUniforms()
- LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms)
- {
- LUAX_PREPARE(L, Shader);
-
- return 0;
- }
-
// shader:SetUniformFloat()
LUAX_IMPL_METHOD(Shader, _SetUniformFloat)
{
@@ -128,5 +126,69 @@ namespace AsuraEngine
return 0;
}
+ // shader:GetAttributeLocation()
+ LUAX_IMPL_METHOD(Shader, _GetAttributeLocation)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetAttribute()
+ LUAX_IMPL_METHOD(Shader, _SetAttribute)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:DisableAttribute()
+ LUAX_IMPL_METHOD(Shader, _DisableAttribute)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetBuiltInModelMatrix()
+ LUAX_IMPL_METHOD(Shader, _SetBuiltInModelMatrix)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetBuiltInViewMatrix()
+ LUAX_IMPL_METHOD(Shader, _SetBuiltInViewMatrix)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetBuiltInProjectionMatrix()
+ LUAX_IMPL_METHOD(Shader, _SetBuiltInProjectionMatrix)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetBuiltInMVPMatrix()
+ LUAX_IMPL_METHOD(Shader, _SetBuiltInMVPMatrix)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
+ // shader:SetBuiltInColor()
+ LUAX_IMPL_METHOD(Shader, _SetBuiltInDrawColor)
+ {
+ LUAX_PREPARE(L, Shader);
+
+ return 0;
+ }
+
}
}
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index 08c50c3..5e6f216 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -21,6 +21,7 @@ namespace AsuraEngine
OpenGL gl;
OpenGL::OpenGL()
+ : mUpdateMVPMatrix(true)
{
#if ASURA_DEBUG
ASSERT(!_instantiated);
@@ -137,36 +138,50 @@ namespace AsuraEngine
void OpenGL::PushMatrix()
{
state.matrix[state.matrixMode].Push();
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::PopMatrix()
{
state.matrix[state.matrixMode].Pop();
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::LoadIdentity()
{
state.matrix[state.matrixMode].LoadIdentity();
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::Rotate(float angle)
{
state.matrix[state.matrixMode].Rotate(angle);
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::Translate(float x, float y)
{
state.matrix[state.matrixMode].Translate(x, y);
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::Scale(float x, float y)
{
state.matrix[state.matrixMode].Scale(x, y);
+
+ mUpdateMVPMatrix = true;
}
void OpenGL::Ortho(float l, float r, float b, float t, float n, float f)
{
state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f);
+
+ mUpdateMVPMatrix = true;
}
AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode)
@@ -176,9 +191,16 @@ namespace AsuraEngine
AEMath::Matrix44 OpenGL::GetMVPMatrix()
{
- return state.matrix[MATRIX_MODE_MODEL].GetTop()
- * state.matrix[MATRIX_MODE_MODEL].GetTop()
- * state.matrix[MATRIX_MODE_MODEL].GetTop();
+ if (mUpdateMVPMatrix)
+ {
+ Matrix44& m = state.matrix[MATRIX_MODE_MODEL].GetTop();
+ Matrix44& v = state.matrix[MATRIX_MODE_VIEW].GetTop();
+ Matrix44& p = state.matrix[MATRIX_MODE_PROJECTION].GetTop();
+ state.mvpMatrix = p * (v * m);
+
+ mUpdateMVPMatrix = false;
+ }
+ return state.mvpMatrix;
}
uint OpenGL::GetMatrixDepth()
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index a4d9de2..6c6ff30 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -105,11 +105,12 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[3]; ///< model, view, projection
- MatrixMode matrixMode; ///< ǰľ
- Color drawColor; ///< Ƶɫ
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[3]; ///< model, view, projection
+ MatrixMode matrixMode; ///< ǰľ
+ AEMath::Matrix44 mvpMatrix; ///< mvp matrix
+ Color drawColor; ///< Ƶɫ
} state;
#if ASURA_GL_PROFILE
@@ -149,6 +150,8 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
+ bool mUpdateMVPMatrix;
+
};
///
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index a0c14b4..833cef0 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -176,12 +176,6 @@ namespace AsuraEngine
glUniform4f(loc, color.r, color.g, color.b, color.a);
}
- //void Shader::GetUniform()
- //{
- // //if(gl.state.shader == this)
- // // glGetUniformfv()
- //}
-
uint Shader::GetGLTextureUnitCount()
{
GLint maxTextureUnits;
@@ -250,5 +244,30 @@ namespace AsuraEngine
glDisableVertexAttribArray(loc);
}
+ void Shader::SetBuiltInModelMatrix(uint loc)
+ {
+ SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_MODEL));
+ }
+
+ void Shader::SetBuiltInViewMatrix(uint loc)
+ {
+ SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_VIEW));
+ }
+
+ void Shader::SetBuiltInProjectionMatrix(uint loc)
+ {
+ SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_PROJECTION));
+ }
+
+ void Shader::SetBuiltInMVPMatrix(uint loc)
+ {
+ SetUniformMatrix44(loc, gl.GetMVPMatrix());
+ }
+
+ void Shader::SetBuiltInDrawColor(uint loc)
+ {
+ SetUniformColor(loc, gl.GetDrawColor());
+ }
+
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index b7bc70d..913332b 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -67,11 +67,14 @@ namespace AsuraEngine
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);
+ ///
+ /// ñ
+ ///
+ void SetBuiltInModelMatrix(uint loc);
+ void SetBuiltInViewMatrix(uint loc);
+ void SetBuiltInProjectionMatrix(uint loc);
+ void SetBuiltInMVPMatrix(uint loc);
+ void SetBuiltInDrawColor(uint loc);
GLuint GetGLProgram();
@@ -99,7 +102,11 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_SetAttribute);
LUAX_DECL_METHOD(_DisableAttribute);
// uniform
- LUAX_DECL_METHOD(_SetBuiltInUniforms);
+ LUAX_DECL_METHOD(_SetBuiltInModelMatrix);
+ LUAX_DECL_METHOD(_SetBuiltInViewMatrix);
+ LUAX_DECL_METHOD(_SetBuiltInProjectionMatrix);
+ LUAX_DECL_METHOD(_SetBuiltInMVPMatrix);
+ LUAX_DECL_METHOD(_SetBuiltInDrawColor);
//----------------------------------------------------------------------------//
diff --git a/source/modules/asura-utils/math/matrix44.cpp b/source/modules/asura-utils/math/matrix44.cpp
index 4472cd8..39fc1de 100644
--- a/source/modules/asura-utils/math/matrix44.cpp
+++ b/source/modules/asura-utils/math/matrix44.cpp
@@ -57,6 +57,7 @@ namespace AsuraEngine
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
+ // ҳ˾ת
Matrix44 Matrix44::operator * (const Matrix44 & m) const
{