1using Kestrel.Framework.World;
2using Silk.NET.OpenGL;
3
4namespace Kestrel.Framework.Client.Graphics.Buffers;
5
6public class CubeMesh(ClientState clientState) : Mesh(clientState)
7{
8 public override unsafe void Generate()
9 {
10 vao = clientState.Window.GL.GenVertexArray();
11 clientState.Window.GL.BindVertexArray(vao);
12
13 vbo = clientState.Window.GL.GenBuffer();
14 clientState.Window.GL.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
15
16 Mesher mesher = new();
17 mesher.AddUpFace(BlockType.Stone, 0, 0, 0);
18 mesher.AddDownFace(BlockType.Stone, 0, 0, 0);
19 mesher.AddEastFace(BlockType.Stone, 0, 0, 0);
20 mesher.AddWestFace(BlockType.Stone, 0, 0, 0);
21 mesher.AddNorthFace(BlockType.Stone, 0, 0, 0);
22 mesher.AddSouthFace(BlockType.Stone, 0, 0, 0);
23 Vertices = mesher.Vertices.ToArray();
24
25 fixed (float* buf = Vertices)
26 clientState.Window.GL.BufferData(BufferTargetARB.ArrayBuffer, (nuint)(Vertices.Length * sizeof(float)), buf, BufferUsageARB.StaticDraw);
27
28 clientState.Window.GL.EnableVertexAttribArray(0);
29 clientState.Window.GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), (void*)0);
30
31 clientState.Window.GL.EnableVertexAttribArray(1);
32 clientState.Window.GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 6 * sizeof(float), (void*)(3 * sizeof(float)));
33
34 clientState.Window.GL.EnableVertexAttribArray(2);
35 clientState.Window.GL.VertexAttribPointer(2, 1, VertexAttribPointerType.Float, false, 6 * sizeof(float), (void*)(5 * sizeof(float)));
36
37 // Clean up
38 clientState.Window.GL.BindVertexArray(0);
39 clientState.Window.GL.BindBuffer(BufferTargetARB.ArrayBuffer, 0);
40 }
41}