Permalink
Browse files

Fix incorrect rendering when chunk had over 65,536 vertices. (Thanks …

…Empy)
  • Loading branch information...
UnknownShadow200 committed Dec 7, 2017
1 parent 1bcf89b commit b2cacf6dc0599a5accfb395b40652a9ef90efbb2
Showing with 25 additions and 29 deletions.
  1. +0 −9 ClassicalSharp/MeshBuilder/Builder.cs
  2. +24 −18 ClassicalSharp/Rendering/MapRenderer.cs
  3. +1 −2 src/Client/MapRenderer.c
@@ -155,13 +155,6 @@ public unsafe abstract partial class ChunkMeshBuilder {
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 @@ public unsafe abstract partial class ChunkMeshBuilder {
}
public struct ChunkPartInfo {
public int VbId, VerticesCount, SpriteCount;
public ushort LeftIndex, RightIndex, FrontIndex, BackIndex, BottomIndex, TopIndex;
public ushort LeftCount, RightCount, FrontCount, BackCount, BottomCount, TopCount;
}
}
@@ -218,42 +218,45 @@ public partial class MapRenderer : IDisposable {
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 @@ public partial class MapRenderer : IDisposable {
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;
}
}
View
@@ -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;
}

0 comments on commit b2cacf6

Please sign in to comment.