Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RTHandles.cs 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. using System;
  2. using UnityEngine.Assertions;
  3. using UnityEngine.Experimental.Rendering;
  4. namespace UnityEngine.Rendering
  5. {
  6. /// <summary>
  7. /// Default instance of a RTHandleSystem
  8. /// </summary>
  9. public static class RTHandles
  10. {
  11. static RTHandleSystem s_DefaultInstance = new RTHandleSystem();
  12. /// <summary>
  13. /// Maximum allocated width of the default RTHandle System
  14. /// </summary>
  15. public static int maxWidth { get { return s_DefaultInstance.GetMaxWidth(); } }
  16. /// <summary>
  17. /// Maximum allocated height of the default RTHandle System
  18. /// </summary>
  19. public static int maxHeight { get { return s_DefaultInstance.GetMaxHeight(); } }
  20. /// <summary>
  21. /// Current properties of the default RTHandle System
  22. /// </summary>
  23. public static RTHandleProperties rtHandleProperties { get { return s_DefaultInstance.rtHandleProperties; } }
  24. /// <summary>
  25. /// Calculate the dimensions (in pixels) of the RTHandles given the scale factor.
  26. /// </summary>
  27. /// <param name="scaleFactor">The scale factor to use when calculating the dimensions. The base unscaled size used, is the sizes passed to the last ResetReferenceSize call.</param>
  28. /// <returns>The calculated dimensions.</returns>
  29. public static Vector2Int CalculateDimensions(Vector2 scaleFactor)
  30. {
  31. return s_DefaultInstance.CalculateDimensions(scaleFactor);
  32. }
  33. /// <summary>
  34. /// Calculate the dimensions (in pixels) of the RTHandles given the scale function. The base unscaled size used, is the sizes passed to the last ResetReferenceSize call.
  35. /// </summary>
  36. /// <param name="scaleFunc">The scale function to use when calculating the dimensions.</param>
  37. /// <returns>The calculated dimensions.</returns>
  38. public static Vector2Int CalculateDimensions(ScaleFunc scaleFunc)
  39. {
  40. return s_DefaultInstance.CalculateDimensions(scaleFunc);
  41. }
  42. /// <summary>
  43. /// Allocate a new fixed sized RTHandle with the default RTHandle System.
  44. /// </summary>
  45. /// <param name="width">With of the RTHandle.</param>
  46. /// <param name="height">Heigh of the RTHandle.</param>
  47. /// <param name="slices">Number of slices of the RTHandle.</param>
  48. /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
  49. /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
  50. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  51. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  52. /// <param name="dimension">Texture dimension of the RTHandle.</param>
  53. /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
  54. /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
  55. /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
  56. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  57. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  58. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  59. /// <param name="msaaSamples">Number of MSAA samples for the RTHandle.</param>
  60. /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
  61. /// <param name="useDynamicScale">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  62. /// <param name="useDynamicScaleExplicit">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  63. /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
  64. /// <param name="vrUsage">Special treatment of the VR eye texture used in stereoscopic rendering.</param>
  65. /// <param name="name">Name of the RTHandle.</param>
  66. /// <returns>A new RTHandle.</returns>
  67. public static RTHandle Alloc(
  68. int width,
  69. int height,
  70. int slices = 1,
  71. DepthBits depthBufferBits = DepthBits.None,
  72. GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
  73. FilterMode filterMode = FilterMode.Point,
  74. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  75. TextureDimension dimension = TextureDimension.Tex2D,
  76. bool enableRandomWrite = false,
  77. bool useMipMap = false,
  78. bool autoGenerateMips = true,
  79. bool isShadowMap = false,
  80. int anisoLevel = 1,
  81. float mipMapBias = 0,
  82. MSAASamples msaaSamples = MSAASamples.None,
  83. bool bindTextureMS = false,
  84. bool useDynamicScale = false,
  85. bool useDynamicScaleExplicit = false,
  86. RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
  87. VRTextureUsage vrUsage = VRTextureUsage.None,
  88. string name = ""
  89. )
  90. {
  91. return s_DefaultInstance.Alloc(
  92. width,
  93. height,
  94. slices,
  95. depthBufferBits,
  96. colorFormat,
  97. filterMode,
  98. wrapMode,
  99. dimension,
  100. enableRandomWrite,
  101. useMipMap,
  102. autoGenerateMips,
  103. isShadowMap,
  104. anisoLevel,
  105. mipMapBias,
  106. msaaSamples,
  107. bindTextureMS,
  108. useDynamicScale,
  109. useDynamicScaleExplicit,
  110. memoryless,
  111. vrUsage,
  112. name
  113. );
  114. }
  115. /// <summary>
  116. /// Allocate a new fixed sized RTHandle with the default RTHandle System.
  117. /// </summary>
  118. /// <param name="width">With of the RTHandle.</param>
  119. /// <param name="height">Heigh of the RTHandle.</param>
  120. /// <param name="wrapModeU">U coordinate wrapping mode of the RTHandle.</param>
  121. /// <param name="wrapModeV">V coordinate wrapping mode of the RTHandle.</param>
  122. /// <param name="wrapModeW">W coordinate wrapping mode of the RTHandle.</param>
  123. /// <param name="slices">Number of slices of the RTHandle.</param>
  124. /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
  125. /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
  126. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  127. /// <param name="dimension">Texture dimension of the RTHandle.</param>
  128. /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
  129. /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
  130. /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
  131. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  132. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  133. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  134. /// <param name="msaaSamples">Number of MSAA samples for the RTHandle.</param>
  135. /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
  136. /// <param name="useDynamicScale">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  137. /// <param name="useDynamicScaleExplicit">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  138. /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
  139. /// <param name="vrUsage">Special treatment of the VR eye texture used in stereoscopic rendering.</param>
  140. /// <param name="name">Name of the RTHandle.</param>
  141. /// <returns>A new RTHandle.</returns>
  142. public static RTHandle Alloc(
  143. int width,
  144. int height,
  145. TextureWrapMode wrapModeU,
  146. TextureWrapMode wrapModeV,
  147. TextureWrapMode wrapModeW = TextureWrapMode.Repeat,
  148. int slices = 1,
  149. DepthBits depthBufferBits = DepthBits.None,
  150. GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
  151. FilterMode filterMode = FilterMode.Point,
  152. TextureDimension dimension = TextureDimension.Tex2D,
  153. bool enableRandomWrite = false,
  154. bool useMipMap = false,
  155. bool autoGenerateMips = true,
  156. bool isShadowMap = false,
  157. int anisoLevel = 1,
  158. float mipMapBias = 0,
  159. MSAASamples msaaSamples = MSAASamples.None,
  160. bool bindTextureMS = false,
  161. bool useDynamicScale = false,
  162. bool useDynamicScaleExplicit = false,
  163. RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
  164. VRTextureUsage vrUsage = VRTextureUsage.None,
  165. string name = ""
  166. )
  167. {
  168. return s_DefaultInstance.Alloc(
  169. width,
  170. height,
  171. wrapModeU,
  172. wrapModeV,
  173. wrapModeW,
  174. slices,
  175. depthBufferBits,
  176. colorFormat,
  177. filterMode,
  178. dimension,
  179. enableRandomWrite,
  180. useMipMap,
  181. autoGenerateMips,
  182. isShadowMap,
  183. anisoLevel,
  184. mipMapBias,
  185. msaaSamples,
  186. bindTextureMS,
  187. useDynamicScale,
  188. useDynamicScaleExplicit,
  189. memoryless,
  190. vrUsage,
  191. name
  192. );
  193. }
  194. /// <summary>
  195. /// Allocate a new fixed sized RTHandle with the default RTHandle System.
  196. /// </summary>
  197. /// <param name="width">With of the RTHandle.</param>
  198. /// <param name="height">Height of the RTHandle.</param>
  199. /// <param name="info">Struct containing details of allocation</param>
  200. /// <returns>A new RTHandle.</returns>
  201. public static RTHandle Alloc(int width, int height, RTHandleAllocInfo info)
  202. {
  203. return s_DefaultInstance.Alloc(width, height, info);
  204. }
  205. /// <summary>
  206. /// Allocate a new fixed sized RTHandle with the default RTHandle System.
  207. /// </summary>
  208. /// <param name="descriptor">RenderTexture descriptor of the RTHandle.</param>
  209. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  210. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  211. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  212. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  213. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  214. /// <param name="name">Name of the RTHandle.</param>
  215. /// <returns>A new RTHandle.</returns>
  216. public static RTHandle Alloc(
  217. in RenderTextureDescriptor descriptor,
  218. FilterMode filterMode = FilterMode.Point,
  219. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  220. bool isShadowMap = false,
  221. int anisoLevel = 1,
  222. float mipMapBias = 0,
  223. string name = ""
  224. )
  225. {
  226. var result = s_DefaultInstance.Alloc(
  227. descriptor.width,
  228. descriptor.height,
  229. descriptor.volumeDepth,
  230. (DepthBits)descriptor.depthBufferBits,
  231. descriptor.graphicsFormat,
  232. filterMode,
  233. wrapMode,
  234. descriptor.dimension,
  235. descriptor.enableRandomWrite,
  236. descriptor.useMipMap,
  237. descriptor.autoGenerateMips,
  238. isShadowMap,
  239. anisoLevel,
  240. mipMapBias,
  241. (MSAASamples)descriptor.msaaSamples,
  242. descriptor.bindMS,
  243. descriptor.useDynamicScale,
  244. descriptor.useDynamicScaleExplicit,
  245. descriptor.memoryless,
  246. descriptor.vrUsage,
  247. name
  248. );
  249. return result;
  250. }
  251. /// <summary>
  252. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  253. /// </summary>
  254. /// <param name="scaleFactor">Constant scale for the RTHandle size computation.</param>
  255. /// <param name="slices">Number of slices of the RTHandle.</param>
  256. /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
  257. /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
  258. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  259. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  260. /// <param name="dimension">Texture dimension of the RTHandle.</param>
  261. /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
  262. /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
  263. /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
  264. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  265. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  266. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  267. /// <param name="msaaSamples">Number of MSAA samples.</param>
  268. /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
  269. /// <param name="useDynamicScale">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  270. /// <param name="useDynamicScaleExplicit">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  271. /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
  272. /// <param name="vrUsage">Special treatment of the VR eye texture used in stereoscopic rendering.</param>
  273. /// <param name="name">Name of the RTHandle.</param>
  274. /// <returns>A new RTHandle.</returns>
  275. public static RTHandle Alloc(
  276. Vector2 scaleFactor,
  277. int slices = 1,
  278. DepthBits depthBufferBits = DepthBits.None,
  279. GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
  280. FilterMode filterMode = FilterMode.Point,
  281. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  282. TextureDimension dimension = TextureDimension.Tex2D,
  283. bool enableRandomWrite = false,
  284. bool useMipMap = false,
  285. bool autoGenerateMips = true,
  286. bool isShadowMap = false,
  287. int anisoLevel = 1,
  288. float mipMapBias = 0,
  289. MSAASamples msaaSamples = MSAASamples.None,
  290. bool bindTextureMS = false,
  291. bool useDynamicScale = false,
  292. bool useDynamicScaleExplicit = false,
  293. RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
  294. VRTextureUsage vrUsage = VRTextureUsage.None,
  295. string name = ""
  296. )
  297. {
  298. return s_DefaultInstance.Alloc(
  299. scaleFactor,
  300. slices,
  301. depthBufferBits,
  302. colorFormat,
  303. filterMode,
  304. wrapMode,
  305. dimension,
  306. enableRandomWrite,
  307. useMipMap,
  308. autoGenerateMips,
  309. isShadowMap,
  310. anisoLevel,
  311. mipMapBias,
  312. msaaSamples,
  313. bindTextureMS,
  314. useDynamicScale,
  315. useDynamicScaleExplicit,
  316. memoryless,
  317. vrUsage,
  318. name
  319. );
  320. }
  321. /// <summary>
  322. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  323. /// </summary>
  324. /// <param name="scaleFactor">Constant scale for the RTHandle size computation.</param>
  325. /// <param name="descriptor">RenderTexture descriptor of the RTHandle.</param>
  326. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  327. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  328. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  329. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  330. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  331. /// <param name="name">Name of the RTHandle.</param>
  332. /// <returns>A new RTHandle.</returns>
  333. public static RTHandle Alloc(
  334. Vector2 scaleFactor,
  335. in RenderTextureDescriptor descriptor,
  336. FilterMode filterMode = FilterMode.Point,
  337. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  338. bool isShadowMap = false,
  339. int anisoLevel = 1,
  340. float mipMapBias = 0,
  341. string name = ""
  342. )
  343. {
  344. return s_DefaultInstance.Alloc(
  345. scaleFactor,
  346. descriptor.volumeDepth,
  347. (DepthBits)descriptor.depthBufferBits,
  348. descriptor.graphicsFormat,
  349. filterMode,
  350. wrapMode,
  351. descriptor.dimension,
  352. descriptor.enableRandomWrite,
  353. descriptor.useMipMap,
  354. descriptor.autoGenerateMips,
  355. isShadowMap,
  356. anisoLevel,
  357. mipMapBias,
  358. (MSAASamples)descriptor.msaaSamples,
  359. descriptor.bindMS,
  360. descriptor.useDynamicScale,
  361. descriptor.useDynamicScaleExplicit,
  362. descriptor.memoryless,
  363. descriptor.vrUsage,
  364. name
  365. );
  366. }
  367. /// <summary>
  368. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  369. /// </summary>
  370. /// <param name="scaleFactor">Constant scale for the RTHandle size computation.</param>
  371. /// <param name="info">Struct containing details of allocation</param>
  372. /// <returns>A new RTHandle.</returns>
  373. public static RTHandle Alloc(Vector2 scaleFactor, RTHandleAllocInfo info)
  374. {
  375. return s_DefaultInstance.Alloc(scaleFactor, info);
  376. }
  377. /// <summary>
  378. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  379. /// </summary>
  380. /// <param name="scaleFunc">Function used for the RTHandle size computation.</param>
  381. /// <param name="slices">Number of slices of the RTHandle.</param>
  382. /// <param name="depthBufferBits">Bit depths of a depth buffer.</param>
  383. /// <param name="colorFormat">GraphicsFormat of a color buffer.</param>
  384. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  385. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  386. /// <param name="dimension">Texture dimension of the RTHandle.</param>
  387. /// <param name="enableRandomWrite">Set to true to enable UAV random read writes on the texture.</param>
  388. /// <param name="useMipMap">Set to true if the texture should have mipmaps.</param>
  389. /// <param name="autoGenerateMips">Set to true to automatically generate mipmaps.</param>
  390. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  391. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  392. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  393. /// <param name="msaaSamples">Number of MSAA samples.</param>
  394. /// <param name="bindTextureMS">Set to true if the texture needs to be bound as a multisampled texture in the shader.</param>
  395. /// <param name="useDynamicScale">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  396. /// <param name="useDynamicScaleExplicit">[See Dynamic Resolution documentation](https://docs.unity3d.com/Manual/DynamicResolution.html)</param>
  397. /// <param name="memoryless">Use this property to set the render texture memoryless modes.</param>
  398. /// <param name="vrUsage">Special treatment of the VR eye texture used in stereoscopic rendering.</param>
  399. /// <param name="name">Name of the RTHandle.</param>
  400. /// <returns>A new RTHandle.</returns>
  401. public static RTHandle Alloc(
  402. ScaleFunc scaleFunc,
  403. int slices = 1,
  404. DepthBits depthBufferBits = DepthBits.None,
  405. GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB,
  406. FilterMode filterMode = FilterMode.Point,
  407. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  408. TextureDimension dimension = TextureDimension.Tex2D,
  409. bool enableRandomWrite = false,
  410. bool useMipMap = false,
  411. bool autoGenerateMips = true,
  412. bool isShadowMap = false,
  413. int anisoLevel = 1,
  414. float mipMapBias = 0,
  415. MSAASamples msaaSamples = MSAASamples.None,
  416. bool bindTextureMS = false,
  417. bool useDynamicScale = false,
  418. bool useDynamicScaleExplicit = false,
  419. RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
  420. VRTextureUsage vrUsage = VRTextureUsage.None,
  421. string name = ""
  422. )
  423. {
  424. return s_DefaultInstance.Alloc(
  425. scaleFunc,
  426. slices,
  427. depthBufferBits,
  428. colorFormat,
  429. filterMode,
  430. wrapMode,
  431. dimension,
  432. enableRandomWrite,
  433. useMipMap,
  434. autoGenerateMips,
  435. isShadowMap,
  436. anisoLevel,
  437. mipMapBias,
  438. msaaSamples,
  439. bindTextureMS,
  440. useDynamicScale,
  441. useDynamicScaleExplicit,
  442. memoryless,
  443. vrUsage,
  444. name
  445. );
  446. }
  447. /// <summary>
  448. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  449. /// </summary>
  450. /// <param name="scaleFunc">Function used for the RTHandle size computation.</param>
  451. /// <param name="descriptor">RenderTexture descriptor of the RTHandle.</param>
  452. /// <param name="filterMode">Filtering mode of the RTHandle.</param>
  453. /// <param name="wrapMode">Addressing mode of the RTHandle.</param>
  454. /// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
  455. /// <param name="anisoLevel">Anisotropic filtering level.</param>
  456. /// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
  457. /// <param name="name">Name of the RTHandle.</param>
  458. /// <returns>A new RTHandle.</returns>
  459. public static RTHandle Alloc(
  460. ScaleFunc scaleFunc,
  461. in RenderTextureDescriptor descriptor,
  462. FilterMode filterMode = FilterMode.Point,
  463. TextureWrapMode wrapMode = TextureWrapMode.Repeat,
  464. bool isShadowMap = false,
  465. int anisoLevel = 1,
  466. float mipMapBias = 0,
  467. string name = ""
  468. )
  469. {
  470. Assert.IsFalse(descriptor.graphicsFormat != GraphicsFormat.None && descriptor.depthStencilFormat != GraphicsFormat.None,
  471. "The RenderTextureDescriptor used to create RTHandle " + name + " contains both graphicsFormat and depthStencilFormat which is not allowed.");
  472. var actualFormat = descriptor.graphicsFormat != GraphicsFormat.None ? descriptor.graphicsFormat : descriptor.depthStencilFormat;
  473. return s_DefaultInstance.Alloc(
  474. scaleFunc,
  475. descriptor.volumeDepth,
  476. (DepthBits)descriptor.depthBufferBits,
  477. actualFormat,
  478. filterMode,
  479. wrapMode,
  480. descriptor.dimension,
  481. descriptor.enableRandomWrite,
  482. descriptor.useMipMap,
  483. descriptor.autoGenerateMips,
  484. isShadowMap,
  485. anisoLevel,
  486. mipMapBias,
  487. (MSAASamples)descriptor.msaaSamples,
  488. descriptor.bindMS,
  489. descriptor.useDynamicScale,
  490. descriptor.useDynamicScaleExplicit,
  491. descriptor.memoryless,
  492. descriptor.vrUsage,
  493. name
  494. );
  495. }
  496. /// <summary>
  497. /// Allocate a new automatically sized RTHandle for the default RTHandle System.
  498. /// </summary>
  499. /// <param name="scaleFunc">Function used for the RTHandle size computation.</param>
  500. /// <param name="info">Struct containing details of allocation</param>
  501. /// <returns>A new RTHandle.</returns>
  502. public static RTHandle Alloc(ScaleFunc scaleFunc, RTHandleAllocInfo info)
  503. {
  504. return s_DefaultInstance.Alloc(scaleFunc, info);
  505. }
  506. /// <summary>
  507. /// Allocate a RTHandle from a regular Texture for the default RTHandle system.
  508. /// </summary>
  509. /// <param name="tex">Input texture</param>
  510. /// <returns>A new RTHandle referencing the input texture.</returns>
  511. public static RTHandle Alloc(Texture tex)
  512. {
  513. return s_DefaultInstance.Alloc(tex);
  514. }
  515. /// <summary>
  516. /// Allocate a RTHandle from a regular RenderTexture for the default RTHandle system.
  517. /// </summary>
  518. /// <param name="tex">Input texture</param>
  519. /// <param name="transferOwnership">To transfer ownership of the RenderTexture to the default RTHandles system, false by default</param>
  520. /// <returns>A new RTHandle referencing the input texture.</returns>
  521. public static RTHandle Alloc(RenderTexture tex, bool transferOwnership = false)
  522. {
  523. return s_DefaultInstance.Alloc(tex, transferOwnership);
  524. }
  525. /// <summary>
  526. /// Allocate a RTHandle from a regular render target identifier for the default RTHandle system.
  527. /// </summary>
  528. /// <param name="tex">Input render target identifier.</param>
  529. /// <returns>A new RTHandle referencing the input render target identifier.</returns>
  530. public static RTHandle Alloc(RenderTargetIdentifier tex)
  531. {
  532. return s_DefaultInstance.Alloc(tex);
  533. }
  534. /// <summary>
  535. /// Allocate a RTHandle from a regular render target identifier for the default RTHandle system.
  536. /// </summary>
  537. /// <param name="tex">Input render target identifier.</param>
  538. /// <param name="name">Name of the render target.</param>
  539. /// <returns>A new RTHandle referencing the input render target identifier.</returns>
  540. public static RTHandle Alloc(RenderTargetIdentifier tex, string name)
  541. {
  542. return s_DefaultInstance.Alloc(tex, name);
  543. }
  544. private static RTHandle Alloc(RTHandle tex)
  545. {
  546. Debug.LogError("Allocation a RTHandle from another one is forbidden.");
  547. return null;
  548. }
  549. /// <summary>
  550. /// Initialize the default RTHandle system.
  551. /// </summary>
  552. /// <param name="width">Initial reference rendering width.</param>
  553. /// <param name="height">Initial reference rendering height.</param>
  554. public static void Initialize(int width, int height)
  555. {
  556. s_DefaultInstance.Initialize(width, height);
  557. }
  558. /// <summary>
  559. /// Initialize the default RTHandle system.
  560. /// </summary>
  561. /// <param name="width">Initial reference rendering width.</param>
  562. /// <param name="height">Initial reference rendering height.</param>
  563. /// <param name="useLegacyDynamicResControl">Use legacy hardware DynamicResolution control in the default RTHandle system.</param>
  564. [Obsolete("useLegacyDynamicResControl is deprecated. Please use SetHardwareDynamicResolutionState() instead.")]
  565. public static void Initialize(int width, int height, bool useLegacyDynamicResControl = false)
  566. {
  567. s_DefaultInstance.Initialize(width, height, useLegacyDynamicResControl);
  568. }
  569. /// <summary>
  570. /// Release memory of a RTHandle from the default RTHandle System
  571. /// </summary>
  572. /// <param name="rth">RTHandle that should be released.</param>
  573. public static void Release(RTHandle rth)
  574. {
  575. s_DefaultInstance.Release(rth);
  576. }
  577. /// <summary>
  578. /// Enable or disable hardware dynamic resolution for the default RTHandle System
  579. /// </summary>
  580. /// <param name="hwDynamicResRequested">State of hardware dynamic resolution.</param>
  581. public static void SetHardwareDynamicResolutionState(bool hwDynamicResRequested)
  582. {
  583. s_DefaultInstance.SetHardwareDynamicResolutionState(hwDynamicResRequested);
  584. }
  585. /// <summary>
  586. /// Sets the reference rendering size for subsequent rendering for the default RTHandle System
  587. /// </summary>
  588. /// <param name="width">Reference rendering width for subsequent rendering.</param>
  589. /// <param name="height">Reference rendering height for subsequent rendering.</param>
  590. public static void SetReferenceSize(int width, int height)
  591. {
  592. s_DefaultInstance.SetReferenceSize(width, height);
  593. }
  594. /// <summary>
  595. /// Reset the reference size of the system and reallocate all textures.
  596. /// </summary>
  597. /// <param name="width">New width.</param>
  598. /// <param name="height">New height.</param>
  599. public static void ResetReferenceSize(int width, int height)
  600. {
  601. s_DefaultInstance.ResetReferenceSize(width, height);
  602. }
  603. /// <summary>
  604. /// Returns the ratio against the current target's max resolution
  605. /// </summary>
  606. /// <param name="width">width to utilize</param>
  607. /// <param name="height">height to utilize</param>
  608. /// <returns> retruns the width,height / maxTargetSize.xy ratio. </returns>
  609. public static Vector2 CalculateRatioAgainstMaxSize(int width, int height)
  610. {
  611. return s_DefaultInstance.CalculateRatioAgainstMaxSize(new Vector2Int(width, height));
  612. }
  613. }
  614. }