Culling, rendering improvements and optimizations, block removing test.
This commit is contained in:
18
Renderer.cs
18
Renderer.cs
@@ -8,13 +8,19 @@ namespace Voxel
|
||||
private static int _vao;
|
||||
private static List<FaceData> _faces = new List<FaceData>();
|
||||
private static Shader _shader;
|
||||
private static Texture _texture;
|
||||
private static bool _needsUpdate = false;
|
||||
|
||||
public static void OnLoad()
|
||||
static Renderer()
|
||||
{
|
||||
string vertexPath = "Shaders/shader.vert";
|
||||
string fragmentPath = "Shaders/shader.frag";
|
||||
string texturePath = "atlas.png";
|
||||
|
||||
_shader = new Shader(vertexPath, fragmentPath);
|
||||
_texture = new Texture(texturePath);
|
||||
|
||||
_shader.SetInt("uTexture", 0);
|
||||
|
||||
_ssbo = GL.GenBuffer();
|
||||
_vao = GL.GenVertexArray();
|
||||
@@ -32,9 +38,8 @@ namespace Voxel
|
||||
if (_needsUpdate)
|
||||
{
|
||||
_needsUpdate = false;
|
||||
Console.WriteLine("Update buffer");
|
||||
uint[] data = _faces.SelectMany(f => f.Pack()).ToArray();
|
||||
GL.BufferData(BufferTarget.ShaderStorageBuffer, data.Length * sizeof(uint), data, BufferUsageHint.StaticRead);
|
||||
byte[] data = _faces.SelectMany(f => f.Pack()).ToArray();
|
||||
GL.BufferData(BufferTarget.ShaderStorageBuffer, data.Length, data, BufferUsageHint.StaticRead);
|
||||
}
|
||||
|
||||
_shader.Use();
|
||||
@@ -51,5 +56,10 @@ namespace Voxel
|
||||
_faces.AddRange(faces);
|
||||
_needsUpdate = true;
|
||||
}
|
||||
|
||||
public static void ClearFaces()
|
||||
{
|
||||
_faces.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user