This commit is contained in:
2026-05-19 17:39:03 +07:00
parent bf0ebe447d
commit 5da832bb57
559 changed files with 69543 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
using UnityEngine.Rendering;
namespace Rive.Components.BuiltIn
{
internal class CommandBufferPool
{
private UnityEngine.Pool.ObjectPool<CommandBuffer> m_pool;
public CommandBufferPool(int defaultCapacity = 10, int maxSize = 100)
{
m_pool = new UnityEngine.Pool.ObjectPool<CommandBuffer>(
createFunc: CreateCommandBuffer,
actionOnGet: null,
actionOnRelease: OnReleaseCommandBuffer,
actionOnDestroy: OnDestroyCommandBuffer,
collectionCheck: true,
defaultCapacity: defaultCapacity,
maxSize: maxSize
);
}
public CommandBuffer Get()
{
return m_pool.Get();
}
public CommandBuffer Get(string name)
{
var commandBuffer = m_pool.Get();
commandBuffer.name = name;
return commandBuffer;
}
public void Release(CommandBuffer commandBuffer)
{
m_pool.Release(commandBuffer);
}
private CommandBuffer CreateCommandBuffer()
{
return new CommandBuffer();
}
private void OnReleaseCommandBuffer(CommandBuffer commandBuffer)
{
commandBuffer.Clear();
}
private void OnDestroyCommandBuffer(CommandBuffer commandBuffer)
{
commandBuffer.Dispose();
}
public void Clear()
{
m_pool.Clear();
}
}
}