From f93be995454375949fd83709fedb5715ebed55f7 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 22 Aug 2022 17:49:43 -0700 Subject: [PATCH 1/6] https links in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8e357c..d9d8250 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ MoonWorks uses strictly Free Open Source Software. It will never have any kind o ## Documentation -High-level documentation is provided here: http://moonside.games/docs/moonworks/ +High-level documentation is provided here: https://moonside.games/docs/moonworks/ For an actual API reference, the source is documented in doc comments that your preferred IDE can read. @@ -24,7 +24,7 @@ For an actual API reference, the source is documented in doc comments that your * [Wellspring](https://gitea.moonside.games/MoonsideGames/Wellspring) - Font Rendering * [Theorafile](https://github.com/FNA-XNA/Theorafile) - Compressed Video -Prebuilt dependencies can be obtained here: http://moonside.games/files/moonlibs.tar.bz2 +Prebuilt dependencies can be obtained here: https://moonside.games/files/moonlibs.tar.bz2 ## License -- 2.25.1 From db66fbf1154dab8d4785ef79bff39dab1f628b9f Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 22 Aug 2022 17:52:21 -0700 Subject: [PATCH 2/6] update to latest SDL2 and FAudio --- lib/FAudio | 2 +- lib/SDL2-CS | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/FAudio b/lib/FAudio index 0b6d5da..09568a0 160000 --- a/lib/FAudio +++ b/lib/FAudio @@ -1 +1 @@ -Subproject commit 0b6d5dabbf428633482fe3a956fbdb53228fcf35 +Subproject commit 09568a04683a497872937a2ffea0f82a359bb21b diff --git a/lib/SDL2-CS b/lib/SDL2-CS index b35aaa4..b72c0c5 160000 --- a/lib/SDL2-CS +++ b/lib/SDL2-CS @@ -1 +1 @@ -Subproject commit b35aaa494e44d08242788ff0ba2cb7a508f4d8f0 +Subproject commit b72c0c57128fafb6fc5aa4f258a41d928f98a438 -- 2.25.1 From 0c6bb538fb13d4416e4fef10e9615474f75981a5 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 22 Aug 2022 19:30:44 -0700 Subject: [PATCH 3/6] fix depth-only render pass invocation + throw instead of return --- src/Graphics/CommandBuffer.cs | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 598d50b..07837ff 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -34,14 +34,12 @@ namespace MoonWorks.Graphics #if DEBUG if (colorAttachmentInfos.Length == 0) { - Logger.LogError("Render pass must contain at least one attachment!"); - return; + throw new System.ArgumentException("Render pass must contain at least one attachment!"); } if (colorAttachmentInfos.Length > 4) { - Logger.LogError("Render pass cannot have more than 4 color attachments!"); - return; + throw new System.ArgumentException("Render pass cannot have more than 4 color attachments!"); } #endif @@ -78,16 +76,9 @@ namespace MoonWorks.Graphics ) { #if DEBUG - if (colorAttachmentInfos.Length == 0) - { - Logger.LogError("Render pass must contain at least one attachment!"); - return; - } - if (colorAttachmentInfos.Length > 4) { - Logger.LogError("Render pass cannot have more than 4 color attachments!"); - return; + throw new System.ArgumentException("Render pass cannot have more than 4 color attachments!"); } #endif @@ -128,14 +119,12 @@ namespace MoonWorks.Graphics #if DEBUG if (colorAttachmentInfos.Length == 0) { - Logger.LogError("Render pass must contain at least one attachment!"); - return; + throw new System.ArgumentException("Render pass must contain at least one attachment!"); } if (colorAttachmentInfos.Length > 4) { - Logger.LogError("Render pass cannot have more than 4 color attachments!"); - return; + throw new System.ArgumentException("Render pass cannot have more than 4 color attachments!"); } #endif @@ -174,16 +163,9 @@ namespace MoonWorks.Graphics ) { #if DEBUG - if (colorAttachmentInfos.Length == 0) - { - Logger.LogError("Render pass must contain at least one attachment!"); - return; - } - if (colorAttachmentInfos.Length > 4) { - Logger.LogError("Render pass cannot have more than 4 color attachments!"); - return; + throw new System.ArgumentException("Render pass cannot have more than 4 color attachments!"); } #endif -- 2.25.1 From 1af16231ce98f48633da1b46a378c4e5b6e2d54a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 25 Aug 2022 12:32:49 -0700 Subject: [PATCH 4/6] Refresh 1.6.0 --- lib/RefreshCS | 2 +- src/Graphics/CommandBuffer.cs | 30 +++++++++++++++++++++++++++ src/Graphics/RefreshEnums.cs | 6 ++++-- src/Graphics/State/RasterizerState.cs | 4 ++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/RefreshCS b/lib/RefreshCS index 98c590a..c378027 160000 --- a/lib/RefreshCS +++ b/lib/RefreshCS @@ -1 +1 @@ -Subproject commit 98c590ae77c3b6a64a370bac439f20728959a8b6 +Subproject commit c378027989dbc4233c7ead476aba4e22b335ba0f diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 07837ff..81a2c91 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -616,6 +616,36 @@ namespace MoonWorks.Graphics ); } + /// + /// Similar to DrawPrimitives, but parameters are set from a buffer. + /// + /// The draw parameters buffer. + /// The offset to start reading from the draw parameters buffer. + /// The number of draw parameter sets that should be read from the buffer. + /// The byte stride between sets of draw parameters. + /// An offset value obtained from PushVertexShaderUniforms. If no uniforms are required then use 0. + /// An offset value obtained from PushFragmentShaderUniforms. If no uniforms are required the use 0. + public void DrawPrimitivesIndirect( + Buffer buffer, + uint offsetInBytes, + uint drawCount, + uint stride, + uint vertexParamOffset, + uint fragmentParamOffset + ) + { + Refresh.Refresh_DrawPrimitivesIndirect( + Device.Handle, + Handle, + buffer.Handle, + offsetInBytes, + drawCount, + stride, + vertexParamOffset, + fragmentParamOffset + ); + } + /// /// Ends the current render pass. /// This must be called before beginning another render pass or submitting the command buffer. diff --git a/src/Graphics/RefreshEnums.cs b/src/Graphics/RefreshEnums.cs index 12d70c8..50ba244 100644 --- a/src/Graphics/RefreshEnums.cs +++ b/src/Graphics/RefreshEnums.cs @@ -91,7 +91,8 @@ namespace MoonWorks.Graphics { Sampler = 1, ColorTarget = 2, - DepthStencilTarget = 4 + DepthStencilTarget = 4, + Compute = 8 } public enum SampleCount @@ -120,7 +121,8 @@ namespace MoonWorks.Graphics { Vertex = 1, Index = 2, - Compute = 4 + Compute = 4, + Indirect = 8 } public enum VertexElementFormat diff --git a/src/Graphics/State/RasterizerState.cs b/src/Graphics/State/RasterizerState.cs index 042a55d..8d5b4ac 100644 --- a/src/Graphics/State/RasterizerState.cs +++ b/src/Graphics/State/RasterizerState.cs @@ -69,7 +69,7 @@ { CullMode = CullMode.None, FrontFace = FrontFace.Clockwise, - FillMode = FillMode.Fill, + FillMode = FillMode.Line, DepthBiasEnable = false }; @@ -101,7 +101,7 @@ { CullMode = CullMode.None, FrontFace = FrontFace.CounterClockwise, - FillMode = FillMode.Fill, + FillMode = FillMode.Line, DepthBiasEnable = false }; } -- 2.25.1 From 041f5493874aa3a569b1fe7c6bf416ed58cd3541 Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Thu, 25 Aug 2022 23:43:01 -0400 Subject: [PATCH 5/6] Fix debug assertion in AudioDevice constructor --- src/Audio/AudioDevice.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Audio/AudioDevice.cs b/src/Audio/AudioDevice.cs index 27cb803..adf4b37 100644 --- a/src/Audio/AudioDevice.cs +++ b/src/Audio/AudioDevice.cs @@ -25,7 +25,7 @@ namespace MoonWorks.Audio public unsafe AudioDevice() { - FAudio.FAudioCreate(out var handle, 0, 0); + FAudio.FAudioCreate(out var handle, 0, FAudio.FAUDIO_DEFAULT_PROCESSOR); Handle = handle; /* Find a suitable device */ -- 2.25.1 From 0933b8e70f193b2ab52e5bfa2b84c1dfd6f79504 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 29 Aug 2022 22:45:28 -0700 Subject: [PATCH 6/6] reset static audio on free + rework filter API --- src/Audio/FilterType.cs | 10 +++ src/Audio/SoundInstance.cs | 140 +++++++++++++++++-------------- src/Audio/StaticSound.cs | 1 + src/Audio/StaticSoundInstance.cs | 12 +++ 4 files changed, 101 insertions(+), 62 deletions(-) create mode 100644 src/Audio/FilterType.cs diff --git a/src/Audio/FilterType.cs b/src/Audio/FilterType.cs new file mode 100644 index 0000000..345aa68 --- /dev/null +++ b/src/Audio/FilterType.cs @@ -0,0 +1,10 @@ +namespace MoonWorks.Audio +{ + public enum FilterType + { + None, + LowPass, + BandPass, + HighPass + } +} diff --git a/src/Audio/SoundInstance.cs b/src/Audio/SoundInstance.cs index 31df632..07d02e3 100644 --- a/src/Audio/SoundInstance.cs +++ b/src/Audio/SoundInstance.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; namespace MoonWorks.Audio @@ -14,21 +14,21 @@ namespace MoonWorks.Audio public virtual SoundState State { get; protected set; } - private float _pan = 0; + private float pan = 0; public float Pan { - get => _pan; + get => pan; set { - _pan = value; + pan = value; - if (_pan < -1f) + if (pan < -1f) { - _pan = -1f; + pan = -1f; } - if (_pan > 1f) + if (pan > 1f) { - _pan = 1f; + pan = 1f; } if (Is3D) { return; } @@ -45,41 +45,41 @@ namespace MoonWorks.Audio } } - private float _pitch = 0; + private float pitch = 0; public float Pitch { - get => _pitch; + get => pitch; set { - _pitch = Math.MathHelper.Clamp(value, -1f, 1f); + pitch = Math.MathHelper.Clamp(value, -1f, 1f); UpdatePitch(); } } - private float _volume = 1; + private float volume = 1; public float Volume { - get => _volume; + get => volume; set { - _volume = value; - FAudio.FAudioVoice_SetVolume(Handle, _volume, 0); + volume = value; + FAudio.FAudioVoice_SetVolume(Handle, volume, 0); } } - private float _reverb; + private float reverb; public unsafe float Reverb { - get => _reverb; + get => reverb; set { - _reverb = value; + reverb = value; float* outputMatrix = (float*) dspSettings.pMatrixCoefficients; - outputMatrix[0] = _reverb; + outputMatrix[0] = reverb; if (dspSettings.SrcChannelCount == 2) { - outputMatrix[1] = _reverb; + outputMatrix[1] = reverb; } FAudio.FAudioVoice_SetOutputMatrix( @@ -93,67 +93,83 @@ namespace MoonWorks.Audio } } - private float _lowPassFilter; - public float LowPassFilter + private const float MAX_FILTER_FREQUENCY = 1f; + private const float MAX_FILTER_ONEOVERQ = 1.5f; + + private FAudio.FAudioFilterParameters filterParameters = new FAudio.FAudioFilterParameters { - get => _lowPassFilter; + Type = FAudio.FAudioFilterType.FAudioLowPassFilter, + Frequency = 1f, + OneOverQ = 1f + }; + + private float FilterFrequency + { + get => filterParameters.Frequency; set { - _lowPassFilter = value; + value = System.Math.Clamp(value, 0.01f, MAX_FILTER_FREQUENCY); + filterParameters.Frequency = value; - FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters - { - Type = FAudio.FAudioFilterType.FAudioLowPassFilter, - Frequency = _lowPassFilter, - OneOverQ = 1f - }; FAudio.FAudioVoice_SetFilterParameters( Handle, - ref p, + ref filterParameters, 0 ); } } - private float _highPassFilter; - public float HighPassFilter + private float FilterOneOverQ { - get => _highPassFilter; + get => filterParameters.OneOverQ; set { - _highPassFilter = value; + value = System.Math.Clamp(value, 0.01f, MAX_FILTER_ONEOVERQ); + filterParameters.OneOverQ = value; - FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters - { - Type = FAudio.FAudioFilterType.FAudioHighPassFilter, - Frequency = _highPassFilter, - OneOverQ = 1f - }; FAudio.FAudioVoice_SetFilterParameters( Handle, - ref p, + ref filterParameters, 0 ); } } - private float _bandPassFilter; - public float BandPassFilter + private FilterType filterType; + public FilterType FilterType { - get => _bandPassFilter; + get => filterType; set { - _bandPassFilter = value; + filterType = value; - FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters + switch (filterType) { - Type = FAudio.FAudioFilterType.FAudioBandPassFilter, - Frequency = _bandPassFilter, - OneOverQ = 1f - }; + case FilterType.None: + filterParameters = new FAudio.FAudioFilterParameters + { + Type = FAudio.FAudioFilterType.FAudioLowPassFilter, + Frequency = 1f, + OneOverQ = 1f + }; + break; + + case FilterType.LowPass: + filterParameters.Type = FAudio.FAudioFilterType.FAudioLowPassFilter; + break; + + case FilterType.BandPass: + filterParameters.Type = FAudio.FAudioFilterType.FAudioBandPassFilter; + break; + + case FilterType.HighPass: + filterParameters.Type = FAudio.FAudioFilterType.FAudioHighPassFilter; + break; + } + FAudio.FAudioVoice_SetFilterParameters( Handle, - ref p, + ref filterParameters, 0 ); } @@ -281,7 +297,7 @@ namespace MoonWorks.Audio FAudio.FAudioSourceVoice_SetFrequencyRatio( Handle, - (float) System.Math.Pow(2.0, _pitch) * doppler, + (float) System.Math.Pow(2.0, pitch) * doppler, 0 ); } @@ -305,8 +321,8 @@ namespace MoonWorks.Audio } else { - outputMatrix[0] = (_pan > 0.0f) ? (1.0f - _pan) : 1.0f; - outputMatrix[1] = (_pan < 0.0f) ? (1.0f + _pan) : 1.0f; + outputMatrix[0] = (pan > 0.0f) ? (1.0f - pan) : 1.0f; + outputMatrix[1] = (pan < 0.0f) ? (1.0f + pan) : 1.0f; } } else @@ -318,23 +334,23 @@ namespace MoonWorks.Audio } else { - if (_pan <= 0.0f) + if (pan <= 0.0f) { // Left speaker blends left/right channels - outputMatrix[0] = 0.5f * _pan + 1.0f; - outputMatrix[1] = 0.5f * -_pan; + outputMatrix[0] = 0.5f * pan + 1.0f; + outputMatrix[1] = 0.5f * -pan; // Right speaker gets less of the right channel outputMatrix[2] = 0.0f; - outputMatrix[3] = _pan + 1.0f; + outputMatrix[3] = pan + 1.0f; } else { // Left speaker gets less of the left channel - outputMatrix[0] = -_pan + 1.0f; + outputMatrix[0] = -pan + 1.0f; outputMatrix[1] = 0.0f; // Right speaker blends right/left channels - outputMatrix[2] = 0.5f * _pan; - outputMatrix[3] = 0.5f * -_pan + 1.0f; + outputMatrix[2] = 0.5f * pan; + outputMatrix[3] = 0.5f * -pan + 1.0f; } } } diff --git a/src/Audio/StaticSound.cs b/src/Audio/StaticSound.cs index 4976244..8707322 100644 --- a/src/Audio/StaticSound.cs +++ b/src/Audio/StaticSound.cs @@ -283,6 +283,7 @@ namespace MoonWorks.Audio internal void FreeInstance(StaticSoundInstance instance) { + instance.Reset(); Instances.Push(instance); } diff --git a/src/Audio/StaticSoundInstance.cs b/src/Audio/StaticSoundInstance.cs index 7f52a97..f2d7549 100644 --- a/src/Audio/StaticSoundInstance.cs +++ b/src/Audio/StaticSoundInstance.cs @@ -107,5 +107,17 @@ namespace MoonWorks.Audio { Parent.FreeInstance(this); } + + internal void Reset() + { + Pan = 0; + Pitch = 0; + Volume = 1; + Reverb = 0; + Loop = false; + Is3D = false; + FilterType = FilterType.None; + Reverb = 0; + } } } -- 2.25.1