Added vertex buffer handler.
This commit is contained in:
parent
953b9137cc
commit
5e21790e2b
46
RecrownedAthenaeum/Graphics/VertexBufferHandle.cs
Normal file
46
RecrownedAthenaeum/Graphics/VertexBufferHandle.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
namespace RecrownedAthenaeum.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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user