UPDATE: The problem goes away when I use D3DMULTISAMPLE_NONE instead of D3DMULTISAMPLE_NONMASKABLE, but it the application. I'm not familiar with Direct3D to know why this is the case. Here is the code that renders pixels from a buffer.
HRESULT D3D9RenderImpl::CaptureDisplayFrame(BYTE* pBuffer, INT* width, INT* height, INT* stride)
{
CComPtr<IDirect3DSurface9> pTargetSurface;
CComPtr<IDirect3DSurface9> pTempSurface;
HR(m_pDevice->GetRenderTarget(0, &pTargetSurface));
D3DSURFACE_DESC desc;
HR(pTargetSurface->GetDesc(&desc));
if(!pBuffer)
{
*width = desc.Width;
*height = desc.Height;
*stride = desc.Width * 4; // Always ARGB32
return S_OK;
}
HR(m_pDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pTempSurface, NULL));
HR(m_pDevice->GetRenderTargetData(pTargetSurface, pTempSurface));
D3DLOCKED_RECT d3drect;
HR(pTempSurface->LockRect(&d3drect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY));
BYTE* pFrame = (BYTE*)d3drect.pBits;
memcpy(pBuffer, pFrame, desc.Height * d3drect.Pitch);
return pTempSurface->UnlockRect();
}
Any help would be appreciated.