From 5b44fee033cac5076505a1aa2b30c570e178b39c Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 1 Mar 2020 18:08:01 -0500 Subject: [PATCH] Buffers now automatically bind when adding to them. Buffer is untested. --- RecrownedGTK/Graphics/ElementBufferArrayHandle.cs | 11 ++++------- RecrownedGTK/Graphics/VertexBufferArrayHandle.cs | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/RecrownedGTK/Graphics/ElementBufferArrayHandle.cs b/RecrownedGTK/Graphics/ElementBufferArrayHandle.cs index c0c07fc..e772a7f 100644 --- a/RecrownedGTK/Graphics/ElementBufferArrayHandle.cs +++ b/RecrownedGTK/Graphics/ElementBufferArrayHandle.cs @@ -7,15 +7,12 @@ namespace RecrownedGTK.Graphics { public ElementBufferArrayHandle() { handle = GL.GenBuffer(); } + public void Bind() { GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle); } - - public void Unbind() { - GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); - } - - public void Flush(uint[] indices, BufferUsageHint hint = BufferUsageHint.StaticDraw) { + public void Buffer(uint[] indices, BufferUsageHint hint = BufferUsageHint.DynamicDraw) { + Bind(); GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, hint); } @@ -30,7 +27,7 @@ namespace RecrownedGTK.Graphics { } disposed = true; - Unbind(); + GL.DeleteBuffer(handle); } diff --git a/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs b/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs index aa32086..9a90b7c 100644 --- a/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs +++ b/RecrownedGTK/Graphics/VertexBufferArrayHandle.cs @@ -10,7 +10,8 @@ namespace RecrownedGTK.Graphics { public void Bind() { GL.BindBuffer(BufferTarget.ArrayBuffer, handle); } - public void Flush(float[] vertices, BufferUsageHint hint = BufferUsageHint.StaticDraw) { + public void Buffer(float[] vertices, BufferUsageHint hint = BufferUsageHint.DynamicCopy) { + Bind(); GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, hint); } public void Dispose() {