2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2009-06-22 07:44:20 +00:00
|
|
|
// ------------------------------------------
|
2011-02-14 02:18:03 +00:00
|
|
|
// Video backend must define these functions
|
2009-06-22 07:44:20 +00:00
|
|
|
// ------------------------------------------
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2021-11-12 19:48:26 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2021-11-12 19:48:26 +00:00
|
|
|
#include "Common/MathUtil.h"
|
|
|
|
#include "VideoCommon/BPMemory.h"
|
|
|
|
struct XFMemory;
|
2016-01-17 21:54:31 +00:00
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
namespace BPFunctions
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2021-11-12 19:48:26 +00:00
|
|
|
struct ScissorRange
|
|
|
|
{
|
|
|
|
constexpr ScissorRange() = default;
|
|
|
|
constexpr ScissorRange(int offset, int start, int end) : offset(offset), start(start), end(end) {}
|
|
|
|
int offset = 0;
|
|
|
|
int start = 0;
|
|
|
|
int end = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ScissorRect
|
|
|
|
{
|
|
|
|
constexpr ScissorRect(ScissorRange x_range, ScissorRange y_range)
|
|
|
|
: // Rectangle ctor takes x0, y0, x1, y1.
|
|
|
|
rect(x_range.start, y_range.start, x_range.end, y_range.end), x_off(x_range.offset),
|
|
|
|
y_off(y_range.offset)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MathUtil::Rectangle<int> rect;
|
|
|
|
int x_off;
|
|
|
|
int y_off;
|
|
|
|
|
|
|
|
int GetArea() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Although the GameCube/Wii have only one scissor configuration and only one viewport
|
|
|
|
// configuration, some values can result in multiple parts of the screen being updated.
|
|
|
|
// This can happen if the scissor offset combined with the bottom or right coordinate ends up
|
|
|
|
// exceeding 1024; then, both sides of the screen will be drawn to, while the middle is not.
|
|
|
|
// Major Minor's Majestic March causes this to happen during loading screens and other scrolling
|
|
|
|
// effects, though it draws on top of one of them.
|
|
|
|
// This can also happen if the scissor rectangle is particularly large, but this will usually
|
|
|
|
// involve drawing content outside of the viewport, which Dolphin does not currently handle.
|
|
|
|
//
|
|
|
|
// The hardware backends can currently only use one viewport and scissor rectangle, so we need to
|
|
|
|
// pick the "best" rectangle based on how much of the viewport would be rendered to the screen.
|
|
|
|
// If we choose the wrong one, then content might not actually show up when the game is expecting it
|
|
|
|
// to. This does happen on Major Minor's Majestic March for the final few frames of the horizontal
|
|
|
|
// scrolling animation, but it isn't that important. Note that the assumption that a "best"
|
|
|
|
// rectangle exists is based on games only wanting to draw one rectangle, and accidentally
|
|
|
|
// configuring the scissor offset and size of the scissor rectangle such that multiple show up;
|
|
|
|
// there are no known games where this is not the case.
|
2021-11-28 01:09:55 +00:00
|
|
|
//
|
|
|
|
// An ImGui overlay that displays the scissor rectangle configuration as well as the generated
|
|
|
|
// rectangles is available by setting OverlayScissorStats (GFX_OVERLAY_SCISSOR_STATS)
|
|
|
|
// under [Settings] to True in GFX.ini.
|
2021-11-12 19:48:26 +00:00
|
|
|
struct ScissorResult
|
|
|
|
{
|
|
|
|
ScissorResult(const BPMemory& bpmem, const XFMemory& xfmem);
|
|
|
|
~ScissorResult() = default;
|
|
|
|
ScissorResult(const ScissorResult& other)
|
|
|
|
: scissor_tl{.hex = other.scissor_tl.hex}, scissor_br{.hex = other.scissor_br.hex},
|
|
|
|
scissor_off{.hex = other.scissor_off.hex}, viewport_left{other.viewport_left},
|
|
|
|
viewport_right{other.viewport_right}, viewport_top{other.viewport_top},
|
|
|
|
viewport_bottom{other.viewport_bottom}, m_result{other.m_result}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ScissorResult& operator=(const ScissorResult& other)
|
|
|
|
{
|
|
|
|
if (this == &other)
|
|
|
|
return *this;
|
|
|
|
scissor_tl.hex = other.scissor_tl.hex;
|
|
|
|
scissor_br.hex = other.scissor_br.hex;
|
|
|
|
scissor_off.hex = other.scissor_off.hex;
|
|
|
|
viewport_left = other.viewport_left;
|
|
|
|
viewport_right = other.viewport_right;
|
|
|
|
viewport_top = other.viewport_top;
|
|
|
|
viewport_bottom = other.viewport_bottom;
|
|
|
|
m_result = other.m_result;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ScissorResult(ScissorResult&& other)
|
|
|
|
: scissor_tl{.hex = other.scissor_tl.hex}, scissor_br{.hex = other.scissor_br.hex},
|
|
|
|
scissor_off{.hex = other.scissor_off.hex}, viewport_left{other.viewport_left},
|
|
|
|
viewport_right{other.viewport_right}, viewport_top{other.viewport_top},
|
|
|
|
viewport_bottom{other.viewport_bottom}, m_result{std::move(other.m_result)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ScissorResult& operator=(ScissorResult&& other)
|
|
|
|
{
|
|
|
|
if (this == &other)
|
|
|
|
return *this;
|
|
|
|
scissor_tl.hex = other.scissor_tl.hex;
|
|
|
|
scissor_br.hex = other.scissor_br.hex;
|
|
|
|
scissor_off.hex = other.scissor_off.hex;
|
|
|
|
viewport_left = other.viewport_left;
|
|
|
|
viewport_right = other.viewport_right;
|
|
|
|
viewport_top = other.viewport_top;
|
|
|
|
viewport_bottom = other.viewport_bottom;
|
|
|
|
m_result = std::move(other.m_result);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input values, for use in statistics
|
|
|
|
ScissorPos scissor_tl;
|
|
|
|
ScissorPos scissor_br;
|
|
|
|
ScissorOffset scissor_off;
|
|
|
|
float viewport_left;
|
|
|
|
float viewport_right;
|
|
|
|
float viewport_top;
|
|
|
|
float viewport_bottom;
|
|
|
|
|
|
|
|
// Actual result
|
|
|
|
std::vector<ScissorRect> m_result;
|
|
|
|
|
|
|
|
ScissorRect Best() const;
|
|
|
|
|
2021-11-28 01:09:55 +00:00
|
|
|
bool ScissorMatches(const ScissorResult& other) const
|
|
|
|
{
|
|
|
|
return scissor_tl.hex == other.scissor_tl.hex && scissor_br.hex == other.scissor_br.hex &&
|
|
|
|
scissor_off.hex == other.scissor_off.hex;
|
|
|
|
}
|
|
|
|
bool ViewportMatches(const ScissorResult& other) const
|
|
|
|
{
|
|
|
|
return viewport_left == other.viewport_left && viewport_right == other.viewport_right &&
|
|
|
|
viewport_top == other.viewport_top && viewport_bottom == other.viewport_bottom;
|
|
|
|
}
|
|
|
|
bool Matches(const ScissorResult& other, bool compare_scissor, bool compare_viewport) const
|
|
|
|
{
|
|
|
|
if (compare_scissor && !ScissorMatches(other))
|
|
|
|
return false;
|
|
|
|
if (compare_viewport && !ViewportMatches(other))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-12 19:48:26 +00:00
|
|
|
private:
|
|
|
|
ScissorResult(const BPMemory& bpmem, std::pair<float, float> viewport_x,
|
|
|
|
std::pair<float, float> viewport_y);
|
|
|
|
|
|
|
|
int GetViewportArea(const ScissorRect& rect) const;
|
|
|
|
bool IsWorse(const ScissorRect& lhs, const ScissorRect& rhs) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
ScissorResult ComputeScissorRects();
|
|
|
|
|
2009-06-22 07:44:20 +00:00
|
|
|
void FlushPipeline();
|
2012-01-01 20:46:02 +00:00
|
|
|
void SetGenerationMode();
|
2021-11-12 19:48:26 +00:00
|
|
|
void SetScissorAndViewport();
|
2012-01-01 20:46:02 +00:00
|
|
|
void SetDepthMode();
|
|
|
|
void SetBlendMode();
|
2019-04-15 14:47:46 +00:00
|
|
|
void ClearScreen(const MathUtil::Rectangle<int>& rc);
|
2012-01-01 20:46:02 +00:00
|
|
|
void OnPixelFormatChange();
|
2009-07-26 09:52:35 +00:00
|
|
|
void SetInterlacingMode(const BPCmd& bp);
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace BPFunctions
|