feat: added support for multiple batches
This commit is contained in:
@@ -4,12 +4,12 @@ using Engine.Core;
|
|||||||
|
|
||||||
namespace Engine.Systems.Graphics;
|
namespace Engine.Systems.Graphics;
|
||||||
|
|
||||||
public class TriangleBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, IDraw
|
||||||
{
|
{
|
||||||
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
||||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||||
|
|
||||||
private ITriangleBatch triangleBatch = null!;
|
private readonly BehaviourCollector<ITriangleBatch> triangleBatches = new();
|
||||||
private ICamera camera = null!;
|
private ICamera camera = null!;
|
||||||
|
|
||||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
||||||
@@ -18,16 +18,25 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
|||||||
{
|
{
|
||||||
camera = Universe.FindRequiredBehaviour<ICamera>();
|
camera = Universe.FindRequiredBehaviour<ICamera>();
|
||||||
|
|
||||||
triangleBatch = Universe.FindRequiredBehaviour<ITriangleBatch>();
|
|
||||||
drawableShapes.Unassign();
|
|
||||||
drawableShapes.Assign(Universe);
|
drawableShapes.Assign(Universe);
|
||||||
|
triangleBatches.Assign(Universe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < triangleBatches.Count; i++)
|
||||||
|
{
|
||||||
|
ITriangleBatch triangleBatch = triangleBatches[i];
|
||||||
triangleBatch.Begin(camera.ViewMatrix, camera.ProjectionMatrix);
|
triangleBatch.Begin(camera.ViewMatrix, camera.ProjectionMatrix);
|
||||||
for (int i = 0; i < drawableShapes.Count; i++)
|
for (int j = 0; j < drawableShapes.Count; j++)
|
||||||
drawableShapes[i].Draw(triangleBatch);
|
drawableShapes[j].Draw(triangleBatch);
|
||||||
triangleBatch.End();
|
triangleBatch.End();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LastActiveFrame()
|
||||||
|
{
|
||||||
|
triangleBatches.Unassign();
|
||||||
|
drawableShapes.Unassign();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user