int
D3DOverdrawWindow::
Loop(void)
{
    int nOverdraw = 0;
    IDirect3DQuery9* pOcclusionQuery;
    DWORD numberOfPixelsDrawn;
    d3d->CreateQuery(D3DQUERYTYPE_OCCLUSION, &pOcclusionQuery);

    for (unsigned int iViewpoint = 0; iViewpoint < m_nViewpointCount;
         iViewpoint++)
    {
        // Add an end marker to the command buffer queue.
        pOcclusionQuery->Issue(D3DISSUE_BEGIN);
        // Draw scene
        SetupDraw(iViewpoint);
        DrawModel();
        d3d->EndScene();
        d3d->Present(NULL, NULL, NULL, NULL);
        // Add an end marker to the command buffer queue.
        pOcclusionQuery->Issue(D3DISSUE_END);

        // Force the driver to execute the commands from the command buffer.
        // Empty the command buffer and wait until the GPU is idle.
        while (S_FALSE == pOcclusionQuery->GetData(&numberOfPixelsDrawn,
                                                   sizeof(DWORD), D3DGETDATA_FLUSH))
            ;

        nOverdraw += numberOfPixelsDrawn;
    }

    pOcclusionQuery->Release();
    return nOverdraw;
}
示例#2
0
bool Display::getOcclusionQuerySupport() const
{
    if (!isInitialized())
    {
        return false;
    }

    IDirect3DQuery9 *query = NULL;
    HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query);

    if (SUCCEEDED(result) && query)
    {
        query->Release();
        return true;
    }
    else
    {
        return false;
    }
}