another try at fixing the mesh class (maybe mesh class is not the problem after all?)
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 20s

This commit is contained in:
2024-01-03 00:22:58 +01:00
parent 049d8cff7e
commit cc3493627d
4 changed files with 49 additions and 46 deletions

View File

@ -28,6 +28,7 @@ namespace Nebulix
result[resultIdx] = array[i].X;
result[resultIdx + 1] = array[i].Y;
result[resultIdx + 2] = array[i].Z;
resultIdx += 3;
}
return result;

View File

@ -46,12 +46,16 @@ namespace Nebulix.Rendering
// getting called by "Engine" which currently is in another assembly, meaning I probably need to make this public
// needs to be change for the real engine
/// <summary>
/// Binds the necessary buffers and draws the mesh. Does not use any Shaders
/// </summary>
/// <param name="gl"></param>
public void Render(GL gl)
{
if (regenerate) Generate(gl);
gl.BindVertexArray(vao);
gl.DrawElements(PrimitiveType.Triangles, (uint)vertices.Length * 3, DrawElementsType.UnsignedInt, 0);
gl.DrawElements(PrimitiveType.Triangles, (uint)indices.Length, DrawElementsType.UnsignedInt, 0);
}
private unsafe void Generate(GL gl)
@ -60,13 +64,13 @@ namespace Nebulix.Rendering
if(vao == 0)
vao = gl.CreateVertexArray();
gl.BindVertexArray(vao);
if(vbo == 0)
vbo = gl.GenBuffer();
if(ebo == 0)
ebo = gl.GenBuffer();
gl.BindVertexArray(vao);
List<float> meshData = new(vertices.Length * 3 + normals.Length * 3);
meshData.AddRange(vertices.ExtractComponents());
//meshData.AddRange(normals.ExtractComponents());
@ -77,7 +81,7 @@ namespace Nebulix.Rendering
ReadOnlySpan<nuint> indicesData = new(indices);
gl.BindBuffer(BufferTargetARB.ElementArrayBuffer, ebo);
gl.BufferData(BufferTargetARB.ElementArrayBuffer, (nuint)(indicesData.Length * sizeof(nuint)), indicesData, BufferUsageARB.StaticDraw);
// vertices
gl.EnableVertexAttribArray(0);
gl.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), null);