diff options
| author | 2014-11-13 19:33:29 +0100 | |
|---|---|---|
| committer | 2014-11-18 13:09:01 +0100 | |
| commit | c5c6e095f037a0128de156103f5b98d5bf2b417c (patch) | |
| tree | 77982e25af8bc7d021b19690603625a1fc91b3f7 /src | |
| parent | EmuWindow: Better document the purpose of OnMinimalClientAreaChangeRequest. (diff) | |
| download | yuzu-c5c6e095f037a0128de156103f5b98d5bf2b417c.tar.gz yuzu-c5c6e095f037a0128de156103f5b98d5bf2b417c.tar.xz yuzu-c5c6e095f037a0128de156103f5b98d5bf2b417c.zip | |
OpenGL Renderer: Cleanup viewport extent calculation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 49 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 24 |
2 files changed, 29 insertions, 44 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 082a464b3..729e8e73d 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -191,8 +191,8 @@ void RendererOpenGL::DrawSingleScreenRotated(const TextureInfo& texture, float x | |||
| 191 | * Draws the emulated screens to the emulator window. | 191 | * Draws the emulated screens to the emulator window. |
| 192 | */ | 192 | */ |
| 193 | void RendererOpenGL::DrawScreens() { | 193 | void RendererOpenGL::DrawScreens() { |
| 194 | UpdateViewportExtent(); | 194 | auto viewport_extent = GetViewportExtent(); |
| 195 | glViewport(viewport_extent.x, viewport_extent.y, viewport_extent.width, viewport_extent.height); | 195 | glViewport(viewport_extent.left, viewport_extent.top, viewport_extent.GetWidth(), viewport_extent.GetHeight()); // TODO: Or bottom? |
| 196 | glClear(GL_COLOR_BUFFER_BIT); | 196 | glClear(GL_COLOR_BUFFER_BIT); |
| 197 | 197 | ||
| 198 | glUseProgram(program_id); | 198 | glUseProgram(program_id); |
| @@ -229,37 +229,32 @@ void RendererOpenGL::SetWindow(EmuWindow* window) { | |||
| 229 | render_window = window; | 229 | render_window = window; |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | void RendererOpenGL::UpdateViewportExtent() { | 232 | MathUtil::Rectangle<unsigned> RendererOpenGL::GetViewportExtent() { |
| 233 | unsigned width_in_pixels; | 233 | unsigned framebuffer_width; |
| 234 | unsigned height_in_pixels; | 234 | unsigned framebuffer_height; |
| 235 | std::tie(framebuffer_width, framebuffer_height) = render_window->GetFramebufferSize(); | ||
| 235 | 236 | ||
| 236 | std::tie(width_in_pixels, height_in_pixels) = render_window->GetFramebufferSize(); | 237 | float window_aspect_ratio = static_cast<float>(framebuffer_height) / framebuffer_width; |
| 237 | |||
| 238 | // No update needed if framebuffer size hasn't changed | ||
| 239 | if (width_in_pixels == framebuffer_size.width && height_in_pixels == framebuffer_size.height) { | ||
| 240 | return; | ||
| 241 | } | ||
| 242 | |||
| 243 | framebuffer_size.width = width_in_pixels; | ||
| 244 | framebuffer_size.height = height_in_pixels; | ||
| 245 | |||
| 246 | float window_aspect_ratio = static_cast<float>(height_in_pixels) / width_in_pixels; | ||
| 247 | float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width; | 238 | float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width; |
| 248 | 239 | ||
| 240 | MathUtil::Rectangle<unsigned> viewport_extent; | ||
| 249 | if (window_aspect_ratio > emulation_aspect_ratio) { | 241 | if (window_aspect_ratio > emulation_aspect_ratio) { |
| 250 | // If the window is more narrow than the emulation content, borders are applied on the | 242 | // Window is narrower than the emulation content => apply borders to the top and bottom |
| 251 | // top and bottom of the window. | 243 | unsigned viewport_height = emulation_aspect_ratio * framebuffer_width; |
| 252 | viewport_extent.width = width_in_pixels; | 244 | viewport_extent.left = 0; |
| 253 | viewport_extent.height = emulation_aspect_ratio * viewport_extent.width; | 245 | viewport_extent.top = (framebuffer_height - viewport_height) / 2; |
| 254 | viewport_extent.x = 0; | 246 | viewport_extent.right = viewport_extent.left + framebuffer_width; |
| 255 | viewport_extent.y = (height_in_pixels - viewport_extent.height) / 2; | 247 | viewport_extent.bottom = viewport_extent.top + viewport_height; |
| 256 | } else { | 248 | } else { |
| 257 | // Otherwise, borders are applied on the left and right sides of the window. | 249 | // Otherwise, apply borders to the left and right sides of the window. |
| 258 | viewport_extent.height = height_in_pixels; | 250 | unsigned viewport_width = framebuffer_height / emulation_aspect_ratio; |
| 259 | viewport_extent.width = (1 / emulation_aspect_ratio) * viewport_extent.height; | 251 | viewport_extent.left = (framebuffer_width - viewport_width) / 2; |
| 260 | viewport_extent.x = (width_in_pixels - viewport_extent.width) / 2; | 252 | viewport_extent.top = 0; |
| 261 | viewport_extent.y = 0; | 253 | viewport_extent.right = viewport_extent.left + viewport_width; |
| 254 | viewport_extent.bottom = viewport_extent.top + framebuffer_height; | ||
| 262 | } | 255 | } |
| 256 | |||
| 257 | return viewport_extent; | ||
| 263 | } | 258 | } |
| 264 | 259 | ||
| 265 | /// Initialize the renderer | 260 | /// Initialize the renderer |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index d440e2bc7..7fdcec731 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h | |||
| @@ -4,13 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | |||
| 7 | #include "generated/gl_3_2_core.h" | 9 | #include "generated/gl_3_2_core.h" |
| 8 | 10 | ||
| 9 | #include "common/common.h" | 11 | #include "common/math_util.h" |
| 12 | |||
| 10 | #include "core/hw/gpu.h" | 13 | #include "core/hw/gpu.h" |
| 11 | #include "video_core/renderer_base.h" | ||
| 12 | 14 | ||
| 13 | #include <array> | 15 | #include "video_core/renderer_base.h" |
| 14 | 16 | ||
| 15 | class EmuWindow; | 17 | class EmuWindow; |
| 16 | 18 | ||
| @@ -52,8 +54,8 @@ private: | |||
| 52 | static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, | 54 | static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, |
| 53 | const TextureInfo& texture); | 55 | const TextureInfo& texture); |
| 54 | 56 | ||
| 55 | /// Updates the viewport rectangle | 57 | /// Computes the viewport rectangle |
| 56 | void UpdateViewportExtent(); | 58 | MathUtil::Rectangle<unsigned> GetViewportExtent(); |
| 57 | 59 | ||
| 58 | EmuWindow* render_window; ///< Handle to render window | 60 | EmuWindow* render_window; ///< Handle to render window |
| 59 | u32 last_mode; ///< Last render mode | 61 | u32 last_mode; ///< Last render mode |
| @@ -61,18 +63,6 @@ private: | |||
| 61 | int resolution_width; ///< Current resolution width | 63 | int resolution_width; ///< Current resolution width |
| 62 | int resolution_height; ///< Current resolution height | 64 | int resolution_height; ///< Current resolution height |
| 63 | 65 | ||
| 64 | struct { | ||
| 65 | int width; | ||
| 66 | int height; | ||
| 67 | } framebuffer_size; ///< Current framebuffer size | ||
| 68 | |||
| 69 | struct { | ||
| 70 | int x; | ||
| 71 | int y; | ||
| 72 | int width; | ||
| 73 | int height; | ||
| 74 | } viewport_extent; ///< Current viewport rectangle | ||
| 75 | |||
| 76 | // OpenGL object IDs | 66 | // OpenGL object IDs |
| 77 | GLuint vertex_array_handle; | 67 | GLuint vertex_array_handle; |
| 78 | GLuint vertex_buffer_handle; | 68 | GLuint vertex_buffer_handle; |