Skip to content
Permalink
Browse files

VideoBackends: Store a backbuffer 'scale'

This is a scaling factor, used for hi-dpi configurations.
  • Loading branch information...
stenzek committed Jan 18, 2019
1 parent e03b8e8 commit c9c0b8505615cb16a770d66650e89c0f41d00dc8
@@ -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;
};
@@ -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;
}
@@ -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;
@@ -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; }
@@ -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>();
@@ -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();
}
@@ -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()),
@@ -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;
@@ -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();
@@ -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))
{
@@ -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))
{
@@ -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();
@@ -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>();
@@ -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();
@@ -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 @@ class Renderer
// 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 @@ class Renderer
// 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 = {};

0 comments on commit c9c0b85

Please sign in to comment.
You can’t perform that action at this time.