recrownedgtk/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2020-02-17 02:44:21 +00:00
using System;
using OpenTK.Graphics.OpenGL;
namespace RecrownedGTK.Graphics {
/// <summary>
/// Handles the openGL vertex buffer.
/// </summary>
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 Buffer(float[] vertices, BufferUsageHint hint = BufferUsageHint.DynamicCopy) {
Bind();
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);
}
}
}