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);
}
Exemplo n.º 3
0
WrappedIDXGISwapChain2::WrappedIDXGISwapChain2(IDXGISwapChain* real, HWND wnd, WrappedID3D11Device *device)
	: RefCountDXGIObject(real), m_pReal(real), m_pDevice(device), m_iRefcount(1), m_Wnd(wnd)
{
	DXGI_SWAP_CHAIN_DESC desc;
	real->GetDesc(&desc);
	
#if defined(INCLUDE_DXGI_1_2)
	m_pReal1 = NULL;
	real->QueryInterface(__uuidof(IDXGISwapChain1), (void **)&m_pReal1);
	m_pReal2 = NULL;
	real->QueryInterface(__uuidof(IDXGISwapChain2), (void **)&m_pReal2);
#endif

	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();
			}
		}
	}

	SAFE_ADDREF(m_pDevice);

	// we do a 'fake' present right at the start, so that we can capture frame 1, by
	// going from this fake present to the first present.
	m_pDevice->FirstFrame(this);
}