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>(
|
|
|
|
T[] data,
|
2021-01-29 05:49:33 +00:00
|
|
|
uint offsetInBytes,
|
2021-01-20 03:33:27 +00:00
|
|
|
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-29 05:49:33 +00:00
|
|
|
public void SetData(
|
2021-01-26 02:18:25 +00:00
|
|
|
IntPtr data,
|
2021-01-29 05:49:33 +00:00
|
|
|
uint offsetInBytes,
|
2021-01-20 03:33:27 +00:00
|
|
|
uint dataLengthInBytes
|
2021-01-29 05:49:33 +00:00
|
|
|
) {
|
2021-01-20 03:33:27 +00:00
|
|
|
Refresh.Refresh_SetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
offsetInBytes,
|
2021-01-26 02:18:25 +00:00
|
|
|
data,
|
2021-01-20 03:33:27 +00:00
|
|
|
dataLengthInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-29 05:49:33 +00:00
|
|
|
public unsafe void SetData<T>(
|
|
|
|
T* data,
|
|
|
|
uint offsetInBytes,
|
|
|
|
uint dataLengthInBytes
|
|
|
|
) where T : unmanaged {
|
|
|
|
Refresh.Refresh_SetBufferData(
|
|
|
|
Device.Handle,
|
|
|
|
Handle,
|
|
|
|
offsetInBytes,
|
|
|
|
(IntPtr) data,
|
|
|
|
dataLengthInBytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-20 03:33:27 +00:00
|
|
|
// 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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|