VideoBackends: Store a backbuffer 'scale'

This is a scaling factor, used for hi-dpi configurations.
This commit is contained in:
Stenzek 2019-01-19 00:35:00 +10:00
parent e03b8e899e
commit c9c0b85056
15 changed files with 26 additions and 17 deletions

View File

@ -32,4 +32,7 @@ struct WindowSystemInfo
// on the platform. e.g. HWND for Windows, Window for X11. If the surface is
// set to nullptr, the video backend will run in headless mode.
void* render_surface = nullptr;
// Scale of the render surface. For hidpi systems, this will be >1.
float render_surface_scale = 1.0f;
};

View File

@ -164,6 +164,7 @@ static WindowSystemInfo GetWindowSystemInfo(QWindow* window)
else
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
#endif
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
return wsi;
}

View File

@ -62,8 +62,9 @@ typedef struct _Nv_Stereo_Image_Header
#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e
Renderer::Renderer(int backbuffer_width, int backbuffer_height)
: ::Renderer(backbuffer_width, backbuffer_height, AbstractTextureFormat::RGBA8)
Renderer::Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale)
: ::Renderer(backbuffer_width, backbuffer_height, backbuffer_scale,
AbstractTextureFormat::RGBA8)
{
m_last_multisamples = g_ActiveConfig.iMultisamples;
m_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;

View File

@ -18,7 +18,7 @@ class D3DTexture2D;
class Renderer : public ::Renderer
{
public:
Renderer(int backbuffer_width, int backbuffer_height);
Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale);
~Renderer() override;
StateCache& GetStateCache() { return m_state_cache; }

View File

@ -147,7 +147,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
}
// internal interfaces
g_renderer = std::make_unique<Renderer>(backbuffer_width, backbuffer_height);
g_renderer =
std::make_unique<Renderer>(backbuffer_width, backbuffer_height, wsi.render_surface_scale);
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
g_texture_cache = std::make_unique<TextureCache>();
g_vertex_manager = std::make_unique<VertexManager>();

View File

@ -14,7 +14,7 @@
namespace Null
{
// Init functions
Renderer::Renderer() : ::Renderer(1, 1, AbstractTextureFormat::RGBA8)
Renderer::Renderer() : ::Renderer(1, 1, 1.0f, AbstractTextureFormat::RGBA8)
{
UpdateActiveConfig();
}

View File

@ -351,10 +351,10 @@ static void InitDriverInfo()
}
// Init functions
Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context)
Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context, float backbuffer_scale)
: ::Renderer(static_cast<int>(std::max(main_gl_context->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u)),
AbstractTextureFormat::RGBA8),
backbuffer_scale, AbstractTextureFormat::RGBA8),
m_main_gl_context(std::move(main_gl_context)),
m_current_rasterization_state(RenderState::GetInvalidRasterizationState()),
m_current_depth_state(RenderState::GetInvalidDepthState()),

View File

@ -83,7 +83,7 @@ extern VideoConfig g_ogl_config;
class Renderer : public ::Renderer
{
public:
Renderer(std::unique_ptr<GLContext> main_gl_context);
Renderer(std::unique_ptr<GLContext> main_gl_context, float backbuffer_scale);
~Renderer() override;
bool IsHeadless() const override;

View File

@ -172,7 +172,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
if (!InitializeGLExtensions(main_gl_context.get()) || !FillBackendInfo())
return false;
g_renderer = std::make_unique<Renderer>(std::move(main_gl_context));
g_renderer = std::make_unique<Renderer>(std::move(main_gl_context), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = GetPerfQuery();
ProgramShaderCache::Init();

View File

@ -25,7 +25,7 @@
#include "VideoCommon/VideoConfig.h"
SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window)
: ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT),
: ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT), 1.0f,
AbstractTextureFormat::RGBA8),
m_window(std::move(window))
{

View File

@ -46,9 +46,9 @@
namespace Vulkan
{
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain)
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale)
: ::Renderer(swap_chain ? static_cast<int>(swap_chain->GetWidth()) : 1,
swap_chain ? static_cast<int>(swap_chain->GetHeight()) : 0,
swap_chain ? static_cast<int>(swap_chain->GetHeight()) : 0, backbuffer_scale,
swap_chain ? swap_chain->GetTextureFormat() : AbstractTextureFormat::Undefined),
m_swap_chain(std::move(swap_chain))
{

View File

@ -29,7 +29,7 @@ class VKTexture;
class Renderer : public ::Renderer
{
public:
Renderer(std::unique_ptr<SwapChain> swap_chain);
Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Renderer() override;
static Renderer* GetInstance();

View File

@ -225,7 +225,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
// Create main wrapper instances.
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_renderer = std::make_unique<Renderer>(std::move(swap_chain));
g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_texture_cache = std::make_unique<TextureCache>();
::g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();

View File

@ -81,10 +81,10 @@ static float AspectToWidescreen(float aspect)
return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f));
}
Renderer::Renderer(int backbuffer_width, int backbuffer_height,
Renderer::Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale,
AbstractTextureFormat backbuffer_format)
: m_backbuffer_width(backbuffer_width), m_backbuffer_height(backbuffer_height),
m_backbuffer_format(backbuffer_format)
m_backbuffer_scale(backbuffer_scale), m_backbuffer_format(backbuffer_format)
{
UpdateActiveConfig();
UpdateDrawRectangle();

View File

@ -63,7 +63,8 @@ extern int frameCount;
class Renderer
{
public:
Renderer(int backbuffer_width, int backbuffer_height, AbstractTextureFormat backbuffer_format);
Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale,
AbstractTextureFormat backbuffer_format);
virtual ~Renderer();
using ClearColor = std::array<float, 4>;
@ -125,6 +126,7 @@ public:
// Display resolution
int GetBackbufferWidth() const { return m_backbuffer_width; }
int GetBackbufferHeight() const { return m_backbuffer_height; }
float GetBackbufferScale() const { return m_backbuffer_scale; }
void SetWindowSize(int width, int height);
// EFB coordinate conversion functions
@ -229,6 +231,7 @@ protected:
// Backbuffer (window) size and render area
int m_backbuffer_width = 0;
int m_backbuffer_height = 0;
float m_backbuffer_scale = 1.0f;
AbstractTextureFormat m_backbuffer_format = AbstractTextureFormat::Undefined;
TargetRectangle m_target_rectangle = {};