开发者

Return error when trying to copy the render target's backbuffer

开发者 https://www.devze.com 2023-03-29 01:35 出处:网络
I have one WDDM user mode display driver for DX9. Now I would like to dump the render target\'s back buffer to a bmp file. Since the render target resource is

I have one WDDM user mode display driver for DX9. Now I would like to dump the render target's back buffer to a bmp file. Since the render target resource is not lockable, I have to create a resource from system buffer and bitblt from the render target to the system buffer and then save the system buffer to the bmp file. However, calling the bitblt always return the error code E_FAIL. I also tried to call the pfnCaptureToSysMem whic开发者_C百科h also returned the same error code. Anything wrong here?

    D3DDDI_SURFACEINFO nfo;
    nfo.Depth = 0;
    nfo.Width = GetRenderSize().cx;
    nfo.Height = GetRenderSize().cy;
    nfo.pSysMem = NULL;
    nfo.SysMemPitch = 0;
    nfo.SysMemSlicePitch = 0;

    D3DDDIARG_CREATERESOURCE resource;
    resource.Format = D3DDDIFMT_A8R8G8B8;
    resource.Pool = D3DDDIPOOL_SYSTEMMEM;
    resource.MultisampleType = D3DDDIMULTISAMPLE_NONE;
    resource.MultisampleQuality = 0;
    resource.pSurfList = &nfo;
    resource.SurfCount = 1;
    resource.MipLevels = 1;
    resource.Fvf = 0;
    resource.VidPnSourceId = 0;
    resource.RefreshRate.Numerator = 0;
    resource.RefreshRate.Denominator = 0;
    resource.hResource = NULL;
    resource.Flags.Value = 0;
    resource.Flags.Texture = 1;
    resource.Flags.Dynamic = 1;
    resource.Rotation = D3DDDI_ROTATION_IDENTITY;

    HRESULT hr = m_pDevice->m_deviceFuncs.pfnCreateResource(m_pDevice->GetDrv(), &resource);
    HANDLE hSysSpace = resource.hResource;

    D3DDDIARG_BLT blt;
    blt.hSrcResource = m_pDevice->m_hRenderTarget;
    blt.hDstResource = hSysSpace;
    blt.SrcRect.left = 0;
    blt.SrcRect.top = 0;
    blt.SrcRect.right = GetRenderSize().cx;
    blt.SrcRect.bottom = GetRenderSize().cy;
    blt.DstRect = blt.SrcRect;
    blt.DstSubResourceIndex = 0;
    blt.SrcSubResourceIndex = 0;
    blt.Flags.Value = 0;        
    blt.ColorKey = 0;

    hr = m_pDevice->m_deviceFuncs.pfnBlt(m_pDevice, &blt);


You are on the right track, but I think you can use the DirectX functions for this.

In order to copy the render target from video memory to system memory you should use the IDirect3DDevice9::GetRenderTargetData() function.

This function requires that the destination surface is an offscreen plain surface created with pool D3DPOOL_SYSTEMMEM. This surface also must have the same dimensions as the render target (no stretching allowed). Use IDirect3DDevice9::CreateOffscreenPlain() to create this surface.

Then this surface can be locked and the color data can be accessed by the CPU.

0

精彩评论

暂无评论...
验证码 换一张
取 消