Skip to content

Instantly share code, notes, and snippets.

@D4KU
Created October 17, 2022 20:06
Show Gist options
  • Select an option

  • Save D4KU/b6bc0cbd247b3a6f6ed3ad0fdb21d4cf to your computer and use it in GitHub Desktop.

Select an option

Save D4KU/b6bc0cbd247b3a6f6ed3ad0fdb21d4cf to your computer and use it in GitHub Desktop.
Collection of C# extension methods for writing graphics code for Unity
using UnityEngine;
using RTF = UnityEngine.RenderTextureFormat;
using TF = UnityEngine.TextureFormat;
public static class RenderingExtensions
{
public static TextureFormat ToTextureFormat(this RenderTextureFormat format)
=> format switch
{
RTF.ARGB32 => TF.ARGB32,
RTF.Depth => TF.RFloat,
RTF.ARGBHalf => TF.RGBAHalf,
RTF.Shadowmap => TF.RFloat,
RTF.RGB565 => TF.RGB565,
RTF.ARGB4444 => TF.ARGB4444,
RTF.ARGB1555 => TF.ARGB32,
RTF.Default => TF.RGBA32,
RTF.ARGB2101010 => TF.ARGB32,
RTF.DefaultHDR => TF.RGBAFloat,
RTF.ARGB64 => TF.RGBA64,
RTF.ARGBFloat => TF.RGBAFloat,
RTF.RGFloat => TF.RGFloat,
RTF.RGHalf => TF.RGHalf,
RTF.RFloat => TF.RFloat,
RTF.RHalf => TF.RHalf,
RTF.R8 => TF.R8,
RTF.ARGBInt => TF.ARGB32,
RTF.RGInt => TF.RG32,
RTF.RInt => TF.R16,
RTF.BGRA32 => TF.BGRA32,
RTF.RGB111110Float => TF.RGB9e5Float,
RTF.RG32 => TF.RG32,
RTF.RGBAUShort => TF.RGBA32,
RTF.RG16 => TF.RG16,
RTF.BGRA10101010_XR => TF.BGRA32,
RTF.BGR101010_XR => TF.RGB24,
RTF.R16 => TF.R16,
_ => throw new System.NotSupportedException(),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment