Files
stgsharp/源代码/StgSharp/Graphics/EBO.cs
T

60 lines
1.5 KiB
C#

using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
{
internal unsafe struct ElementBuffer : IDisposable
{
uint _bufferID;
public ElementBuffer(int n)
{
fixed (uint* id = &_bufferID)
{
Graphic.glGenBuffers(n, id);
}
}
public void Bind()
{
Graphic.glBindBuffer(GLFW.GL_ELEMENT_ARRAY_BUFFER, _bufferID);
}
public void SetData<T>(T bufferData, BufferReadType readType) where T : IMat
{
int size = Marshal.SizeOf(bufferData);
Graphic.glBufferData(
(int)BufferType.ELEMENT_ARRAY_BUFFER,
size,
&bufferData,
(int)readType);
}
public void SetData<T>(T[] bufferArray, BufferReadType readType) where T : struct, IConvertible
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
fixed (void* bufferPtr = &bufferArray[0])
Graphic.glBufferData(
(int)BufferType.ELEMENT_ARRAY_BUFFER,
size,
bufferPtr,
(int)readType);
}
public void Dispose()
{
fixed (uint* id = &_bufferID)
{
Graphic.glDeleteBuffers(1, id);
}
}
}
}