Download

RHILockTexture2D without texture clear

Hello guys.
I have a problem with RHILockTexture2D for edit raw texture data.


void AMyActor::UpdateRenderTargetLine(int RenderTargetPosX, int RenderTargetPosY, const uint8* Data, int Offset, int Len)
{
    // Make temp data block to give it to RHI & fill it with source data
    auto DataCopy = FMemory::SystemMalloc(Len);
    FMemory::Memcpy(DataCopy, Data + Offset, Len);

    // Copy data from source to render target & free temp data we've just made
    ENQUEUE_RENDER_COMMAND(UpdateRenderTargetLine)([this, DataCopy, Offset, Len, RenderTargetPosX, RenderTargetPosY](FRHICommandListImmediate& RHICmdList)
    {
        uint32 Stride = 0; // Assigned by RHILockTexture2D
        auto RHITexture = GetRenderTargetXY(RenderTargetPosX, RenderTargetPosY)->GetRenderTargetResource()->GetTextureRenderTarget2DResource()->GetTextureRHI();
        auto Dest = StaticCast<uint8*>(RHILockTexture2D(RHITexture, 0, RLM_WriteOnly_NoOverwrite, Stride, false));
        FMemory::Memcpy(Dest + Offset, DataCopy, Len);
        RHIUnlockTexture2D(RHITexture, 0, false);
        FMemory::SystemFree(DataCopy);
    });
}

It works fine if I use it with RLM_WriteOnly flag and rewrite whole data there, but with RLM_WriteOnly_NoOverwrite flag it just crash on locking.
I need to overwrite few bytes there, not whole texture.
Could someone help me, please?