Files
stgsharp/源代码/StgSharp/Graphics/GL/Buffer/VAO.cs
T

64 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(uint count)
{
return new VertexArray(count, gl);
}
}
public unsafe class VertexArray : IBufferObject
{
internal VertexArray(uint n, IglFunc gl)
{
_bufferID = new uint[n];
GL = gl;
fixed (uint* id = _bufferID)
{
GL.GenVertexArrays(n, id);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sealed override void Bind(int index)
{
GL.BindVertexArray(_bufferID[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BindNull()
{
GL.BindVertexArray(0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetVertexAttribute(uint index, int vertexLength, Type dataType, bool isNomalized, uint stride, int pointer)
{
GL.SetVertexAttribute(
index, vertexLength, dataType,
isNomalized,
stride, pointer);
}
protected sealed override void Dispose(bool disposing)
{
if (disposing)
{
GL.DeleteVertexArrays((uint)_bufferID.Length, _bufferID);
}
}
}
}