Files
stgsharp/源代码/StgSharp/Graphics/GL/Buffer/EBO.cs
T

60 lines
1.5 KiB
C#

using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
protected ElementBuffer CreateElementBuffer(int n)
{
return new ElementBuffer(n, GL);
}
protected unsafe class ElementBuffer : IDisposable
{
uint[] _bufferID;
private IglFunc GL;
internal ElementBuffer(int n, IglFunc glFunc)
{
_bufferID = new uint[n];
GL = glFunc;
fixed (uint* id = _bufferID)
{
GL.GenBuffers(n, id);
}
}
public uint this[int n]
{
get { return _bufferID[n]; }
}
public void Bind(int index)
{
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
}
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
where T : struct, IConvertible
{
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
}
public void Dispose()
{
fixed (uint* id = _bufferID)
{
GL.DeleteBuffers(_bufferID.Length, id);
}
}
}
}
}