using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
///
/// Create aset of .
///
/// Amount of Object to be created.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexBuffer CreateVertexBuffer(uint count)
{
return new VertexBuffer(count, gl);
}
}
public unsafe class VertexBuffer : IBufferObject
{
internal VertexBuffer(uint n, IglFunc glFunc)
{
_bufferID = new uint[n];
GL = glFunc;
fixed (uint* ptr = _bufferID)
{
GL.GenBuffers(n, ptr);
}
}
///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
}
public sealed override void Bind(int index)
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, (uint)index);
}
internal void ChangeEnvironment(IglFunc gl)
{
GL = gl;
}
protected sealed override void Dispose(bool disposing)
{
if (disposing)
{
fixed (uint* id = _bufferID)
{
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
}
}
}
///
/// Set data to current vertex buffer object
///
/// Type of bufferData
/// Index to find certain VBO in this instance
/// Data to write in
/// How OpenGL use these data, defined by
public void SetValue(int index, T bufferData, BufferUsage usage) where T : IMat
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
}
///
/// Set data to current vertex buffer object
///
/// Type of bufferData
/// Index to find certain VBO in this instance
/// A array of data to write in
/// How OpenGL use these data, defined by
public void SetValueArray(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
{
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
}
}
}