/Runtime/Export/Graphics/GraphicsFormatUtility.bindings.cs

https://github.com/Unity-Technologies/UnityCsReference · C# · 215 lines · 152 code · 60 blank · 3 comment · 10 complexity · c6028cdd7d4f35872413c6e1efce7a82 MD5 · raw file

  1. // Unity C# reference source
  2. // Copyright (c) Unity Technologies. For terms of use, see
  3. // https://unity3d.com/legal/licenses/Unity_Reference_Only_License
  4. using System;
  5. using UnityEngine.Bindings;
  6. using UnityEngine.Rendering;
  7. namespace UnityEngine
  8. {
  9. namespace Experimental
  10. {
  11. namespace Rendering
  12. {
  13. [NativeHeader("Runtime/Graphics/Format.h")]
  14. [NativeHeader("Runtime/Graphics/TextureFormat.h")]
  15. [NativeHeader("Runtime/Graphics/GraphicsFormatUtility.bindings.h")]
  16. public class GraphicsFormatUtility
  17. {
  18. [FreeFunction]
  19. extern internal static GraphicsFormat GetFormat(Texture texture);
  20. public static GraphicsFormat GetGraphicsFormat(TextureFormat format, bool isSRGB)
  21. {
  22. return GetGraphicsFormat_Native_TextureFormat(format, isSRGB);
  23. }
  24. [FreeFunction(IsThreadSafe = true)]
  25. extern private static GraphicsFormat GetGraphicsFormat_Native_TextureFormat(TextureFormat format, bool isSRGB);
  26. public static TextureFormat GetTextureFormat(GraphicsFormat format)
  27. {
  28. return GetTextureFormat_Native_GraphicsFormat(format);
  29. }
  30. [FreeFunction(IsThreadSafe = true)]
  31. extern private static TextureFormat GetTextureFormat_Native_GraphicsFormat(GraphicsFormat format);
  32. public static GraphicsFormat GetGraphicsFormat(RenderTextureFormat format, bool isSRGB)
  33. {
  34. return GetGraphicsFormat_Native_RenderTextureFormat(format, isSRGB);
  35. }
  36. [FreeFunction]
  37. extern private static GraphicsFormat GetGraphicsFormat_Native_RenderTextureFormat(RenderTextureFormat format, bool isSRGB);
  38. public static GraphicsFormat GetGraphicsFormat(RenderTextureFormat format, RenderTextureReadWrite readWrite)
  39. {
  40. bool defaultSRGB = QualitySettings.activeColorSpace == ColorSpace.Linear;
  41. bool sRGB = readWrite == RenderTextureReadWrite.Default ? defaultSRGB : readWrite == RenderTextureReadWrite.sRGB;
  42. return GetGraphicsFormat(format, sRGB);
  43. }
  44. [FreeFunction(IsThreadSafe = true)]
  45. extern public static bool IsSRGBFormat(GraphicsFormat format);
  46. [FreeFunction(IsThreadSafe = true)]
  47. extern public static bool IsSwizzleFormat(GraphicsFormat format);
  48. [FreeFunction(IsThreadSafe = true)]
  49. extern public static GraphicsFormat GetSRGBFormat(GraphicsFormat format);
  50. [FreeFunction(IsThreadSafe = true)]
  51. extern public static GraphicsFormat GetLinearFormat(GraphicsFormat format);
  52. [FreeFunction(IsThreadSafe = true)]
  53. extern public static RenderTextureFormat GetRenderTextureFormat(GraphicsFormat format);
  54. [FreeFunction(IsThreadSafe = true)]
  55. extern public static UInt32 GetColorComponentCount(GraphicsFormat format);
  56. [FreeFunction(IsThreadSafe = true)]
  57. extern public static UInt32 GetAlphaComponentCount(GraphicsFormat format);
  58. [FreeFunction(IsThreadSafe = true)]
  59. extern public static UInt32 GetComponentCount(GraphicsFormat format);
  60. [FreeFunction(IsThreadSafe = true)]
  61. extern public static string GetFormatString(GraphicsFormat format);
  62. [FreeFunction(IsThreadSafe = true)]
  63. extern public static bool IsCompressedFormat(GraphicsFormat format);
  64. [FreeFunction("IsAnyCompressedTextureFormat", true)]
  65. extern internal static bool IsCompressedTextureFormat(TextureFormat format);
  66. [FreeFunction(IsThreadSafe = true)]
  67. extern public static bool IsPackedFormat(GraphicsFormat format);
  68. [FreeFunction(IsThreadSafe = true)]
  69. extern public static bool Is16BitPackedFormat(GraphicsFormat format);
  70. [FreeFunction(IsThreadSafe = true)]
  71. extern public static GraphicsFormat ConvertToAlphaFormat(GraphicsFormat format);
  72. [FreeFunction(IsThreadSafe = true)]
  73. extern public static bool IsAlphaOnlyFormat(GraphicsFormat format);
  74. [FreeFunction(IsThreadSafe = true)]
  75. extern public static bool IsAlphaTestFormat(GraphicsFormat format);
  76. [FreeFunction(IsThreadSafe = true)]
  77. extern public static bool HasAlphaChannel(GraphicsFormat format);
  78. [FreeFunction(IsThreadSafe = true)]
  79. extern public static bool IsDepthFormat(GraphicsFormat format);
  80. [FreeFunction(IsThreadSafe = true)]
  81. extern public static bool IsStencilFormat(GraphicsFormat format);
  82. [FreeFunction(IsThreadSafe = true)]
  83. extern public static bool IsIEEE754Format(GraphicsFormat format);
  84. [FreeFunction(IsThreadSafe = true)]
  85. extern public static bool IsFloatFormat(GraphicsFormat format);
  86. [FreeFunction(IsThreadSafe = true)]
  87. extern public static bool IsHalfFormat(GraphicsFormat format);
  88. [FreeFunction(IsThreadSafe = true)]
  89. extern public static bool IsUnsignedFormat(GraphicsFormat format);
  90. [FreeFunction(IsThreadSafe = true)]
  91. extern public static bool IsSignedFormat(GraphicsFormat format);
  92. [FreeFunction(IsThreadSafe = true)]
  93. extern public static bool IsNormFormat(GraphicsFormat format);
  94. [FreeFunction(IsThreadSafe = true)]
  95. extern public static bool IsUNormFormat(GraphicsFormat format);
  96. [FreeFunction(IsThreadSafe = true)]
  97. extern public static bool IsSNormFormat(GraphicsFormat format);
  98. [FreeFunction(IsThreadSafe = true)]
  99. extern public static bool IsIntegerFormat(GraphicsFormat format);
  100. [FreeFunction(IsThreadSafe = true)]
  101. extern public static bool IsUIntFormat(GraphicsFormat format);
  102. [FreeFunction(IsThreadSafe = true)]
  103. extern public static bool IsSIntFormat(GraphicsFormat format);
  104. [FreeFunction(IsThreadSafe = true)]
  105. extern public static bool IsXRFormat(GraphicsFormat format);
  106. [FreeFunction(IsThreadSafe = true)]
  107. extern public static bool IsDXTCFormat(GraphicsFormat format);
  108. [FreeFunction(IsThreadSafe = true)]
  109. extern public static bool IsRGTCFormat(GraphicsFormat format);
  110. [FreeFunction(IsThreadSafe = true)]
  111. extern public static bool IsBPTCFormat(GraphicsFormat format);
  112. [FreeFunction(IsThreadSafe = true)]
  113. extern public static bool IsBCFormat(GraphicsFormat format);
  114. [FreeFunction(IsThreadSafe = true)]
  115. extern public static bool IsPVRTCFormat(GraphicsFormat format);
  116. [FreeFunction(IsThreadSafe = true)]
  117. extern public static bool IsETCFormat(GraphicsFormat format);
  118. [FreeFunction(IsThreadSafe = true)]
  119. extern public static bool IsEACFormat(GraphicsFormat format);
  120. [FreeFunction(IsThreadSafe = true)]
  121. extern public static bool IsASTCFormat(GraphicsFormat format);
  122. public static bool IsCrunchFormat(TextureFormat format)
  123. {
  124. return format == TextureFormat.DXT1Crunched || format == TextureFormat.DXT5Crunched || format == TextureFormat.ETC_RGB4Crunched || format == TextureFormat.ETC2_RGBA8Crunched;
  125. }
  126. [FreeFunction(IsThreadSafe = true)]
  127. extern public static FormatSwizzle GetSwizzleR(GraphicsFormat format);
  128. [FreeFunction(IsThreadSafe = true)]
  129. extern public static FormatSwizzle GetSwizzleG(GraphicsFormat format);
  130. [FreeFunction(IsThreadSafe = true)]
  131. extern public static FormatSwizzle GetSwizzleB(GraphicsFormat format);
  132. [FreeFunction(IsThreadSafe = true)]
  133. extern public static FormatSwizzle GetSwizzleA(GraphicsFormat format);
  134. [FreeFunction(IsThreadSafe = true)]
  135. extern public static UInt32 GetBlockSize(GraphicsFormat format);
  136. [FreeFunction(IsThreadSafe = true)]
  137. extern public static UInt32 GetBlockWidth(GraphicsFormat format);
  138. [FreeFunction(IsThreadSafe = true)]
  139. extern public static UInt32 GetBlockHeight(GraphicsFormat format);
  140. public static UInt32 ComputeMipmapSize(int width, int height, GraphicsFormat format)
  141. {
  142. return ComputeMipmapSize_Native_2D(width, height, format);
  143. }
  144. [FreeFunction]
  145. extern private static UInt32 ComputeMipmapSize_Native_2D(int width, int height, GraphicsFormat format);
  146. public static UInt32 ComputeMipmapSize(int width, int height, int depth, GraphicsFormat format)
  147. {
  148. return ComputeMipmapSize_Native_3D(width, height, depth, format);
  149. }
  150. [FreeFunction]
  151. extern private static UInt32 ComputeMipmapSize_Native_3D(int width, int height, int depth, GraphicsFormat format);
  152. }
  153. } // namespace Rendering
  154. } // namespace Experimental
  155. } // Namespace