convert many things to params arrays

main
cosmonaut 2021-01-15 20:14:45 -08:00
parent a3daa49228
commit 0edf8e5230
3 changed files with 74 additions and 57 deletions

14
src/BufferBinding.cs Normal file
View File

@ -0,0 +1,14 @@
namespace Campari
{
public struct BufferBinding
{
public Buffer Buffer;
public ulong Offset;
public BufferBinding(Buffer buffer, ulong offset)
{
Buffer = buffer;
Offset = offset;
}
}
}

View File

@ -16,50 +16,47 @@ namespace Campari
Handle = IntPtr.Zero;
}
public void BeginRenderPass(
public unsafe void BeginRenderPass(
RenderPass renderPass,
Framebuffer framebuffer,
ref Refresh.Rect renderArea,
Refresh.Color[] clearColors,
ref Refresh.DepthStencilValue depthStencilClearValue
ref Refresh.DepthStencilValue depthStencilClearValue,
params Refresh.Color[] clearColors
) {
var clearColorHandle = GCHandle.Alloc(clearColors, GCHandleType.Pinned);
fixed (Refresh.Color* clearColorPtr = &clearColors[0])
{
Refresh.Refresh_BeginRenderPass(
Device.Handle,
Handle,
renderPass.Handle,
framebuffer.Handle,
ref renderArea,
clearColorHandle.AddrOfPinnedObject(),
(uint) clearColors.Length,
(IntPtr) clearColorPtr,
(uint)clearColors.Length,
ref depthStencilClearValue
);
clearColorHandle.Free();
}
}
public void BeginRenderPass(
public unsafe void BeginRenderPass(
RenderPass renderPass,
Framebuffer framebuffer,
ref Refresh.Rect renderArea,
Refresh.Color[] clearColors
params Refresh.Color[] clearColors
) {
var clearColorHandle = GCHandle.Alloc(clearColors, GCHandleType.Pinned);
fixed (Refresh.Color* clearColorPtr = &clearColors[0])
{
Refresh.Refresh_BeginRenderPass(
Device.Handle,
Handle,
renderPass.Handle,
framebuffer.Handle,
ref renderArea,
clearColorHandle.AddrOfPinnedObject(),
(IntPtr) clearColorPtr,
(uint) clearColors.Length,
IntPtr.Zero
);
clearColorHandle.Free();
}
}
public void BindComputePipeline(
@ -163,28 +160,25 @@ namespace Campari
public unsafe void BindVertexBuffers(
uint firstBinding,
uint bindingCount,
Buffer[] buffers,
UInt64[] offsets
params BufferBinding[] bufferBindings
) {
var bufferPtrs = stackalloc IntPtr[buffers.Length];
var bufferPtrs = stackalloc IntPtr[bufferBindings.Length];
var offsets = stackalloc ulong[bufferBindings.Length];
for (var i = 0; i < buffers.Length; i += 1)
for (var i = 0; i < bufferBindings.Length; i += 1)
{
bufferPtrs[i] = buffers[i].Handle;
bufferPtrs[i] = bufferBindings[i].Buffer.Handle;
offsets[i] = bufferBindings[i].Offset;
}
var offsetHandle = GCHandle.Alloc(offsets, GCHandleType.Pinned);
Refresh.Refresh_BindVertexBuffers(
Device.Handle,
Handle,
firstBinding,
bindingCount,
(uint) bufferBindings.Length,
(IntPtr) bufferPtrs,
offsetHandle.AddrOfPinnedObject()
(IntPtr) offsets
);
offsetHandle.Free();
}
public void BindIndexBuffer(
@ -227,20 +221,15 @@ namespace Campari
}
public unsafe void BindFragmentSamplers(
Texture[] textures,
Sampler[] samplers
params TextureSamplerBinding[] textureSamplerBindings
) {
var texturePtrs = stackalloc IntPtr[textures.Length];
var samplerPtrs = stackalloc IntPtr[samplers.Length];
var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length];
var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Length];
for (var i = 0; i < textures.Length; i += 1)
for (var i = 0; i < textureSamplerBindings.Length; i += 1)
{
texturePtrs[i] = textures[i].Handle;
}
for (var i = 0; i < samplers.Length; i += 1)
{
samplerPtrs[i] = samplers[i].Handle;
texturePtrs[i] = textureSamplerBindings[i].Texture.Handle;
samplerPtrs[i] = textureSamplerBindings[i].Sampler.Handle;
}
Refresh.Refresh_BindFragmentSamplers(

View File

@ -0,0 +1,14 @@
namespace Campari
{
public struct TextureSamplerBinding
{
public Texture Texture;
public Sampler Sampler;
public TextureSamplerBinding(Texture texture, Sampler sampler)
{
Texture = texture;
Sampler = sampler;
}
}
}