diff options
Diffstat (limited to 'src/video_core')
-rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 31 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 11 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 8483f79be..729e8e73d 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -191,7 +191,8 @@ void RendererOpenGL::DrawSingleScreenRotated(const TextureInfo& texture, float x * Draws the emulated screens to the emulator window. */ void RendererOpenGL::DrawScreens() { - glViewport(0, 0, resolution_width, resolution_height); + auto viewport_extent = GetViewportExtent(); + glViewport(viewport_extent.left, viewport_extent.top, viewport_extent.GetWidth(), viewport_extent.GetHeight()); // TODO: Or bottom? glClear(GL_COLOR_BUFFER_BIT); glUseProgram(program_id); @@ -228,6 +229,34 @@ void RendererOpenGL::SetWindow(EmuWindow* window) { render_window = window; } +MathUtil::Rectangle<unsigned> RendererOpenGL::GetViewportExtent() { + unsigned framebuffer_width; + unsigned framebuffer_height; + std::tie(framebuffer_width, framebuffer_height) = render_window->GetFramebufferSize(); + + float window_aspect_ratio = static_cast<float>(framebuffer_height) / framebuffer_width; + float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width; + + MathUtil::Rectangle<unsigned> viewport_extent; + if (window_aspect_ratio > emulation_aspect_ratio) { + // Window is narrower than the emulation content => apply borders to the top and bottom + unsigned viewport_height = emulation_aspect_ratio * framebuffer_width; + viewport_extent.left = 0; + viewport_extent.top = (framebuffer_height - viewport_height) / 2; + viewport_extent.right = viewport_extent.left + framebuffer_width; + viewport_extent.bottom = viewport_extent.top + viewport_height; + } else { + // Otherwise, apply borders to the left and right sides of the window. + unsigned viewport_width = framebuffer_height / emulation_aspect_ratio; + viewport_extent.left = (framebuffer_width - viewport_width) / 2; + viewport_extent.top = 0; + viewport_extent.right = viewport_extent.left + viewport_width; + viewport_extent.bottom = viewport_extent.top + framebuffer_height; + } + + return viewport_extent; +} + /// Initialize the renderer void RendererOpenGL::Init() { render_window->MakeCurrent(); diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index eed201a95..7fdcec731 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -4,13 +4,15 @@ #pragma once +#include <array> + #include "generated/gl_3_2_core.h" -#include "common/common.h" +#include "common/math_util.h" + #include "core/hw/gpu.h" -#include "video_core/renderer_base.h" -#include <array> +#include "video_core/renderer_base.h" class EmuWindow; @@ -52,6 +54,9 @@ private: static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, const TextureInfo& texture); + /// Computes the viewport rectangle + MathUtil::Rectangle<unsigned> GetViewportExtent(); + EmuWindow* render_window; ///< Handle to render window u32 last_mode; ///< Last render mode |