浏览代码

Added comments

/main
Frédéric Vauchelles 7 年前
当前提交
dd12e0c4
共有 1 个文件被更改,包括 73 次插入6 次删除
  1. 79
      ScriptableRenderPipeline/Core/CoreRP/Textures/BufferedRTHandleSystem.cs

79
ScriptableRenderPipeline/Core/CoreRP/Textures/BufferedRTHandleSystem.cs


namespace UnityEngine.Experimental.Rendering
{
/// <summary>
/// Implement a multiple buffering for RenderTextures.
/// </summary>
/// <exemple>
/// <code>
/// 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
/// }
/// </code>
/// </exemple>
public class BufferedRTHandleSystem : IDisposable
{
Dictionary<int, RTHandleSystem.RTHandle[]> m_RTHandles = new Dictionary<int, RTHandleSystem.RTHandle[]>();

public RTHandleSystem.RTHandle GetFrameRT(int historyId, int frameIndex)
/// <summary>
/// Return the frame RT or null.
/// </summary>
/// <param name="bufferId">Defines the buffer to use.</param>
/// <param name="frameIndex"></param>
/// <returns>The frame RT or null when the <paramref name="bufferId"/> was not previously allocated (<see cref="BufferedRTHandleSystem.AllocBuffer(int, Func{RTHandleSystem, int, RTHandleSystem.RTHandle}, int)" />).</returns>
public RTHandleSystem.RTHandle GetFrameRT(int bufferId, int frameIndex)
if (!m_RTHandles.ContainsKey(historyId))
if (!m_RTHandles.ContainsKey(bufferId))
Assert.IsTrue(frameIndex >= 0 && frameIndex < m_RTHandles[historyId].Length);
Assert.IsTrue(frameIndex >= 0 && frameIndex < m_RTHandles[bufferId].Length);
return m_RTHandles[historyId][frameIndex];
return m_RTHandles[bufferId][frameIndex];
/// <summary>
/// Allocate RT handles for a buffer.
/// </summary>
/// <param name="bufferId">The buffer to allocate.</param>
/// <param name="allocator">The functor to use for allocation.</param>
/// <param name="bufferCount">The number of RT handles for this buffer.</param>
int id,
int bufferId,
m_RTHandles.Add(id, buffer);
m_RTHandles.Add(bufferId, buffer);
// First is autoresized
buffer[0] = allocator(m_RTHandleSystem, 0);

}
}
/// <summary>
/// Set the reference size for this RT Handle System (<see cref="RTHandleSystem.SetReferenceSize(int, int, bool, MSAASamples)"/>)
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="msaa"></param>
/// <param name="msaaSamples"></param>
/// <summary>
/// Swap the buffers.
///
/// Take care that if the new current frame needs resizing, it will occurs during the this call.
/// </summary>
public void Swap()
{
foreach (var item in m_RTHandles)

Dispose(true);
}
/// <summary>
/// Deallocate and clear all buffers.
/// </summary>
public void ReleaseAll()
{
foreach (var item in m_RTHandles)

正在加载...
取消
保存