Ejemplo n.º 1
0
void D3D9Texture::ReadData(Grid<float> &Data)
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_R32F, "ReadData called on invalid surface");
    Data.Allocate(_Height, _Width);
    D3DLOCKED_RECT Rect;
    if(_RenderTarget)
    {
        D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
        D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    }
    else
    {
        D3DAlwaysValidate(_SurfaceTopLevel->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    }
    BYTE *Bytes = (BYTE *)Rect.pBits;
    for(UINT y = 0; y < _Height; y++)
    {
        float *CurRow = (float *)(Bytes + y * Rect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            Data(y, x) = CurRow[x];
        }
    }
    if(_RenderTarget)
    {
        D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
    }
    else
    {
        D3DValidate(_SurfaceTopLevel->UnlockRect(), "UnlockRect");
    }
}
Ejemplo n.º 2
0
void D3D9Texture::ReadData(Grid<Vec3f> &Data)
{
    PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_A32B32G32R32F && _RenderTarget, "ReadData called on invalid surface");
    Data.Allocate(_Height, _Width);
    D3DLOCKED_RECT Rect;
    D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData");
    D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect");
    BYTE *Bytes = (BYTE *)Rect.pBits;
    for(UINT y = 0; y < _Height; y++)
    {
        Vec4f *CurRow = (Vec4f *)(Bytes + y * Rect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            Data(y, x) = Vec3f(CurRow[x].x, CurRow[x].y, CurRow[x].z);
        }
    }
    D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect");
}
void D3D9RenderTargetTexture::GetDepthData(Grid<float> &DepthMap)
{
    PersistentAssert(_DepthSurface != NULL, "_DepthSurface == NULL unexpected");
    D3DLOCKED_RECT LockedRect;
    D3DAlwaysValidate(_DepthSurface->LockRect(&LockedRect, NULL, 0), "LockRect");
    BYTE *Data = (BYTE *)LockedRect.pBits;
    
    DepthMap.Allocate(_Height, _Width);
    
    for(UINT y = 0; y < _Height; y++)
    {
        float *RowStart = (float *)(Data + y * LockedRect.Pitch);
        for(UINT x = 0; x < _Width; x++)
        {
            DepthMap.GetElement(y, x) = RowStart[x];
        }
    }
    D3DAlwaysValidate(_DepthSurface->UnlockRect(), "UnlockRect");
}