2014-09-14 16:52:51 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-09-14 16:52:51 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
#include <array>
|
2023-01-26 22:34:59 +00:00
|
|
|
#include <memory>
|
2023-12-09 19:54:17 +00:00
|
|
|
#include <span>
|
2021-06-09 11:42:21 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-09-14 16:52:51 +00:00
|
|
|
|
2022-12-27 16:42:02 +00:00
|
|
|
class PixelShaderManager;
|
2016-01-17 21:54:31 +00:00
|
|
|
class PointerWrap;
|
2014-09-14 16:52:51 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
using BBoxType = s32;
|
|
|
|
constexpr u32 NUM_BBOX_VALUES = 4;
|
|
|
|
|
|
|
|
class BoundingBox
|
2014-09-14 16:52:51 +00:00
|
|
|
{
|
2021-06-09 11:42:21 +00:00
|
|
|
public:
|
|
|
|
explicit BoundingBox() = default;
|
|
|
|
virtual ~BoundingBox() = default;
|
2014-09-14 16:52:51 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
bool IsEnabled() const { return m_is_active; }
|
2022-12-27 16:42:02 +00:00
|
|
|
void Enable(PixelShaderManager& pixel_shader_manager);
|
|
|
|
void Disable(PixelShaderManager& pixel_shader_manager);
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
void Flush();
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
u16 Get(u32 index);
|
|
|
|
void Set(u32 index, u16 value);
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
void DoState(PointerWrap& p);
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
// Initialize, Read, and Write are only safe to call if the backend supports bounding box,
|
|
|
|
// otherwise unexpected exceptions can occur
|
|
|
|
virtual bool Initialize() = 0;
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
protected:
|
|
|
|
virtual std::vector<BBoxType> Read(u32 index, u32 length) = 0;
|
2023-12-09 19:54:17 +00:00
|
|
|
virtual void Write(u32 index, std::span<const BBoxType> values) = 0;
|
2019-12-05 15:58:03 +00:00
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
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;
|
2023-01-29 14:40:15 +00:00
|
|
|
|
|
|
|
// Nintendo's SDK seems to write "default" bounding box values before every draw (1023 0 1023 0
|
|
|
|
// are the only values encountered so far, which happen to be the extents allowed by the BP
|
|
|
|
// registers) to reset the registers for comparison in the pixel engine, and presumably to detect
|
|
|
|
// whether GX has updated the registers with real values.
|
|
|
|
//
|
|
|
|
// We can store these values when Bounding Box emulation is disabled and return them on read,
|
|
|
|
// which the game will interpret as "no pixels have been drawn"
|
|
|
|
//
|
|
|
|
// This produces much better results than just returning garbage, which can cause games like
|
|
|
|
// Ultimate Spider-Man to crash
|
|
|
|
std::array<u16, 4> m_bounding_box_fallback = {};
|
2021-06-09 11:42:21 +00:00
|
|
|
};
|
2023-01-26 22:34:59 +00:00
|
|
|
|
|
|
|
extern std::unique_ptr<BoundingBox> g_bounding_box;
|