From 09641ec313814b90298e42af05934f16c23ac291 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Oct 2015 20:11:25 -0400 Subject: [PATCH 1/2] MathUtil: Default initialize Rectangle class data members Puts Rectangles into a valid state upon creation --- Source/Core/Common/MathUtil.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index b8642bf80d..253ac5c2a0 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -117,10 +117,10 @@ double ApproximateReciprocal(double val); template struct Rectangle { - T left; - T top; - T right; - T bottom; + T left{}; + T top{}; + T right{}; + T bottom{}; Rectangle() { } From 10c1fd7f388de2ea361211b8995d4b00020bc48c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Oct 2015 20:24:11 -0400 Subject: [PATCH 2/2] MathUtil: Make Rectangle constructors and equality operator constexpr --- Source/Core/Common/MathUtil.h | 12 +++++++----- Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp | 6 +----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index 253ac5c2a0..968c865a3c 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -122,14 +122,16 @@ struct Rectangle T right{}; T bottom{}; - Rectangle() - { } + constexpr Rectangle() = default; - Rectangle(T theLeft, T theTop, T theRight, T theBottom) + constexpr Rectangle(T theLeft, T theTop, T theRight, T theBottom) : left(theLeft), top(theTop), right(theRight), bottom(theBottom) - { } + {} - bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; } + constexpr bool operator==(const Rectangle& r) const + { + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } T GetWidth() const { return abs(right - left); } T GetHeight() const { return abs(bottom - top); } diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp index 736bf2f042..a18275b90b 100644 --- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp @@ -104,11 +104,7 @@ void PSTextureEncoder::Encode(u8* dst, const TextureCache::TCacheEntryBase *text D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, FLOAT(texture_entry->CacheLinesPerRow() * 8), FLOAT(texture_entry->NumBlocksY())); D3D::context->RSSetViewports(1, &vp); - EFBRectangle fullSrcRect; - fullSrcRect.left = 0; - fullSrcRect.top = 0; - fullSrcRect.right = EFB_WIDTH; - fullSrcRect.bottom = EFB_HEIGHT; + constexpr EFBRectangle fullSrcRect(0, 0, EFB_WIDTH, EFB_HEIGHT); TargetRectangle targetRect = g_renderer->ConvertEFBRectangle(fullSrcRect); D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr);