RenderTexture coordinate system origin is bottom-left on iPad, but top-left on iPhone 5S

I’m using RenderTexture to take screenshots in my Unity game.

I have successfully managed to draw the Camera contents to the target RenderTexture and grab part of the RenderTexture’s contents (i.e.: A Region Of Interest) using the code below:

RenderTexture currentActiveRT =RenderTexture.active;

var renderTex =newRenderTexture((int)renderTexSize.x,(int)renderTexSize.y,24,RenderTextureFormat.ARGB32);

CameraScreenshot.targetTexture = renderTex;CameraScreenshot.gameObject.SetActive(true);CameraScreenshot.Render();

RenderTexture.active = renderTex;

// 4. Create the final output Texture, which will have the the ROI drawn in the final size.var tex =newTexture2D((int)screenshotSize.x,(int)screenshotSize.y,TextureFormat.RGB24,false);
tex.ReadPixels(fROI,0,0,true);

// 5. Restore context and release resources.
RenderTexture.active = currentActiveRT;

Everything works as expected on both the Unity Editor and the iPad device, however, on my iPhone 5S device the final output gets wrong because a different region of the RenderTexture is used. After some debugging I realised that on both Editor and iPad the origin of the RenderTexturecoordinate system is bottom-left (upwards) but on the iPhone it is top-left (downwards).

Does anyone know how can I fix that?

Original S.O. thread: ios - Unity RenderTexture coordinate system origin is bottom-left on iPad, but top-left on iPhone 5S - Stack Overflow

You are wrong in your reasoning - it is because of metal vs opegl es difference.

well you can always check if you are running on metal or gles. Though i agree we should look into handling it better

Thanks for the reply, I added the following code as a workaround.

if(SystemInfo.graphicsDeviceVersion.StartsWith("Metal")){
    var metalY=(1f-nROI.y-nROI.height);
    nROI=newRect(nROI.x,metalY,nROI.width,nROI.height);
}

Although it’s a weird solution it’s working now.

Looks like the screenshot was corrupted (see attached image). Any idea why could it happen?
I’m invoking the screenshot procedure as a coroutine:

that looks weird indeed. Please create small repro project (as in - just cube or smth and scripts you need to do your magic) and bug report it (drop case number here so i dont miss it)