Я пытаюсь нарисовать RenderTexture
в Texture2D
с целью сохранения его на диск. Этот подход работает в редакторе OSX, а также на Android.iOS зависает при вызове Texture2D.readPixels
Я не вижу каких-либо ошибок в консоли XCode, и мое приложение становится полностью заморожен, когда я звоню Texture2D.ReadPixels()
Вот краткое описание кода:
// declaring variables...
RenderTexture outputTexture;
RenderTextureFormat RTFormat = RenderTextureFormat.ARGB32;
// use an appropriate format for render textures
if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)){
RTFormat = RenderTextureFormat.ARGBFloat;
}else if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)){
RTFormat = RenderTextureFormat.ARGBHalf;
}
// create instance of output texture
outputTexture = new RenderTexture (res.x, res.y, 0, RTFormat);
// in Update, draw stuff to outputTexture
Graphics.Blit (outputTexture, canvasTexture);
Graphics.Blit (canvasTexture, outputTexture, material);
// later... user wants to save the image
// draw rendertexture to a Texture2D so we can write to disk
RenderTexture.active = outputTexture;
tmpTexture = new Texture2D (outputTexture.width, outputTexture.height, TextureFormat.ARGB32, false);
tmpTexture.ReadPixels (new Rect (0, 0, outputTexture.width, outputTexture.height), 0, 0, false);
tmpTexture.Apply();
RenderTexture.active = null;
Я попытался с помощью различных RenderTextureFormat
и TextureFormat
, но ничего не работает!
Где вы звоните по этому коду? Это внутри пользовательской функции или метода обратного вызова Unity? –
Также, на каком устройстве вы тестируете? Проверьте, нет ли у вас памяти. RenderTexture - дорогой метод. –