51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#include "Rendering/D3D12/D3D12WindowSwapChainPresenter.h"
|
|
|
|
#include <sstream>
|
|
|
|
namespace XCEngine::UI::Editor::Host {
|
|
|
|
bool D3D12WindowSwapChainPresenter::PreparePresentSurface(
|
|
const ::XCEngine::Rendering::RenderContext& renderContext) {
|
|
if (!renderContext.IsValid() || renderContext.commandList == nullptr) {
|
|
m_lastError = "PreparePresentSurface requires a valid render context.";
|
|
return false;
|
|
}
|
|
|
|
if (m_swapChain == nullptr) {
|
|
m_lastError = "PreparePresentSurface requires an initialized swap chain.";
|
|
return false;
|
|
}
|
|
|
|
const std::uint32_t backBufferIndex = m_swapChain->GetCurrentBackBufferIndex();
|
|
if (backBufferIndex >= m_backBufferViews.size() ||
|
|
m_backBufferViews[backBufferIndex] == nullptr) {
|
|
std::ostringstream error = {};
|
|
error << "PreparePresentSurface could not find the current swap chain RTV. index="
|
|
<< backBufferIndex
|
|
<< " rtvCount="
|
|
<< m_backBufferViews.size();
|
|
m_lastError = error.str();
|
|
return false;
|
|
}
|
|
|
|
renderContext.commandList->TransitionBarrier(
|
|
m_backBufferViews[backBufferIndex],
|
|
::XCEngine::RHI::ResourceStates::Present,
|
|
::XCEngine::RHI::ResourceStates::RenderTarget);
|
|
m_lastError.clear();
|
|
return true;
|
|
}
|
|
|
|
bool D3D12WindowSwapChainPresenter::PresentFrame() {
|
|
if (m_swapChain == nullptr) {
|
|
m_lastError = "PresentFrame requires an initialized swap chain.";
|
|
return false;
|
|
}
|
|
|
|
m_swapChain->Present(0, 0);
|
|
m_lastError.clear();
|
|
return true;
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|