Initialise VertexBuffers immediately

This commit is contained in:
Gustas
2025-02-22 16:04:23 +02:00
committed by Paul Chote
parent a2096b6768
commit 39aec39364
10 changed files with 63 additions and 18 deletions

View File

@@ -55,6 +55,28 @@ namespace OpenRA.Platforms.Default
}
}
public VertexBuffer(T[] data, bool dynamic = true)
{
OpenGL.glGenBuffers(1, out buffer);
OpenGL.CheckGLError();
Bind();
var ptr = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
OpenGL.glBufferData(OpenGL.GL_ARRAY_BUFFER,
new IntPtr(VertexSize * data.Length),
ptr.AddrOfPinnedObject(),
dynamic ? OpenGL.GL_DYNAMIC_DRAW : OpenGL.GL_STATIC_DRAW);
}
finally
{
ptr.Free();
}
OpenGL.CheckGLError();
}
public void SetData(T[] data, int length)
{
SetData(data, 0, 0, length);