66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.ThoMagic.Renderer
|
|
{
|
|
public class DrawGroup
|
|
{
|
|
private List<DrawCall> _drawCalls = new List<DrawCall>();
|
|
|
|
public void Add(DrawCall drawCall) => _drawCalls.Add(drawCall);
|
|
|
|
private int lodNr;
|
|
|
|
public DrawGroup(int lodNr)
|
|
{
|
|
this.lodNr = lodNr;
|
|
}
|
|
|
|
public uint Add(
|
|
Mesh mesh,
|
|
Material[] materials,
|
|
Matrix4x4 matrix,
|
|
uint indirectArgsCount,
|
|
List<GraphicsBuffer.IndirectDrawIndexedArgs> indirectDrawIndexedArgs,
|
|
in RenderParams renderParams)
|
|
{
|
|
var drawCall = new DrawCall(lodNr, mesh, materials, matrix, indirectArgsCount, indirectDrawIndexedArgs, in renderParams);
|
|
_drawCalls.Add(drawCall);
|
|
return (uint)drawCall.Mesh.subMeshCount;
|
|
}
|
|
|
|
public uint Add(
|
|
BillboardAsset mesh,
|
|
Material material,
|
|
Matrix4x4 matrix,
|
|
uint indirectArgsCount,
|
|
List<GraphicsBuffer.IndirectDrawIndexedArgs> indirectDrawIndexedArgs,
|
|
in RenderParams renderParams)
|
|
{
|
|
var drawCall = new BillboardDrawCall(lodNr, mesh, material, matrix, indirectArgsCount, indirectDrawIndexedArgs, in renderParams);
|
|
_drawCalls.Add(drawCall);
|
|
return (uint)drawCall.Mesh.subMeshCount;
|
|
}
|
|
|
|
public void Draw(Camera camera, ObjectData obj, GraphicsBuffer indirectDrawIndexedArgs)
|
|
{
|
|
foreach (var drawCall in _drawCalls)
|
|
drawCall?.Draw(camera, obj, indirectDrawIndexedArgs);
|
|
}
|
|
|
|
public virtual void SetInstances(ComputeBuffer instances, ComputeBuffer visibleIndexBuffer, ComputeBuffer metaBuffer)
|
|
{
|
|
foreach (var drawCall in _drawCalls)
|
|
drawCall?.SetInstances(instances, visibleIndexBuffer, metaBuffer);
|
|
}
|
|
|
|
internal void Dispose()
|
|
{
|
|
foreach (var drawCall in _drawCalls)
|
|
drawCall?.Dispose();
|
|
|
|
_drawCalls.Clear();
|
|
}
|
|
}
|
|
}
|