change refs + a SetData convenience method

pull/14/head
cosmonaut 2021-01-21 17:27:25 -08:00
parent a6ea645e91
commit db44c3e37a
15 changed files with 124 additions and 51 deletions

@ -1 +1 @@
Subproject commit ba183e8c0f9d21e4397d76941078b4969d4f6686 Subproject commit 718aaad80ebf075192e05bf7af97241d7cf7e726

View File

@ -19,8 +19,8 @@ namespace MoonWorks.Graphics
public unsafe void BeginRenderPass( public unsafe void BeginRenderPass(
RenderPass renderPass, RenderPass renderPass,
Framebuffer framebuffer, Framebuffer framebuffer,
ref Rect renderArea, in Rect renderArea,
ref DepthStencilValue depthStencilClearValue, in DepthStencilValue depthStencilClearValue,
params Color[] clearColors params Color[] clearColors
) { ) {
var refreshRenderArea = renderArea.ToRefresh(); var refreshRenderArea = renderArea.ToRefresh();
@ -33,10 +33,10 @@ namespace MoonWorks.Graphics
Handle, Handle,
renderPass.Handle, renderPass.Handle,
framebuffer.Handle, framebuffer.Handle,
ref refreshRenderArea, refreshRenderArea,
(IntPtr) clearColorPtr, (IntPtr) clearColorPtr,
(uint)clearColors.Length, (uint)clearColors.Length,
ref refreshDepthStencilClearValue refreshDepthStencilClearValue
); );
} }
} }
@ -44,7 +44,7 @@ namespace MoonWorks.Graphics
public unsafe void BeginRenderPass( public unsafe void BeginRenderPass(
RenderPass renderPass, RenderPass renderPass,
Framebuffer framebuffer, Framebuffer framebuffer,
ref Rect renderArea, in Rect renderArea,
params Color[] clearColors params Color[] clearColors
) { ) {
var refreshRenderArea = renderArea.ToRefresh(); var refreshRenderArea = renderArea.ToRefresh();
@ -56,7 +56,7 @@ namespace MoonWorks.Graphics
Handle, Handle,
renderPass.Handle, renderPass.Handle,
framebuffer.Handle, framebuffer.Handle,
ref refreshRenderArea, refreshRenderArea,
(IntPtr) clearColorPtr, (IntPtr) clearColorPtr,
(uint) clearColors.Length, (uint) clearColors.Length,
IntPtr.Zero IntPtr.Zero
@ -246,18 +246,18 @@ namespace MoonWorks.Graphics
} }
public void Clear( public void Clear(
ref Refresh.Rect clearRect, in Refresh.Rect clearRect,
Refresh.ClearOptionsFlags clearOptions, Refresh.ClearOptionsFlags clearOptions,
ref Refresh.Color[] colors, in Refresh.Color[] colors,
float depth, float depth,
int stencil int stencil
) { ) {
Refresh.Refresh_Clear( Refresh.Refresh_Clear(
Device.Handle, Device.Handle,
Handle, Handle,
ref clearRect, in clearRect,
clearOptions, clearOptions,
ref colors, in colors,
(uint) colors.Length, (uint) colors.Length,
depth, depth,
stencil stencil
@ -351,8 +351,8 @@ namespace MoonWorks.Graphics
Refresh.Refresh_QueuePresent( Refresh.Refresh_QueuePresent(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, refreshTextureSlice,
ref refreshRect, refreshRect,
(Refresh.Filter)filter (Refresh.Filter)filter
); );
} }
@ -368,8 +368,8 @@ namespace MoonWorks.Graphics
Refresh.Refresh_QueuePresent( Refresh.Refresh_QueuePresent(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, refreshTextureSlice,
ref refreshRect, refreshRect,
(Refresh.Filter) filter (Refresh.Filter) filter
); );
} }
@ -378,12 +378,10 @@ namespace MoonWorks.Graphics
in TextureSlice textureSlice, in TextureSlice textureSlice,
Filter filter Filter filter
) { ) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
Refresh.Refresh_QueuePresent( Refresh.Refresh_QueuePresent(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, textureSlice.ToRefreshTextureSlice(),
IntPtr.Zero, IntPtr.Zero,
(Refresh.Filter) filter (Refresh.Filter) filter
); );
@ -411,7 +409,7 @@ namespace MoonWorks.Graphics
Refresh.Refresh_QueuePresent( Refresh.Refresh_QueuePresent(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, refreshTextureSlice,
IntPtr.Zero, IntPtr.Zero,
(Refresh.Filter) filter (Refresh.Filter) filter
); );
@ -428,8 +426,8 @@ namespace MoonWorks.Graphics
Refresh.Refresh_CopyTextureToTexture( Refresh.Refresh_CopyTextureToTexture(
Device.Handle, Device.Handle,
Handle, Handle,
ref sourceRefreshTextureSlice, sourceRefreshTextureSlice,
ref destRefreshTextureSlice, destRefreshTextureSlice,
(Refresh.Filter) filter (Refresh.Filter) filter
); );
} }
@ -443,7 +441,7 @@ namespace MoonWorks.Graphics
Refresh.Refresh_CopyTextureToBuffer( Refresh.Refresh_CopyTextureToBuffer(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, refreshTextureSlice,
buffer.Handle buffer.Handle
); );
} }

