Files
VoxelEngine/Rendering/ChunkRenderer.cs
MDietermann 9193df2710 style: drop redundant type qualifiers, use explicit types (IDE cleanup)
Pure formatting from the IDE's code cleanup: remove redundant ClassName./namespace qualifiers and replace var with explicit types. No behavior change.
2026-06-03 16:26:32 +02:00

53 lines
1.6 KiB
C#

using OpenTK.Graphics.OpenGL4;
namespace VoxelEngine.Rendering;
public sealed class ChunkRenderer : World.Streaming.IChunkRenderer
{
private const int FloatsPerVertex = 6; // pos.xyz, uv, shade
private readonly int _vao;
private readonly int _vbo;
private readonly int _vertexCount;
public ChunkRenderer(float[] vertices)
{
this._vertexCount = vertices.Length / FloatsPerVertex;
int stride = FloatsPerVertex * sizeof(float);
this._vao = GL.GenVertexArray();
GL.BindVertexArray(this._vao);
this._vbo = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, this._vbo);
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
// location 0: position (vec3) at offset 0
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, stride, 0);
GL.EnableVertexAttribArray(0);
// location 1: uv (vec2) at offset 3 floats
GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, stride, 3 * sizeof(float));
GL.EnableVertexAttribArray(1);
// location 2: shade (float) at offset 5 floats
GL.VertexAttribPointer(2, 1, VertexAttribPointerType.Float, false, stride, 5 * sizeof(float));
GL.EnableVertexAttribArray(2);
GL.BindVertexArray(0);
}
public void Draw()
{
GL.BindVertexArray(this._vao);
GL.DrawArrays(PrimitiveType.Triangles, 0, this._vertexCount);
GL.BindVertexArray(0);
}
public void Dispose()
{
GL.DeleteBuffer(this._vbo);
GL.DeleteVertexArray(this._vao);
}
}