recrownedgtk/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs

32 lines
994 B
C#
Raw Normal View History

2020-02-17 02:44:21 +00:00
using System;
using OpenTK.Graphics.OpenGL;
namespace RecrownedGTK.Graphics {
2020-02-20 21:07:18 +00:00
public class VertexBufferArrayHandle : IDisposable {
2020-02-17 02:44:21 +00:00
private bool disposed;
private int handle;
2020-02-20 21:07:18 +00:00
public VertexBufferArrayHandle() {
2020-02-17 02:44:21 +00:00
handle = GL.GenBuffer();
}
public void Bind() {
GL.BindBuffer(BufferTarget.ArrayBuffer, handle);
}
public void Flush(float[] vertices, BufferUsageHint hint = BufferUsageHint.StaticDraw) {
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, hint);
2020-02-17 02:44:21 +00:00
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposed) return;
if (disposing) {
}
GL.DeleteBuffer(handle);
disposed = true;
}
2020-02-20 21:07:18 +00:00
~VertexBufferArrayHandle() {
2020-02-17 02:44:21 +00:00
Dispose(false);
}
}
}