2020-02-17 02:44:21 +00:00
|
|
|
using System;
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
namespace RecrownedGTK.Graphics {
|
2020-04-04 22:35:06 +00:00
|
|
|
/// <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);
|
|
|
|
}
|
2020-03-01 23:08:01 +00:00
|
|
|
public void Buffer(float[] vertices, BufferUsageHint hint = BufferUsageHint.DynamicCopy) {
|
|
|
|
Bind();
|
2020-02-17 07:27:14 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|