summaryrefslogtreecommitdiff
path: root/Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs')
-rw-r--r--Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs126
1 files changed, 126 insertions, 0 deletions
diff --git a/Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs b/Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs
new file mode 100644
index 0000000..d662af3
--- /dev/null
+++ b/Valheim_v0.141.2_r202102/Valheim/assembly_postprocessing/UnityEngine.PostProcessing/GraphicsUtils.cs
@@ -0,0 +1,126 @@
+namespace UnityEngine.PostProcessing;
+
+public static class GraphicsUtils
+{
+ private static Texture2D s_WhiteTexture;
+
+ private static Mesh s_Quad;
+
+ public static bool isLinearColorSpace => QualitySettings.activeColorSpace == ColorSpace.Linear;
+
+ public static bool supportsDX11
+ {
+ get
+ {
+ if (SystemInfo.graphicsShaderLevel >= 50)
+ {
+ return SystemInfo.supportsComputeShaders;
+ }
+ return false;
+ }
+ }
+
+ public static Texture2D whiteTexture
+ {
+ get
+ {
+ if (s_WhiteTexture != null)
+ {
+ return s_WhiteTexture;
+ }
+ s_WhiteTexture = new Texture2D(1, 1, TextureFormat.ARGB32, mipChain: false);
+ s_WhiteTexture.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
+ s_WhiteTexture.Apply();
+ return s_WhiteTexture;
+ }
+ }
+
+ public static Mesh quad
+ {
+ get
+ {
+ if (s_Quad != null)
+ {
+ return s_Quad;
+ }
+ Vector3[] vertices = new Vector3[4]
+ {
+ new Vector3(-1f, -1f, 0f),
+ new Vector3(1f, 1f, 0f),
+ new Vector3(1f, -1f, 0f),
+ new Vector3(-1f, 1f, 0f)
+ };
+ Vector2[] uv = new Vector2[4]
+ {
+ new Vector2(0f, 0f),
+ new Vector2(1f, 1f),
+ new Vector2(1f, 0f),
+ new Vector2(0f, 1f)
+ };
+ int[] triangles = new int[6] { 0, 1, 2, 1, 0, 3 };
+ s_Quad = new Mesh
+ {
+ vertices = vertices,
+ uv = uv,
+ triangles = triangles
+ };
+ s_Quad.RecalculateNormals();
+ s_Quad.RecalculateBounds();
+ return s_Quad;
+ }
+ }
+
+ public static void Blit(Material material, int pass)
+ {
+ GL.PushMatrix();
+ GL.LoadOrtho();
+ material.SetPass(pass);
+ GL.Begin(5);
+ GL.TexCoord2(0f, 0f);
+ GL.Vertex3(0f, 0f, 0.1f);
+ GL.TexCoord2(1f, 0f);
+ GL.Vertex3(1f, 0f, 0.1f);
+ GL.TexCoord2(0f, 1f);
+ GL.Vertex3(0f, 1f, 0.1f);
+ GL.TexCoord2(1f, 1f);
+ GL.Vertex3(1f, 1f, 0.1f);
+ GL.End();
+ GL.PopMatrix();
+ }
+
+ public static void ClearAndBlit(Texture source, RenderTexture destination, Material material, int pass, bool clearColor = true, bool clearDepth = false)
+ {
+ RenderTexture active = RenderTexture.active;
+ RenderTexture.active = destination;
+ GL.Clear(clearDepth: false, clearColor, Color.clear);
+ GL.PushMatrix();
+ GL.LoadOrtho();
+ material.SetTexture("_MainTex", source);
+ material.SetPass(pass);
+ GL.Begin(5);
+ GL.TexCoord2(0f, 0f);
+ GL.Vertex3(0f, 0f, 0.1f);
+ GL.TexCoord2(1f, 0f);
+ GL.Vertex3(1f, 0f, 0.1f);
+ GL.TexCoord2(0f, 1f);
+ GL.Vertex3(0f, 1f, 0.1f);
+ GL.TexCoord2(1f, 1f);
+ GL.Vertex3(1f, 1f, 0.1f);
+ GL.End();
+ GL.PopMatrix();
+ RenderTexture.active = active;
+ }
+
+ public static void Destroy(Object obj)
+ {
+ if (obj != null)
+ {
+ Object.Destroy(obj);
+ }
+ }
+
+ public static void Dispose()
+ {
+ Destroy(s_Quad);
+ }
+}