RenderTextureFactory.cs
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
namespace UnityEngine.PostProcessing
{
public sealed class RenderTextureFactory : IDisposable
{
HashSet<RenderTexture> m_TemporaryRTs;
public RenderTextureFactory()
{
m_TemporaryRTs = new HashSet<RenderTexture>();
}
public RenderTexture Get(RenderTexture baseRenderTexture)
{
return Get(
baseRenderTexture.width,
baseRenderTexture.height,
baseRenderTexture.depth,
baseRenderTexture.format,
baseRenderTexture.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear,
baseRenderTexture.filterMode,
baseRenderTexture.wrapMode
);
}
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")
{
var rt = RenderTexture.GetTemporary(width, height, depthBuffer, format);
rt.filterMode = filterMode;
rt.wrapMode = wrapMode;
rt.name = name;
m_TemporaryRTs.Add(rt);
return rt;
}
public void Release(RenderTexture rt)
{
if (rt == null)
return;
if (!m_TemporaryRTs.Contains(rt))
throw new ArgumentException(string.Format("Attempting to remove a RenderTexture that was not allocated: {0}", rt));
m_TemporaryRTs.Remove(rt);
RenderTexture.ReleaseTemporary(rt);
}
public void ReleaseAll()
{
var enumerator = m_TemporaryRTs.GetEnumerator();
while (enumerator.MoveNext())
RenderTexture.ReleaseTemporary(enumerator.Current);
m_TemporaryRTs.Clear();
}
public void Dispose()
{
ReleaseAll();
}
}
}