removing explicit RefreshCS references in API

pull/14/head
cosmonaut 2021-01-20 13:32:48 -08:00
parent 52b60b66f4
commit d22a70c116
25 changed files with 501 additions and 85 deletions

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Audio
{
/// <summary>
/// For streaming long playback. Reads an OGG file.
/// For streaming long playback.
/// Can be extended to support custom decoders.
/// </summary>
public abstract class StreamingSound : SoundInstance
{

View File

@ -19,21 +19,24 @@ namespace MoonWorks.Graphics
public unsafe void BeginRenderPass(
RenderPass renderPass,
Framebuffer framebuffer,
ref Refresh.Rect renderArea,
ref Refresh.DepthStencilValue depthStencilClearValue,
params Refresh.Color[] clearColors
ref Rect renderArea,
ref DepthStencilValue depthStencilClearValue,
params Color[] clearColors
) {
fixed (Refresh.Color* clearColorPtr = &clearColors[0])
var refreshRenderArea = renderArea.ToRefresh();
var refreshDepthStencilClearValue = depthStencilClearValue.ToRefresh();
fixed (Color* clearColorPtr = &clearColors[0])
{
Refresh.Refresh_BeginRenderPass(
Device.Handle,
Handle,
renderPass.Handle,
framebuffer.Handle,
ref renderArea,
ref refreshRenderArea,
(IntPtr) clearColorPtr,
(uint)clearColors.Length,
ref depthStencilClearValue
ref refreshDepthStencilClearValue
);
}
}
@ -41,17 +44,19 @@ namespace MoonWorks.Graphics
public unsafe void BeginRenderPass(
RenderPass renderPass,
Framebuffer framebuffer,
ref Refresh.Rect renderArea,
params Refresh.Color[] clearColors
ref Rect renderArea,
params Color[] clearColors
) {
fixed (Refresh.Color* clearColorPtr = &clearColors[0])
var refreshRenderArea = renderArea.ToRefresh();
fixed (Color* clearColorPtr = &clearColors[0])
{
Refresh.Refresh_BeginRenderPass(
Device.Handle,
Handle,
renderPass.Handle,
framebuffer.Handle,
ref renderArea,
ref refreshRenderArea,
(IntPtr) clearColorPtr,
(uint) clearColors.Length,
IntPtr.Zero
@ -323,23 +328,24 @@ namespace MoonWorks.Graphics
public void QueuePresent(
ref TextureSlice textureSlice,
ref Refresh.Rect destinationRectangle,
Refresh.Filter filter
ref Rect destinationRectangle,
Filter filter
) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
var refreshRect = destinationRectangle.ToRefresh();
Refresh.Refresh_QueuePresent(
Device.Handle,
Handle,
ref refreshTextureSlice,
ref destinationRectangle,
filter
ref refreshRect,
(Refresh.Filter) filter
);
}
public void QueuePresent(
ref TextureSlice textureSlice,
Refresh.Filter filter
Filter filter
) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
@ -348,13 +354,13 @@ namespace MoonWorks.Graphics
Handle,
ref refreshTextureSlice,
IntPtr.Zero,
filter
(Refresh.Filter) filter
);
}
public void QueuePresent(
Texture texture,
Refresh.Filter filter
Filter filter
) {
var refreshTextureSlice = new Refresh.TextureSlice
{
@ -376,14 +382,14 @@ namespace MoonWorks.Graphics
Handle,
ref refreshTextureSlice,
IntPtr.Zero,
filter
(Refresh.Filter) filter
);
}
public void CopyTextureToTexture(
ref TextureSlice sourceTextureSlice,
ref TextureSlice destinationTextureSlice,
Refresh.Filter filter
Filter filter
) {
var sourceRefreshTextureSlice = sourceTextureSlice.ToRefreshTextureSlice();
var destRefreshTextureSlice = destinationTextureSlice.ToRefreshTextureSlice();
@ -393,7 +399,7 @@ namespace MoonWorks.Graphics
Handle,
ref sourceRefreshTextureSlice,
ref destRefreshTextureSlice,
filter
(Refresh.Filter) filter
);
}

View File

@ -0,0 +1,298 @@
using System;
/* Recreate all the enums in here so we don't need to explicitly
* reference the RefreshCS namespace when using MoonWorks.Graphics
*/
namespace MoonWorks.Graphics
{
public enum PresentMode
{
Immediate,
Mailbox,
FIFO,
FIFORelaxed
}
public enum PrimitiveType
{
PointList,
LineList,
LineStrip,
TriangleList,
TriangleStrip
}
public enum LoadOp
{
Load,
Clear,
DontCare
}
public enum StoreOp
{
Store,
DontCare
}
[Flags]
public enum ClearOptionsFlags : uint
{
Color = 1,
Depth = 2,
Stencil = 4,
DepthStencil = Depth | Stencil,
All = Color | Depth | Stencil
}
public enum IndexElementSize
{
Sixteen,
ThirtyTwo
}
public enum ColorFormat
{
R8G8B8A8,
R5G6B5,
A1R5G5B5,
B4G4R4A4,
BC1,
BC2,
BC3,
R8G8_SNORM,
R8G8B8A8_SNORM,
A2R10G10B10,
R16G16,
R16G16B16A16,
R8,
R32_SFLOAT,
R32G32_SFLOAT,
R32G32B32A32_SFLOAT,
R16_SFLOAT,
R16G16_SFLOAT,
R16G16B16A16_SFLOAT
}
public enum DepthFormat
{
Depth16,
Depth32,
Depth16Stencil8,
Depth32Stencil8
}
[Flags]
public enum TextureUsageFlags : uint
{
SamplerBit = 1,
ColorTargetBit = 2
}
public enum SampleCount
{
One,
Two,
Four,
Eight,
Sixteen,
ThirtyTwo,
SixtyFour
}
public enum CubeMapFace
{
PositiveX,
NegativeX,
PositiveY,
NegativeY,
PositiveZ,
NegativeZ
}
[Flags]
public enum BufferUsageFlags : uint
{
Vertex = 1,
Index = 2,
Compute = 4
}
public enum VertexElementFormat
{
Single,
Vector2,
Vector3,
Vector4,
Color,
Byte4,
Short2,
Short4,
NormalizedShort2,
NormalizedShort4,
HalfVector2,
HalfVector4
}
public enum VertexInputRate
{
Vertex,
Instance
}
public enum FillMode
{
Fill,
Line,
Point
}
public enum CullMode
{
None,
Front,
Back,
FrontAndBack
}
public enum FrontFace
{
CounterClockwise,
Clockwise
}
public enum CompareOp
{
Never,
Less,
Equal,
LessOrEqual,
Greater,
NotEqual,
GreaterOrEqual,
Always
}
public enum StencilOp
{
Keep,
Zero,
Replace,
IncrementAndClamp,
DecrementAndClamp,
Invert,
IncrementAndWrap,
DecrementAndWrap
}
public enum BlendOp
{
Add,
Subtract,
ReverseSubtract,
Min,
Max
}
public enum LogicOp
{
Clear,
And,
AndReverse,
Copy,
AndInverted,
NoOp,
Xor,
Or,
Nor,
Equivalent,
Invert,
OrReverse,
CopyInverted,
OrInverted,
Nand,
Set
}
public enum BlendFactor
{
Zero,
One,
SourceColor,
OneMinusSourceColor,
DestinationColor,
OneMinusDestinationColor,
SourceAlpha,
OneMinusSourceAlpha,
DestinationAlpha,
OneMinusDestinationAlpha,
ConstantColor,
OneMinusConstantColor,
ConstantAlpha,
OneMinusConstantAlpha,
SourceAlphaSaturate,
SourceOneColor,
OneMinusSourceOneColor,
SourceOneAlpha,
OneMinusSourceOneAlpha
}
[Flags]
public enum ColorComponentFlags : uint
{
R = 1,
G = 2,
B = 4,
A = 8,
RG = R | G,
RB = R | B,
RA = R | A,
GB = G | B,
GA = G | A,
BA = B | A,
RGB = R | G | B,
RGA = R | G | A,
GBA = G | B | A,
RGBA = R | G | B | A
}
public enum ShaderStageType
{
Vertex,
Fragment
}
public enum Filter
{
Nearest,
Linear,
Cubic
}
public enum SamplerMipmapMode
{
Nearest,
Linear
}
public enum SamplerAddressMode
{
Repeat,
MirroredRepeat,
ClampToEdge,
ClampToBorder
}
public enum BorderColor
{
FloatTransparentBlack,
IntTransparentBlack,
FloatOpaqueBlack,
IntOpaqueBlack,
FloatOpaqueWhite,
IntOpaqueWhite
}
}

View File

@ -0,0 +1,111 @@
using RefreshCS;
using System.Runtime.InteropServices;
/* Recreate some structs in here so we don't need to explicitly
* reference the RefreshCS namespace when using MoonWorks.Graphics
*/
namespace MoonWorks.Graphics
{
[StructLayout(LayoutKind.Sequential)]
public struct Color
{
public byte r;
public byte g;
public byte b;
public byte a;
}
[StructLayout(LayoutKind.Sequential)]
public struct DepthStencilValue
{
public float depth;
public uint stencil;
// FIXME: can we do an unsafe cast somehow?
public Refresh.DepthStencilValue ToRefresh()
{
return new Refresh.DepthStencilValue
{
depth = depth,
stencil = stencil
};
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int x;
public int y;
public int w;
public int h;
// FIXME: can we do an unsafe cast somehow?
public Refresh.Rect ToRefresh()
{
return new Refresh.Rect
{
x = x,
y = y,
w = w,
h = h
};
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Vec4
{
public float x;
public float y;
public float z;
public float w;
}
[StructLayout(LayoutKind.Sequential)]
public struct Viewport
{
public float x;
public float y;
public float w;
public float h;
public float minDepth;
public float maxDepth;
}
[StructLayout(LayoutKind.Sequential)]
public struct VertexBinding
{
public uint binding;
public uint stride;
public VertexInputRate inputRate;
}
[StructLayout(LayoutKind.Sequential)]
public struct VertexAttribute
{
public uint location;
public uint binding;
public VertexElementFormat format;
public uint offset;
}
[StructLayout(LayoutKind.Sequential)]
public struct ColorTargetDescription
{
public ColorFormat format;
public SampleCount multisampleCount;
public LoadOp loadOp;
public StoreOp storeOp;
}
[StructLayout(LayoutKind.Sequential)]
public struct DepthStencilTargetDescription
{
public DepthFormat depthFormat;
public LoadOp loadOp;
public StoreOp storeOp;
public LoadOp stencilLoadOp;
public StoreOp stencilStoreOp;
}
}

View File

@ -9,13 +9,13 @@ namespace MoonWorks.Graphics
public Buffer(
GraphicsDevice device,
Refresh.BufferUsageFlags usageFlags,
BufferUsageFlags usageFlags,
uint sizeInBytes
) : base(device)
{
Handle = Refresh.Refresh_CreateBuffer(
device.Handle,
usageFlags,
(Refresh.BufferUsageFlags) usageFlags,
sizeInBytes
);
}

View File

@ -9,7 +9,7 @@ namespace MoonWorks.Graphics
public uint Height { get; }
public Texture Texture { get; }
public Refresh.ColorFormat Format => Texture.Format;
public ColorFormat Format => Texture.Format;
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyColorTarget;
@ -17,14 +17,14 @@ namespace MoonWorks.Graphics
GraphicsDevice device,
uint width,
uint height,
Refresh.ColorFormat format,
ColorFormat format,
bool canBeSampled,
Refresh.SampleCount sampleCount = Refresh.SampleCount.One,
SampleCount sampleCount = SampleCount.One,
uint levelCount = 1
)
{
var flags = Refresh.TextureUsageFlags.ColorTargetBit;
if (canBeSampled) { flags |= Refresh.TextureUsageFlags.SamplerBit; }
var flags = TextureUsageFlags.ColorTargetBit;
if (canBeSampled) { flags |= TextureUsageFlags.SamplerBit; }
var texture = Texture.CreateTexture2D(
device,
@ -41,10 +41,14 @@ namespace MoonWorks.Graphics
return new ColorTarget(device, sampleCount, ref textureSlice);
}
public ColorTarget(GraphicsDevice device, Refresh.SampleCount sampleCount, ref TextureSlice textureSlice) : base(device)
public ColorTarget(GraphicsDevice device, SampleCount sampleCount, ref TextureSlice textureSlice) : base(device)
{
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
Handle = Refresh.Refresh_CreateColorTarget(device.Handle, sampleCount, ref refreshTextureSlice);
Handle = Refresh.Refresh_CreateColorTarget(
device.Handle,
(Refresh.SampleCount) sampleCount,
ref refreshTextureSlice
);
}
}
}

View File

@ -7,7 +7,7 @@ namespace MoonWorks.Graphics
{
public uint Width { get; }
public uint Height { get; }
public Refresh.DepthFormat Format { get; }
public DepthFormat Format { get; }
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyDepthStencilTarget;
@ -15,12 +15,18 @@ namespace MoonWorks.Graphics
GraphicsDevice device,
uint width,
uint height,
Refresh.DepthFormat depthFormat
DepthFormat depthFormat
) : base(device)
{
Handle = Refresh.Refresh_CreateDepthStencilTarget(device.Handle, width, height, depthFormat);
Handle = Refresh.Refresh_CreateDepthStencilTarget(
device.Handle,
width,
height,
(Refresh.DepthFormat) depthFormat
);
Width = width;
Height = height;
Format = depthFormat;
}
}
}

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Graphics
MultisampleState multisampleState,
GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo,
RasterizerState rasterizerState,
Refresh.PrimitiveType primitiveType,
PrimitiveType primitiveType,
VertexInputState vertexInputState,
ViewportState viewportState,
RenderPass renderPass
@ -38,7 +38,7 @@ namespace MoonWorks.Graphics
Refresh.GraphicsPipelineCreateInfo graphicsPipelineCreateInfo;
graphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable);
graphicsPipelineCreateInfo.colorBlendState.logicOp = colorBlendState.LogicOp;
graphicsPipelineCreateInfo.colorBlendState.logicOp = (Refresh.LogicOp) colorBlendState.LogicOp;
graphicsPipelineCreateInfo.colorBlendState.blendStates = (IntPtr) colorTargetBlendStates;
graphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R;
@ -90,7 +90,7 @@ namespace MoonWorks.Graphics
graphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length;
graphicsPipelineCreateInfo.primitiveType = primitiveType;
graphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
graphicsPipelineCreateInfo.renderPass = renderPass.Handle;
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, ref graphicsPipelineCreateInfo);

