allow sampler binding calls to take array segment

pull/35/head
cosmonaut 2022-11-15 17:53:30 -08:00
parent c2ef78d136
commit 02b20f79f5
1 changed files with 34 additions and 12 deletions

View File

@ -368,7 +368,7 @@ namespace MoonWorks.Graphics
/// </summary> /// </summary>
/// <param name="textureSamplerBindings">The texture-sampler pairs to bind.</param> /// <param name="textureSamplerBindings">The texture-sampler pairs to bind.</param>
public unsafe void BindVertexSamplers( public unsafe void BindVertexSamplers(
params TextureSamplerBinding[] textureSamplerBindings ArraySegment<TextureSamplerBinding> textureSamplerBindings
) )
{ {
#if DEBUG #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!"); 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!"); throw new System.InvalidOperationException("Vertex sampler count exceeds the amount used by the vertex shader!");
} }
#endif #endif
var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length]; var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Count];
var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Length]; 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 #if DEBUG
AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]); AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]);
@ -408,13 +408,24 @@ namespace MoonWorks.Graphics
} }
/// <summary> /// <summary>
/// Binds samplers to be used by the fragment shader. /// Binds samplers to be used by the vertex shader.
/// </summary> /// </summary>
/// <param name="textureSamplerBindings">An array of texture-sampler pairs to bind.</param> /// <param name="textureSamplerBindings">The texture-sampler pairs to bind.</param>
public unsafe void BindFragmentSamplers( public unsafe void BindVertexSamplers(
params TextureSamplerBinding[] textureSamplerBindings params TextureSamplerBinding[] textureSamplerBindings
) )
{ {
BindVertexSamplers(new ArraySegment<TextureSamplerBinding>(textureSamplerBindings));
}
/// <summary>
/// Binds samplers to be used by the vertex shader.
/// </summary>
/// <param name="textureSamplerBindings">The texture-sampler pairs to bind.</param>
public unsafe void BindFragmentSamplers(
ArraySegment<TextureSamplerBinding> textureSamplerBindings
)
{
#if DEBUG #if DEBUG
AssertGraphicsPipelineBound(); 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!"); 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!"); throw new System.InvalidOperationException("Fragment sampler count exceeds the amount used by the fragment shader!");
} }
#endif #endif
var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Length]; var texturePtrs = stackalloc IntPtr[textureSamplerBindings.Count];
var samplerPtrs = stackalloc IntPtr[textureSamplerBindings.Length]; 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 #if DEBUG
AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]); AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]);
@ -451,6 +462,17 @@ namespace MoonWorks.Graphics
); );
} }
/// <summary>
/// Binds samplers to be used by the fragment shader.
/// </summary>
/// <param name="textureSamplerBindings">An array of texture-sampler pairs to bind.</param>
public unsafe void BindFragmentSamplers(
params TextureSamplerBinding[] textureSamplerBindings
)
{
BindFragmentSamplers(new ArraySegment<TextureSamplerBinding>(textureSamplerBindings));
}
/// <summary> /// <summary>
/// Pushes vertex shader uniforms to the device. /// Pushes vertex shader uniforms to the device.
/// </summary> /// </summary>