private static void RendererInit() { if (!Services.TryGet <IBlockTextures>("BlockTextures", out var textures)) { return; } uint[] id = { textures.Add("Textures/Blocks/GrassTop"), textures.Add("Textures/Blocks/GrassRound"), textures.Add("Textures/Blocks/Dirt"), textures.Add("Textures/Blocks/Rock"), textures.Add("Textures/Blocks/Sand"), textures.Add("Textures/Blocks/Water") }; var grass = new DefaultBlockRenderer(new[] { id[1], id[1], id[0], id[2], id[1], id[1] }); var rock = new DefaultBlockRenderer(new[] { id[3], id[3], id[3], id[3], id[3], id[3] }); var dirt = new DefaultBlockRenderer(new[] { id[2], id[2], id[2], id[2], id[2], id[2] }); var sand = new DefaultBlockRenderer(new[] { id[4], id[4], id[4], id[4], id[4], id[4] }); var water = new DefaultBlockRenderer(new[] { id[5], id[5], id[5], id[5], id[5], id[5] }); BlockRenderers.Add(_grassId, grass); BlockRenderers.Add(_rockId, rock); BlockRenderers.Add(_dirtId, dirt); BlockRenderers.Add(_sandId, sand); BlockRenderers.Add(_waterId, water); }
/** * \brief Generate the render data, namely VA, from a chunk. * Does not involve OpenGL functions. * \param chunk the chunk to be rendered. */ public ChunkVboGen Generate(Chunk chunk) { using (VertexBuilder vaOpacity = new VertexBuilder(262144), vaTranslucent = new VertexBuilder(262144)) { var tmp = new Int3(); var context = new BlockRenderContext(chunk, chunk.GetNeighbors()); for (tmp.X = 0; tmp.X < Chunk.RowSize; ++tmp.X) { for (tmp.Y = 0; tmp.Y < Chunk.RowSize; ++tmp.Y) { for (tmp.Z = 0; tmp.Z < Chunk.RowSize; ++tmp.Z) { var b = chunk[tmp]; var target = Blocks.Index[b.Id].IsTranslucent ? vaTranslucent : vaOpacity; BlockRenderers.Render(target, b.Id, context, tmp); } } } var mesh0 = vaOpacity.Dump(); var mesh1 = vaTranslucent.Dump(); Model = mesh0 != null || mesh1 != null ? new Model { new MaterialInstance(Context.Material), new MaterialInstance(Context.MaterialTransparent) } : null; if (mesh0 != null) { Model.Add(mesh0); } if (mesh1 != null) { Model.Add(mesh1); mesh1.MaterialIndex = 1; } } return(this); }