From f416b7192536d340685cf17297f1bcb02adb9baa Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 5 Mar 2022 00:41:14 -0600 Subject: VideoCommon: add logic to handle a GraphicsMod while Dolphin is running --- .../Runtime/Actions/ScaleAction.cpp | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp (limited to 'Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp') diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp new file mode 100644 index 0000000000..d0cac24acb --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp @@ -0,0 +1,59 @@ +// Copyright 2022 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h" + +std::unique_ptr ScaleAction::Create(const picojson::value& json_data) +{ + Common::Vec3 scale; + const auto& x = json_data.get("X"); + if (x.is()) + { + scale.x = static_cast(x.get()); + } + + const auto& y = json_data.get("Y"); + if (y.is()) + { + scale.y = static_cast(y.get()); + } + + const auto& z = json_data.get("Z"); + if (z.is()) + { + scale.z = static_cast(z.get()); + } + return std::make_unique(scale); +} + +ScaleAction::ScaleAction(Common::Vec3 scale) : m_scale(scale) +{ +} + +void ScaleAction::OnEFB(bool*, u32 texture_width, u32 texture_height, u32* scaled_width, + u32* scaled_height) +{ + if (scaled_width && m_scale.x > 0) + *scaled_width = texture_width * m_scale.x; + + if (scaled_height && m_scale.y > 0) + *scaled_height = texture_height * m_scale.y; +} + +void ScaleAction::OnProjection(Common::Matrix44* matrix) +{ + if (!matrix) + return; + auto& the_matrix = *matrix; + the_matrix.data[0] = the_matrix.data[0] * m_scale.x; + the_matrix.data[5] = the_matrix.data[5] * m_scale.y; +} + +void ScaleAction::OnProjectionAndTexture(Common::Matrix44* matrix) +{ + if (!matrix) + return; + auto& the_matrix = *matrix; + the_matrix.data[0] = the_matrix.data[0] * m_scale.x; + the_matrix.data[5] = the_matrix.data[5] * m_scale.y; +} -- cgit v1.2.3