View File

@ -25,7 +25,7 @@ namespace MoonWorks.Graphics
}; };
Handle = Refresh.Refresh_CreateDevice( Handle = Refresh.Refresh_CreateDevice(
ref presentationParameters, presentationParameters,
Conversions.BoolToByte(debugMode) Conversions.BoolToByte(debugMode)
); );

View File

@ -99,4 +99,31 @@ namespace MoonWorks.Graphics
public LoadOp stencilLoadOp; public LoadOp stencilLoadOp;
public StoreOp stencilStoreOp; public StoreOp stencilStoreOp;
} }
[StructLayout(LayoutKind.Sequential)]
public struct StencilOpState
{
public StencilOp failOp;
public StencilOp passOp;
public StencilOp depthFailOp;
public CompareOp compareOp;
public uint compareMask;
public uint writeMask;
public uint reference;
// FIXME: can we do an explicit cast here?
public Refresh.StencilOpState ToRefresh()
{
return new Refresh.StencilOpState
{
failOp = (Refresh.StencilOp)failOp,
passOp = (Refresh.StencilOp)passOp,
depthFailOp = (Refresh.StencilOp)depthFailOp,
compareOp = (Refresh.CompareOp)compareOp,
compareMask = compareMask,
writeMask = writeMask,
reference = reference
};
}
}
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.InteropServices;
using RefreshCS; using RefreshCS;
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
@ -38,6 +39,22 @@ namespace MoonWorks.Graphics
} }
} }
public unsafe void SetData<T>(
T[] data
) where T : unmanaged
{
fixed (T* ptr = &data[0])
{
Refresh.Refresh_SetBufferData(
Device.Handle,
Handle,
0,
(IntPtr)ptr,
(uint) (data.Length * Marshal.SizeOf<T>())
);
}
}
public unsafe void SetData<T>( public unsafe void SetData<T>(
uint offsetInBytes, uint offsetInBytes,
T* data, T* data,

View File

@ -40,11 +40,10 @@ namespace MoonWorks.Graphics
public ColorTarget(GraphicsDevice device, 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( Handle = Refresh.Refresh_CreateColorTarget(
device.Handle, device.Handle,
(Refresh.SampleCount) sampleCount, (Refresh.SampleCount) sampleCount,
ref refreshTextureSlice textureSlice.ToRefreshTextureSlice()
); );
TextureSlice = textureSlice; TextureSlice = textureSlice;
} }

View File

@ -32,7 +32,7 @@ namespace MoonWorks.Graphics
Handle = Refresh.Refresh_CreateComputePipeline( Handle = Refresh.Refresh_CreateComputePipeline(
device.Handle, device.Handle,
ref computePipelineCreateInfo computePipelineCreateInfo
); );
} }
} }

View File

@ -44,7 +44,7 @@ namespace MoonWorks.Graphics
renderPass = renderPass.Handle renderPass = renderPass.Handle
}; };
Handle = Refresh.Refresh_CreateFramebuffer(device.Handle, ref framebufferCreateInfo); Handle = Refresh.Refresh_CreateFramebuffer(device.Handle, framebufferCreateInfo);
} }
} }
} }

View File

@ -46,12 +46,12 @@ namespace MoonWorks.Graphics
graphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B; graphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A; graphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A;
graphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState; graphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh();
graphicsPipelineCreateInfo.depthStencilState.compareOp = depthStencilState.CompareOp; graphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp;
graphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable); graphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable);
graphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable); graphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable);
graphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable); graphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable);
graphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState; graphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh();
graphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds; graphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds;
graphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds; graphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds;
graphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable); graphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable);
@ -93,7 +93,7 @@ namespace MoonWorks.Graphics
graphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType; graphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
graphicsPipelineCreateInfo.renderPass = renderPass.Handle; graphicsPipelineCreateInfo.renderPass = renderPass.Handle;
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, ref graphicsPipelineCreateInfo); Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, graphicsPipelineCreateInfo);
vertexAttributesHandle.Free(); vertexAttributesHandle.Free();
vertexBindingsHandle.Free(); vertexBindingsHandle.Free();

