diff options
| author | Anthony <Helios747@users.noreply.github.com> | 2019-02-03 10:23:08 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-03 10:23:08 -0800 |
| commit | d11ee96eaca2033d4b4d1febe14becf107a2d0e7 (patch) | |
| tree | 59f0e92bf501c2231f75d56526fd33e62804386e /Source/Core/VideoCommon/VertexShaderManager.cpp | |
| parent | 3b4486bad3f0e44c3a572bba411879a634ece325 (diff) | |
| parent | 69b617ce766e5b1b8956a29f7a8caeed21f6024d (diff) | |
Merge pull request #7759 from jordan-woyak/matrix-cleanup
Common: Clean up matrix math funcs and remove redundant matrix class from WiimoteEmu
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderManager.cpp | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index fca6a420c5..b0821df950 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -13,7 +13,7 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Common/MathUtil.h" +#include "Common/Matrix.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "VideoCommon/BPFunctions.h" @@ -27,7 +27,7 @@ #include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h" -alignas(16) static float g_fProjectionMatrix[16]; +alignas(16) static std::array<float, 16> g_fProjectionMatrix; // track changes static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged; @@ -38,10 +38,10 @@ static int nNormalMatricesChanged[2]; // min,max static int nPostTransformMatricesChanged[2]; // min,max static int nLightsChanged[2]; // min,max -static Matrix44 s_viewportCorrection; -static Matrix33 s_viewRotationMatrix; -static Matrix33 s_viewInvRotationMatrix; -static float s_fViewTranslationVector[3]; +static Common::Matrix44 s_viewportCorrection; +static Common::Matrix33 s_viewRotationMatrix; +static Common::Matrix33 s_viewInvRotationMatrix; +static Common::Vec3 s_fViewTranslationVector; static float s_fViewRotation[2]; VertexShaderConstants VertexShaderManager::constants; @@ -57,7 +57,7 @@ bool VertexShaderManager::dirty; // [ 0 (ih/ah) 0 ((-ih + 2*(ay-iy)) / ah + 1) ] // [ 0 0 1 0 ] // [ 0 0 0 1 ] -static void ViewportCorrectionMatrix(Matrix44& result) +static void ViewportCorrectionMatrix(Common::Matrix44& result) { int scissorXOff = bpmem.scissorOffset.x * 2; int scissorYOff = bpmem.scissorOffset.y * 2; @@ -86,7 +86,7 @@ static void ViewportCorrectionMatrix(Matrix44& result) float Wd = (X + intendedWd <= EFB_WIDTH) ? intendedWd : (EFB_WIDTH - X); float Ht = (Y + intendedHt <= EFB_HEIGHT) ? intendedHt : (EFB_HEIGHT - Y); - Matrix44::LoadIdentity(result); + result = Common::Matrix44::Identity(); if (Wd == 0 || Ht == 0) return; @@ -121,10 +121,8 @@ void VertexShaderManager::Init() ResetView(); // TODO: should these go inside ResetView()? - Matrix44::LoadIdentity(s_viewportCorrection); - memset(g_fProjectionMatrix, 0, sizeof(g_fProjectionMatrix)); - for (int i = 0; i < 4; ++i) - g_fProjectionMatrix[i * 5] = 1.0f; + s_viewportCorrection = Common::Matrix44::Identity(); + g_fProjectionMatrix = Common::Matrix44::Identity().data; dirty = true; } @@ -454,26 +452,21 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE) { - Matrix44 mtxA; - Matrix44 mtxB; - Matrix44 viewMtx; - - Matrix44::Translate(mtxA, s_fViewTranslationVector); - Matrix44::LoadMatrix33(mtxB, s_viewRotationMatrix); - Matrix44::Multiply(mtxB, mtxA, viewMtx); // view = rotation x translation - Matrix44::Set(mtxB, g_fProjectionMatrix); - Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view - Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA - memcpy(constants.projection.data(), mtxB.data, 4 * sizeof(float4)); + using Common::Matrix44; + + auto mtxA = Matrix44::Translate(s_fViewTranslationVector); + auto mtxB = Matrix44::FromMatrix33(s_viewRotationMatrix); + const auto viewMtx = mtxB * mtxA; // view = rotation x translation + + mtxA = Matrix44::FromArray(g_fProjectionMatrix) * viewMtx; // mtxA = projection x view + mtxB = s_viewportCorrection * mtxA; // mtxB = viewportCorrection x mtxA + memcpy(constants.projection.data(), mtxB.data.data(), 4 * sizeof(float4)); } else { - Matrix44 projMtx; - Matrix44::Set(projMtx, g_fProjectionMatrix); - - Matrix44 correctedMtx; - Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx); - memcpy(constants.projection.data(), correctedMtx.data, 4 * sizeof(float4)); + const auto projMtx = Common::Matrix44::FromArray(g_fProjectionMatrix); + const auto correctedMtx = s_viewportCorrection * projMtx; + memcpy(constants.projection.data(), correctedMtx.data.data(), 4 * sizeof(float4)); } dirty = true; @@ -661,41 +654,35 @@ void VertexShaderManager::SetMaterialColorChanged(int index) void VertexShaderManager::TranslateView(float x, float y, float z) { - float result[3]; - float vector[3] = {x, z, y}; - - Matrix33::Multiply(s_viewInvRotationMatrix, vector, result); - - for (size_t i = 0; i < ArraySize(result); i++) - s_fViewTranslationVector[i] += result[i]; + s_fViewTranslationVector += s_viewInvRotationMatrix * Common::Vec3{x, z, y}; bProjectionChanged = true; } void VertexShaderManager::RotateView(float x, float y) { + using Common::Matrix33; + s_fViewRotation[0] += x; s_fViewRotation[1] += y; - Matrix33 mx; - Matrix33 my; - Matrix33::RotateX(mx, s_fViewRotation[1]); - Matrix33::RotateY(my, s_fViewRotation[0]); - Matrix33::Multiply(mx, my, s_viewRotationMatrix); + s_viewRotationMatrix = + Matrix33::RotateX(s_fViewRotation[1]) * Matrix33::RotateY(s_fViewRotation[0]); // reverse rotation - Matrix33::RotateX(mx, -s_fViewRotation[1]); - Matrix33::RotateY(my, -s_fViewRotation[0]); - Matrix33::Multiply(my, mx, s_viewInvRotationMatrix); + s_viewInvRotationMatrix = + Matrix33::RotateY(-s_fViewRotation[0]) * Matrix33::RotateX(-s_fViewRotation[1]); bProjectionChanged = true; } void VertexShaderManager::ResetView() { - memset(s_fViewTranslationVector, 0, sizeof(s_fViewTranslationVector)); - Matrix33::LoadIdentity(s_viewRotationMatrix); - Matrix33::LoadIdentity(s_viewInvRotationMatrix); + using Common::Matrix33; + + s_fViewTranslationVector = {}; + s_viewRotationMatrix = Matrix33::Identity(); + s_viewInvRotationMatrix = Matrix33::Identity(); s_fViewRotation[0] = s_fViewRotation[1] = 0.0f; bProjectionChanged = true; |
