81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using StgSharp.Math;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Security;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
public partial class Form
|
|
{
|
|
protected VertexBuffer CreateVertexBuffer(int n)
|
|
{
|
|
return new VertexBuffer(n, GL);
|
|
}
|
|
|
|
protected unsafe struct VertexBuffer : IDisposable
|
|
{
|
|
internal uint[] _bufferID;
|
|
private IglFunc GL;
|
|
|
|
internal VertexBuffer(int n, IglFunc glFunc)
|
|
{
|
|
_bufferID = new uint[n];
|
|
GL = glFunc;
|
|
fixed (uint* ptr = _bufferID)
|
|
{
|
|
GL.GenBuffers(n, ptr);
|
|
}
|
|
}
|
|
|
|
public uint this[int n]
|
|
{
|
|
get { return _bufferID[n]; }
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void Unbind()
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
|
}
|
|
|
|
public void Bind(int index)
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
fixed (uint* id = _bufferID)
|
|
{
|
|
GL.DeleteBuffers(_bufferID.Length, id);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="bufferData"></param>
|
|
/// <param name="readType"></param>
|
|
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : IMat
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
|
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
|
|
|
}
|
|
|
|
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
|
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|