change Marshal.SizeOf to sizeof

pull/19/head
cosmonaut 2022-04-27 14:14:15 -07:00
parent 810f270a41
commit a0082bcec6
7 changed files with 26 additions and 26 deletions

View File

@ -107,13 +107,13 @@ namespace MoonWorks.Audio
IntPtr chainPtr;
chainPtr = Marshal.AllocHGlobal(
Marshal.SizeOf<FAudio.FAudioEffectChain>()
sizeof(FAudio.FAudioEffectChain)
);
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
reverbChain->EffectCount = 1;
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
sizeof(FAudio.FAudioEffectDescriptor)
);
FAudio.FAudioEffectDescriptor* reverbDescriptor =
@ -146,7 +146,7 @@ namespace MoonWorks.Audio
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
sizeof(FAudio.FAudioFXReverbParameters)
);
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
@ -176,7 +176,7 @@ namespace MoonWorks.Audio
ReverbVoice,
0,
reverbParamsPtr,
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
(uint) sizeof(FAudio.FAudioFXReverbParameters),
0
);
Marshal.FreeHGlobal(reverbParamsPtr);
@ -187,7 +187,7 @@ namespace MoonWorks.Audio
{
SendCount = 2,
pSends = Marshal.AllocHGlobal(
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
2 * sizeof(FAudio.FAudioSendDescriptor)
)
};
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;

View File

@ -511,7 +511,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) ptr,
(uint) (uniforms.Length * Marshal.SizeOf<T>())
(uint) (uniforms.Length * sizeof(T))
);
}
}
@ -530,7 +530,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) ptr,
(uint) (uniforms.Length * Marshal.SizeOf<T>())
(uint) (uniforms.Length * sizeof(T))
);
}
}
@ -549,7 +549,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) ptr,
(uint) (uniforms.Length * Marshal.SizeOf<T>())
(uint) (uniforms.Length * sizeof(T))
);
}
}
@ -745,7 +745,7 @@ namespace MoonWorks.Graphics
uint numElements
) where T : unmanaged
{
var elementSize = Marshal.SizeOf<T>();
var elementSize = sizeof(T);
fixed (T* ptr = &data[0])
{
@ -762,19 +762,19 @@ namespace MoonWorks.Graphics
}
}
public void SetBufferData<T>(
public unsafe void SetBufferData<T>(
Buffer buffer,
IntPtr dataPtr,
uint bufferOffsetInElements,
uint numElements
) {
) where T : unmanaged {
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
buffer.Handle,
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
(uint) sizeof(T) * bufferOffsetInElements,
dataPtr,
(uint) Marshal.SizeOf<T>() * numElements
(uint) sizeof(T) * numElements
);
}
@ -794,7 +794,7 @@ namespace MoonWorks.Graphics
/// <param name="data">An array of data to copy into the texture.</param>
public unsafe void SetTextureData<T>(in TextureSlice textureSlice, T[] data) where T : unmanaged
{
var size = Marshal.SizeOf<T>();
var size = sizeof(T);
fixed (T* ptr = &data[0])
{

View File

@ -25,8 +25,8 @@ namespace MoonWorks.Graphics.Font
{
fixed (FontRange *pFontRanges = &fontRanges[0])
{
var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf<Wellspring.FontRange>());
var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange);
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange));
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);

View File

@ -128,13 +128,13 @@ namespace MoonWorks.Graphics
public VertexInputRate InputRate;
// Shortcut for the common case of having a single vertex binding.
public static VertexBinding Create<T>()
public unsafe static VertexBinding Create<T>() where T : unmanaged
{
return new VertexBinding
{
Binding = 0,
InputRate = VertexInputRate.Vertex,
Stride = (uint) Marshal.SizeOf<T>()
Stride = (uint) sizeof(T)
};
}
}

View File

@ -24,16 +24,16 @@ namespace MoonWorks.Graphics
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
/// <param name="elementCount">How many elements of type T the buffer will contain.</param>
/// <returns></returns>
public static Buffer Create<T>(
public unsafe static Buffer Create<T>(
GraphicsDevice device,
BufferUsageFlags usageFlags,
uint elementCount
)
) where T : unmanaged
{
return new Buffer(
device,
usageFlags,
(uint) Marshal.SizeOf<T>() * elementCount
(uint) sizeof(T) * elementCount
);
}

View File

@ -13,18 +13,18 @@ namespace MoonWorks.Graphics
public uint BufferBindingCount;
public uint ImageBindingCount;
public static ComputeShaderInfo Create<T>(
public unsafe static ComputeShaderInfo Create<T>(
ShaderModule shaderModule,
string entryPointName,
uint bufferBindingCount,
uint imageBindingCount
)
) where T : unmanaged
{
return new ComputeShaderInfo
{
ShaderModule = shaderModule,
EntryPointName = entryPointName,
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
UniformBufferSize = (uint) sizeof(T),
BufferBindingCount = bufferBindingCount,
ImageBindingCount = imageBindingCount
};

View File

@ -12,7 +12,7 @@ namespace MoonWorks.Graphics
public uint UniformBufferSize;
public uint SamplerBindingCount;
public static GraphicsShaderInfo Create<T>(
public unsafe static GraphicsShaderInfo Create<T>(
ShaderModule shaderModule,
string entryPointName,
uint samplerBindingCount
@ -22,7 +22,7 @@ namespace MoonWorks.Graphics
{
ShaderModule = shaderModule,
EntryPointName = entryPointName,
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
UniformBufferSize = (uint) sizeof(T),
SamplerBindingCount = samplerBindingCount
};
}