View File

@ -9,10 +9,10 @@ namespace MoonWorks.Graphics
public unsafe RenderPass(
GraphicsDevice device,
params Refresh.ColorTargetDescription[] colorTargetDescriptions
params ColorTargetDescription[] colorTargetDescriptions
) : base(device)
{
fixed (Refresh.ColorTargetDescription* ptr = colorTargetDescriptions)
fixed (ColorTargetDescription* ptr = colorTargetDescriptions)
{
Refresh.RenderPassCreateInfo renderPassCreateInfo;
renderPassCreateInfo.colorTargetCount = (uint) colorTargetDescriptions.Length;
@ -25,13 +25,13 @@ namespace MoonWorks.Graphics
public unsafe RenderPass(
GraphicsDevice device,
Refresh.DepthStencilTargetDescription depthStencilTargetDescription,
params Refresh.ColorTargetDescription[] colorTargetDescriptions
DepthStencilTargetDescription depthStencilTargetDescription,
params ColorTargetDescription[] colorTargetDescriptions
) : base(device)
{
Refresh.DepthStencilTargetDescription* depthStencilPtr = &depthStencilTargetDescription;
DepthStencilTargetDescription* depthStencilPtr = &depthStencilTargetDescription;
fixed (Refresh.ColorTargetDescription* colorPtr = colorTargetDescriptions)
fixed (ColorTargetDescription* colorPtr = colorTargetDescriptions)
{
Refresh.RenderPassCreateInfo renderPassCreateInfo;
renderPassCreateInfo.colorTargetCount = (uint)colorTargetDescriptions.Length;

View File

@ -10,7 +10,7 @@ namespace MoonWorks.Graphics
public unsafe ShaderModule(GraphicsDevice device, FileInfo fileInfo) : base(device)
{
fixed (uint* ptr = Bytecode.ReadBytecode(fileInfo))
fixed (uint* ptr = Bytecode.ReadBytecodeAsUInt32(fileInfo))
{
Refresh.ShaderModuleCreateInfo shaderModuleCreateInfo;
shaderModuleCreateInfo.codeSize = (UIntPtr) fileInfo.Length;

View File

@ -8,7 +8,7 @@ namespace MoonWorks.Graphics
{
public uint Width { get; }
public uint Height { get; }
public Refresh.ColorFormat Format { get; }
public ColorFormat Format { get; }
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
@ -21,15 +21,15 @@ namespace MoonWorks.Graphics
out var channels
);
MoonWorks.Graphics.TextureCreateInfo textureCreateInfo;
TextureCreateInfo textureCreateInfo;
textureCreateInfo.Width = (uint)width;
textureCreateInfo.Height = (uint)height;
textureCreateInfo.Depth = 1;
textureCreateInfo.Format = Refresh.ColorFormat.R8G8B8A8;
textureCreateInfo.Format = ColorFormat.R8G8B8A8;
textureCreateInfo.IsCube = false;
textureCreateInfo.LevelCount = 1;
textureCreateInfo.SampleCount = Refresh.SampleCount.One;
textureCreateInfo.UsageFlags = Refresh.TextureUsageFlags.SamplerBit;
textureCreateInfo.SampleCount = SampleCount.One;
textureCreateInfo.UsageFlags = TextureUsageFlags.SamplerBit;
var texture = new Texture(device, ref textureCreateInfo);
@ -51,13 +51,13 @@ namespace MoonWorks.Graphics
GraphicsDevice device,
uint width,
uint height,
Refresh.ColorFormat format,
Refresh.TextureUsageFlags usageFlags,
Refresh.SampleCount sampleCount = Refresh.SampleCount.One,
ColorFormat format,
TextureUsageFlags usageFlags,
SampleCount sampleCount = SampleCount.One,
uint levelCount = 1
)
{
var textureCreateInfo = new MoonWorks.Graphics.TextureCreateInfo
var textureCreateInfo = new TextureCreateInfo
{
Width = width,
Height = height,
@ -77,13 +77,13 @@ namespace MoonWorks.Graphics
uint width,
uint height,
uint depth,
Refresh.ColorFormat format,
Refresh.TextureUsageFlags usageFlags,
Refresh.SampleCount sampleCount = Refresh.SampleCount.One,
ColorFormat format,
TextureUsageFlags usageFlags,
SampleCount sampleCount = SampleCount.One,
uint levelCount = 1
)
{
var textureCreateInfo = new MoonWorks.Graphics.TextureCreateInfo
var textureCreateInfo = new TextureCreateInfo
{
Width = width,
Height = height,
@ -101,13 +101,13 @@ namespace MoonWorks.Graphics
public static Texture CreateTextureCube(
GraphicsDevice device,
uint size,
Refresh.ColorFormat format,
Refresh.TextureUsageFlags usageFlags,
Refresh.SampleCount sampleCount = Refresh.SampleCount.One,
ColorFormat format,
TextureUsageFlags usageFlags,
SampleCount sampleCount = SampleCount.One,
uint levelCount = 1
)
{
var textureCreateInfo = new MoonWorks.Graphics.TextureCreateInfo
var textureCreateInfo = new TextureCreateInfo
{
Width = size,
Height = size,
@ -122,7 +122,7 @@ namespace MoonWorks.Graphics
return new Texture(device, ref textureCreateInfo);
}
public Texture(GraphicsDevice device, ref MoonWorks.Graphics.TextureCreateInfo textureCreateInfo) : base(device)
public Texture(GraphicsDevice device, ref TextureCreateInfo textureCreateInfo) : base(device)
{
var refreshTextureCreateInfo = textureCreateInfo.ToRefreshTextureCreateInfo();

View File

@ -5,7 +5,7 @@ namespace MoonWorks.Graphics
public unsafe struct ColorBlendState
{
public bool LogicOpEnable;
public Refresh.LogicOp LogicOp;
public LogicOp LogicOp;
public BlendConstants BlendConstants;
public ColorTargetBlendState[] ColorTargetBlendStates;
}

View File

@ -8,10 +8,10 @@ namespace MoonWorks.Graphics
public uint Height;
public uint Depth;
public bool IsCube;
public Refresh.SampleCount SampleCount;
public SampleCount SampleCount;
public uint LevelCount;
public Refresh.ColorFormat Format;
public Refresh.TextureUsageFlags UsageFlags;
public ColorFormat Format;
public TextureUsageFlags UsageFlags;
public Refresh.TextureCreateInfo ToRefreshTextureCreateInfo()
{
@ -21,10 +21,10 @@ namespace MoonWorks.Graphics
height = Height,
depth = Depth,
isCube = Conversions.BoolToByte(IsCube),
sampleCount = SampleCount,
sampleCount = (Refresh.SampleCount) SampleCount,
levelCount = LevelCount,
format = Format,
usageFlags = UsageFlags
format = (Refresh.ColorFormat) Format,
usageFlags = (Refresh.TextureUsageFlags) UsageFlags
};
}
}

View File

@ -4,7 +4,7 @@ namespace MoonWorks.Graphics
{
public struct VertexInputState
{
public Refresh.VertexBinding[] VertexBindings;
public Refresh.VertexAttribute[] VertexAttributes;
public VertexBinding[] VertexBindings;
public VertexAttribute[] VertexAttributes;
}
}

View File

@ -4,7 +4,7 @@ namespace MoonWorks.Graphics
{
public struct ViewportState
{
public Refresh.Viewport[] Viewports;
public Refresh.Rect[] Scissors;
public Viewport[] Viewports;
public Rect[] Scissors;
}
}

View File

@ -34,9 +34,9 @@ namespace MoonWorks.Graphics
Level = level;
}
public RefreshCS.Refresh.TextureSlice ToRefreshTextureSlice()
public Refresh.TextureSlice ToRefreshTextureSlice()
{
RefreshCS.Refresh.TextureSlice textureSlice = new RefreshCS.Refresh.TextureSlice
Refresh.TextureSlice textureSlice = new Refresh.TextureSlice
{
texture = Texture.Handle,
rectangle = Rectangle,

View File

@ -4,7 +4,7 @@ namespace MoonWorks.Graphics
{
public static class Bytecode
{
public static uint[] ReadBytecode(FileInfo fileInfo)
public static uint[] ReadBytecodeAsUInt32(FileInfo fileInfo)
{
byte[] data;
int size;

View File

@ -1,10 +0,0 @@
namespace MoonWorks
{
public enum PresentMode
{
Immediate,
Mailbox,
FIFO,
FIFORelaxed
}
}