Renderer: Adjust target rectangle in the base class

This commit is contained in:
Stenzek 2019-04-28 17:00:18 +10:00
parent 3c64f0c616
commit 32359bf2bb
8 changed files with 42 additions and 34 deletions

View File

@ -327,10 +327,12 @@ void Renderer::WaitForGPUIdle()
D3D::context->Flush();
}
void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil::Rectangle<int>& rc)
void Renderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc)
{
if (g_ActiveConfig.stereo_mode != StereoMode::Nvidia3DVision)
return ::Renderer::RenderXFBToScreen(texture, rc);
return ::Renderer::RenderXFBToScreen(target_rc, source_texture, source_rc);
if (!m_3d_vision_texture)
Create3DVisionTexture(m_backbuffer_width, m_backbuffer_height);
@ -338,14 +340,11 @@ void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil:
// Render to staging texture which is double the width of the backbuffer
SetAndClearFramebuffer(m_3d_vision_framebuffer.get());
auto adjusted_rc = rc;
auto target_rc = GetTargetRectangle();
AdjustRectanglesToFitBounds(&target_rc, &adjusted_rc, m_backbuffer_width, m_backbuffer_height);
m_post_processor->BlitFromTexture(target_rc, adjusted_rc, texture, 0);
m_post_processor->BlitFromTexture(target_rc, source_rc, source_texture, 0);
m_post_processor->BlitFromTexture(
MathUtil::Rectangle<int>(target_rc.left + m_backbuffer_width, target_rc.top,
target_rc.right + m_backbuffer_width, target_rc.bottom),
adjusted_rc, texture, 1);
source_rc, source_texture, 1);
// Copy the left eye to the backbuffer, if Nvidia 3D Vision is enabled it should
// recognize the signature and automatically include the right eye frame.

View File

@ -67,8 +67,9 @@ public:
void Flush() override;
void WaitForGPUIdle() override;
void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc) override;
void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc) override;
void OnConfigChanged(u32 bits) override;
private:

View File

@ -978,21 +978,19 @@ void Renderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable,
BPFunctions::SetScissor();
}
void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil::Rectangle<int>& rc)
void Renderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc)
{
// Quad-buffered stereo is annoying on GL.
if (g_ActiveConfig.stereo_mode != StereoMode::QuadBuffer)
return ::Renderer::RenderXFBToScreen(texture, rc);
auto adjusted_rc = rc;
auto target_rc = GetTargetRectangle();
AdjustRectanglesToFitBounds(&target_rc, &adjusted_rc, m_backbuffer_width, m_backbuffer_height);
return ::Renderer::RenderXFBToScreen(target_rc, source_texture, source_rc);
glDrawBuffer(GL_BACK_LEFT);
m_post_processor->BlitFromTexture(target_rc, adjusted_rc, texture, 0);
m_post_processor->BlitFromTexture(target_rc, source_rc, source_texture, 0);
glDrawBuffer(GL_BACK_RIGHT);
m_post_processor->BlitFromTexture(target_rc, adjusted_rc, texture, 1);
m_post_processor->BlitFromTexture(target_rc, source_rc, source_texture, 1);
glDrawBuffer(GL_BACK);
}

View File

@ -134,8 +134,9 @@ public:
void Flush() override;
void WaitForGPUIdle() override;
void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc) override;
void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc) override;
void OnConfigChanged(u32 bits) override;
void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,

View File

@ -94,11 +94,12 @@ std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipel
}
// Called on the GPU thread
void SWRenderer::RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& xfb_region)
void SWRenderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc)
{
if (!IsHeadless())
m_window->ShowImage(texture, xfb_region);
m_window->ShowImage(source_texture, source_rc);
}
u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)

View File

@ -42,8 +42,9 @@ public:
u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc) override;
void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc) override;
void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z) override;

View File

@ -1251,7 +1251,14 @@ void Renderer::Swap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u6
{
BindBackbuffer({{0.0f, 0.0f, 0.0f, 1.0f}});
UpdateDrawRectangle();
RenderXFBToScreen(xfb_entry->texture.get(), xfb_rect);
// Adjust the source rectangle instead of using an oversized viewport to render the XFB.
auto render_target_rc = GetTargetRectangle();
auto render_source_rc = xfb_rect;
AdjustRectanglesToFitBounds(&render_target_rc, &xfb_rect, m_backbuffer_width,
m_backbuffer_height);
RenderXFBToScreen(render_target_rc, xfb_entry->texture.get(), render_source_rc);
DrawImGui();
// Present to the window system.
@ -1319,23 +1326,22 @@ void Renderer::Swap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u6
}
}
void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const MathUtil::Rectangle<int>& rc)
void Renderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc)
{
auto adjusted_rc = rc;
auto target_rc = GetTargetRectangle();
AdjustRectanglesToFitBounds(&target_rc, &adjusted_rc, m_backbuffer_width, m_backbuffer_height);
if (g_ActiveConfig.stereo_mode == StereoMode::SBS ||
g_ActiveConfig.stereo_mode == StereoMode::TAB)
{
MathUtil::Rectangle<int> left_rc, right_rc;
std::tie(left_rc, right_rc) = ConvertStereoRectangle(target_rc);
m_post_processor->BlitFromTexture(left_rc, adjusted_rc, texture, 0);
m_post_processor->BlitFromTexture(right_rc, adjusted_rc, texture, 1);
m_post_processor->BlitFromTexture(left_rc, source_rc, source_texture, 0);
m_post_processor->BlitFromTexture(right_rc, source_rc, source_texture, 1);
}
else
{
m_post_processor->BlitFromTexture(target_rc, adjusted_rc, texture, 0);
m_post_processor->BlitFromTexture(target_rc, source_rc, source_texture, 0);
}
}

View File

@ -223,8 +223,9 @@ public:
// Draws the specified XFB buffer to the screen, performing any post-processing.
// Assumes that the backbuffer has already been bound and cleared.
virtual void RenderXFBToScreen(const AbstractTexture* texture,
const MathUtil::Rectangle<int>& rc);
virtual void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
const MathUtil::Rectangle<int>& source_rc);
// Called when the configuration changes, and backend structures need to be updated.
virtual void OnConfigChanged(u32 bits) {}