Skip to content

Commit

Permalink
Round viewport coordinates when vertex rounding is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Jan 27, 2022
1 parent f84cf95 commit 690cfb9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -298,7 +298,7 @@
<string name="disable_bbox">Disable Bounding Box</string>
<string name="disable_bbox_description">Disables bounding box emulation. This may improve GPU performance significantly, but some games will break. If unsure, leave this checked.</string>
<string name="vertex_rounding">Vertex Rounding</string>
<string name="vertex_rounding_description">Rounds 2D vertices to whole pixels. Fixes graphical problems in some games at higher internal resolutions. This setting has no effect when native internal resolution is used. If unsure, leave this unchecked.</string>
<string name="vertex_rounding_description">Rounds 2D vertices to whole pixels and rounds the viewport size to a whole number. Fixes graphical problems in some games at higher internal resolutions. This setting has no effect when native internal resolution is used. If unsure, leave this unchecked.</string>
<string name="texture_cache_to_state">Save Texture Cache to State</string>
<string name="texture_cache_to_state_description">Includes the contents of the embedded frame buffer (EFB) and upscaled EFB copies in save states. Fixes missing and/or non-upscaled textures/objects when loading states at the cost of additional save/load time.</string>
<string name="aspect_ratio">Aspect Ratio</string>
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp
Expand Up @@ -272,10 +272,10 @@ void HacksWidget::AddDescriptions()
"states at the cost of additional save/load time.<br><br><dolphin_emphasis>If "
"unsure, leave this checked.</dolphin_emphasis>");
static const char TR_VERTEX_ROUNDING_DESCRIPTION[] = QT_TR_NOOP(
"Rounds 2D vertices to whole pixels.<br><br>Fixes graphical problems in some games at "
"higher internal resolutions. This setting has no effect when native internal "
"resolution is used.<br><br><dolphin_emphasis>If unsure, leave this "
"unchecked.</dolphin_emphasis>");
"Rounds 2D vertices to whole pixels and rounds the viewport size to a whole number.<br><br>"
"Fixes graphical problems in some games at higher internal resolutions. This setting has no "
"effect when native internal resolution is used.<br><br>"
"<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>");

m_skip_efb_cpu->SetDescription(tr(TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION));
m_ignore_format_changes->SetDescription(tr(TR_IGNORE_FORMAT_CHANGE_DESCRIPTION));
Expand Down
26 changes: 20 additions & 6 deletions Source/Core/VideoCommon/BPFunctions.cpp
Expand Up @@ -4,6 +4,7 @@
#include "VideoCommon/BPFunctions.h"

#include <algorithm>
#include <cmath>
#include <string_view>

#include "Common/CommonTypes.h"
Expand Down Expand Up @@ -74,13 +75,26 @@ void SetScissor()

void SetViewport()
{
s32 xoff = bpmem.scissorOffset.x * 2;
s32 yoff = bpmem.scissorOffset.y * 2;
float x = g_renderer->EFBToScaledXf(xfmem.viewport.xOrig - xfmem.viewport.wd - xoff);
float y = g_renderer->EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - yoff);
const s32 xoff = bpmem.scissorOffset.x * 2;
const s32 yoff = bpmem.scissorOffset.y * 2;
float raw_x = xfmem.viewport.xOrig - xfmem.viewport.wd - xoff;
float raw_y = xfmem.viewport.yOrig + xfmem.viewport.ht - yoff;
float raw_width = 2.0f * xfmem.viewport.wd;
float raw_height = -2.0f * xfmem.viewport.ht;
if (g_ActiveConfig.UseVertexRounding())
{
// Round the viewport to match full 1x IR pixels as well.
// This eliminates a line in the archery mode in Wii Sports Resort at 3x IR and higher.
raw_x = std::round(raw_x);
raw_y = std::round(raw_y);
raw_width = std::round(raw_width);
raw_height = std::round(raw_height);
}

float width = g_renderer->EFBToScaledXf(2.0f * xfmem.viewport.wd);
float height = g_renderer->EFBToScaledYf(-2.0f * xfmem.viewport.ht);
float x = g_renderer->EFBToScaledXf(raw_x);
float y = g_renderer->EFBToScaledYf(raw_y);
float width = g_renderer->EFBToScaledXf(raw_width);
float height = g_renderer->EFBToScaledYf(raw_height);
float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float max_depth = xfmem.viewport.farZ / 16777216.0f;
if (width < 0.f)
Expand Down

0 comments on commit 690cfb9

Please sign in to comment.