52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using StgSharp.Math;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// A collecion of handle to Element Buffer Object in OpenGL.
|
|
/// Each <see cref="uint"/> value indexed from instance of this class this
|
|
/// is the only handle to one Element Buffer Object.
|
|
/// </summary>
|
|
public unsafe class ElementBuffer : IBufferObject
|
|
{
|
|
internal ElementBuffer(uint n, IglFunc gl)
|
|
{
|
|
_bufferHandle = new glHandle((int)n);
|
|
GL = gl;
|
|
GL.GenBuffers(n, _bufferHandle);
|
|
}
|
|
|
|
public uint this[int n]
|
|
{
|
|
get { return _bufferHandle[n]; }
|
|
}
|
|
|
|
public override void Bind(int index)
|
|
{
|
|
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
|
}
|
|
|
|
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
|
where T : struct, IConvertible
|
|
{
|
|
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
|
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
|
}
|
|
|
|
protected sealed override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
GL.DeleteBuffers(_bufferHandle);
|
|
}
|
|
}
|
|
}
|
|
}
|