MoonWorks/src/Graphics/Utility/Conversions.cs

46 lines
938 B
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)
{
if (type == typeof(float))
{
return Graphics.VertexElementFormat.Single;
}
else if (type == typeof(Math.Vector2))
{
return Graphics.VertexElementFormat.Vector2;
}
else if (type == typeof(Math.Vector3))
{
return Graphics.VertexElementFormat.Vector3;
}
else if (type == typeof(Math.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
}
}