From a4acbf4b332bd4e8e406d51f5e4589388f16ad1f Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Fri, 23 Feb 2024 18:22:32 +0100
Subject: [PATCH] SkinRenderer - Reduced guidelines buffer size
---
PCK-Studio/PckStudio.csproj | 1 +
PCK-Studio/Rendering/CubeBatchMesh.cs | 6 ++-
PCK-Studio/Rendering/CubeData.cs | 66 +++++++++++------------
PCK-Studio/Rendering/IndexBuffer.cs | 14 ++---
PCK-Studio/Rendering/OutlineDefinition.cs | 15 ++++++
PCK-Studio/Rendering/SkinRenderer.cs | 40 +++++++-------
6 files changed, 78 insertions(+), 64 deletions(-)
create mode 100644 PCK-Studio/Rendering/OutlineDefinition.cs
diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj
index 51942590..c64e6a28 100644
--- a/PCK-Studio/PckStudio.csproj
+++ b/PCK-Studio/PckStudio.csproj
@@ -159,6 +159,7 @@
+
diff --git a/PCK-Studio/Rendering/CubeBatchMesh.cs b/PCK-Studio/Rendering/CubeBatchMesh.cs
index 9c6c37ee..2401a06e 100644
--- a/PCK-Studio/Rendering/CubeBatchMesh.cs
+++ b/PCK-Studio/Rendering/CubeBatchMesh.cs
@@ -115,13 +115,15 @@ namespace PckStudio.Rendering
return cubes[index].Center + Transform;
}
- internal Vector3[] GetCubical(int index)
+ internal OutlineDefinition GetOutline(int index)
{
if (!cubes.IndexInRange(index))
throw new IndexOutOfRangeException();
CubeData cube = cubes[index];
- return cube.GetOutline().Select(pos => pos + Transform).ToArray();
+ OutlineDefinition outline = cube.GetOutline();
+ outline.verticies = outline.verticies.Select(pos => pos + Transform).ToArray();
+ return outline;
}
internal Vector3 GetFaceCenter(int index, CubeData.CubeFace face)
diff --git a/PCK-Studio/Rendering/CubeData.cs b/PCK-Studio/Rendering/CubeData.cs
index a3aa3b8a..67b6d073 100644
--- a/PCK-Studio/Rendering/CubeData.cs
+++ b/PCK-Studio/Rendering/CubeData.cs
@@ -146,7 +146,7 @@ namespace PckStudio.Rendering
}
}
- internal Vector3[] GetOutline()
+ internal OutlineDefinition GetOutline()
{
List verts = new List();
@@ -160,43 +160,37 @@ namespace PckStudio.Rendering
Vector3 topLeftFront = vertices[6].Position;
Vector3 topRightFront = vertices[7].Position;
+ OutlineDefinition outline = new OutlineDefinition();
+ outline.verticies = [
+ bottomRightBack,
+ bottomLeftBack,
+ topLeftBack,
+ topRightBack,
- return [
- topLeftBack,
- topLeftFront,
-
- topLeftBack,
- topRightBack,
-
- topRightBack,
- topRightFront,
-
- topLeftFront,
- topRightFront,
-
- bottomLeftBack,
- bottomLeftFront,
-
- bottomLeftBack,
- bottomRightBack,
-
- bottomRightBack,
- bottomRightFront,
-
- bottomLeftFront,
- bottomRightFront,
-
- topLeftFront,
- bottomLeftFront,
-
- topRightFront,
- bottomRightFront,
- topLeftBack,
- bottomLeftBack,
-
- topRightBack,
- bottomRightBack,
+ bottomRightFront,
+ bottomLeftFront,
+ topLeftFront,
+ topRightFront,
];
+
+ outline.indicies = [
+ 0, 1,
+ 1, 2,
+ 2, 3,
+ 3, 0,
+
+ 4, 5,
+ 5, 6,
+ 6, 7,
+ 7, 4,
+
+ 0, 4,
+ 1, 5,
+ 2, 6,
+ 3, 7,
+ ];
+
+ return outline;
}
private void UpdateVertices()
diff --git a/PCK-Studio/Rendering/IndexBuffer.cs b/PCK-Studio/Rendering/IndexBuffer.cs
index 991fb453..ce69abd6 100644
--- a/PCK-Studio/Rendering/IndexBuffer.cs
+++ b/PCK-Studio/Rendering/IndexBuffer.cs
@@ -11,21 +11,21 @@ namespace PckStudio.Rendering
internal class IndexBuffer : IDisposable
{
private int _id;
- private List _indecies;
+ private List _indicies;
public IndexBuffer(params int[] indecies)
{
- _indecies = new List(indecies);
+ _indicies = new List(indecies);
}
///
/// Creates and attaches created index buffer
///
- ///
+ ///
///
- public static IndexBuffer Create(params int[] indecies)
+ public static IndexBuffer Create(params int[] indicies)
{
- var ib = new IndexBuffer(indecies);
+ var ib = new IndexBuffer(indicies);
ib.Attach();
return ib;
}
@@ -34,11 +34,11 @@ namespace PckStudio.Rendering
{
_id = GL.GenBuffer();
Bind();
- GL.BufferData(BufferTarget.ElementArrayBuffer, _indecies.Count * sizeof(int), _indecies.ToArray(), BufferUsageHint.StaticDraw);
+ GL.BufferData(BufferTarget.ElementArrayBuffer, _indicies.Count * sizeof(int), _indicies.ToArray(), BufferUsageHint.StaticDraw);
Unbind();
}
- public int GetCount() => _indecies.Count;
+ public int GetCount() => _indicies.Count;
public void Bind()
{
diff --git a/PCK-Studio/Rendering/OutlineDefinition.cs b/PCK-Studio/Rendering/OutlineDefinition.cs
new file mode 100644
index 00000000..0b3da4b1
--- /dev/null
+++ b/PCK-Studio/Rendering/OutlineDefinition.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK;
+
+namespace PckStudio.Rendering
+{
+ internal struct OutlineDefinition
+ {
+ internal int[] indicies;
+ internal Vector3[] verticies;
+ }
+}
diff --git a/PCK-Studio/Rendering/SkinRenderer.cs b/PCK-Studio/Rendering/SkinRenderer.cs
index 70a60e1a..ca268fe4 100644
--- a/PCK-Studio/Rendering/SkinRenderer.cs
+++ b/PCK-Studio/Rendering/SkinRenderer.cs
@@ -503,13 +503,22 @@ namespace PckStudio.Rendering
// Cubical draw context
{
VertexArray lineVAO = new VertexArray();
- List vertices = new List(24 * 6);
- vertices.AddRange(head.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
- vertices.AddRange(body.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
- vertices.AddRange(rightArm.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
- vertices.AddRange(leftArm.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
- vertices.AddRange(rightLeg.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
- vertices.AddRange(leftLeg.GetCubical(0).Select(pos => new LineVertex(pos, lineColor)));
+
+ void AddOutline(OutlineDefinition outline, ref List vertices, ref List indices)
+ {
+ int offset = vertices.Count;
+ vertices.AddRange(outline.verticies.Select(pos => new LineVertex(pos, lineColor)));
+ indices.AddRange(outline.indicies.Select(i => i + offset));
+ }
+
+ List vertices = new List(8 * 6);
+ List indices = new List(24 * 6);
+ AddOutline(head.GetOutline(0), ref vertices, ref indices);
+ AddOutline(body.GetOutline(0), ref vertices, ref indices);
+ AddOutline(rightArm.GetOutline(0), ref vertices, ref indices);
+ AddOutline(leftArm.GetOutline(0), ref vertices, ref indices);
+ AddOutline(rightLeg.GetOutline(0), ref vertices, ref indices);
+ AddOutline(leftLeg.GetOutline(0), ref vertices, ref indices);
VertexBuffer buffer = new VertexBuffer();
buffer.SetData(vertices.ToArray());
VertexBufferLayout layout = new VertexBufferLayout();
@@ -518,7 +527,7 @@ namespace PckStudio.Rendering
lineVAO.AddBuffer(buffer, layout);
lineVAO.Bind();
- _cubicalDrawContext = new DrawContext(lineVAO, buffer.GenIndexBuffer(), PrimitiveType.Lines);
+ _cubicalDrawContext = new DrawContext(lineVAO, IndexBuffer.Create(indices.ToArray()), PrimitiveType.Lines);
}
GLErrorCheck();
@@ -530,31 +539,23 @@ namespace PckStudio.Rendering
Vector3 bodyCenterBottom = body.GetFaceCenter(0, CubeData.CubeFace.Bottom);
LineVertex[] data = [
new LineVertex(head.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(bodyCenterTop, lineColor),
+ new LineVertex(bodyCenterBottom, lineColor),
new LineVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
new LineVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
new LineVertex(rightArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(bodyCenterTop, lineColor),
+ new LineVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
new LineVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
new LineVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(leftArm.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(bodyCenterTop, lineColor),
new LineVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
new LineVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
new LineVertex(rightLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(bodyCenterBottom, lineColor),
- new LineVertex(bodyCenterBottom, lineColor),
- new LineVertex(bodyCenterTop, lineColor),
+ new LineVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
new LineVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Bottom), lineColor),
new LineVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(leftLeg.GetFaceCenter(0, CubeData.CubeFace.Top), lineColor),
- new LineVertex(bodyCenterBottom, lineColor),
- new LineVertex(bodyCenterBottom, lineColor),
- new LineVertex(bodyCenterTop, lineColor),
];
VertexBuffer buffer = new VertexBuffer();
buffer.SetData(data);
@@ -730,6 +731,7 @@ namespace PckStudio.Rendering
int slimValue = slim ? 3 : 4;
rightArm.ReplaceCube(0, new(-3, -2, -2), new(slimValue, 12, 4), new(40, 16));
rightArmOverlay.ReplaceCube(0, new(-3, -2, -2), new(slimValue, 12, 4), new(40, 32), scale: OverlayScale);
+
leftArm.ReplaceCube(0, new(-1, -2, -2), new(slimValue, 12, 4), new(32, 48));
leftArmOverlay.ReplaceCube(0, new(-1, -2, -2), new(slimValue, 12, 4), new(48, 48), scale: OverlayScale);