From b2cacf6dc0599a5accfb395b40652a9ef90efbb2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 7 Dec 2017 19:24:53 +1100 Subject: [PATCH] Fix incorrect rendering when chunk had over 65,536 vertices. (Thanks Empy) --- ClassicalSharp/MeshBuilder/Builder.cs | 9 ------ ClassicalSharp/Rendering/MapRenderer.cs | 42 ++++++++++++++----------- src/Client/MapRenderer.c | 3 +- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/ClassicalSharp/MeshBuilder/Builder.cs b/ClassicalSharp/MeshBuilder/Builder.cs index 040302c78..1d731e575 100644 --- a/ClassicalSharp/MeshBuilder/Builder.cs +++ b/ClassicalSharp/MeshBuilder/Builder.cs @@ -155,13 +155,6 @@ namespace ClassicalSharp { info.TopCount = (ushort)part.vCount[Side.Top]; info.SpriteCount = part.spriteCount; - info.LeftIndex = (ushort)(info.SpriteCount); - info.RightIndex = (ushort)(info.LeftIndex + info.LeftCount); - info.FrontIndex = (ushort)(info.RightIndex + info.RightCount); - info.BackIndex = (ushort)(info.FrontIndex + info.FrontCount); - info.BottomIndex = (ushort)(info.BackIndex + info.BackCount); - info.TopIndex = (ushort)(info.BottomIndex + info.BottomCount); - // Lazy initalize part arrays so we can save time in MapRenderer for chunks that only contain 1 or 2 part types. if (parts == null) parts = new ChunkPartInfo[arraysCount]; @@ -312,9 +305,7 @@ namespace ClassicalSharp { } public struct ChunkPartInfo { - public int VbId, VerticesCount, SpriteCount; - public ushort LeftIndex, RightIndex, FrontIndex, BackIndex, BottomIndex, TopIndex; public ushort LeftCount, RightCount, FrontCount, BackCount, BottomCount, TopCount; } } \ No newline at end of file diff --git a/ClassicalSharp/Rendering/MapRenderer.cs b/ClassicalSharp/Rendering/MapRenderer.cs index a7334d9c3..3a3f8beb7 100644 --- a/ClassicalSharp/Rendering/MapRenderer.cs +++ b/ClassicalSharp/Rendering/MapRenderer.cs @@ -218,42 +218,45 @@ namespace ClassicalSharp.Renderers { bool drawFront = info.DrawFront && part.FrontCount > 0; bool drawBack = info.DrawBack && part.BackCount > 0; + int offset = part.SpriteCount; if (drawLeft && drawRight) { gfx.FaceCulling = true; - gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, part.LeftIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, offset); gfx.FaceCulling = false; game.Vertices += part.LeftCount + part.RightCount; } else if (drawLeft) { - gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, part.LeftIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); game.Vertices += part.LeftCount; } else if (drawRight) { - gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, part.RightIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, offset + part.LeftCount); game.Vertices += part.RightCount; } + offset += part.LeftCount + part.RightCount; if (drawFront && drawBack) { gfx.FaceCulling = true; - gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, part.FrontIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, offset); gfx.FaceCulling = false; game.Vertices += part.FrontCount + part.BackCount; } else if (drawFront) { - gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, part.FrontIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { - gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, part.BackIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, offset + part.FrontCount); game.Vertices += part.BackCount; } + offset += part.FrontCount + part.BackCount; if (drawBottom && drawTop) { gfx.FaceCulling = true; - gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, offset); gfx.FaceCulling = false; game.Vertices += part.TopCount + part.BottomCount; } else if (drawBottom) { - gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { - gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } @@ -293,36 +296,39 @@ namespace ClassicalSharp.Renderers { bool drawFront = (inTranslucent || info.DrawFront) && part.FrontCount > 0; bool drawBack = (inTranslucent || info.DrawBack) && part.BackCount > 0; + int offset = 0; if (drawLeft && drawRight) { - gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, part.LeftIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, offset); game.Vertices += (part.LeftCount + part.RightCount); } else if (drawLeft) { - gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, part.LeftIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); game.Vertices += part.LeftCount; } else if (drawRight) { - gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, part.RightIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, offset + part.LeftCount); game.Vertices += part.RightCount; } + offset += part.LeftCount + part.RightCount; if (drawFront && drawBack) { - gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, part.FrontIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, offset); game.Vertices += (part.FrontCount + part.BackCount); } else if (drawFront) { - gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, part.FrontIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { - gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, part.BackIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, offset + part.FrontCount); game.Vertices += part.BackCount; } + offset += part.FrontCount + part.BackCount; if (drawBottom && drawTop) { - gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, offset); game.Vertices += (part.BottomCount + part.TopCount); } else if (drawBottom) { - gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { - gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex); + gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } } diff --git a/src/Client/MapRenderer.c b/src/Client/MapRenderer.c index 9efe03c05..57d7cff55 100644 --- a/src/Client/MapRenderer.c +++ b/src/Client/MapRenderer.c @@ -101,8 +101,7 @@ void MapRenderer_RenderNormalBatch(UInt32 batch) { Gfx_DrawIndexedVb_TrisT2fC4b(part.YMinCount, offset); Game_Vertices += part.YMinCount; } else if (drawYMax) { - offset += part.YMinCount; - Gfx_DrawIndexedVb_TrisT2fC4b(part.YMaxCount, offset); + Gfx_DrawIndexedVb_TrisT2fC4b(part.YMaxCount, offset + part.YMinCount); Game_Vertices += part.YMaxCount; }