-
-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathBufferObject.cs
39 lines (33 loc) · 1005 Bytes
/
BufferObject.cs
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
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Silk.NET.OpenGL;
namespace AndroidDemo
{
public class BufferObject<TDataType> : IDisposable
where TDataType : unmanaged
{
private uint _handle;
private BufferTargetARB _bufferType;
private GL _gl;
public unsafe BufferObject(GL gl, Span<TDataType> data, BufferTargetARB bufferType)
{
_gl = gl;
_bufferType = bufferType;
_handle = _gl.GenBuffer();
Bind();
fixed (void* d = data)
{
_gl.BufferData(bufferType, (nuint) (data.Length * sizeof(TDataType)), d, BufferUsageARB.StaticDraw);
}
}
public void Bind()
{
_gl.BindBuffer(_bufferType, _handle);
}
public void Dispose()
{
_gl.DeleteBuffer(_handle);
}
}
}