52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using StgSharp.Math;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
public unsafe class ElementBuffer : IDisposable, IBufferObject
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|