76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
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 unsafe class VertexBuffer : BufferObjectBase
|
|
{
|
|
internal VertexBuffer(int n, IglFunc glFunc)
|
|
{
|
|
GL = glFunc;
|
|
_bufferHandle = GL.GenBuffers(n);
|
|
}
|
|
|
|
public override sealed void Bind(int index)
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set data to current vertex buffer object
|
|
/// </summary>
|
|
/// <typeparam name="T">Type of bufferData</typeparam>
|
|
/// <param name="index">Index to find certain VBO in this instance</param>
|
|
/// <param name="bufferData">Data to write in</param>
|
|
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
|
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : struct, IMat
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
|
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set data to current vertex buffer object
|
|
/// </summary>
|
|
/// <typeparam name="T">Type of bufferData</typeparam>
|
|
/// <param name="index">Index to find certain VBO in this instance</param>
|
|
/// <param name="bufferArray">A array of data to write in</param>
|
|
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
|
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
|
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void Unbind()
|
|
{
|
|
GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ChangeEnvironment(IglFunc gl)
|
|
{
|
|
GL = gl;
|
|
}
|
|
|
|
protected override sealed void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
GL.DeleteBuffers(_bufferHandle);
|
|
_bufferHandle.Release();
|
|
}
|
|
}
|
|
}
|
|
} |