using System; using System.Collections.Generic; namespace UnityEngine.PostProcessing { public sealed class RenderTextureFactory : IDisposable { public RenderTextureFactory() { this.m_TemporaryRTs = new HashSet(); } public RenderTexture Get(RenderTexture baseRenderTexture) { return this.Get(baseRenderTexture.width, baseRenderTexture.height, baseRenderTexture.depth, baseRenderTexture.format, (!baseRenderTexture.sRGB) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB, baseRenderTexture.filterMode, baseRenderTexture.wrapMode, "FactoryTempTexture"); } public RenderTexture Get(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.ARGBHalf, RenderTextureReadWrite rw = RenderTextureReadWrite.Default, FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, string name = "FactoryTempTexture") { RenderTexture temporary = RenderTexture.GetTemporary(width, height, depthBuffer, format, rw); temporary.filterMode = filterMode; temporary.wrapMode = wrapMode; temporary.name = name; this.m_TemporaryRTs.Add(temporary); return temporary; } public void Release(RenderTexture rt) { if (rt == null) { return; } if (!this.m_TemporaryRTs.Contains(rt)) { throw new ArgumentException(string.Format("Attempting to remove a RenderTexture that was not allocated: {0}", rt)); } this.m_TemporaryRTs.Remove(rt); RenderTexture.ReleaseTemporary(rt); } public void ReleaseAll() { foreach (RenderTexture temp in this.m_TemporaryRTs) { RenderTexture.ReleaseTemporary(temp); } this.m_TemporaryRTs.Clear(); } public void Dispose() { this.ReleaseAll(); } private HashSet m_TemporaryRTs; } }