Exemplo n.º 1
0
HRESULT WrappedIDXGISwapChain2::ResizeBuffers(
    /* [in] */ UINT BufferCount,
    /* [in] */ UINT Width,
    /* [in] */ UINT Height,
    /* [in] */ DXGI_FORMAT NewFormat,
    /* [in] */ UINT SwapChainFlags)
{
    for(int i=0; i < MAX_NUM_BACKBUFFERS; i++)
    {
        WrappedID3D11Texture2D *wrapped = (WrappedID3D11Texture2D*)m_pBackBuffers[i];
        if(wrapped)
        {
            m_pDevice->GetImmediateContext()->GetCurrentPipelineState()->UnbindIUnknownForWrite(wrapped);
            m_pDevice->GetImmediateContext()->GetCurrentPipelineState()->UnbindForRead(wrapped);

            wrapped->ViewRelease();
        }

        wrapped = NULL;
    }

    m_pDevice->ReleaseSwapchainResources(this);

    HRESULT ret = m_pReal->ResizeBuffers(BufferCount, Width, Height, NewFormat, SwapChainFlags);

    DXGI_SWAP_CHAIN_DESC desc;
    m_pReal->GetDesc(&desc);

    int bufCount = desc.BufferCount;

    if(desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD)
        bufCount = 1;

    RDCASSERT(bufCount < MAX_NUM_BACKBUFFERS);

    for(int i=0; i < MAX_NUM_BACKBUFFERS; i++)
    {
        m_pBackBuffers[i] = NULL;

        if(i < bufCount)
        {
            GetBuffer(i, __uuidof(ID3D11Texture2D), (void **)&m_pBackBuffers[i]);

            WrappedID3D11Texture2D *wrapped = (WrappedID3D11Texture2D *)m_pBackBuffers[i];

            if(wrapped)
            {
                // keep ref as a 'view' (invisible to user)
                wrapped->ViewAddRef();
                wrapped->Release();
            }
        }
    }

    return ret;
}
Exemplo n.º 2
0
WrappedIDXGISwapChain2::~WrappedIDXGISwapChain2()
{
    m_pDevice->ReleaseSwapchainResources(this);

    for(int i=0; i < MAX_NUM_BACKBUFFERS; i++)
    {
        WrappedID3D11Texture2D *wrapped = (WrappedID3D11Texture2D *)m_pBackBuffers[i];
        if(wrapped)
            wrapped->ViewRelease();
        m_pBackBuffers[i] = NULL;
    }
    SAFE_RELEASE(m_pReal1);
    SAFE_RELEASE(m_pReal2);
    SAFE_RELEASE(m_pReal);

    SAFE_RELEASE(m_pDevice);
}