From 68bb51439fba97805e92b6e64b1a399c739f7f42 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 1 Feb 2021 22:53:24 -0800 Subject: [PATCH] change type buffer setdata to use element offset and length --- src/Graphics/Resources/Buffer.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Graphics/Resources/Buffer.cs b/src/Graphics/Resources/Buffer.cs index 3fbcfd7f..0f3900da 100644 --- a/src/Graphics/Resources/Buffer.cs +++ b/src/Graphics/Resources/Buffer.cs @@ -23,18 +23,20 @@ namespace MoonWorks.Graphics public unsafe void SetData( T[] data, - uint offsetInBytes, - uint dataLengthInBytes + uint offsetInElements, + uint lengthInElements ) where T : unmanaged { + var elementSize = Marshal.SizeOf(); + fixed (T* ptr = &data[0]) { Refresh.Refresh_SetBufferData( Device.Handle, Handle, - offsetInBytes, + (uint) (offsetInElements * elementSize), (IntPtr) ptr, - dataLengthInBytes + (uint) (lengthInElements * elementSize) ); } } @@ -71,15 +73,16 @@ namespace MoonWorks.Graphics public unsafe void SetData( T* data, - uint offsetInBytes, - uint dataLengthInBytes + uint offsetInElements, + uint lengthInElements ) where T : unmanaged { + var elementSize = Marshal.SizeOf(); Refresh.Refresh_SetBufferData( Device.Handle, Handle, - offsetInBytes, + (uint) (offsetInElements * elementSize), (IntPtr) data, - dataLengthInBytes + (uint) (lengthInElements * elementSize) ); }