Class BufferedRTHandleSystem
Implement a multiple buffering for RenderTextures.
Implements
Inherited Members
Namespace: UnityEngine.Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
public class BufferedRTHandleSystem : IDisposable
Examples
enum BufferType
{
Color,
Depth
}
void Render()
{
var camera = GetCamera();
var buffers = GetFrameHistoryBuffersFor(camera);
// Set reference size in case the rendering size changed this frame
buffers.SetReferenceSize(
GetCameraWidth(camera), GetCameraHeight(camera),
GetCameraUseMSAA(camera), GetCameraMSAASamples(camera)
);
buffers.Swap();
var currentColor = buffer.GetFrameRT((int)BufferType.Color, 0);
if (currentColor == null) // Buffer was not allocated
{
buffer.AllocBuffer(
(int)BufferType.Color, // Color buffer id
ColorBufferAllocator, // Custom functor to implement allocation
2 // Use 2 RT for this buffer for double buffering
);
currentColor = buffer.GetFrameRT((int)BufferType.Color, 0);
}
var previousColor = buffers.GetFrameRT((int)BufferType.Color, 1);
// Use previousColor and write into currentColor
}
Properties
maxHeight
Maximum allocated height of the Buffered RTHandle System
Declaration
public int maxHeight { get; }
Property Value
Type | Description |
---|---|
int |
maxWidth
Maximum allocated width of the Buffered RTHandle System
Declaration
public int maxWidth { get; }
Property Value
Type | Description |
---|---|
int |
rtHandleProperties
Current properties of the Buffered RTHandle System
Declaration
public RTHandleProperties rtHandleProperties { get; }
Property Value
Type | Description |
---|---|
RTHandleProperties |
Methods
AllocBuffer(int, Func<RTHandleSystem, int, RTHandle>, int)
Allocate RT handles for a buffer.
Declaration
public void AllocBuffer(int bufferId, Func<RTHandleSystem, int, RTHandle> allocator, int bufferCount)
Parameters
Type | Name | Description |
---|---|---|
int | bufferId | The buffer to allocate. |
Func<RTHandleSystem, int, RTHandle> | allocator | The functor to use for allocation. |
int | bufferCount | The number of RT handles for this buffer. |
AllocBuffer(int, int, ref RenderTextureDescriptor, FilterMode, TextureWrapMode, bool, int, float, string)
Allocate RT handles for a buffer using a RenderTextureDescriptor.
Declaration
public void AllocBuffer(int bufferId, int bufferCount, ref RenderTextureDescriptor descriptor, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, bool isShadowMap = false, int anisoLevel = 1, float mipMapBias = 0, string name = "")
Parameters
Type | Name | Description |
---|---|---|
int | bufferId | The buffer to allocate. |
int | bufferCount | The number of RT handles for this buffer. |
RenderTextureDescriptor | descriptor | RenderTexture descriptor of the RTHandles. |
FilterMode | filterMode | Filtering mode of the RTHandles. |
TextureWrapMode | wrapMode | Addressing mode of the RTHandles. |
bool | isShadowMap | Set to true if the depth buffer should be used as a shadow map. |
int | anisoLevel | Anisotropic filtering level. |
float | mipMapBias | Bias applied to mipmaps during filtering. |
string | name | Name of the RTHandle. |
CalculateRatioAgainstMaxSize(int, int)
Returns the ratio against the current target's max resolution
Declaration
public Vector2 CalculateRatioAgainstMaxSize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | width to utilize |
int | height | height to utilize |
Returns
Type | Description |
---|---|
Vector2 | retruns the width,height / maxTargetSize.xy ratio. |
ClearBuffers(CommandBuffer)
Clears all the previously created history buffers
Declaration
public void ClearBuffers(CommandBuffer cmd)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | Defines the command buffer used for clearing. |
Dispose()
Dispose implementation
Declaration
public void Dispose()
GetFrameRT(int, int)
Return the frame RT or null.
Declaration
public RTHandle GetFrameRT(int bufferId, int frameIndex)
Parameters
Type | Name | Description |
---|---|---|
int | bufferId | Defines the buffer to use. |
int | frameIndex | Defines which frame to access within the buffer. |
Returns
Type | Description |
---|---|
RTHandle | The frame RT or null when the |
GetNumFramesAllocated(int)
Queries the number of RT handle buffers allocated for a buffer ID.
Declaration
public int GetNumFramesAllocated(int bufferId)
Parameters
Type | Name | Description |
---|---|---|
int | bufferId | The buffer ID to query. |
Returns
Type | Description |
---|---|
int | The num of frames allocated |
ReleaseAll()
Deallocate and clear all buffers.
Declaration
public void ReleaseAll()
ReleaseBuffer(int)
Release a buffer
Declaration
public void ReleaseBuffer(int bufferId)
Parameters
Type | Name | Description |
---|---|---|
int | bufferId | Id of the buffer that needs to be released. |
ResetReferenceSize(int, int)
Reset the reference size of the system and reallocate all textures.
Declaration
public void ResetReferenceSize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | New width. |
int | height | New height. |
SwapAndSetReferenceSize(int, int)
Swap buffers Set the reference size for this RT Handle System (SetReferenceSize(int, int, bool))
Declaration
public void SwapAndSetReferenceSize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | The width of the RTs of this buffer. |
int | height | The height of the RTs of this buffer. |