width | 以像素为单位的宽度。 |
height | 以像素为单位的高度。 |
depthBuffer | 深度缓冲区位数(0、16 或 24)。请注意,只有 24 位深度具有模板缓冲区。 |
format | 渲染纹理格式。 |
readWrite | 颜色空间转换模式。 |
antiAliasing | 存储在纹理中的抗锯齿样本数。有效值为 1、2、4 和 8。如果传递任何其他值,则会引发异常。 |
memorylessMode | 渲染纹理无内存模式。 |
vrUsage | Unity 如何将 RenderTexture 用作 VR 眼部纹理。默认为 VRTextureUsage.None。 |
useDynamicScale | 确定 Unity 是否使用动态分辨率缩放渲染纹理。默认为 false 。 |
desc | 创建临时 RenderTexture 时,使用此 RenderTextureDesc 进行设置。 |
分配一个临时渲染纹理。
当您需要一个快速的 RenderTexture 来进行一些临时计算时,此函数经过优化。完成后,请使用 ReleaseTemporary 释放它,以便另一个调用可以在需要时开始重用它。
在内部,Unity 保持了一个临时渲染纹理池,因此对 GetTemporary 的调用通常只返回一个已创建的纹理(如果大小和格式匹配)。这些临时渲染纹理实际上在几帧未使用时会被销毁。
如果您正在执行一系列后期处理“blit”,为了提高性能,最好为每个 blit 获取和释放一个临时渲染纹理,而不是预先获取一个或两个渲染纹理并重用它们。这主要对移动设备(基于图块)和多 GPU 系统有利:GetTemporary 将在内部执行 DiscardContents 调用,这有助于避免对先前渲染纹理内容进行代价高昂的还原操作。
您不能依赖从 GetTemporary 函数获得的 RenderTexture 的任何特定内容。它可能是垃圾,也可能被清除为某种颜色,具体取决于平台。
其他资源:ReleaseTemporary。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.