I have IDirect3DSurface9, default pool, YUV format. How can I efficiently get bitmap bits from it? At the moment I:
device->CreateRenderTarget(surf_desc.Width, surf_desc.Height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &render_target, NULL)
device->StretchRect(videomem_surf, NULL, render_target_, NULL, D3DTEXF_NONE)
device->CreateOffscreenPlainSurface(surf_desc.Width, surf_desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &sysmem_offscreen_surf, NULL)
device->GetRenderTargetData(render_target, sysmem_offscreen_surface)
this looks a bit of overhead, because of so many copying: from original surface to render target, then to offscreen surface, then to compatible bitmap, and then finally to my buffer. How can this be improved?
thanks
Since you create you render target in lockable mode (6th parameter to CreateRenderTarget
), you can lock the render target with LockRect
and copy the data directly from there.
MSDN does not recommend using lockable render targets, and says:
If you need read access to render targets, use GetRenderTargetData instead of lockable render targets.
So an alternative is to call GetRenderTargetData
into the offscreen surface, and then lock the offscreen surface (instead of using DCs and bitmaps).