public void Render(double deltaTime) { if (sidesVb == -1 || edgesVb == -1) { return; } graphics.Texturing = true; graphics.AlphaTest = true; graphics.BindTexture(sideTexId); graphics.SetBatchFormat(VertexFormat.Pos3fTex2fCol4b); if (game.Map.SidesBlock != Block.Air) { graphics.BindVb(sidesVb); graphics.DrawIndexedVb_TrisT2fC4b(sidesVertices * 6 / 4, 0); } graphics.AlphaBlending = true; graphics.BindTexture(edgeTexId); graphics.BindVb(edgesVb); // Do not draw water when we cannot see it. // Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. float yVisible = Math.Min(0, map.SidesHeight); if (game.Map.EdgeBlock != Block.Air && game.CurrentCameraPos.Y >= yVisible) { graphics.DrawIndexedVb_TrisT2fC4b(edgesVertices * 6 / 4, 0); } graphics.AlphaBlending = false; graphics.Texturing = false; graphics.AlphaTest = false; }
public void RenderSides(double delta) { if (sidesVb == -1) { return; } byte block = game.World.Env.SidesBlock; if (game.BlockInfo.IsAir[block]) { return; } graphics.Texturing = true; graphics.AlphaTest = true; graphics.BindTexture(sideTexId); graphics.SetBatchFormat(VertexFormat.P3fT2fC4b); graphics.BindVb(sidesVb); graphics.DrawIndexedVb_TrisT2fC4b(sidesVertices * 6 / 4, 0); graphics.Texturing = false; graphics.AlphaTest = false; }
public void RenderSides(double delta) { if (sidesVb == -1) { return; } BlockID block = game.World.Env.SidesBlock; if (game.BlockInfo.Draw[block] == DrawType.Gas) { return; } gfx.SetupAlphaState(game.BlockInfo.Draw[block]); gfx.Texturing = true; gfx.BindTexture(sideTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(sidesVb); gfx.DrawIndexedVb_TrisT2fC4b(sidesVertices * 6 / 4, 0); gfx.RestoreAlphaState(game.BlockInfo.Draw[block]); gfx.Texturing = false; }
void RenderNormalBatch(int batch) { for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.NormalParts == null) { continue; } ChunkPartInfo part = info.NormalParts[batch]; if (part.IndicesCount == 0) { continue; } usedNormal[batch] = true; if (part.IndicesCount > maxIndices) { DrawBigPart(info, ref part); } else { DrawPart(info, ref part); } if (part.SpriteCount > 0) { int count = part.SpriteCount / 4; // 4 per sprite gfx.FaceCulling = true; if (info.DrawRight || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, 0); game.Vertices += count; } if (info.DrawLeft || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count); game.Vertices += count; } if (info.DrawLeft || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 2); game.Vertices += count; } if (info.DrawRight || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 3); game.Vertices += count; } gfx.FaceCulling = false; } } }
void RenderTranslucentBatch(int batch) { IGraphicsApi gfx = game.Graphics; for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.TranslucentParts == null) { continue; } ChunkPartInfo part = info.TranslucentParts[batch]; if (part.VerticesCount == 0) { continue; } usedTranslucent[batch] = true; gfx.BindVb(part.VbId); bool drawLeft = (inTranslucent || info.DrawLeft) && part.LeftCount > 0; bool drawRight = (inTranslucent || info.DrawRight) && part.RightCount > 0; bool drawBottom = (inTranslucent || info.DrawBottom) && part.BottomCount > 0; bool drawTop = (inTranslucent || info.DrawTop) && part.TopCount > 0; 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, offset); game.Vertices += (part.LeftCount + part.RightCount); } else if (drawLeft) { gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); game.Vertices += part.LeftCount; } else if (drawRight) { 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, offset); game.Vertices += (part.FrontCount + part.BackCount); } else if (drawFront) { gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { 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, offset); game.Vertices += (part.BottomCount + part.TopCount); } else if (drawBottom) { gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } } }
void RenderLiquidBatch(int batch) { IGraphicsApi gfx = game.Graphics; for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.LiquidParts == null) { continue; } ChunkPartInfo part = info.LiquidParts[batch]; if (part.VerticesCount == 0) { continue; } usedLiquid[batch] = true; gfx.BindVb(part.VbId); bool drawLeft = (inLiquid || info.DrawLeft) && part.LeftCount > 0; bool drawRight = (inLiquid || info.DrawRight) && part.RightCount > 0; bool drawBottom = (inLiquid || info.DrawBottom) && part.BottomCount > 0; bool drawTop = (inLiquid || info.DrawTop) && part.TopCount > 0; bool drawFront = (inLiquid || info.DrawFront) && part.FrontCount > 0; bool drawBack = (inLiquid || info.DrawBack) && part.BackCount > 0; int offset = 0; if (drawLeft && drawRight) { gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, offset); game.Vertices += part.LeftCount + part.RightCount; } else if (drawLeft) { gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); game.Vertices += part.LeftCount; } else if (drawRight) { 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, offset); game.Vertices += part.FrontCount + part.BackCount; } else if (drawFront) { gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { 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, offset); game.Vertices += part.TopCount + part.BottomCount; } else if (drawBottom) { gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } /*if (part.SpriteCount == 0) continue; * int count = part.SpriteCount / 4; // 4 per sprite * gfx.FaceCulling = true; * if (info.DrawRight || info.DrawFront) { * gfx.DrawIndexedVb_TrisT2fC4b(count, 0); game.Vertices += count; * } * if (info.DrawLeft || info.DrawBack) { * gfx.DrawIndexedVb_TrisT2fC4b(count, count); game.Vertices += count; * } * if (info.DrawLeft || info.DrawFront) { * gfx.DrawIndexedVb_TrisT2fC4b(count, count * 2); game.Vertices += count; * } * if (info.DrawRight || info.DrawBack) { * gfx.DrawIndexedVb_TrisT2fC4b(count, count * 3); game.Vertices += count; * } * gfx.FaceCulling = false;*/ } }
void RenderNormalBatch(int batch) { IGraphicsApi gfx = game.Graphics; for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.NormalParts == null) { continue; } ChunkPartInfo part = info.NormalParts[batch]; if (part.VerticesCount == 0) { continue; } usedNormal[batch] = true; gfx.BindVb(part.VbId); bool drawLeft = info.DrawLeft && part.LeftCount > 0; bool drawRight = info.DrawRight && part.RightCount > 0; bool drawBottom = info.DrawBottom && part.BottomCount > 0; bool drawTop = info.DrawTop && part.TopCount > 0; bool drawFront = info.DrawFront && part.FrontCount > 0; bool drawBack = info.DrawBack && part.BackCount > 0; bool camCloseX = Math.Abs(info.CentreX - game.CurrentCameraPos.X) < 8; bool camCloseY = Math.Abs(info.CentreY - game.CurrentCameraPos.Y) < 8; bool camCloseZ = Math.Abs(info.CentreZ - game.CurrentCameraPos.Z) < 8; //camCloseX = true; //camCloseY = true; //camCloseZ = true; int offset = part.SpriteCount; if (drawLeft && drawRight) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, offset); gfx.FaceCulling = false; game.Vertices += part.LeftCount + part.RightCount; } else if (drawLeft && camCloseX) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); gfx.FaceCulling = false; game.Vertices += part.LeftCount; } else if (drawRight && camCloseX) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, offset + part.LeftCount); gfx.FaceCulling = false; game.Vertices += part.RightCount; } else if (drawLeft) { gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, offset); game.Vertices += part.LeftCount; } else if (drawRight) { 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, offset); gfx.FaceCulling = false; game.Vertices += part.FrontCount + part.BackCount; } else if (drawFront && camCloseZ) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); gfx.FaceCulling = false; game.Vertices += part.FrontCount; } else if (drawBack && camCloseZ) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, offset + part.FrontCount); gfx.FaceCulling = false; game.Vertices += part.BackCount; } else if (drawFront) { gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { 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, offset); gfx.FaceCulling = false; game.Vertices += part.TopCount + part.BottomCount; } else if (drawBottom && camCloseY) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); gfx.FaceCulling = false; game.Vertices += part.BottomCount; } else if (drawTop && camCloseY) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); gfx.FaceCulling = false; game.Vertices += part.TopCount; } else if (drawBottom) { gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } if (part.SpriteCount == 0) { continue; } int count = part.SpriteCount / 4; // 4 per sprite gfx.FaceCulling = true; if (info.DrawRight || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, 0); game.Vertices += count; } if (info.DrawLeft || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count); game.Vertices += count; } if (info.DrawLeft || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 2); game.Vertices += count; } if (info.DrawRight || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 3); game.Vertices += count; } gfx.FaceCulling = false; } }
void RenderNormalBatch(int batch) { for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.NormalParts == null) { continue; } ChunkPartInfo part = info.NormalParts[batch]; if (part.VerticesCount == 0) { continue; } usedNormal[batch] = true; gfx.BindVb(part.VbId); bool drawLeft = info.DrawLeft && part.LeftCount > 0; bool drawRight = info.DrawRight && part.RightCount > 0; bool drawBottom = info.DrawBottom && part.BottomCount > 0; bool drawTop = info.DrawTop && part.TopCount > 0; bool drawFront = info.DrawFront && part.FrontCount > 0; bool drawBack = info.DrawBack && part.BackCount > 0; if (drawLeft && drawRight) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, part.LeftIndex); gfx.FaceCulling = false; game.Vertices += part.LeftCount + part.RightCount; } else if (drawLeft) { gfx.DrawIndexedVb_TrisT2fC4b(part.LeftCount, part.LeftIndex); game.Vertices += part.LeftCount; } else if (drawRight) { gfx.DrawIndexedVb_TrisT2fC4b(part.RightCount, part.RightIndex); game.Vertices += part.RightCount; } if (drawFront && drawBack) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, part.FrontIndex); gfx.FaceCulling = false; game.Vertices += part.FrontCount + part.BackCount; } else if (drawFront) { gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, part.FrontIndex); game.Vertices += part.FrontCount; } else if (drawBack) { gfx.DrawIndexedVb_TrisT2fC4b(part.BackCount, part.BackIndex); game.Vertices += part.BackCount; } if (drawBottom && drawTop) { gfx.FaceCulling = true; gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex); gfx.FaceCulling = false; game.Vertices += part.TopCount + part.BottomCount; } else if (drawBottom) { gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex); game.Vertices += part.BottomCount; } else if (drawTop) { gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex); game.Vertices += part.TopCount; } if (part.SpriteCount == 0) { continue; } int count = part.SpriteCount / 4; // 4 per sprite gfx.FaceCulling = true; if (info.DrawRight || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, 0); game.Vertices += count; } if (info.DrawLeft || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count); game.Vertices += count; } if (info.DrawLeft || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 2); game.Vertices += count; } if (info.DrawRight || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, count * 3); game.Vertices += count; } gfx.FaceCulling = false; } }
void RenderNormalBatch(int batch) { IGraphicsApi gfx = game.Graphics; for (int i = 0; i < renderCount; i++) { ChunkInfo info = renderChunks[i]; if (info.NormalParts == null) { continue; } ChunkPartInfo part = info.NormalParts[batch]; if (part.Offset < 0) { continue; } usedNormal[batch] = true; #if !GL11 gfx.BindVb(info.Vb); #else gfx.BindVb(part.Vb); #endif bool drawLeft = info.DrawLeft && part.LeftCount > 0; bool drawRight = info.DrawRight && part.RightCount > 0; bool drawBottom = info.DrawBottom && part.BottomCount > 0; bool drawTop = info.DrawTop && part.TopCount > 0; bool drawFront = info.DrawFront && part.FrontCount > 0; bool drawBack = info.DrawBack && part.BackCount > 0; int offset = part.Offset + part.SpriteCount; if (drawLeft && drawRight) { gfx.FaceCulling = true; 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, offset); game.Vertices += part.LeftCount; } else if (drawRight) { 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, offset); gfx.FaceCulling = false; game.Vertices += part.FrontCount + part.BackCount; } else if (drawFront) { gfx.DrawIndexedVb_TrisT2fC4b(part.FrontCount, offset); game.Vertices += part.FrontCount; } else if (drawBack) { 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, offset); gfx.FaceCulling = false; game.Vertices += part.TopCount + part.BottomCount; } else if (drawBottom) { gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, offset); game.Vertices += part.BottomCount; } else if (drawTop) { gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, offset + part.BottomCount); game.Vertices += part.TopCount; } if (part.SpriteCount == 0) { continue; } offset = part.Offset; int count = part.SpriteCount / 4; // 4 per sprite gfx.FaceCulling = true; if (info.DrawRight || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, offset); game.Vertices += count; } offset += count; if (info.DrawLeft || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, offset); game.Vertices += count; } offset += count; if (info.DrawLeft || info.DrawFront) { gfx.DrawIndexedVb_TrisT2fC4b(count, offset); game.Vertices += count; } offset += count; if (info.DrawRight || info.DrawBack) { gfx.DrawIndexedVb_TrisT2fC4b(count, offset); game.Vertices += count; } offset += count; gfx.FaceCulling = false; } }
void RenderNormalBatch(int batch) { for (int i = 0; i < chunks.Length; i++) { ChunkInfo info = chunks[i]; #if OCCLUSION if (info.NormalParts == null || !info.Visible || info.Occluded) { continue; } #else if (info.NormalParts == null || !info.Visible) { continue; } #endif ChunkPartInfo part = info.NormalParts[batch]; if (part.IndicesCount == 0) { continue; } usedNormal[batch] = true; if (part.IndicesCount > maxIndices) { DrawBigPart(info, ref part); } else { DrawPart(info, ref part); } if (part.SpriteCount > 0) { int groupCount = part.SpriteCount / 4; api.FaceCulling = true; if (info.DrawRight || info.DrawFront) { api.DrawIndexedVb_TrisT2fC4b(groupCount, 0); } if (info.DrawLeft || info.DrawBack) { api.DrawIndexedVb_TrisT2fC4b(groupCount, groupCount); } if (info.DrawLeft || info.DrawFront) { api.DrawIndexedVb_TrisT2fC4b(groupCount, groupCount * 2); } if (info.DrawRight || info.DrawBack) { api.DrawIndexedVb_TrisT2fC4b(groupCount, groupCount * 3); } api.FaceCulling = false; } game.Vertices += part.IndicesCount; } }