Debian Codegraph @

Source/Core/VideoCommon/BoundingBox.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8 #include <span>
9 #include <vector>
10
11 #include "Common/CommonTypes.h"
12
13 class PixelShaderManager;
14 class PointerWrap;
15
16 using BBoxType = s32;
17 constexpr u32 NUM_BBOX_VALUES = 4;
18
19 class BoundingBox
20 {
21 public:
22 explicit BoundingBox() = default;
23 virtual ~BoundingBox() = default;
24
25 bool IsEnabled() const { return m_is_active; }
26 void Enable(PixelShaderManager& pixel_shader_manager);
27 void Disable(PixelShaderManager& pixel_shader_manager);
28
29 void Flush();
30
31 u16 Get(u32 index);
32 void Set(u32 index, u16 value);
33
34 void DoState(PointerWrap& p);
35
36 // Initialize, Read, and Write are only safe to call if the backend supports bounding box,
37 // otherwise unexpected exceptions can occur
38 virtual bool Initialize() = 0;
39
40 protected:
41 virtual std::vector<BBoxType> Read(u32 index, u32 length) = 0;
42 virtual void Write(u32 index, std::span<const BBoxType> values) = 0;
43
44 private:
45 void Readback();
46
47 bool m_is_active = false;
48
49 std::array<BBoxType, NUM_BBOX_VALUES> m_values = {};
50 std::array<bool, NUM_BBOX_VALUES> m_dirty = {};
51 bool m_is_valid = true;
52
53 // Nintendo's SDK seems to write "default" bounding box values before every draw (1023 0 1023 0
54 // are the only values encountered so far, which happen to be the extents allowed by the BP
55 // registers) to reset the registers for comparison in the pixel engine, and presumably to detect
56 // whether GX has updated the registers with real values.
57 //
58 // We can store these values when Bounding Box emulation is disabled and return them on read,
59 // which the game will interpret as "no pixels have been drawn"
60 //
61 // This produces much better results than just returning garbage, which can cause games like
62 // Ultimate Spider-Man to crash
63 std::array<u16, 4> m_bounding_box_fallback = {};
64 };
65
66 extern std::unique_ptr<BoundingBox> g_bounding_box;