gl_rasterizer: Add a SyncViewport method.

This commit is contained in:
bunnei 2018-03-26 20:45:10 -04:00
parent 67bc2f5ecd
commit d30110348b
3 changed files with 30 additions and 18 deletions

View file

@ -11,6 +11,7 @@
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/math_util.h"
#include "video_core/gpu.h" #include "video_core/gpu.h"
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
#include "video_core/textures/texture.h" #include "video_core/textures/texture.h"
@ -281,6 +282,15 @@ public:
}; };
float depth_range_near; float depth_range_near;
float depth_range_far; float depth_range_far;
MathUtil::Rectangle<s32> GetRect() const {
return {
static_cast<s32>(x), // left
static_cast<s32>(y + height), // top
static_cast<s32>(x + width), // right
static_cast<s32>(y) // bottom
};
};
} viewport[NumViewports]; } viewport[NumViewports];
INSERT_PADDING_WORDS(0x1D); INSERT_PADDING_WORDS(0x1D);

View file

@ -228,13 +228,7 @@ void RasterizerOpenGL::DrawArrays() {
const bool has_stencil = false; const bool has_stencil = false;
const bool using_color_fb = true; const bool using_color_fb = true;
const bool using_depth_fb = false; const bool using_depth_fb = false;
const MathUtil::Rectangle<s32> viewport_rect{regs.viewport[0].GetRect()};
MathUtil::Rectangle<s32> viewport_rect_unscaled{
static_cast<s32>(regs.viewport[0].x), // left
static_cast<s32>(regs.viewport[0].y + regs.viewport[0].height), // top
static_cast<s32>(regs.viewport[0].x + regs.viewport[0].width), // right
static_cast<s32>(regs.viewport[0].y) // bottom
};
const bool write_color_fb = const bool write_color_fb =
state.color_mask.red_enabled == GL_TRUE || state.color_mask.green_enabled == GL_TRUE || state.color_mask.red_enabled == GL_TRUE || state.color_mask.green_enabled == GL_TRUE ||
@ -248,7 +242,7 @@ void RasterizerOpenGL::DrawArrays() {
Surface depth_surface; Surface depth_surface;
MathUtil::Rectangle<u32> surfaces_rect; MathUtil::Rectangle<u32> surfaces_rect;
std::tie(color_surface, depth_surface, 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 const u16 res_scale = color_surface != nullptr
? color_surface->res_scale ? color_surface->res_scale
@ -256,16 +250,16 @@ void RasterizerOpenGL::DrawArrays() {
MathUtil::Rectangle<u32> draw_rect{ MathUtil::Rectangle<u32> draw_rect{
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) + static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
viewport_rect_unscaled.left * res_scale, viewport_rect.left * res_scale,
surfaces_rect.left, surfaces_rect.right)), // Left surfaces_rect.left, surfaces_rect.right)), // Left
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) + static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
viewport_rect_unscaled.top * res_scale, viewport_rect.top * res_scale,
surfaces_rect.bottom, surfaces_rect.top)), // Top surfaces_rect.bottom, surfaces_rect.top)), // Top
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) + static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
viewport_rect_unscaled.right * res_scale, viewport_rect.right * res_scale,
surfaces_rect.left, surfaces_rect.right)), // Right surfaces_rect.left, surfaces_rect.right)), // Right
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) + static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
viewport_rect_unscaled.bottom * res_scale, viewport_rect.bottom * res_scale,
surfaces_rect.bottom, surfaces_rect.top))}; // Bottom surfaces_rect.bottom, surfaces_rect.top))}; // Bottom
// Bind the framebuffer surfaces // Bind the framebuffer surfaces
@ -293,12 +287,7 @@ void RasterizerOpenGL::DrawArrays() {
} }
// Sync the viewport // Sync the viewport
state.viewport.x = SyncViewport(surfaces_rect, res_scale);
static_cast<GLint>(surfaces_rect.left) + viewport_rect_unscaled.left * res_scale;
state.viewport.y =
static_cast<GLint>(surfaces_rect.bottom) + viewport_rect_unscaled.bottom * res_scale;
state.viewport.width = static_cast<GLsizei>(viewport_rect_unscaled.GetWidth() * res_scale);
state.viewport.height = static_cast<GLsizei>(viewport_rect_unscaled.GetHeight() * res_scale);
// TODO(bunnei): Sync framebuffer_scale uniform here // TODO(bunnei): Sync framebuffer_scale uniform here
// TODO(bunnei): Sync scissorbox uniform(s) here // TODO(bunnei): Sync scissorbox uniform(s) here
@ -541,6 +530,16 @@ void main() {
} }
} }
void RasterizerOpenGL::SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale) {
const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
const MathUtil::Rectangle<s32> viewport_rect{regs.viewport[0].GetRect()};
state.viewport.x = static_cast<GLint>(surfaces_rect.left) + viewport_rect.left * res_scale;
state.viewport.y = static_cast<GLint>(surfaces_rect.bottom) + viewport_rect.bottom * res_scale;
state.viewport.width = static_cast<GLsizei>(viewport_rect.GetWidth() * res_scale);
state.viewport.height = static_cast<GLsizei>(viewport_rect.GetHeight() * res_scale);
}
void RasterizerOpenGL::SyncClipEnabled() { void RasterizerOpenGL::SyncClipEnabled() {
UNREACHABLE(); UNREACHABLE();
} }

View file

@ -87,6 +87,9 @@ public:
private: private:
struct SamplerInfo {}; struct SamplerInfo {};
/// Syncs the viewport to match the guest state
void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale);
/// Syncs the clip enabled status to match the guest state /// Syncs the clip enabled status to match the guest state
void SyncClipEnabled(); void SyncClipEnabled();