View File

@ -19,7 +19,7 @@ namespace MoonWorks.Graphics
renderPassCreateInfo.colorTargetDescriptions = (IntPtr) ptr; renderPassCreateInfo.colorTargetDescriptions = (IntPtr) ptr;
renderPassCreateInfo.depthStencilTargetDescription = IntPtr.Zero; renderPassCreateInfo.depthStencilTargetDescription = IntPtr.Zero;
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, ref renderPassCreateInfo); Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
} }
} }
@ -38,7 +38,7 @@ namespace MoonWorks.Graphics
renderPassCreateInfo.colorTargetDescriptions = (IntPtr)colorPtr; renderPassCreateInfo.colorTargetDescriptions = (IntPtr)colorPtr;
renderPassCreateInfo.depthStencilTargetDescription = (IntPtr) depthStencilPtr; renderPassCreateInfo.depthStencilTargetDescription = (IntPtr) depthStencilPtr;
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, ref renderPassCreateInfo); Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
} }
} }
} }

View File

@ -12,11 +12,9 @@ namespace MoonWorks.Graphics
ref SamplerState samplerState ref SamplerState samplerState
) : base(device) ) : base(device)
{ {
var refreshSamplerStateCreateInfo = samplerState.ToRefreshSamplerStateCreateInfo();
Handle = Refresh.Refresh_CreateSampler( Handle = Refresh.Refresh_CreateSampler(
device.Handle, device.Handle,
ref refreshSamplerStateCreateInfo samplerState.ToRefreshSamplerStateCreateInfo()
); );
} }
} }

View File

@ -16,7 +16,7 @@ namespace MoonWorks.Graphics
shaderModuleCreateInfo.codeSize = (UIntPtr) fileInfo.Length; shaderModuleCreateInfo.codeSize = (UIntPtr) fileInfo.Length;
shaderModuleCreateInfo.byteCode = (IntPtr) ptr; shaderModuleCreateInfo.byteCode = (IntPtr) ptr;
Handle = Refresh.Refresh_CreateShaderModule(device.Handle, ref shaderModuleCreateInfo); Handle = Refresh.Refresh_CreateShaderModule(device.Handle, shaderModuleCreateInfo);
} }
} }
} }

View File

@ -124,11 +124,9 @@ namespace MoonWorks.Graphics
public Texture(GraphicsDevice device, ref TextureCreateInfo textureCreateInfo) : base(device) public Texture(GraphicsDevice device, ref TextureCreateInfo textureCreateInfo) : base(device)
{ {
var refreshTextureCreateInfo = textureCreateInfo.ToRefreshTextureCreateInfo();
Handle = Refresh.Refresh_CreateTexture( Handle = Refresh.Refresh_CreateTexture(
device.Handle, device.Handle,
ref refreshTextureCreateInfo textureCreateInfo.ToRefreshTextureCreateInfo()
); );
Format = textureCreateInfo.Format; Format = textureCreateInfo.Format;
@ -150,7 +148,7 @@ namespace MoonWorks.Graphics
Refresh.Refresh_SetTextureData( Refresh.Refresh_SetTextureData(
Device.Handle, Device.Handle,
ref textureSlice, textureSlice,
data, data,
dataLengthInBytes dataLengthInBytes
); );
@ -162,7 +160,7 @@ namespace MoonWorks.Graphics
Refresh.Refresh_SetTextureData( Refresh.Refresh_SetTextureData(
Device.Handle, Device.Handle,
ref refreshTextureSlice, refreshTextureSlice,
data, data,
dataLengthInBytes dataLengthInBytes
); );

View File

@ -5,9 +5,9 @@ namespace MoonWorks.Graphics
public struct DepthStencilState public struct DepthStencilState
{ {
public bool DepthTestEnable; public bool DepthTestEnable;
public Refresh.StencilOpState BackStencilState; public StencilOpState BackStencilState;
public Refresh.StencilOpState FrontStencilState; public StencilOpState FrontStencilState;
public Refresh.CompareOp CompareOp; public CompareOp CompareOp;
public bool DepthBoundsTestEnable; public bool DepthBoundsTestEnable;
public bool DepthWriteEnable; public bool DepthWriteEnable;
public float MinDepthBounds; public float MinDepthBounds;
@ -20,7 +20,7 @@ namespace MoonWorks.Graphics
DepthWriteEnable = true, DepthWriteEnable = true,
DepthBoundsTestEnable = false, DepthBoundsTestEnable = false,
StencilTestEnable = false, StencilTestEnable = false,
CompareOp = Refresh.CompareOp.LessOrEqual CompareOp = CompareOp.LessOrEqual
}; };
public static readonly DepthStencilState DepthRead = new DepthStencilState public static readonly DepthStencilState DepthRead = new DepthStencilState
@ -29,7 +29,7 @@ namespace MoonWorks.Graphics
DepthWriteEnable = false, DepthWriteEnable = false,
DepthBoundsTestEnable = false, DepthBoundsTestEnable = false,
StencilTestEnable = false, StencilTestEnable = false,
CompareOp = Refresh.CompareOp.LessOrEqual CompareOp = CompareOp.LessOrEqual
}; };
public static readonly DepthStencilState Disable = new DepthStencilState public static readonly DepthStencilState Disable = new DepthStencilState

