VideoConfig: Make AspectMode an enum class

Makes for more strongly-typed identifiers (and doesn't pollute
surrounding namespaces)
This commit is contained in:
Lioncash 2017-11-10 22:45:32 -05:00
parent 609a17a0cd
commit 10697bcbe3
6 changed files with 45 additions and 41 deletions

View File

@ -22,9 +22,9 @@ const ConfigInfo<int> GFX_ADAPTER{{System::GFX, "Hardware", "Adapter"}, 0};
const ConfigInfo<bool> GFX_WIDESCREEN_HACK{{System::GFX, "Settings", "wideScreenHack"}, false};
const ConfigInfo<int> GFX_ASPECT_RATIO{{System::GFX, "Settings", "AspectRatio"},
static_cast<int>(ASPECT_AUTO)};
static_cast<int>(AspectMode::Auto)};
const ConfigInfo<int> GFX_SUGGESTED_ASPECT_RATIO{{System::GFX, "Settings", "SuggestedAspectRatio"},
static_cast<int>(ASPECT_AUTO)};
static_cast<int>(AspectMode::Auto)};
const ConfigInfo<bool> GFX_CROP{{System::GFX, "Settings", "Crop"}, false};
const ConfigInfo<int> GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES{
{System::GFX, "Settings", "SafeTextureCacheColorSamples"}, 128};

View File

@ -221,7 +221,10 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_TOGGLE_CROP))
g_Config.bCrop = !g_Config.bCrop;
if (IsHotkey(HK_TOGGLE_AR))
g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
{
g_Config.aspect_mode =
static_cast<AspectMode>((static_cast<int>(g_Config.aspect_mode) + 1) & 3);
}
if (IsHotkey(HK_TOGGLE_EFBCOPIES))
g_Config.bSkipEFBCopyToRam = !g_Config.bSkipEFBCopyToRam;
if (IsHotkey(HK_TOGGLE_XFBCOPIES))

View File

