From f6c0498c9728a286c13980ed3b60763d02e1b3a0 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 11 May 2019 12:08:45 +0800 Subject: *misc --- source/modules/asura-core/graphics/gl.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'source/modules/asura-core/graphics/gl.cpp') 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() -- cgit v1.1-26-g67d0