using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using Nerfed.Runtime.Graphics;
using Nerfed.Runtime.Graphics.PackedVector;
namespace Nerfed.Runtime;
///
/// Conversion utilities for interop.
///
public static class Conversions
{
private readonly static Dictionary Sizes = new Dictionary
{
{ VertexElementFormat.Byte4, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Color, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Float, (uint) Marshal.SizeOf() },
{ VertexElementFormat.HalfVector2, (uint) Marshal.SizeOf() },
{ VertexElementFormat.HalfVector4, (uint) Marshal.SizeOf() },
{ VertexElementFormat.NormalizedShort2, (uint) Marshal.SizeOf() },
{ VertexElementFormat.NormalizedShort4, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Short2, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Short4, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Uint, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Vector2, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Vector3, (uint) Marshal.SizeOf() },
{ VertexElementFormat.Vector4, (uint) Marshal.SizeOf() }
};
public static byte BoolToByte(bool b)
{
return (byte) (b ? 1 : 0);
}
public static bool ByteToBool(byte b)
{
return b != 0;
}
public static int BoolToInt(bool b)
{
return b ? 1 : 0;
}
public static bool IntToBool(int b)
{
return b != 0;
}
public static uint VertexElementFormatSize(VertexElementFormat format)
{
return Sizes[format];
}
}