Files
JJBB/Assets/Project/Script/GUI/Base/RenderTexturePool.cs
2024-08-23 15:49:34 +08:00

32 lines
1003 B
C#

using Module.Log;
using UnityEngine;
public class RenderTexturePool : Singleton<RenderTexturePool>
{
#if UNITY_EDITOR
private static int totalTexture;
#endif
//private readonly Queue<RenderTexture> _textureQueue = new Queue<RenderTexture>();
public RenderTexture GetRenderTexture(Vector2 size)
{
return CreateRenderTexture(size);
}
public void ReleaseRenderTexture(RenderTexture renderTexture)
{
#if UNITY_EDITOR
totalTexture--;
LogModule.WarningLog("Release Render Texture " + totalTexture);
#endif
RenderTexture.ReleaseTemporary(renderTexture);
}
private RenderTexture CreateRenderTexture(Vector2 size)
{
#if UNITY_EDITOR
LogModule.WarningLog("Create RenderTexture: " + totalTexture);
totalTexture++;
#endif
return RenderTexture.GetTemporary(Mathf.FloorToInt(size.x), Mathf.FloorToInt(size.y), 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
}
}