File: SWBoundingBox.cpp

package info (click to toggle)
dolphin-emu 2503%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 111,624 kB
  • sloc: cpp: 787,747; ansic: 217,914; xml: 31,400; python: 4,226; yacc: 3,985; javascript: 2,430; makefile: 777; asm: 726; sh: 281; pascal: 257; perl: 97; objc: 75
file content (66 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoBackends/Software/SWBoundingBox.h"

#include <algorithm>
#include <array>

#include "Common/CommonTypes.h"

namespace BBoxManager
{
namespace
{
// Current bounding box coordinates.
std::array<u16, 4> s_coordinates{};
}  // Anonymous namespace

u16 GetCoordinate(Coordinate coordinate)
{
  return s_coordinates[static_cast<u32>(coordinate)];
}

void SetCoordinate(Coordinate coordinate, u16 value)
{
  s_coordinates[static_cast<u32>(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<BBoxType> SWBoundingBox::Read(u32 index, u32 length)
{
  std::vector<BBoxType> values(length);

  for (u32 i = 0; i < length; i++)
  {
    values[i] = BBoxManager::GetCoordinate(static_cast<BBoxManager::Coordinate>(index + i));
  }

  return values;
}

void SWBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
  for (size_t i = 0; i < values.size(); i++)
  {
    BBoxManager::SetCoordinate(static_cast<BBoxManager::Coordinate>(index + i), values[i]);
  }
}

}  // namespace SW