From 02b20f79f5c6607a4533e5b45a08852375c44967 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 15 Nov 2022 17:53:30 -0800 Subject: [PATCH] allow sampler binding calls to take array segment --- src/Graphics/CommandBuffer.cs | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 7782c2c..2d72e4f 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -368,7 +368,7 @@ namespace MoonWorks.Graphics /// /// The texture-sampler pairs to bind. public unsafe void BindVertexSamplers( - params TextureSamplerBinding[] textureSamplerBindings + ArraySegment textureSamplerBindings ) { #if DEBUG @@ -379,16 +379,16 @@ namespace MoonWorks.Graphics throw new System.InvalidOperationException("The vertex shader of the current graphics pipeline does not take any samplers!"); } - if (currentGraphicsPipeline.VertexShaderInfo.SamplerBindingCount < textureSamplerBindings.Length) + if (currentGraphicsPipeline.VertexShaderInfo.SamplerBindingCount < textureSamplerBindings.Count) { throw new System.InvalidOperationException("Vertex sampler count exceeds the amount used by the vertex shader!"); } #endif - var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length]; - var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Length]; + var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Count]; + var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Count]; - for (var i = 0; i < textureSamplerBindings.Length; i += 1) + for (var i = 0; i < textureSamplerBindings.Count; i += 1) { #if DEBUG AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]); @@ -408,13 +408,24 @@ namespace MoonWorks.Graphics } /// - /// Binds samplers to be used by the fragment shader. + /// Binds samplers to be used by the vertex shader. /// - /// An array of texture-sampler pairs to bind. - public unsafe void BindFragmentSamplers( + /// The texture-sampler pairs to bind. + public unsafe void BindVertexSamplers( params TextureSamplerBinding[] textureSamplerBindings ) { + BindVertexSamplers(new ArraySegment(textureSamplerBindings)); + } + + /// + /// Binds samplers to be used by the vertex shader. + /// + /// The texture-sampler pairs to bind. + public unsafe void BindFragmentSamplers( + ArraySegment textureSamplerBindings + ) + { #if DEBUG AssertGraphicsPipelineBound(); @@ -423,16 +434,16 @@ namespace MoonWorks.Graphics throw new System.InvalidOperationException("The fragment shader of the current graphics pipeline does not take any samplers!"); } - if (currentGraphicsPipeline.FragmentShaderInfo.SamplerBindingCount < textureSamplerBindings.Length) + if (currentGraphicsPipeline.FragmentShaderInfo.SamplerBindingCount < textureSamplerBindings.Count) { throw new System.InvalidOperationException("Fragment sampler count exceeds the amount used by the fragment shader!"); } #endif - var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length]; - var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Length]; + var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Count]; + var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Count]; - for (var i = 0; i < textureSamplerBindings.Length; i += 1) + for (var i = 0; i < textureSamplerBindings.Count; i += 1) { #if DEBUG AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]); @@ -451,6 +462,17 @@ namespace MoonWorks.Graphics ); } + /// + /// Binds samplers to be used by the fragment shader. + /// + /// An array of texture-sampler pairs to bind. + public unsafe void BindFragmentSamplers( + params TextureSamplerBinding[] textureSamplerBindings + ) + { + BindFragmentSamplers(new ArraySegment(textureSamplerBindings)); + } + /// /// Pushes vertex shader uniforms to the device. ///