Culling, rendering improvements and optimizations, block removing test.

This commit is contained in:
2025-09-02 22:43:35 +02:00
parent a9cab195b6
commit 00713db79e
16 changed files with 390 additions and 210 deletions

View File

@@ -11,6 +11,11 @@ namespace Voxel
public uint frames = 0;
public double timeElapsed = 0;
// testing
public Chunk Chunk;
private Dictionary<int, bool> _cache = new Dictionary<int, bool>();
private bool chunkEmpty = false;
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
@@ -19,6 +24,31 @@ namespace Voxel
{
Close();
}
RemoveRandomBlocks();
}
private void RemoveRandomBlocks()
{
if (Chunk != null && !chunkEmpty)
{
Random rng = new Random();
int GetNum()
{
int max = 4096;
int num = rng.Next(max);
if (_cache.ContainsKey(num)) return GetNum();
_cache[num] = true;
if (_cache.Count == max) chunkEmpty = true;
return num;
}
Chunk.SetBlockIndex(GetNum(), Blocks.Air);
}
Renderer.ClearFaces();
Renderer.AddFaces(Chunk.GetChunkMesh().Faces);
}
protected override void OnRenderFrame(FrameEventArgs e)
@@ -46,6 +76,8 @@ namespace Voxel
{
base.OnFramebufferResize(e);
Camera.UpdateProjection(e.Width, e.Height);
GL.Viewport(0, 0, e.Width, e.Height);
}
@@ -53,15 +85,17 @@ namespace Voxel
{
base.OnLoad();
Renderer.OnLoad();
GL.ClearColor(0.72f, 0.88f, 0.97f, 1f);
GL.Enable(EnableCap.CullFace);
GL.Enable(EnableCap.DepthTest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
CursorState = CursorState.Grabbed;
VSync = VSyncMode.On;
Camera.UpdateProjection(Width, Height);
}
protected override void OnMouseMove(MouseMoveEventArgs e)