MoonWorks/src/Graphics/Utility/Conversions.cs

50 lines
1.0 KiB
C#
Raw Normal View History

2022-02-23 05:14:32 +00:00
namespace MoonWorks
{
2022-02-23 05:14:32 +00:00
public static class Conversions
{
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)
{
return b != 0;
2022-02-23 05:14:32 +00:00
}
public static Graphics.VertexElementFormat TypeToVertexElementFormat(System.Type type)
{
2022-03-17 21:42:30 +00:00
if (type == typeof(uint))
{
return Graphics.VertexElementFormat.UInt;
}
if (type == typeof(float))
{
2022-03-17 21:42:30 +00:00
return Graphics.VertexElementFormat.Float;
}
else if (type == typeof(Math.Float.Vector2))
{
return Graphics.VertexElementFormat.Vector2;
}
else if (type == typeof(Math.Float.Vector3))
{
return Graphics.VertexElementFormat.Vector3;
}
else if (type == typeof(Math.Float.Vector4))
{
return Graphics.VertexElementFormat.Vector4;
}
else if (type == typeof(Graphics.Color))
{
return Graphics.VertexElementFormat.Color;
}
else
{
throw new System.ArgumentException(
"Cannot automatically convert this type to a VertexElementFormat!"
);
}
}
2022-02-23 05:14:32 +00:00
}
}