forked from MoonsideGames/MoonWorks
Compare commits
No commits in common. "807deb2c339312f70d79d47d79e78da995574acc" and "230c1b41b451a74d32be7a82ed443e6e40f2a890" have entirely different histories.
807deb2c33
...
230c1b41b4
|
@ -1,10 +1,9 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>11</LangVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 11ba6b37509a6c2fa2690f2643ee7bf5ce2ab4f2
|
Subproject commit 6567310793f90e24438ae8682492c660207275af
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1643061386177f62b516ccaad0ea04607cae2333
|
Subproject commit 9068263afcf5743ac8f2c023eb68610523feb905
|
|
@ -1 +1 @@
|
||||||
Subproject commit f8c6fc407fbb22072fdafcda918aec52b2102519
|
Subproject commit eb2178f6d042038463fb18bd756576cd5152003e
|
|
@ -1,7 +0,0 @@
|
||||||
namespace MoonWorks.Graphics
|
|
||||||
{
|
|
||||||
public interface IVertexType
|
|
||||||
{
|
|
||||||
static abstract VertexElementFormat[] Formats { get; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -127,11 +127,12 @@ namespace MoonWorks.Graphics
|
||||||
public uint Stride;
|
public uint Stride;
|
||||||
public VertexInputRate InputRate;
|
public VertexInputRate InputRate;
|
||||||
|
|
||||||
public static VertexBinding Create<T>(uint binding = 0) where T : unmanaged
|
// Shortcut for the common case of having a single vertex binding.
|
||||||
|
public unsafe static VertexBinding Create<T>() where T : unmanaged
|
||||||
{
|
{
|
||||||
return new VertexBinding
|
return new VertexBinding
|
||||||
{
|
{
|
||||||
Binding = binding,
|
Binding = 0,
|
||||||
InputRate = VertexInputRate.Vertex,
|
InputRate = VertexInputRate.Vertex,
|
||||||
Stride = (uint) Marshal.SizeOf<T>()
|
Stride = (uint) Marshal.SizeOf<T>()
|
||||||
};
|
};
|
||||||
|
@ -145,6 +146,28 @@ namespace MoonWorks.Graphics
|
||||||
public uint Binding;
|
public uint Binding;
|
||||||
public VertexElementFormat Format;
|
public VertexElementFormat Format;
|
||||||
public uint Offset;
|
public uint Offset;
|
||||||
|
|
||||||
|
public static VertexAttribute Create<T>(
|
||||||
|
string fieldName,
|
||||||
|
uint location,
|
||||||
|
uint binding = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var fieldInfo = typeof(T).GetField(fieldName);
|
||||||
|
|
||||||
|
if (fieldInfo == null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentException("Field not recognized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new VertexAttribute
|
||||||
|
{
|
||||||
|
Binding = binding,
|
||||||
|
Location = location,
|
||||||
|
Format = Conversions.TypeToVertexElementFormat(fieldInfo.FieldType),
|
||||||
|
Offset = (uint) Marshal.OffsetOf<T>(fieldName)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|
|
@ -272,12 +272,14 @@ namespace MoonWorks.Graphics
|
||||||
const uint DDS_MAGIC = 0x20534444;
|
const uint DDS_MAGIC = 0x20534444;
|
||||||
const uint DDS_HEADERSIZE = 124;
|
const uint DDS_HEADERSIZE = 124;
|
||||||
const uint DDS_PIXFMTSIZE = 32;
|
const uint DDS_PIXFMTSIZE = 32;
|
||||||
|
const uint DDSD_CAPS = 0x1;
|
||||||
const uint DDSD_HEIGHT = 0x2;
|
const uint DDSD_HEIGHT = 0x2;
|
||||||
const uint DDSD_WIDTH = 0x4;
|
const uint DDSD_WIDTH = 0x4;
|
||||||
const uint DDSD_PITCH = 0x8;
|
const uint DDSD_PITCH = 0x8;
|
||||||
|
const uint DDSD_FMT = 0x1000;
|
||||||
const uint DDSD_LINEARSIZE = 0x80000;
|
const uint DDSD_LINEARSIZE = 0x80000;
|
||||||
const uint DDSD_REQ = (
|
const uint DDSD_REQ = (
|
||||||
DDSD_HEIGHT | DDSD_WIDTH
|
DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_FMT
|
||||||
);
|
);
|
||||||
const uint DDSCAPS_MIPMAP = 0x400000;
|
const uint DDSCAPS_MIPMAP = 0x400000;
|
||||||
const uint DDSCAPS_TEXTURE = 0x1000;
|
const uint DDSCAPS_TEXTURE = 0x1000;
|
||||||
|
|
|
@ -10,61 +10,16 @@
|
||||||
|
|
||||||
public static readonly VertexInputState Empty = new VertexInputState
|
public static readonly VertexInputState Empty = new VertexInputState
|
||||||
{
|
{
|
||||||
VertexBindings = System.Array.Empty<VertexBinding>(),
|
VertexBindings = new VertexBinding[0],
|
||||||
VertexAttributes = System.Array.Empty<VertexAttribute>()
|
VertexAttributes = new VertexAttribute[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
public VertexInputState(
|
public VertexInputState(
|
||||||
VertexBinding vertexBinding,
|
VertexBinding vertexBinding,
|
||||||
VertexAttribute[] vertexAttributes
|
params VertexAttribute[] vertexAttributes
|
||||||
) {
|
) {
|
||||||
VertexBindings = new VertexBinding[] { vertexBinding };
|
VertexBindings = new VertexBinding[] { vertexBinding };
|
||||||
VertexAttributes = vertexAttributes;
|
VertexAttributes = vertexAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VertexInputState(
|
|
||||||
VertexBinding[] vertexBindings,
|
|
||||||
VertexAttribute[] vertexAttributes
|
|
||||||
) {
|
|
||||||
VertexBindings = vertexBindings;
|
|
||||||
VertexAttributes = vertexAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexInputState(
|
|
||||||
VertexBindingAndAttributes bindingAndAttributes
|
|
||||||
) {
|
|
||||||
VertexBindings = new VertexBinding[] { bindingAndAttributes.VertexBinding };
|
|
||||||
VertexAttributes = bindingAndAttributes.VertexAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexInputState(
|
|
||||||
VertexBindingAndAttributes[] bindingAndAttributesArray
|
|
||||||
) {
|
|
||||||
VertexBindings = new VertexBinding[bindingAndAttributesArray.Length];
|
|
||||||
var attributesLength = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < bindingAndAttributesArray.Length; i += 1)
|
|
||||||
{
|
|
||||||
VertexBindings[i] = bindingAndAttributesArray[i].VertexBinding;
|
|
||||||
attributesLength += bindingAndAttributesArray[i].VertexAttributes.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
VertexAttributes = new VertexAttribute[attributesLength];
|
|
||||||
|
|
||||||
var attributeIndex = 0;
|
|
||||||
for (var i = 0; i < bindingAndAttributesArray.Length; i += 1)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < bindingAndAttributesArray[i].VertexAttributes.Length; j += 1)
|
|
||||||
{
|
|
||||||
VertexAttributes[attributeIndex] = bindingAndAttributesArray[i].VertexAttributes[j];
|
|
||||||
attributeIndex += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VertexInputState CreateSingleBinding<T>() where T : unmanaged, IVertexType
|
|
||||||
{
|
|
||||||
return new VertexInputState(VertexBindingAndAttributes.Create<T>(0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,7 @@
|
||||||
using System.Collections.Generic;
|
namespace MoonWorks
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using MoonWorks.Graphics;
|
|
||||||
|
|
||||||
namespace MoonWorks
|
|
||||||
{
|
{
|
||||||
public static class Conversions
|
public static class Conversions
|
||||||
{
|
{
|
||||||
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>() }
|
|
||||||
};
|
|
||||||
|
|
||||||
public static byte BoolToByte(bool b)
|
public static byte BoolToByte(bool b)
|
||||||
{
|
{
|
||||||
return (byte) (b ? 1 : 0);
|
return (byte) (b ? 1 : 0);
|
||||||
|
@ -33,9 +12,38 @@ namespace MoonWorks
|
||||||
return b != 0;
|
return b != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint VertexElementFormatSize(VertexElementFormat format)
|
public static Graphics.VertexElementFormat TypeToVertexElementFormat(System.Type type)
|
||||||
{
|
{
|
||||||
return Sizes[format];
|
if (type == typeof(uint))
|
||||||
|
{
|
||||||
|
return Graphics.VertexElementFormat.UInt;
|
||||||
|
}
|
||||||
|
if (type == typeof(float))
|
||||||
|
{
|
||||||
|
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!"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
namespace MoonWorks.Graphics
|
|
||||||
{
|
|
||||||
// This is a convenience structure for pairing a vertex binding with its associated attributes.
|
|
||||||
public struct VertexBindingAndAttributes
|
|
||||||
{
|
|
||||||
public VertexBinding VertexBinding { get; }
|
|
||||||
public VertexAttribute[] VertexAttributes { get; }
|
|
||||||
|
|
||||||
public VertexBindingAndAttributes(VertexBinding binding, VertexAttribute[] attributes)
|
|
||||||
{
|
|
||||||
VertexBinding = binding;
|
|
||||||
VertexAttributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VertexBindingAndAttributes Create<T>(uint bindingIndex) where T : unmanaged, IVertexType
|
|
||||||
{
|
|
||||||
VertexBinding binding = VertexBinding.Create<T>(bindingIndex);
|
|
||||||
VertexAttribute[] attributes = new VertexAttribute[T.Formats.Length];
|
|
||||||
uint offset = 0;
|
|
||||||
|
|
||||||
for (uint i = 0; i < T.Formats.Length; i += 1)
|
|
||||||
{
|
|
||||||
var format = T.Formats[i];
|
|
||||||
|
|
||||||
attributes[i] = new VertexAttribute
|
|
||||||
{
|
|
||||||
Binding = bindingIndex,
|
|
||||||
Location = i,
|
|
||||||
Format = format,
|
|
||||||
Offset = offset
|
|
||||||
};
|
|
||||||
|
|
||||||
offset += Conversions.VertexElementFormatSize(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new VertexBindingAndAttributes(binding, attributes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue