Function resizeSwapChain

Synopsis

#include <Source/Falcor/Core/API/Device.h>

Fbo::SharedPtr resizeSwapChain(uint32_t width, uint32_t height)

Description

Resize the swap-chain

Returns
A new FBO object

Source

Lines 213-274 in Source/Falcor/Core/API/Device.cpp. Line 143 in Source/Falcor/Core/API/Device.h.

Fbo::SharedPtr Device::resizeSwapChain(uint32_t width, uint32_t height)
{
    assert(width > 0 && height > 0);
    mpRenderContext->flush(true);
    // Store the FBO parameters
    ResourceFormat colorFormat = mpSwapChainFbos[0]->getColorTexture(0)->getFormat();
    const auto& pDepth = mpSwapChainFbos[0]->getDepthStencilTexture();
    ResourceFormat depthFormat = pDepth ? pDepth->getFormat() : ResourceFormat::Unknown;
    // updateDefaultFBO() attaches the resized swapchain to new Texture objects, with Undefined resource state.
    // This is fine in Vulkan because a new swapchain is created, but D3D12 can resize without changing
    // internal resource state, so we must cache the Falcor resource state to track it correctly in the new Texture object.
    // #TODO Is there a better place to cache state within D3D12 implementation instead of #ifdef-ing here?
ef FALCOR_D3D12
    // Save FBO resource states
    std::array<Resource::State, kSwapChainBuffersCount> fboColorStates;
    std::array<Resource::State, kSwapChainBuffersCount> fboDepthStates;
    for (uint32_t i = 0; i < kSwapChainBuffersCount; i++)
    {
        assert(mpSwapChainFbos[i]->getColorTexture(0)->isStateGlobal());
        fboColorStates[i] = mpSwapChainFbos[i]->getColorTexture(0)->getGlobalState();
        const auto& pSwapChainDepth = mpSwapChainFbos[i]->getDepthStencilTexture();
        if (pSwapChainDepth != nullptr)
        {
            assert(pSwapChainDepth->isStateGlobal());
            fboDepthStates[i] = pSwapChainDepth->getGlobalState();
        }
    }
if
    assert(mpSwapChainFbos[0]->getSampleCount() == 1);
    // Delete all the FBOs
    releaseFboData();
    apiResizeSwapChain(width, height, colorFormat);
    updateDefaultFBO(width, height, colorFormat, depthFormat);
ef FALCOR_D3D12
    // Restore FBO resource states
    for (uint32_t i = 0; i < kSwapChainBuffersCount; i++)
    {
        assert(mpSwapChainFbos[i]->getColorTexture(0)->isStateGlobal());
        mpSwapChainFbos[i]->getColorTexture(0)->setGlobalState(fboColorStates[i]);
        const auto& pSwapChainDepth = mpSwapChainFbos[i]->getDepthStencilTexture();
        if (pSwapChainDepth != nullptr)
        {
            assert(pSwapChainDepth->isStateGlobal());
            pSwapChainDepth->setGlobalState(fboDepthStates[i]);
        }
    }
if
!defined(FALCOR_D3D12) && !defined(FALCOR_VK)
or Verify state handling on swapchain resize for this API
if
    return getSwapChainFbo();
}





Add Discussion as Guest

Log in