Debian Codegraph @

Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp

raw symbols SCIP
1 // Copyright 2022 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h"
5
6 std::unique_ptr<ScaleAction> ScaleAction::Create(const picojson::value& json_data)
7 {
8 Common::Vec3 scale;
9 const auto& x = json_data.get("X");
10 if (x.is<double>())
11 {
12 scale.x = static_cast<float>(x.get<double>());
13 }
14
15 const auto& y = json_data.get("Y");
16 if (y.is<double>())
17 {
18 scale.y = static_cast<float>(y.get<double>());
19 }
20
21 const auto& z = json_data.get("Z");
22 if (z.is<double>())
23 {
24 scale.z = static_cast<float>(z.get<double>());
25 }
26 return std::make_unique<ScaleAction>(scale);
27 }
28
29 ScaleAction::ScaleAction(Common::Vec3 scale) : m_scale(scale)
30 {
31 }
32
33 void ScaleAction::BeforeEFB(GraphicsModActionData::PreEFB* efb)
34 {
35 if (!efb) [[unlikely]]
36 return;
37
38 if (!efb->scaled_width) [[unlikely]]
39 return;
40
41 if (!efb->scaled_height) [[unlikely]]
42 return;
43
44 if (m_scale.x > 0)
45 *efb->scaled_width = efb->texture_width * m_scale.x;
46
47 if (m_scale.y > 0)
48 *efb->scaled_height = efb->texture_height * m_scale.y;
49 }
50
51 void ScaleAction::OnProjection(GraphicsModActionData::Projection* projection)
52 {
53 if (!projection) [[unlikely]]
54 return;
55
56 if (!projection->matrix) [[unlikely]]
57 return;
58
59 auto& matrix = *projection->matrix;
60 matrix.data[0] = matrix.data[0] * m_scale.x;
61 matrix.data[5] = matrix.data[5] * m_scale.y;
62 }
63
64 void ScaleAction::OnProjectionAndTexture(GraphicsModActionData::Projection* projection)
65 {
66 if (!projection) [[unlikely]]
67 return;
68
69 if (!projection->matrix) [[unlikely]]
70 return;
71
72 auto& matrix = *projection->matrix;
73 matrix.data[0] = matrix.data[0] * m_scale.x;
74 matrix.data[5] = matrix.data[5] * m_scale.y;
75 }