@ -717,10 +717,10 @@ void Renderer::CheckForSurfaceChange()
void Renderer::CheckForConfigChanges()
{
// Save the video config so we can compare against to determine which settings have changed.
int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
int old_aspect_ratio = g_ActiveConfig.iAspectRatio;
int old_efb_scale = g_ActiveConfig.iEFBScale;
bool old_force_filtering = g_ActiveConfig.bForceFiltering;
const int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
const AspectMode old_aspect_mode = g_ActiveConfig.aspect_mode;
const int old_efb_scale = g_ActiveConfig.iEFBScale;
const bool old_force_filtering = g_ActiveConfig.bForceFiltering;
// Copy g_Config to g_ActiveConfig.
// NOTE: This can potentially race with the UI thread, however if it does, the changes will be
@ -728,10 +728,11 @@ void Renderer::CheckForConfigChanges()
UpdateActiveConfig();
// Determine which (if any) settings have changed.
bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy;
bool force_texture_filtering_changed = old_force_filtering != g_ActiveConfig.bForceFiltering;
bool efb_scale_changed = old_efb_scale != g_ActiveConfig.iEFBScale;
bool aspect_changed = old_aspect_ratio != g_ActiveConfig.iAspectRatio;
const bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy;
const bool force_texture_filtering_changed =
old_force_filtering != g_ActiveConfig.bForceFiltering;
const bool efb_scale_changed = old_efb_scale != g_ActiveConfig.iEFBScale;
const bool aspect_changed = old_aspect_mode != g_ActiveConfig.aspect_mode;
// Update texture cache settings with any changed options.
TextureCache::GetInstance()->OnConfigChanged(g_ActiveConfig);

View File

@ -312,19 +312,20 @@ void Renderer::DrawDebugText()
break;
}
const char* ar_text = "";
switch (g_ActiveConfig.iAspectRatio)
switch (g_ActiveConfig.aspect_mode)
{
case ASPECT_AUTO:
case AspectMode::Auto:
ar_text = "Auto";
break;
case ASPECT_STRETCH:
case AspectMode::Stretch:
ar_text = "Stretch";
break;
case ASPECT_ANALOG:
case AspectMode::Analog:
ar_text = "Force 4:3";
break;
case ASPECT_ANALOG_WIDE:
case AspectMode::AnalogWide:
ar_text = "Force 16:9";
break;
}
const char* const efbcopy_text = g_ActiveConfig.bSkipEFBCopyToRam ? "to Texture" : "to RAM";
@ -381,15 +382,15 @@ void Renderer::DrawDebugText()
float Renderer::CalculateDrawAspectRatio() const
{
if (g_ActiveConfig.iAspectRatio == ASPECT_STRETCH)
if (g_ActiveConfig.aspect_mode == AspectMode::Stretch)
{
// If stretch is enabled, we prefer the aspect ratio of the window.
return (static_cast<float>(m_backbuffer_width) / static_cast<float>(m_backbuffer_height));
}
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
if (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE ||
(g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && m_aspect_wide))
if (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide))
{
return AspectToWidescreen(VideoInterface::GetAspectRatio());
}
@ -428,21 +429,20 @@ void Renderer::UpdateDrawRectangle()
float source_aspect = VideoInterface::GetAspectRatio();
if (m_aspect_wide)
source_aspect = AspectToWidescreen(source_aspect);
float target_aspect;
float target_aspect = 0.0f;
switch (g_ActiveConfig.iAspectRatio)
switch (g_ActiveConfig.aspect_mode)
{
case ASPECT_STRETCH:
case AspectMode::Stretch:
target_aspect = win_width / win_height;
break;
case ASPECT_ANALOG:
case AspectMode::Analog:
target_aspect = VideoInterface::GetAspectRatio();
break;
case ASPECT_ANALOG_WIDE:
case AspectMode::AnalogWide:
target_aspect = AspectToWidescreen(VideoInterface::GetAspectRatio());
break;
default:
// ASPECT_AUTO
case AspectMode::Auto:
target_aspect = source_aspect;
break;
}
@ -475,10 +475,10 @@ void Renderer::UpdateDrawRectangle()
draw_height = crop_height = 1;
// crop the picture to a standard aspect ratio
if (g_ActiveConfig.bCrop && g_ActiveConfig.iAspectRatio != ASPECT_STRETCH)
if (g_ActiveConfig.bCrop && g_ActiveConfig.aspect_mode != AspectMode::Stretch)
{
float expected_aspect = (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE ||
(g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && m_aspect_wide)) ?
float expected_aspect = (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide)) ?
(16.0f / 9.0f) :
(4.0f / 3.0f);
if (crop_width / crop_height >= expected_aspect)
@ -550,8 +550,8 @@ std::tuple<int, int> Renderer::CalculateOutputDimensions(int width, int height)
{
// Force 4:3 or 16:9 by cropping the image.
float current_aspect = scaled_width / scaled_height;
float expected_aspect = (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE ||
(g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && m_aspect_wide)) ?
float expected_aspect = (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide)) ?
(16.0f / 9.0f) :
(4.0f / 3.0f);
if (current_aspect > expected_aspect)

View File

@ -61,11 +61,11 @@ void VideoConfig::Refresh()
iAdapter = Config::Get(Config::GFX_ADAPTER);
bWidescreenHack = Config::Get(Config::GFX_WIDESCREEN_HACK);
const int aspect_ratio = Config::Get(Config::GFX_ASPECT_RATIO);
if (aspect_ratio == ASPECT_AUTO)
iAspectRatio = Config::Get(Config::GFX_SUGGESTED_ASPECT_RATIO);
const auto config_aspect_mode = static_cast<AspectMode>(Config::Get(Config::GFX_ASPECT_RATIO));
if (config_aspect_mode == AspectMode::Auto)
aspect_mode = static_cast<AspectMode>(Config::Get(Config::GFX_SUGGESTED_ASPECT_RATIO));
else
iAspectRatio = aspect_ratio;
aspect_mode = config_aspect_mode;
bCrop = Config::Get(Config::GFX_CROP);
iSafeTextureCache_ColorSamples = Config::Get(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES);
bShowFPS = Config::Get(Config::GFX_SHOW_FPS);

View File

@ -24,12 +24,12 @@
constexpr int EFB_SCALE_AUTO_INTEGRAL = 0;
enum AspectMode
enum class AspectMode
{
ASPECT_AUTO = 0,
ASPECT_ANALOG_WIDE = 1,
ASPECT_ANALOG = 2,
ASPECT_STRETCH = 3,
Auto,
AnalogWide,
Analog,
Stretch,
};
enum StereoMode
@ -63,7 +63,7 @@ struct VideoConfig final
// General
bool bVSync;
bool bWidescreenHack;
int iAspectRatio;
AspectMode aspect_mode;
bool bCrop; // Aspect ratio controls.
bool bShaderCache;