Fix viewport to surface rect clamping

This commit is contained in:
Phantom 2017-12-29 17:07:01 +01:00
parent 19672cfee8
commit be1d0cee1e

View File

@ -271,14 +271,18 @@ void RasterizerOpenGL::DrawTriangles() {
: (depth_surface == nullptr ? 1u : depth_surface->res_scale); : (depth_surface == nullptr ? 1u : depth_surface->res_scale);
MathUtil::Rectangle<u32> draw_rect{ MathUtil::Rectangle<u32> draw_rect{
MathUtil::Clamp(surfaces_rect.left + viewport_rect_unscaled.left * res_scale, // left static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
surfaces_rect.left, surfaces_rect.right), viewport_rect_unscaled.left * res_scale,
MathUtil::Clamp(surfaces_rect.bottom + viewport_rect_unscaled.top * res_scale, // top surfaces_rect.left, surfaces_rect.right)), // Left
surfaces_rect.bottom, surfaces_rect.top), static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
MathUtil::Clamp(surfaces_rect.left + viewport_rect_unscaled.right * res_scale, // right viewport_rect_unscaled.top * res_scale,
surfaces_rect.left, surfaces_rect.right), surfaces_rect.bottom, surfaces_rect.top)), // Top
MathUtil::Clamp(surfaces_rect.bottom + viewport_rect_unscaled.bottom * res_scale, // bottom static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.left) +
surfaces_rect.bottom, surfaces_rect.top)}; viewport_rect_unscaled.right * res_scale,
surfaces_rect.left, surfaces_rect.right)), // Right
static_cast<u32>(MathUtil::Clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
viewport_rect_unscaled.bottom * res_scale,
surfaces_rect.bottom, surfaces_rect.top))}; // Bottom
// Bind the framebuffer surfaces // Bind the framebuffer surfaces
state.draw.draw_framebuffer = framebuffer.handle; state.draw.draw_framebuffer = framebuffer.handle;
@ -306,9 +310,9 @@ void RasterizerOpenGL::DrawTriangles() {
// Sync the viewport // Sync the viewport
state.viewport.x = state.viewport.x =
static_cast<GLint>(surfaces_rect.left + viewport_rect_unscaled.left * res_scale); static_cast<GLint>(surfaces_rect.left) + viewport_rect_unscaled.left * res_scale;
state.viewport.y = state.viewport.y =
static_cast<GLint>(surfaces_rect.bottom + viewport_rect_unscaled.bottom * res_scale); 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.width = static_cast<GLsizei>(viewport_rect_unscaled.GetWidth() * res_scale);
state.viewport.height = static_cast<GLsizei>(viewport_rect_unscaled.GetHeight() * res_scale); state.viewport.height = static_cast<GLsizei>(viewport_rect_unscaled.GetHeight() * res_scale);