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; Handle = IntPtr.Zero;
} }
public void BeginRenderPass( public unsafe void BeginRenderPass(
RenderPass renderPass, RenderPass renderPass,
Framebuffer framebuffer, Framebuffer framebuffer,
ref Refresh.Rect renderArea, 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( Refresh.Refresh_BeginRenderPass(
Device.Handle, Device.Handle,
Handle, Handle,
renderPass.Handle, renderPass.Handle,
framebuffer.Handle, framebuffer.Handle,
ref renderArea, ref renderArea,
clearColorHandle.AddrOfPinnedObject(), (IntPtr) clearColorPtr,
(uint) clearColors.Length, (uint)clearColors.Length,
ref depthStencilClearValue ref depthStencilClearValue
); );
}
clearColorHandle.Free();
} }
public void BeginRenderPass( public unsafe void BeginRenderPass(
RenderPass renderPass, RenderPass renderPass,
Framebuffer framebuffer, Framebuffer framebuffer,
ref Refresh.Rect renderArea, 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( Refresh.Refresh_BeginRenderPass(
Device.Handle, Device.Handle,
Handle, Handle,
renderPass.Handle, renderPass.Handle,
framebuffer.Handle, framebuffer.Handle,
ref renderArea, ref renderArea,
clearColorHandle.AddrOfPinnedObject(), (IntPtr) clearColorPtr,
(uint) clearColors.Length, (uint) clearColors.Length,
IntPtr.Zero IntPtr.Zero
); );
}
clearColorHandle.Free();
} }
public void BindComputePipeline( public void BindComputePipeline(
@ -74,7 +71,7 @@ namespace Campari
public unsafe uint PushComputeShaderParams<T>( public unsafe uint PushComputeShaderParams<T>(
params T[] uniforms params T[] uniforms
) where T : unmanaged ) where T : unmanaged
{ {
fixed (T* ptr = &uniforms[0]) fixed (T* ptr = &uniforms[0])
{ {
@ -163,28 +160,25 @@ namespace Campari
public unsafe void BindVertexBuffers( public unsafe void BindVertexBuffers(
uint firstBinding, uint firstBinding,
uint bindingCount, params BufferBinding[] bufferBindings
Buffer[] buffers,
UInt64[] offsets
) { ) {
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( Refresh.Refresh_BindVertexBuffers(
Device.Handle, Device.Handle,
Handle, Handle,
firstBinding, firstBinding,
bindingCount, (uint) bufferBindings.Length,
(IntPtr) bufferPtrs, (IntPtr) bufferPtrs,
offsetHandle.AddrOfPinnedObject() (IntPtr) offsets
); );
offsetHandle.Free();
} }
public void BindIndexBuffer( public void BindIndexBuffer(
@ -227,20 +221,15 @@ namespace Campari
} }
public unsafe void BindFragmentSamplers( public unsafe void BindFragmentSamplers(
Texture[] textures, params TextureSamplerBinding[] textureSamplerBindings
Sampler[] samplers
) { ) {
var texturePtrs = stackalloc IntPtr[textures.Length]; var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length];
var samplerPtrs = stackalloc IntPtr[samplers.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; texturePtrs[i] = textureSamplerBindings[i].Texture.Handle;
} samplerPtrs[i] = textureSamplerBindings[i].Sampler.Handle;
for (var i = 0; i < samplers.Length; i += 1)
{
samplerPtrs[i] = samplers[i].Handle;
} }
Refresh.Refresh_BindFragmentSamplers( 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;
}
}
}