View File

@ -14,7 +14,7 @@ namespace MoonWorks.Graphics
public Refresh.FrontFace FrontFace; public Refresh.FrontFace FrontFace;
public float LineWidth; public float LineWidth;
public static readonly RasterizerState CullClockwise = new RasterizerState public static readonly RasterizerState CW_CullFront = new RasterizerState
{ {
CullMode = Refresh.CullMode.Front, CullMode = Refresh.CullMode.Front,
FrontFace = Refresh.FrontFace.Clockwise, FrontFace = Refresh.FrontFace.Clockwise,
@ -23,7 +23,7 @@ namespace MoonWorks.Graphics
LineWidth = 1f LineWidth = 1f
}; };
public static readonly RasterizerState CullCounterClockwise = new RasterizerState public static readonly RasterizerState CW_CullBack = new RasterizerState
{ {
CullMode = Refresh.CullMode.Back, CullMode = Refresh.CullMode.Back,
FrontFace = Refresh.FrontFace.Clockwise, FrontFace = Refresh.FrontFace.Clockwise,
@ -32,7 +32,7 @@ namespace MoonWorks.Graphics
LineWidth = 1f LineWidth = 1f
}; };
public static readonly RasterizerState CullNone = new RasterizerState public static readonly RasterizerState CW_CullNone = new RasterizerState
{ {
CullMode = Refresh.CullMode.None, CullMode = Refresh.CullMode.None,
FrontFace = Refresh.FrontFace.Clockwise, FrontFace = Refresh.FrontFace.Clockwise,
@ -41,7 +41,7 @@ namespace MoonWorks.Graphics
LineWidth = 1f LineWidth = 1f
}; };
public static readonly RasterizerState Wireframe = new RasterizerState public static readonly RasterizerState CW_Wireframe = new RasterizerState
{ {
CullMode = Refresh.CullMode.None, CullMode = Refresh.CullMode.None,
FrontFace = Refresh.FrontFace.Clockwise, FrontFace = Refresh.FrontFace.Clockwise,
@ -49,5 +49,41 @@ namespace MoonWorks.Graphics
DepthBiasEnable = false, DepthBiasEnable = false,
LineWidth = 1f LineWidth = 1f
}; };
public static readonly RasterizerState CCW_CullFront = new RasterizerState
{
CullMode = Refresh.CullMode.Front,
FrontFace = Refresh.FrontFace.CounterClockwise,
FillMode = Refresh.FillMode.Fill,
DepthBiasEnable = false,
LineWidth = 1f
};
public static readonly RasterizerState CCW_CullBack = new RasterizerState
{
CullMode = Refresh.CullMode.Back,
FrontFace = Refresh.FrontFace.CounterClockwise,
FillMode = Refresh.FillMode.Fill,
DepthBiasEnable = false,
LineWidth = 1f
};
public static readonly RasterizerState CCW_CullNone = new RasterizerState
{
CullMode = Refresh.CullMode.None,
FrontFace = Refresh.FrontFace.CounterClockwise,
FillMode = Refresh.FillMode.Fill,
DepthBiasEnable = false,
LineWidth = 1f
};
public static readonly RasterizerState CCW_Wireframe = new RasterizerState
{
CullMode = Refresh.CullMode.None,
FrontFace = Refresh.FrontFace.CounterClockwise,
FillMode = Refresh.FillMode.Fill,
DepthBiasEnable = false,
LineWidth = 1f
};
} }
} }