Hello everyone,
I am trying to create a simple CAD application using OpenTK (C#).
However I’m running into a problem, when I call GL.BufferData(…) it uses much more memory than it should need.
for instance if I draw 4000 lines the process memory shoots up 300+ mb. but it should only be a couple of kb.
I have a simple mesh class:
public abstract class Mesh
{
private int VertexArrayObject { get; set; }
private int VertexBufferObject { get; set; }
private int ElementBufferObject { get; set; }
private int NumberOfVertices { get; set; }
public abstract PrimitiveType PrimitiveType { get; }
public void Update(float[] vertices, uint[] indices)
{
NumberOfVertices = indices.Length;
GL.BindVertexArray(VertexArrayObject);
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices,
BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
GL.BufferData(BufferTarget.ElementArrayBuffer, NumberOfVertices * sizeof(uint), indices,
BufferUsageHint.DynamicRead);
}
public Mesh()
{
VertexBufferObject = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
ElementBufferObject = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
VertexArrayObject = GL.GenVertexArray();
GL.BindVertexArray(VertexArrayObject);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
GL.EnableVertexAttribArray(0);
}
public virtual void Draw()
{
GL.BindVertexArray(VertexArrayObject);
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
GL.DrawElements(PrimitiveType, NumberOfVertices, DrawElementsType.UnsignedInt, 0);
}
}
Any help is much appreciated.
Kind regards