summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/Render.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoBackends/D3D/Render.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/Render.cpp55
1 files changed, 48 insertions, 7 deletions
diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp
index f1751e44f2..79fa51a504 100644
--- a/Source/Core/VideoBackends/D3D/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Render.cpp
@@ -90,6 +90,8 @@ Renderer::Renderer(int backbuffer_width, int backbuffer_height)
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)m_target_width, (float)m_target_height);
D3D::context->RSSetViewports(1, &vp);
FramebufferManager::BindEFBRenderTarget();
+ m_current_framebuffer_width = m_target_width;
+ m_current_framebuffer_height = m_target_height;
}
Renderer::~Renderer()
@@ -243,6 +245,14 @@ std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTe
return DXStagingTexture::Create(type, config);
}
+std::unique_ptr<AbstractFramebuffer>
+Renderer::CreateFramebuffer(const AbstractTexture* color_attachment,
+ const AbstractTexture* depth_attachment)
+{
+ return DXFramebuffer::Create(static_cast<const DXTexture*>(color_attachment),
+ static_cast<const DXTexture*>(depth_attachment));
+}
+
void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{
D3D::DrawTextScaled(static_cast<float>(left + 1), static_cast<float>(top + 1), 20.f, 0.0f,
@@ -450,7 +460,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
VertexShaderCache::GetSimpleInputLayout());
// Restore expected game state.
- FramebufferManager::BindEFBRenderTarget();
RestoreAPIState();
// Copy the pixel from the renderable to cpu-readable buffer.
@@ -525,7 +534,6 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num
D3D11_VIEWPORT vp =
CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight());
D3D::context->RSSetViewports(1, &vp);
- FramebufferManager::BindEFBRenderTarget(false);
}
else // if (type == EFBAccessType::PokeZ)
{
@@ -536,7 +544,6 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num
CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight());
D3D::context->RSSetViewports(1, &vp);
- FramebufferManager::BindEFBRenderTarget();
}
D3D::DrawEFBPokeQuads(type, points, num_points);
@@ -627,10 +634,8 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
GetTargetHeight(), pixel_shader, VertexShaderCache::GetSimpleVertexShader(),
VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader());
- RestoreAPIState();
-
FramebufferManager::SwapReinterpretTexture();
- FramebufferManager::BindEFBRenderTarget();
+ RestoreAPIState();
}
void Renderer::SetBlendingState(const BlendingState& state)
@@ -653,6 +658,9 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
static constexpr std::array<float, 4> clear_color{{0.f, 0.f, 0.f, 1.f}};
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr);
D3D::context->ClearRenderTargetView(D3D::GetBackBuffer()->GetRTV(), clear_color.data());
+ m_current_framebuffer = nullptr;
+ m_current_framebuffer_width = m_backbuffer_width;
+ m_current_framebuffer_height = m_backbuffer_height;
// activate linear filtering for the buffer copies
D3D::SetLinearCopySampler();
@@ -707,7 +715,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
// begin next frame
RestoreAPIState();
- FramebufferManager::BindEFBRenderTarget();
}
void Renderer::CheckForSurfaceChange()
@@ -769,6 +776,10 @@ void Renderer::ResetAPIState()
void Renderer::RestoreAPIState()
{
// Gets us back into a more game-like state.
+ m_current_framebuffer = nullptr;
+ m_current_framebuffer_width = m_target_width;
+ m_current_framebuffer_height = m_target_height;
+ FramebufferManager::BindEFBRenderTarget();
BPFunctions::SetViewport();
BPFunctions::SetScissor();
}
@@ -797,6 +808,36 @@ void Renderer::RestoreState()
{
}
+void Renderer::SetFramebuffer(const AbstractFramebuffer* framebuffer)
+{
+ const DXFramebuffer* fb = static_cast<const DXFramebuffer*>(framebuffer);
+ D3D::context->OMSetRenderTargets(fb->GetNumRTVs(), fb->GetRTVArray(), fb->GetDSV());
+ m_current_framebuffer = fb;
+ m_current_framebuffer_width = fb->GetWidth();
+ m_current_framebuffer_height = fb->GetHeight();
+}
+
+void Renderer::SetAndDiscardFramebuffer(const AbstractFramebuffer* framebuffer)
+{
+ SetFramebuffer(framebuffer);
+}
+
+void Renderer::SetAndClearFramebuffer(const AbstractFramebuffer* framebuffer,
+ const ClearColor& color_value, float depth_value)
+{
+ SetFramebuffer(framebuffer);
+ if (framebuffer->GetColorFormat() != AbstractTextureFormat::Undefined)
+ {
+ D3D::context->ClearRenderTargetView(
+ static_cast<const DXFramebuffer*>(framebuffer)->GetRTVArray()[0], color_value.data());
+ }
+ if (framebuffer->GetDepthFormat() != AbstractTextureFormat::Undefined)
+ {
+ D3D::context->ClearDepthStencilView(static_cast<const DXFramebuffer*>(framebuffer)->GetDSV(),
+ D3D11_CLEAR_DEPTH, depth_value, 0);
+ }
+}
+
void Renderer::SetRasterizationState(const RasterizationState& state)
{
m_gx_state.raster.hex = state.hex;