46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
|
using System;
|
||
|
using OpenTK.Graphics.OpenGL;
|
||
|
namespace RecrownedGTK.Graphics {
|
||
|
public class VertexBufferHandle : IDisposable {
|
||
|
private bool disposed;
|
||
|
private int handle;
|
||
|
public bool Bound {
|
||
|
get;
|
||
|
private set;
|
||
|
}
|
||
|
public VertexBufferHandle() {
|
||
|
handle = GL.GenBuffer();
|
||
|
}
|
||
|
public void Bind() {
|
||
|
Bound = true;
|
||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, handle);
|
||
|
}
|
||
|
public void Unbind() {
|
||
|
Bound = false;
|
||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||
|
}
|
||
|
public void Buffer(float[] vertices, BufferUsageHint hint = BufferUsageHint.StaticDraw) {
|
||
|
if (Bound) {
|
||
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, hint);
|
||
|
return;
|
||
|
}
|
||
|
throw new InvalidOperationException("Buffer is not bound.");
|
||
|
}
|
||
|
public void Dispose() {
|
||
|
Dispose(true);
|
||
|
GC.SuppressFinalize(this);
|
||
|
}
|
||
|
protected virtual void Dispose(bool disposing) {
|
||
|
if (disposed) return;
|
||
|
if (disposing) {
|
||
|
|
||
|
}
|
||
|
Unbind();
|
||
|
GL.DeleteBuffer(handle);
|
||
|
disposed = true;
|
||
|
}
|
||
|
~VertexBufferHandle() {
|
||
|
Dispose(false);
|
||
|
}
|
||
|
}
|
||
|
}
|