using StgSharp.Math; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; namespace StgSharp.Graphics { public unsafe struct VertexBuffer : IDisposable { internal uint _bufferID; public VertexBuffer(int n) { fixed (uint* id = &_bufferID) { Graphic.glGenBuffers(n, id); } } public uint BufferID { get { return _bufferID; } } public void Bind() { Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, _bufferID); } public void Dispose() { fixed (uint* id = &_bufferID) { Graphic.glDeleteBuffers(1, id); } } public void SetData(T bufferData, BufferReadType readType) where T : IMat { int size = Marshal.SizeOf(bufferData); Graphic.glBufferData( (int)BufferType.ARRAY_BUFFER, size, &bufferData, (int)readType); } public void SetData(T[] bufferArray, BufferReadType readType) where T : struct, IConvertible { int size = bufferArray.Length * Marshal.SizeOf(typeof(T)); fixed (void* bufferPtr = &bufferArray[0]) Graphic.glBufferData( (int)BufferType.ARRAY_BUFFER, size, bufferPtr, (int)readType); } } }