2023-01-05 21:41:48 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using MoonWorks.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace MoonWorks
|
2021-01-20 03:33:27 +00:00
|
|
|
|
{
|
2022-02-23 05:14:32 +00:00
|
|
|
|
public static class Conversions
|
|
|
|
|
{
|
2023-01-05 21:41:48 +00:00
|
|
|
|
private readonly static Dictionary<VertexElementFormat, uint> Sizes = new Dictionary<VertexElementFormat, uint>
|
|
|
|
|
{
|
|
|
|
|
{ VertexElementFormat.Byte4, (uint) Marshal.SizeOf<Byte4>() },
|
|
|
|
|
{ VertexElementFormat.Color, (uint) Marshal.SizeOf<Color>() },
|
|
|
|
|
{ VertexElementFormat.Float, (uint) Marshal.SizeOf<float>() },
|
|
|
|
|
{ VertexElementFormat.HalfVector2, (uint) Marshal.SizeOf<HalfVector2>() },
|
|
|
|
|
{ VertexElementFormat.HalfVector4, (uint) Marshal.SizeOf<HalfVector4>() },
|
|
|
|
|
{ VertexElementFormat.NormalizedShort2, (uint) Marshal.SizeOf<NormalizedShort2>() },
|
|
|
|
|
{ VertexElementFormat.NormalizedShort4, (uint) Marshal.SizeOf<NormalizedShort4>() },
|
|
|
|
|
{ VertexElementFormat.Short2, (uint) Marshal.SizeOf<Short2>() },
|
|
|
|
|
{ VertexElementFormat.Short4, (uint) Marshal.SizeOf<Short4>() },
|
|
|
|
|
{ VertexElementFormat.UInt, (uint) Marshal.SizeOf<uint>() },
|
|
|
|
|
{ VertexElementFormat.Vector2, (uint) Marshal.SizeOf<Math.Float.Vector2>() },
|
|
|
|
|
{ VertexElementFormat.Vector3, (uint) Marshal.SizeOf<Math.Float.Vector3>() },
|
|
|
|
|
{ VertexElementFormat.Vector4, (uint) Marshal.SizeOf<Math.Float.Vector4>() }
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-23 05:14:32 +00:00
|
|
|
|
public static byte BoolToByte(bool b)
|
|
|
|
|
{
|
|
|
|
|
return (byte) (b ? 1 : 0);
|
|
|
|
|
}
|
2021-01-22 22:41:34 +00:00
|
|
|
|
|
2022-02-23 05:14:32 +00:00
|
|
|
|
public static bool ByteToBool(byte b)
|
|
|
|
|
{
|
2022-02-25 05:34:36 +00:00
|
|
|
|
return b != 0;
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
2023-01-05 21:41:48 +00:00
|
|
|
|
|
|
|
|
|
public static uint VertexElementFormatSize(VertexElementFormat format)
|
|
|
|
|
{
|
|
|
|
|
return Sizes[format];
|
|
|
|
|
}
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
2021-01-20 03:33:27 +00:00
|
|
|
|
}
|