Download

Cannot access render target pixel data on iOS

Also posted this here

This short story is that ReadPixels is returning an array of the right size but garbage data. Sometimes it points at random texture data but typically its pretty random:


UTexture2D *USharedRenderTarget::Create2DTexture() const
{
    UTexture2D *p2dTex = UTexture2D::CreateTransient(RenderTexture->SizeX, RenderTexture->SizeY, PF_B8G8R8A8);
#if WITH_EDITORONLY_DATA
    p2dTex->MipGenSettings = TMGS_NoMipmaps;
#endif
    p2dTex->SRGB = RenderTexture->SRGB;
    
    // Read the pixels from the RenderTarget and store them in a FColor array
    TArray<FColor> SurfData;
    FRenderTarget *RenderTarget = RenderTexture->GameThread_GetRenderTargetResource();
    **RenderTarget->ReadPixels(SurfData);**

It seems like this should be possible and the workaround that’s come to mind (use UIImage Objective C functionality to do what I’m doing) is both annoying to implement and inferior in the long term.

Right now I’m saving the data into a jpg. It works on PC, is untested on MAC, fails on iPhone.

Any idea how to get the pixel array for the top mip of a render target?

Looks like its 50/50 on MAC. I have a 32x32 render texture with the same garbage seen on iOS and a 256x256 target that’s giving me valid data (neither work on iOS, both work on PC).

I’ve answered your question on AnswerHub. You’ve found a bug in our iOS implementation but I’m a bit less sure why it won’t work on Mac.