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; }
void DrawPart(ChunkInfo info, ref ChunkPartInfo part) { api.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) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.LeftCount + part.RightCount, part.LeftIndex); api.FaceCulling = false; } else if (drawLeft) { api.DrawIndexedVb_TrisT2fC4b(part.LeftCount, part.LeftIndex); } else if (drawRight) { api.DrawIndexedVb_TrisT2fC4b(part.RightCount, part.RightIndex); } if (drawFront && drawBack) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.FrontCount + part.BackCount, part.FrontIndex); api.FaceCulling = false; } else if (drawFront) { api.DrawIndexedVb_TrisT2fC4b(part.FrontCount, part.FrontIndex); } else if (drawBack) { api.DrawIndexedVb_TrisT2fC4b(part.BackCount, part.BackIndex); } if (drawBottom && drawTop) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex); api.FaceCulling = false; } else if (drawBottom) { api.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex); } else if (drawTop) { api.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex); } }
public void RenderEdges(double delta) { if (edgesVb == -1) { return; } BlockID block = game.World.Env.EdgeBlock; IGraphicsApi gfx = game.Graphics; Vector3 camPos = game.CurrentCameraPos; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(edgeTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.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.Env.SidesHeight); if (camPos.Y >= yVisible) { gfx.DrawVb_IndexedTris(edgesVertices); } gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = false; }
void RenderClouds(double delta) { if (game.World.Env.CloudHeight < -2000) { return; } double time = game.accumulator; float offset = (float)(time / 2048f * 0.6f * map.Env.CloudsSpeed); IGraphicsApi gfx = game.Graphics; gfx.SetMatrixMode(MatrixType.Texture); Matrix4 matrix = Matrix4.Identity; matrix.Row3.X = offset; // translate X axis gfx.LoadMatrix(ref matrix); gfx.SetMatrixMode(MatrixType.Modelview); gfx.AlphaTest = true; gfx.Texturing = true; gfx.BindTexture(cloudsTex); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(cloudsVb); gfx.DrawVb_IndexedTris(cloudVertices); gfx.AlphaTest = false; gfx.Texturing = false; gfx.SetMatrixMode(MatrixType.Texture); gfx.LoadIdentityMatrix(); gfx.SetMatrixMode(MatrixType.Modelview); }
void RenderSky(double delta) { if (game.SkyboxRenderer.ShouldRender) { return; } Vector3 pos = game.CurrentCameraPos; float normalY = map.Height + 8; float skyY = Math.Max(pos.Y + 8, normalY); IGraphicsApi gfx = game.Graphics; gfx.SetBatchFormat(VertexFormat.P3fC4b); gfx.BindVb(skyVb); if (skyY == normalY) { gfx.DrawVb_IndexedTris(skyVertices); } else { Matrix4 m = game.Graphics.View; float dy = skyY - normalY; // inlined Y translation matrix multiply m.Row3.X += dy * m.Row1.X; m.Row3.Y += dy * m.Row1.Y; m.Row3.Z += dy * m.Row1.Z; m.Row3.W += dy * m.Row1.W; gfx.LoadMatrix(ref m); gfx.DrawVb_IndexedTris(skyVertices); gfx.LoadMatrix(ref game.Graphics.View); } }
public void RenderSides(double delta) { if (sidesVb == -1) { return; } BlockID block = game.World.Env.SidesBlock; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(sideTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(sidesVb); gfx.DrawVb_IndexedTris(sidesVertices); gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = 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 RenderBorders(BlockID block, int vb, int tex, int count) { if (vb == 0) { return; } IGraphicsApi gfx = game.Graphics; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(tex); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(vb); if (count > 0) { gfx.DrawVb_IndexedTris(count); } gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = 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; } }
public void Render(double delta) { if (game.Graphics.LostContext) { return; } IGraphicsApi gfx = game.Graphics; #if !USE_DX && !ANDROID gfx.AlphaBlending = true; //gfx.DepthWrite = false; gfx.DrawLine(new Vector3(pos2.X, pos2.Y, pos2.Z), new Vector3(pos1.X, pos2.Y, pos2.Z)); gfx.DrawLine(new Vector3(pos1.X, pos2.Y, pos2.Z), new Vector3(pos1.X, pos2.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos1.X, pos2.Y, pos1.Z), new Vector3(pos2.X, pos2.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos2.X, pos2.Y, pos1.Z), new Vector3(pos2.X, pos2.Y, pos2.Z)); gfx.DrawLine(new Vector3(pos2.X, pos2.Y, pos2.Z), new Vector3(pos2.X, pos1.Y, pos2.Z)); gfx.DrawLine(new Vector3(pos1.X, pos2.Y, pos2.Z), new Vector3(pos1.X, pos1.Y, pos2.Z)); gfx.DrawLine(new Vector3(pos1.X, pos2.Y, pos1.Z), new Vector3(pos1.X, pos1.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos2.X, pos2.Y, pos1.Z), new Vector3(pos2.X, pos1.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos2.X, pos1.Y, pos2.Z), new Vector3(pos1.X, pos1.Y, pos2.Z)); gfx.DrawLine(new Vector3(pos1.X, pos1.Y, pos2.Z), new Vector3(pos1.X, pos1.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos1.X, pos1.Y, pos1.Z), new Vector3(pos2.X, pos1.Y, pos1.Z)); gfx.DrawLine(new Vector3(pos2.X, pos1.Y, pos1.Z), new Vector3(pos2.X, pos1.Y, pos2.Z)); //gfx.DepthWrite = true; gfx.AlphaBlending = false; #else gfx.AlphaBlending = true; gfx.DepthWrite = false; gfx.SetBatchFormat(VertexFormat.P3fC4b); gfx.UpdateDynamicVb_IndexedTris(vb, vertices, index); gfx.DepthWrite = true; gfx.AlphaBlending = false; #endif if (pickingBlock) { //gfx.AlphaTest = true; gfx.Texturing = true; //gfx.AlphaTest = true; gfx.AlphaBlending = true; gfx.FaceCulling = true; float[] texCols = new float[4]; texCols[0] = (127f / 256f); texCols[1] = (127f / 256f); texCols[2] = (127f / 256f); texCols[3] = (128f / 256f); /*GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Combine); * //GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.CombineRgb, (int)TextureEnvModeCombine.Subtract); * GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.CombineAlpha, (int)TextureEnvModeCombine.Subtract); * GL.TexEnvfv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvColor, texCols); * //GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.Source0Rgb, (int)TextureEnvModeSource.Texture); * GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.Src0Alpha, (int)TextureEnvModeSource.PrimaryColor); * //GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.Src1Rgb, (int)TextureEnvModeSource.Constant); * GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.Src1Alpha, (int)TextureEnvModeSource.Constant);*/ //GL.Enable(EnableCap.ColorMaterial); //graphics.AlphaTestFunc(CompareFunc.Greater, 0.0f); //GL.BlendFuncSeparate(BlendingFactor.DstColor, BlendingFactor.SrcColor, BlendingFactor.DstAlpha, BlendingFactor.DstAlpha); graphics.RGBAlphaBlendFunc(BlendFunc.DestColor, BlendFunc.SourceColor, BlendFunc.DestAlpha, BlendFunc.SourceAlpha); //VertexP3fT2fC4b[] vertices2 = new VertexP3fT2fC4b[8 * 10 * (4 * 4)]; //game.Graphics.CreateDynamicVb(VertexFormat.P3fT2fC4b, vertices.Length); gfx.BindTexture(pickTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(vb2); gfx.UpdateDynamicVb_IndexedTris(vb2, vertices2, index2); //graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); //graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f); //GL.Disable(EnableCap.ColorMaterial); //GL.TexEnvi(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate); gfx.FaceCulling = false; gfx.AlphaBlending = false; //gfx.AlphaTest = false; gfx.Texturing = false; //gfx.AlphaTest = 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; } }