VideoCommon: Abstract bounding box

This moves much of the duplicated bounding box code into VideoCommon,
leaving only the specific buffer implementations in each backend.
This commit is contained in:
Techjar
2021-06-09 07:42:21 -04:00
parent 7ec02ee4d3
commit 1161af8059
41 changed files with 617 additions and 708 deletions

View File

@ -3,40 +3,48 @@
#pragma once
#include <array>
#include <vector>
#include "Common/CommonTypes.h"
class PointerWrap;
// Bounding Box manager
namespace BoundingBox
using BBoxType = s32;
constexpr u32 NUM_BBOX_VALUES = 4;
class BoundingBox
{
// Indicates a coordinate of the bounding box.
enum class Coordinate
{
Left, // The X coordinate of the left side of the bounding box.
Right, // The X coordinate of the right side of the bounding box.
Top, // The Y coordinate of the top of the bounding box.
Bottom, // The Y coordinate of the bottom of the bounding box.
public:
explicit BoundingBox() = default;
virtual ~BoundingBox() = default;
bool IsEnabled() const { return m_is_active; }
void Enable();
void Disable();
void Flush();
u16 Get(u32 index);
void Set(u32 index, u16 value);
void DoState(PointerWrap& p);
// Initialize, Read, and Write are only safe to call if the backend supports bounding box,
// otherwise unexpected exceptions can occur
virtual bool Initialize() = 0;
protected:
virtual std::vector<BBoxType> Read(u32 index, u32 length) = 0;
// TODO: This can likely use std::span once we're on C++20
virtual void Write(u32 index, const std::vector<BBoxType>& values) = 0;
private:
void Readback();
bool m_is_active = false;
std::array<BBoxType, NUM_BBOX_VALUES> m_values = {};
std::array<bool, NUM_BBOX_VALUES> m_dirty = {};
bool m_is_valid = true;
};
// Enables bounding box.
void Enable();
// Disables bounding box.
void Disable();
// Determines if bounding box is enabled.
bool IsEnabled();
// Gets a particular coordinate for the bounding box.
u16 GetCoordinate(Coordinate coordinate);
// Sets a particular coordinate for the bounding box.
void SetCoordinate(Coordinate coordinate, u16 value);
// Updates all bounding box coordinates.
void Update(u16 left, u16 right, u16 top, u16 bottom);
// Save state
void DoState(PointerWrap& p);
} // namespace BoundingBox