using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
///
/// Create a set of .
///
/// Amount of EBO to be created.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ElementBuffer CreateElementBuffer(uint count)
{
return new ElementBuffer(count, this.gl);
}
}
///
/// A collecion of handle to Element Buffer Object in OpenGL.
/// Each value indexed from instance of this class this
/// is the only handle to one Element Buffer Object.
///
public unsafe class ElementBuffer : IBufferObject
{
internal ElementBuffer(uint n, IglFunc gl)
{
_bufferID = new uint[n];
GL = gl;
fixed (uint* id = _bufferID)
{
GL.GenBuffers(n, id);
}
}
public uint this[int n]
{
get { return _bufferID[n]; }
}
public override void Bind(int index)
{
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
}
public void SetValue(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);
}
protected sealed override void Dispose(bool disposing)
{
if (disposing)
{
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
}
}
}
}