Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 27, 2018 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/408809f274c896e446a9e918629a8dae to your computer and use it in GitHub Desktop.
Save baobao/408809f274c896e446a9e918629a8dae to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEngine;
public class RenderTextureMemoryAlloc : MonoBehaviour
{
public Texture tex;
[SerializeField]
private List<RenderTexture> _rtList = new List<RenderTexture>();
void CreateRT(int cnt = 2)
{
int size = 2048;
for (int i = 0; i < cnt; i++)
{
var rt = new RenderTexture(size, size, 24, RenderTextureFormat.ARGB32);
_rtList.Add(rt);
}
}
void StartBlit()
{
for (int i = 0; i < _rtList.Count; i++)
{
Graphics.Blit(tex, _rtList[i]);
}
}
void ReleaseRT()
{
for (int i = 0; i < _rtList.Count; i++)
{
_rtList[i].Release();
}
}
void DestroyRT()
{
for (int i = 0; i < _rtList.Count; i++)
{
Destroy(_rtList[i]);
}
_rtList.Clear();
}
void OnGUI()
{
var w = 200f;
var h = 100f;
if (GUILayout.Button("CreateRT", GUILayout.Width(w), GUILayout.Height(h)))
{
CreateRT();
}
if (GUILayout.Button("CreateRT 50", GUILayout.Width(w), GUILayout.Height(h)))
{
// 試しに50枚作ってみる
CreateRT(50);
}
if (GUILayout.Button("StartBlit", GUILayout.Width(w), GUILayout.Height(h)))
{
StartBlit();
}
if (GUILayout.Button("ReleaseRT", GUILayout.Width(w), GUILayout.Height(h)))
{
ReleaseRT();
}
if (GUILayout.Button("DestroyRT", GUILayout.Width(w), GUILayout.Height(h)))
{
DestroyRT();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment