-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBufferObject.cs
More file actions
36 lines (31 loc) · 912 Bytes
/
BufferObject.cs
File metadata and controls
36 lines (31 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Silk.NET.OpenGL;
using System;
namespace OpenGL_Demo
{
public class BufferObject<TDataType> : IDisposable
where TDataType : unmanaged
{
uint _handle;
BufferTargetARB _bufferType;
public BufferObject(BufferTargetARB bufferType)
{
_bufferType = bufferType;
_handle = Program.GL.GenBuffer();
}
public void Bind()
{
Program.GL.BindBuffer(_bufferType, _handle);
}
public unsafe void BufferData(Span<TDataType> data, BufferUsageARB bufferUsage = BufferUsageARB.StaticDraw)
{
fixed (void* d = &data[0])
{
Program.GL.BufferData(_bufferType, (nuint)(data.Length * sizeof(TDataType)), d, bufferUsage);
}
}
public unsafe void Dispose()
{
Program.GL.DeleteBuffer(_handle);
}
}
}