| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include <utility> |
| 11 |
#include <vector> |
| 12 |
|
| 13 |
#include "Common/MathUtil.h" |
| 14 |
#include "VideoCommon/BPMemory.h" |
| 15 |
|
| 16 |
class FramebufferManager; |
| 17 |
struct Viewport; |
| 18 |
|
| 19 |
namespace BPFunctions |
| 20 |
{ |
| 21 |
struct ScissorRange |
| 22 |
{ |
| 23 |
constexpr ScissorRange() = default; |
| 24 |
constexpr ScissorRange(int offset_, int start_, int end_) |
| 25 |
: offset(offset_), start(start_), end(end_) |
| 26 |
{ |
| 27 |
} |
| 28 |
int offset = 0; |
| 29 |
int start = 0; |
| 30 |
int end = 0; |
| 31 |
}; |
| 32 |
|
| 33 |
struct ScissorRect |
| 34 |
{ |
| 35 |
constexpr ScissorRect(ScissorRange x_range, ScissorRange y_range) |
| 36 |
: |
| 37 |
rect(x_range.start, y_range.start, x_range.end, y_range.end), x_off(x_range.offset), |
| 38 |
y_off(y_range.offset) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
MathUtil::Rectangle<int> rect; |
| 43 |
int x_off; |
| 44 |
int y_off; |
| 45 |
|
| 46 |
int GetArea() const; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
struct ScissorResult |
| 71 |
{ |
| 72 |
ScissorResult(ScissorPos scissor_top_left, ScissorPos scissor_bottom_right, |
| 73 |
ScissorOffset scissor_offset, const Viewport& viewport); |
| 74 |
~ScissorResult() = default; |
| 75 |
ScissorResult(const ScissorResult& other) |
| 76 |
: scissor_tl{.hex = other.scissor_tl.hex}, scissor_br{.hex = other.scissor_br.hex}, |
| 77 |
scissor_off{.hex = other.scissor_off.hex}, viewport_left{other.viewport_left}, |
| 78 |
viewport_right{other.viewport_right}, viewport_top{other.viewport_top}, |
| 79 |
viewport_bottom{other.viewport_bottom}, rectangles{other.rectangles} |
| 80 |
{ |
| 81 |
} |
| 82 |
ScissorResult& operator=(const ScissorResult& other) |
| 83 |
{ |
| 84 |
if (this == &other) |
| 85 |
return *this; |
| 86 |
scissor_tl.hex = other.scissor_tl.hex; |
| 87 |
scissor_br.hex = other.scissor_br.hex; |
| 88 |
scissor_off.hex = other.scissor_off.hex; |
| 89 |
viewport_left = other.viewport_left; |
| 90 |
viewport_right = other.viewport_right; |
| 91 |
viewport_top = other.viewport_top; |
| 92 |
viewport_bottom = other.viewport_bottom; |
| 93 |
rectangles = other.rectangles; |
| 94 |
return *this; |
| 95 |
} |
| 96 |
ScissorResult(ScissorResult&& other) |
| 97 |
: scissor_tl{.hex = other.scissor_tl.hex}, scissor_br{.hex = other.scissor_br.hex}, |
| 98 |
scissor_off{.hex = other.scissor_off.hex}, viewport_left{other.viewport_left}, |
| 99 |
viewport_right{other.viewport_right}, viewport_top{other.viewport_top}, |
| 100 |
viewport_bottom{other.viewport_bottom}, rectangles{std::move(other.rectangles)} |
| 101 |
{ |
| 102 |
} |
| 103 |
ScissorResult& operator=(ScissorResult&& other) |
| 104 |
{ |
| 105 |
if (this == &other) |
| 106 |
return *this; |
| 107 |
scissor_tl.hex = other.scissor_tl.hex; |
| 108 |
scissor_br.hex = other.scissor_br.hex; |
| 109 |
scissor_off.hex = other.scissor_off.hex; |
| 110 |
viewport_left = other.viewport_left; |
| 111 |
viewport_right = other.viewport_right; |
| 112 |
viewport_top = other.viewport_top; |
| 113 |
viewport_bottom = other.viewport_bottom; |
| 114 |
rectangles = std::move(other.rectangles); |
| 115 |
return *this; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
ScissorPos scissor_tl; |
| 120 |
ScissorPos scissor_br; |
| 121 |
ScissorOffset scissor_off; |
| 122 |
float viewport_left; |
| 123 |
float viewport_right; |
| 124 |
float viewport_top; |
| 125 |
float viewport_bottom; |
| 126 |
|
| 127 |
std::vector<ScissorRect> rectangles; |
| 128 |
|
| 129 |
ScissorRect Best() const; |
| 130 |
|
| 131 |
bool ScissorMatches(const ScissorResult& other) const |
| 132 |
{ |
| 133 |
return scissor_tl.hex == other.scissor_tl.hex && scissor_br.hex == other.scissor_br.hex && |
| 134 |
scissor_off.hex == other.scissor_off.hex; |
| 135 |
} |
| 136 |
bool ViewportMatches(const ScissorResult& other) const |
| 137 |
{ |
| 138 |
return viewport_left == other.viewport_left && viewport_right == other.viewport_right && |
| 139 |
viewport_top == other.viewport_top && viewport_bottom == other.viewport_bottom; |
| 140 |
} |
| 141 |
bool Matches(const ScissorResult& other, bool compare_scissor, bool compare_viewport) const |
| 142 |
{ |
| 143 |
if (compare_scissor && !ScissorMatches(other)) |
| 144 |
return false; |
| 145 |
if (compare_viewport && !ViewportMatches(other)) |
| 146 |
return false; |
| 147 |
return true; |
| 148 |
} |
| 149 |
|
| 150 |
private: |
| 151 |
ScissorResult(ScissorPos scissor_top_left, ScissorPos scissor_bottom_right, |
| 152 |
ScissorOffset scissor_offset, std::pair<float, float> viewport_x, |
| 153 |
std::pair<float, float> viewport_y); |
| 154 |
|
| 155 |
int GetViewportArea(const ScissorRect& rect) const; |
| 156 |
bool IsWorse(const ScissorRect& lhs, const ScissorRect& rhs) const; |
| 157 |
}; |
| 158 |
|
| 159 |
ScissorResult ComputeScissorRects(ScissorPos scissor_top_left, ScissorPos scissor_bottom_right, |
| 160 |
ScissorOffset scissor_offset, const Viewport& viewport); |
| 161 |
|
| 162 |
void FlushPipeline(); |
| 163 |
void SetGenerationMode(); |
| 164 |
void SetScissorAndViewport(FramebufferManager* frame_buffer_manager, ScissorPos scissor_top_left, |
| 165 |
ScissorPos scissor_bottom_right, ScissorOffset scissor_offset, |
| 166 |
Viewport viewport); |
| 167 |
void SetDepthMode(); |
| 168 |
void SetBlendMode(); |
| 169 |
|
| 170 |
|
| 171 |
bool ClearScreen(FramebufferManager* frame_buffer_manager, const MathUtil::Rectangle<int>& rc, |
| 172 |
bool color_enable, bool alpha_enable, bool z_enable, PixelFormat pixel_format, |
| 173 |
u32 clear_color_ar, u32 clear_color_gb, u32 clear_z_value); |
| 174 |
|
| 175 |
void OnPixelFormatChange(FramebufferManager* frame_buffer_manager, PixelFormat pixel_format, |
| 176 |
DepthFormat z_format); |
| 177 |
void SetInterlacingMode(const BPCmd& bp); |
| 178 |
} |