2021-01-20 03:33:27 +00:00
|
|
|
using System;
|
2021-01-22 01:27:25 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2021-01-20 03:33:27 +00:00
|
|
|
using RefreshCS;
|
|
|
|
|
|
|
|
namespace MoonWorks.Graphics
|
|
|
|
{
|
|
|
|
public class Buffer : GraphicsResource
|
|
|
|
{
|
|
|
|
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
|
|
|
|
|
|
|
|
public Buffer(
|
|
|
|
GraphicsDevice device,
|
2021-01-20 21:32:48 +00:00
|
|
|
BufferUsageFlags usageFlags,
|
2021-01-20 03:33:27 +00:00
|
|
|
uint sizeInBytes
|
|
|
|
) : base(device)
|
|
|
|
{
|
|
|
|
Handle = Refresh.Refresh_CreateBuffer(
|
|
|
|
device.Handle,
|
2021-01-20 21:32:48 +00:00
|
|
|
(Refresh.BufferUsageFlags) usageFlags,
|
2021-01-20 03:33:27 +00:00
|
|
|
sizeInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public unsafe void SetData<T>(
|
|
|
|
uint offsetInBytes,
|
|
|
|
T[] data,
|
|
|
|
uint dataLengthInBytes
|
|
|
|
) where T : unmanaged
|
|
|
|
{
|
|
|
|
fixed (T* ptr = &data[0])
|
|
|
|
{
|
|
|
|
Refresh.Refresh_SetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
offsetInBytes,
|
|
|
|
(IntPtr) ptr,
|
|
|
|
dataLengthInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 01:27:25 +00:00
|
|
|
public unsafe void SetData<T>(
|
|
|
|
T[] data
|
|
|
|
) where T : unmanaged
|
|
|
|
{
|
|
|
|
fixed (T* ptr = &data[0])
|
|
|
|
{
|
|
|
|
Refresh.Refresh_SetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
0,
|
|
|
|
(IntPtr)ptr,
|
|
|
|
(uint) (data.Length * Marshal.SizeOf<T>())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 03:33:27 +00:00
|
|
|
public unsafe void SetData<T>(
|
|
|
|
uint offsetInBytes,
|
|
|
|
T* data,
|
|
|
|
uint dataLengthInBytes
|
|
|
|
) where T : unmanaged
|
|
|
|
{
|
|
|
|
Refresh.Refresh_SetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
offsetInBytes,
|
|
|
|
(IntPtr) data,
|
|
|
|
dataLengthInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: You want to wait on the device before calling this
|
|
|
|
public unsafe void GetData<T>(
|
|
|
|
T[] data,
|
|
|
|
uint dataLengthInBytes
|
|
|
|
) where T : unmanaged
|
|
|
|
{
|
|
|
|
fixed (T* ptr = &data[0])
|
|
|
|
{
|
|
|
|
Refresh.Refresh_GetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
(IntPtr)ptr,
|
|
|
|
dataLengthInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|