TheNew1234
TheNew1234
SSilk.NET
Created by TheNew1234 on 10/24/2024 in #help-and-questions
Why doesn't this work? Launching the
Mesh class:
public unsafe class Mesh
{
private BufferObject<float> VBO;
private BufferObject<uint> EBO;
private VAO<float, uint> VAO;

private List<float> vertices;
private List<uint> indices;

public Mesh(List<float> vertices, List<uint> indices)
{
this.vertices = vertices;
this.indices = indices;

VAO = new VAO<float, uint>(VBO, EBO);
VAO.Bind();

VBO = new BufferObject<float>(this.vertices, BufferTargetARB.ArrayBuffer, BufferUsageARB.StaticDraw);
VBO.Bind();

EBO = new BufferObject<uint>(this.indices, BufferTargetARB.ElementArrayBuffer, BufferUsageARB.StaticDraw);
EBO.Bind();


VAO.Attributes(VBO, 0, 2, VertexAttribPointerType.Float, 2, 0 * sizeof(float));

/*VBO.Unbind();
EBO.Unbind();
VAO.Unbind();*/
}

public void Render()
{
VBO.Bind();
EBO.Bind();

gl.DrawElements(PrimitiveType.Triangles, (uint)indices.Count, DrawElementsType.UnsignedInt, null);
}

public void Dispose()
{
VBO.Dispose();
VAO.Dispose();
EBO.Dispose();
}
}
public unsafe class Mesh
{
private BufferObject<float> VBO;
private BufferObject<uint> EBO;
private VAO<float, uint> VAO;

private List<float> vertices;
private List<uint> indices;

public Mesh(List<float> vertices, List<uint> indices)
{
this.vertices = vertices;
this.indices = indices;

VAO = new VAO<float, uint>(VBO, EBO);
VAO.Bind();

VBO = new BufferObject<float>(this.vertices, BufferTargetARB.ArrayBuffer, BufferUsageARB.StaticDraw);
VBO.Bind();

EBO = new BufferObject<uint>(this.indices, BufferTargetARB.ElementArrayBuffer, BufferUsageARB.StaticDraw);
EBO.Bind();


VAO.Attributes(VBO, 0, 2, VertexAttribPointerType.Float, 2, 0 * sizeof(float));

/*VBO.Unbind();
EBO.Unbind();
VAO.Unbind();*/
}

public void Render()
{
VBO.Bind();
EBO.Bind();

gl.DrawElements(PrimitiveType.Triangles, (uint)indices.Count, DrawElementsType.UnsignedInt, null);
}

public void Dispose()
{
VBO.Dispose();
VAO.Dispose();
EBO.Dispose();
}
}
3 replies
SSilk.NET
Created by TheNew1234 on 10/24/2024 in #help-and-questions
Why doesn't this work? Launching the
VAO class:
public class VAO<TVboType, TEboType> where TVboType : unmanaged where TEboType : unmanaged
{
private uint handleID;

public VAO(BufferObject<TVboType> VBO, BufferObject<TEboType> EBO)
{
handleID = gl.GenVertexArray();
}

public unsafe void Attributes(BufferObject<TVboType> vbo, uint layout, uint numComponents, VertexAttribPointerType type, uint vertexSize, uint offset)
{
vbo.Bind();
gl.VertexAttribPointer(layout, (int)numComponents, type, false, (uint)(vertexSize * sizeof(TVboType)), (void*)offset);
gl.EnableVertexAttribArray(layout);
vbo.Unbind();
}

public void Bind()
{
gl.BindVertexArray(handleID);
}

public void Unbind()
{
gl.BindVertexArray(0);
}

public void Dispose()
{
gl.DeleteVertexArray(handleID);
}
}
public class VAO<TVboType, TEboType> where TVboType : unmanaged where TEboType : unmanaged
{
private uint handleID;

public VAO(BufferObject<TVboType> VBO, BufferObject<TEboType> EBO)
{
handleID = gl.GenVertexArray();
}

public unsafe void Attributes(BufferObject<TVboType> vbo, uint layout, uint numComponents, VertexAttribPointerType type, uint vertexSize, uint offset)
{
vbo.Bind();
gl.VertexAttribPointer(layout, (int)numComponents, type, false, (uint)(vertexSize * sizeof(TVboType)), (void*)offset);
gl.EnableVertexAttribArray(layout);
vbo.Unbind();
}

public void Bind()
{
gl.BindVertexArray(handleID);
}

public void Unbind()
{
gl.BindVertexArray(0);
}

public void Dispose()
{
gl.DeleteVertexArray(handleID);
}
}
3 replies
SSilk.NET
Created by TheNew1234 on 10/24/2024 in #help-and-questions
Why doesn't this work? Launching the
BufferObject class:
public class BufferObject<TType> where TType : unmanaged
{
private uint handleID;
private BufferTargetARB bufferType;

public unsafe BufferObject(TType[] data, BufferTargetARB bufferType, BufferUsageARB bufferUsage)
{
this.bufferType = bufferType;
handleID = gl.GenBuffer();

fixed (void* dataPointer = data)
{
gl.BufferData(this.bufferType, (nuint)(data.Length * sizeof(TType)), dataPointer, bufferUsage);
}
}

public unsafe BufferObject(List<TType> data, BufferTargetARB bufferType, BufferUsageARB bufferUsage)
{
this.bufferType = bufferType;
handleID = gl.GenBuffer();

fixed (void* dataPointer = data.ToArray())
{
gl.BufferData(bufferType, (nuint)(data.Count * sizeof(TType)), dataPointer, bufferUsage);
logger.Information("Buffer {bufferID} data: {data}", handleID, data);
}
}

public void Bind()
{
gl.BindBuffer(bufferType, handleID);
}

public void Unbind()
{
gl.BindBuffer(bufferType, 0);
}

public void Dispose()
{
gl.DeleteBuffer(handleID);
}
}
public class BufferObject<TType> where TType : unmanaged
{
private uint handleID;
private BufferTargetARB bufferType;

public unsafe BufferObject(TType[] data, BufferTargetARB bufferType, BufferUsageARB bufferUsage)
{
this.bufferType = bufferType;
handleID = gl.GenBuffer();

fixed (void* dataPointer = data)
{
gl.BufferData(this.bufferType, (nuint)(data.Length * sizeof(TType)), dataPointer, bufferUsage);
}
}

public unsafe BufferObject(List<TType> data, BufferTargetARB bufferType, BufferUsageARB bufferUsage)
{
this.bufferType = bufferType;
handleID = gl.GenBuffer();

fixed (void* dataPointer = data.ToArray())
{
gl.BufferData(bufferType, (nuint)(data.Count * sizeof(TType)), dataPointer, bufferUsage);
logger.Information("Buffer {bufferID} data: {data}", handleID, data);
}
}

public void Bind()
{
gl.BindBuffer(bufferType, handleID);
}

public void Unbind()
{
gl.BindBuffer(bufferType, 0);
}

public void Dispose()
{
gl.DeleteBuffer(handleID);
}
}
3 replies