Skip to content

Commit 2e35013

Browse files
committed
OpenAL: Change soft parameter from exclusive to preference
This means that now if loading OpenAL soft fails, ittl try to fall back to native, and if loading OpenAL native fails, ittl fall back to OpenAL soft
1 parent 7614784 commit 2e35013

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

src/OpenAL/Silk.NET.OpenAL/AL/AL.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public AL(INativeContext ctx)
2929
public override partial bool IsExtensionPresent(string name);
3030

3131
/// <inheritdoc />
32-
public SearchPathContainer SearchPaths => _searchPaths ??= (_soft
33-
? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer());
32+
public SearchPathContainer SearchPaths => _searchPaths ??= new OpenALLibraryNameContainer(_soft);
3433

3534
/// <inheritdoc />
3635
public partial nint GetProcAddress(string name);
@@ -333,11 +332,12 @@ public partial void GetSourceProperty(uint source, GetSourceInteger param, out i
333332
/// <summary>
334333
/// Gets an instance of the API.
335334
/// </summary>
336-
/// <param name="soft">Use OpenAL Soft libraries.</param>
335+
/// <param name="soft">Prefer OpenAL Soft libraries.</param>
337336
/// <returns>The instance.</returns>
338337
public static AL GetApi(bool soft = false)
339338
{
340-
SearchPathContainer searchPaths = soft ? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer();
339+
SearchPathContainer searchPaths = new OpenALLibraryNameContainer(soft);
340+
341341
var ctx = new MultiNativeContext
342342
(CreateDefaultContext(searchPaths.GetLibraryNames()), null);
343343
var ret = new AL(ctx);

src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public ALContext(INativeContext ctx)
2525
{
2626
}
2727

28-
public SearchPathContainer SearchPaths => _searchPaths ??= (_soft
29-
? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer());
28+
public SearchPathContainer SearchPaths => _searchPaths ??= new OpenALLibraryNameContainer(_soft);
3029

3130
public override unsafe bool IsExtensionPresent(string name)
3231
=> IsExtensionPresent(GetContextsDevice(GetCurrentContext()), name);
@@ -85,11 +84,11 @@ public override unsafe bool IsExtensionPresent(string name)
8584
/// <summary>
8685
/// Gets an instance of the API.
8786
/// </summary>
88-
/// <param name="soft">Use OpenAL Soft libraries.</param>
87+
/// <param name="soft">Prefer OpenAL Soft libraries.</param>
8988
/// <returns>The instance.</returns>
9089
public static unsafe ALContext GetApi(bool soft = false)
9190
{
92-
SearchPathContainer searchPaths = soft ? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer();
91+
SearchPathContainer searchPaths = new OpenALLibraryNameContainer(soft);
9392
var ctx = new MultiNativeContext
9493
(CreateDefaultContext(searchPaths.GetLibraryNames()), null);
9594
var ret = new ALContext(ctx);
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Linq;
45
using Silk.NET.Core.Loader;
56

67
namespace Silk.NET.OpenAL
@@ -10,11 +11,28 @@ namespace Silk.NET.OpenAL
1011
/// </summary>
1112
internal class OpenALLibraryNameContainer : SearchPathContainer
1213
{
14+
private readonly bool _preferSoft;
15+
16+
private readonly SearchPathContainer _soft;
17+
private readonly SearchPathContainer _native;
18+
19+
public OpenALLibraryNameContainer(bool preferSoft)
20+
{
21+
_preferSoft = preferSoft;
22+
23+
_soft = new OpenALSoftLibraryNameContainer();
24+
_native = new OpenALNativeLibraryNameContainer();
25+
}
26+
1327
/// <inheritdoc />
14-
public override string[] Linux => new[] { "libopenal.so.1" };
28+
public override string[] Linux => _preferSoft
29+
? _soft.Linux.Concat(_native.Linux).ToArray()
30+
: _native.Linux.Concat(_soft.Linux).ToArray();
1531

1632
/// <inheritdoc />
17-
public override string[] MacOS => new[] { "/System/Library/Frameworks/OpenAL.framework/OpenAL" };
33+
public override string[] MacOS => _preferSoft
34+
? _soft.MacOS.Concat(_native.MacOS).ToArray()
35+
: _native.MacOS.Concat(_soft.MacOS).ToArray();
1836

1937
/// <inheritdoc />
2038
public override string[] Android => Linux;
@@ -23,9 +41,13 @@ internal class OpenALLibraryNameContainer : SearchPathContainer
2341
public override string[] IOS => MacOS;
2442

2543
/// <inheritdoc />
26-
public override string[] Windows86 => new[] { "openal32.dll" };
44+
public override string[] Windows86 => _preferSoft
45+
? _soft.Windows86.Concat(_native.Windows86).ToArray()
46+
: _native.Windows86.Concat(_soft.Windows86).ToArray();
2747

2848
/// <inheritdoc />
29-
public override string[] Windows64 => new[] { "openal32.dll" };
49+
public override string[] Windows64 => _preferSoft
50+
? _soft.Windows64.Concat(_native.Windows64).ToArray()
51+
: _native.Windows64.Concat(_soft.Windows64).ToArray();
3052
}
31-
}
53+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.Core.Loader;
5+
6+
namespace Silk.NET.OpenAL
7+
{
8+
/// <summary>
9+
/// Contains the library name of OpenAL.
10+
/// </summary>
11+
internal class OpenALNativeLibraryNameContainer : SearchPathContainer
12+
{
13+
/// <inheritdoc />
14+
public override string[] Linux => new[] { "libopenal.so.1" };
15+
16+
/// <inheritdoc />
17+
public override string[] MacOS => new[] { "/System/Library/Frameworks/OpenAL.framework/OpenAL" };
18+
19+
/// <inheritdoc />
20+
public override string[] Android => Linux;
21+
22+
/// <inheritdoc />
23+
public override string[] IOS => MacOS;
24+
25+
/// <inheritdoc />
26+
public override string[] Windows86 => new[] { "openal32.dll" };
27+
28+
/// <inheritdoc />
29+
public override string[] Windows64 => new[] { "openal32.dll" };
30+
}
31+
}

0 commit comments

Comments
 (0)