Skip to content

Commit

Permalink
🔒 Enforce index buffer type
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcscharf committed Aug 5, 2024
1 parent 8c9f9cb commit 7ee3e59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
17 changes: 6 additions & 11 deletions Bearded.Graphics/Core/Rendering/BufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ public static IVertexBuffer AsVertexBuffer<TVertex>(this BufferStream<TVertex> b
return VertexBuffer.From(buffer);
}

public static IIndexBuffer AsIndexBuffer<TIndex>(this Buffer<TIndex> buffer)
where TIndex : struct
{
return IndexBuffer.From(buffer);
}

public static IIndexBuffer AsIndexBuffer<TIndex>(this BufferStream<TIndex> buffer)
where TIndex : struct
{
return IndexBuffer.From(buffer);
}
public static IIndexBuffer AsIndexBuffer(this Buffer<byte> buffer) => IndexBuffer.From(buffer);
public static IIndexBuffer AsIndexBuffer(this Buffer<ushort> buffer) => IndexBuffer.From(buffer);
public static IIndexBuffer AsIndexBuffer(this Buffer<uint> buffer) => IndexBuffer.From(buffer);
public static IIndexBuffer AsIndexBuffer(this BufferStream<byte> buffer) => IndexBuffer.From(buffer);
public static IIndexBuffer AsIndexBuffer(this BufferStream<ushort> buffer) => IndexBuffer.From(buffer);
public static IIndexBuffer AsIndexBuffer(this BufferStream<uint> buffer) => IndexBuffer.From(buffer);
}
16 changes: 6 additions & 10 deletions Bearded.Graphics/Core/Rendering/IndexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ public interface IIndexBuffer

public static class IndexBuffer
{
public static IIndexBuffer From<TIndex>(Buffer<TIndex> buffer)
where TIndex : struct
{
return new Static<TIndex>(buffer);
}
public static IIndexBuffer From(Buffer<byte> buffer) => new Static<byte>(buffer);
public static IIndexBuffer From(Buffer<ushort> buffer) => new Static<ushort>(buffer);
public static IIndexBuffer From(Buffer<uint> buffer) => new Static<uint>(buffer);

public static IIndexBuffer From<TIndex>(BufferStream<TIndex> stream)
where TIndex : struct
{
return new Streaming<TIndex>(stream);
}
public static IIndexBuffer From(BufferStream<byte> stream) => new Streaming<byte>(stream);
public static IIndexBuffer From(BufferStream<ushort> stream) => new Streaming<ushort>(stream);
public static IIndexBuffer From(BufferStream<uint> stream) => new Streaming<uint>(stream);

private sealed class Static<TIndex>(Buffer<TIndex> buffer) : IIndexBuffer
where TIndex : struct
Expand Down

0 comments on commit 7ee3e59

Please sign in to comment.