From d30110348b10e1cf9765a5c7cec294a4e076a3af Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 Mar 2018 20:45:10 -0400 Subject: gl_rasterizer: Add a SyncViewport method. --- src/video_core/engines/maxwell_3d.h | 10 +++++++ src/video_core/renderer_opengl/gl_rasterizer.cpp | 35 ++++++++++++------------ src/video_core/renderer_opengl/gl_rasterizer.h | 3 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 0e1ae5912..3066bc606 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -11,6 +11,7 @@ #include "common/bit_field.h" #include "common/common_funcs.h" #include "common/common_types.h" +#include "common/math_util.h" #include "video_core/gpu.h" #include "video_core/memory_manager.h" #include "video_core/textures/texture.h" @@ -281,6 +282,15 @@ public: }; float depth_range_near; float depth_range_far; + + MathUtil::Rectangle GetRect() const { + return { + static_cast(x), // left + static_cast(y + height), // top + static_cast(x + width), // right + static_cast(y) // bottom + }; + }; } viewport[NumViewports]; INSERT_PADDING_WORDS(0x1D); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 487d37a26..d83c38cf8 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -228,13 +228,7 @@ void RasterizerOpenGL::DrawArrays() { const bool has_stencil = false; const bool using_color_fb = true; const bool using_depth_fb = false; - - MathUtil::Rectangle viewport_rect_unscaled{ - static_cast(regs.viewport[0].x), // left - static_cast(regs.viewport[0].y + regs.viewport[0].height), // top - static_cast(regs.viewport[0].x + regs.viewport[0].width), // right - static_cast(regs.viewport[0].y) // bottom - }; + const MathUtil::Rectangle viewport_rect{regs.viewport[0].GetRect()}; const bool write_color_fb = state.color_mask.red_enabled == GL_TRUE || state.color_mask.green_enabled == GL_TRUE || @@ -248,7 +242,7 @@ void RasterizerOpenGL::DrawArrays() { Surface depth_surface; MathUtil::Rectangle surfaces_rect; std::tie(color_surface, depth_surface, surfaces_rect) = - res_cache.GetFramebufferSurfaces(using_color_fb, using_depth_fb, viewport_rect_unscaled); + res_cache.GetFramebufferSurfaces(using_color_fb, using_depth_fb, viewport_rect); const u16 res_scale = color_surface != nullptr ? color_surface->res_scale @@ -256,16 +250,16 @@ void RasterizerOpenGL::DrawArrays() { MathUtil::Rectangle draw_rect{ static_cast(MathUtil::Clamp(static_cast(surfaces_rect.left) + - viewport_rect_unscaled.left * res_scale, + viewport_rect.left * res_scale, surfaces_rect.left, surfaces_rect.right)), // Left static_cast(MathUtil::Clamp(static_cast(surfaces_rect.bottom) + - viewport_rect_unscaled.top * res_scale, + viewport_rect.top * res_scale, surfaces_rect.bottom, surfaces_rect.top)), // Top static_cast(MathUtil::Clamp(static_cast(surfaces_rect.left) + - viewport_rect_unscaled.right * res_scale, + viewport_rect.right * res_scale, surfaces_rect.left, surfaces_rect.right)), // Right static_cast(MathUtil::Clamp(static_cast(surfaces_rect.bottom) + - viewport_rect_unscaled.bottom * res_scale, + viewport_rect.bottom * res_scale, surfaces_rect.bottom, surfaces_rect.top))}; // Bottom // Bind the framebuffer surfaces @@ -293,12 +287,7 @@ void RasterizerOpenGL::DrawArrays() { } // Sync the viewport - state.viewport.x = - static_cast(surfaces_rect.left) + viewport_rect_unscaled.left * res_scale; - state.viewport.y = - static_cast(surfaces_rect.bottom) + viewport_rect_unscaled.bottom * res_scale; - state.viewport.width = static_cast(viewport_rect_unscaled.GetWidth() * res_scale); - state.viewport.height = static_cast(viewport_rect_unscaled.GetHeight() * res_scale); + SyncViewport(surfaces_rect, res_scale); // TODO(bunnei): Sync framebuffer_scale uniform here // TODO(bunnei): Sync scissorbox uniform(s) here @@ -541,6 +530,16 @@ void main() { } } +void RasterizerOpenGL::SyncViewport(const MathUtil::Rectangle& surfaces_rect, u16 res_scale) { + const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; + const MathUtil::Rectangle viewport_rect{regs.viewport[0].GetRect()}; + + state.viewport.x = static_cast(surfaces_rect.left) + viewport_rect.left * res_scale; + state.viewport.y = static_cast(surfaces_rect.bottom) + viewport_rect.bottom * res_scale; + state.viewport.width = static_cast(viewport_rect.GetWidth() * res_scale); + state.viewport.height = static_cast(viewport_rect.GetHeight() * res_scale); +} + void RasterizerOpenGL::SyncClipEnabled() { UNREACHABLE(); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index c889b1aff..1cd46c96a 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -87,6 +87,9 @@ public: private: struct SamplerInfo {}; + /// Syncs the viewport to match the guest state + void SyncViewport(const MathUtil::Rectangle& surfaces_rect, u16 res_scale); + /// Syncs the clip enabled status to match the guest state void SyncClipEnabled(); -- cgit v1.2.3