change type buffer setdata to use element offset and length

pull/14/head
cosmonaut 2021-02-01 22:53:24 -08:00
parent ada9a1bb05
commit 68bb51439f
1 changed files with 11 additions and 8 deletions

View File

@ -23,18 +23,20 @@ namespace MoonWorks.Graphics
public unsafe void SetData<T>( public unsafe void SetData<T>(
T[] data, T[] data,
uint offsetInBytes, uint offsetInElements,
uint dataLengthInBytes uint lengthInElements
) where T : unmanaged ) where T : unmanaged
{ {
var elementSize = Marshal.SizeOf<T>();
fixed (T* ptr = &data[0]) fixed (T* ptr = &data[0])
{ {
Refresh.Refresh_SetBufferData( Refresh.Refresh_SetBufferData(
Device.Handle, Device.Handle,
Handle, Handle,
offsetInBytes, (uint) (offsetInElements * elementSize),
(IntPtr) ptr, (IntPtr) ptr,
dataLengthInBytes (uint) (lengthInElements * elementSize)
); );
} }
} }
@ -71,15 +73,16 @@ namespace MoonWorks.Graphics
public unsafe void SetData<T>( public unsafe void SetData<T>(
T* data, T* data,
uint offsetInBytes, uint offsetInElements,
uint dataLengthInBytes uint lengthInElements
) where T : unmanaged { ) where T : unmanaged {
var elementSize = Marshal.SizeOf<T>();
Refresh.Refresh_SetBufferData( Refresh.Refresh_SetBufferData(
Device.Handle, Device.Handle,
Handle, Handle,
offsetInBytes, (uint) (offsetInElements * elementSize),
(IntPtr) data, (IntPtr) data,
dataLengthInBytes (uint) (lengthInElements * elementSize)
); );
} }