File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
src/OpenAL/Silk.NET.OpenAL Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Numerics ;
6
- using Microsoft . Extensions . DependencyModel ;
7
6
using Silk . NET . Core . Attributes ;
8
7
using Silk . NET . Core . Contexts ;
9
8
using Silk . NET . Core . Loader ;
@@ -350,11 +349,31 @@ public static AL GetApi(bool soft = false)
350
349
return ret ;
351
350
}
352
351
352
+ /// <summary>
353
+ /// Attempts to load a native OpenAL extension of type <typeparamref name="T" />.
354
+ /// </summary>
355
+ /// <param name="ext">The loaded extension.</param>
356
+ /// <typeparam name="T">Type of <see cref="NativeExtension{T}" /> to load.</typeparam>
357
+ /// <returns><c>true</c> if the extension was loaded, otherwise <c>false</c>.</returns>
358
+ public bool TryGetExtension < T > ( out T ext )
359
+ where T : NativeExtension < AL >
360
+ {
361
+ ext = IsExtensionPresent ( ExtensionAttribute . GetExtensionAttribute ( typeof ( T ) ) . Name )
362
+ ? ( T ) Activator . CreateInstance ( typeof ( T ) , Context )
363
+ : null ;
364
+ return ext is not null ;
365
+ }
366
+
353
367
/// <summary>
354
368
/// Gets an instance of the API of an extension to the API.
355
369
/// </summary>
356
370
/// <typeparam name="TExtension">The extension type.</typeparam>
357
371
/// <returns>The extension.</returns>
372
+ [ Obsolete
373
+ (
374
+ "This method has been deprecated and will be removed in Silk.NET 3.0. " +
375
+ "Please use TryGetExtension instead."
376
+ ) ]
358
377
public TExtension GetExtension < TExtension > ( )
359
378
where TExtension : NativeExtension < AL >
360
379
{
Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
+ using Silk . NET . Core . Attributes ;
5
6
using Silk . NET . Core . Contexts ;
6
7
using Silk . NET . Core . Loader ;
7
8
using Silk . NET . Core . Native ;
@@ -110,12 +111,29 @@ public static unsafe ALContext GetApi(bool soft = false)
110
111
return ret ;
111
112
}
112
113
114
+ /// <summary>
115
+ /// Attempts to load the given extension.
116
+ /// </summary>
117
+ /// <typeparam name="T">The extension type.</typeparam>
118
+ /// <param name="device">The device the context is on.</param>
119
+ /// <param name="ext">The extension to check for.</param>
120
+ /// <returns>Whether the extension is available.</returns>
121
+ public unsafe bool TryGetExtension < T > ( Device * device , out T ext ) where T : NativeExtension < ALContext >
122
+ => ! ( ( ext = IsExtensionPresent ( device , ExtensionAttribute . GetExtensionAttribute ( typeof ( T ) ) . Name )
123
+ ? ( T ) Activator . CreateInstance ( typeof ( T ) , Context )
124
+ : null ) is null ) ;
125
+
113
126
/// <summary>
114
127
/// Gets an instance of the API of an extension to the API.
115
128
/// </summary>
116
129
/// <typeparam name="TContextExtension">The extension type.</typeparam>
117
130
/// <param name="device">The device the context is on.</param>
118
131
/// <returns>The extension.</returns>
132
+ [ Obsolete
133
+ (
134
+ "This method has been deprecated and will be removed in Silk.NET 3.0. " +
135
+ "Please use TryGetExtension instead."
136
+ ) ]
119
137
public unsafe TContextExtension GetExtension < TContextExtension > ( Device * device )
120
138
where TContextExtension : ContextExtensionBase
121
139
{
Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ namespace Silk.NET.OpenAL.Extensions
11
11
/// <summary>
12
12
/// A loader for OpenAL extensions.
13
13
/// </summary>
14
+ [ Obsolete
15
+ (
16
+ "This class is deprecated and will be removed in Silk.NET 3.0. " +
17
+ "Please use the TryGetExtension method on ALContext."
18
+ ) ]
14
19
public static class ALExtensionLoader
15
20
{
16
21
/// <summary>
You can’t perform that action at this time.
0 commit comments