From 1161af80594c403233e3d21589af004ee2d75594 Mon Sep 17 00:00:00 2001 From: Techjar Date: Wed, 9 Jun 2021 07:42:21 -0400 Subject: VideoCommon: Abstract bounding box This moves much of the duplicated bounding box code into VideoCommon, leaving only the specific buffer implementations in each backend. --- .../Core/VideoBackends/Software/SWBoundingBox.cpp | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Source/Core/VideoBackends/Software/SWBoundingBox.cpp (limited to 'Source/Core/VideoBackends/Software/SWBoundingBox.cpp') diff --git a/Source/Core/VideoBackends/Software/SWBoundingBox.cpp b/Source/Core/VideoBackends/Software/SWBoundingBox.cpp new file mode 100644 index 0000000000..96d38517b8 --- /dev/null +++ b/Source/Core/VideoBackends/Software/SWBoundingBox.cpp @@ -0,0 +1,66 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoBackends/Software/SWBoundingBox.h" + +#include +#include + +#include "Common/CommonTypes.h" + +namespace BBoxManager +{ +namespace +{ +// Current bounding box coordinates. +std::array s_coordinates{}; +} // Anonymous namespace + +u16 GetCoordinate(Coordinate coordinate) +{ + return s_coordinates[static_cast(coordinate)]; +} + +void SetCoordinate(Coordinate coordinate, u16 value) +{ + s_coordinates[static_cast(coordinate)] = value; +} + +void Update(u16 left, u16 right, u16 top, u16 bottom) +{ + const u16 new_left = std::min(left, GetCoordinate(Coordinate::Left)); + const u16 new_right = std::max(right, GetCoordinate(Coordinate::Right)); + const u16 new_top = std::min(top, GetCoordinate(Coordinate::Top)); + const u16 new_bottom = std::max(bottom, GetCoordinate(Coordinate::Bottom)); + + SetCoordinate(Coordinate::Left, new_left); + SetCoordinate(Coordinate::Right, new_right); + SetCoordinate(Coordinate::Top, new_top); + SetCoordinate(Coordinate::Bottom, new_bottom); +} + +} // namespace BBoxManager + +namespace SW +{ +std::vector SWBoundingBox::Read(u32 index, u32 length) +{ + std::vector values(length); + + for (u32 i = 0; i < length; i++) + { + values[i] = BBoxManager::GetCoordinate(static_cast(index + i)); + } + + return values; +} + +void SWBoundingBox::Write(u32 index, const std::vector& values) +{ + for (size_t i = 0; i < values.size(); i++) + { + BBoxManager::SetCoordinate(static_cast(index + i), values[i]); + } +} + +} // namespace SW -- cgit v1.2.3