Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/OpenAL/Silk.NET.OpenAL/AL/AL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Numerics;
using Microsoft.Extensions.DependencyModel;
using Silk.NET.Core.Attributes;
using Silk.NET.Core.Contexts;
using Silk.NET.Core.Loader;
Expand Down Expand Up @@ -350,11 +349,31 @@ public static AL GetApi(bool soft = false)
return ret;
}

/// <summary>
/// Attempts to load a native OpenAL extension of type <typeparamref name="T" />.
/// </summary>
/// <param name="ext">The loaded extension.</param>
/// <typeparam name="T">Type of <see cref="NativeExtension{T}" /> to load.</typeparam>
/// <returns><c>true</c> if the extension was loaded, otherwise <c>false</c>.</returns>
public bool TryGetExtension<T>(out T ext)
where T : NativeExtension<AL>
{
ext = IsExtensionPresent(ExtensionAttribute.GetExtensionAttribute(typeof(T)).Name)
? (T) Activator.CreateInstance(typeof(T), Context)
: null;
return ext is not null;
}

/// <summary>
/// Gets an instance of the API of an extension to the API.
/// </summary>
/// <typeparam name="TExtension">The extension type.</typeparam>
/// <returns>The extension.</returns>
[Obsolete
(
"This method has been deprecated and will be removed in Silk.NET 3.0. " +
"Please use TryGetExtension instead."
)]
public TExtension GetExtension<TExtension>()
where TExtension : NativeExtension<AL>
{
Expand Down
18 changes: 18 additions & 0 deletions src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Silk.NET.Core.Attributes;
using Silk.NET.Core.Contexts;
using Silk.NET.Core.Loader;
using Silk.NET.Core.Native;
Expand Down Expand Up @@ -110,12 +111,29 @@ public static unsafe ALContext GetApi(bool soft = false)
return ret;
}

/// <summary>
/// Attempts to load the given extension.
/// </summary>
/// <typeparam name="T">The extension type.</typeparam>
/// <param name="device">The device the context is on.</param>
/// <param name="ext">The extension to check for.</param>
/// <returns>Whether the extension is available.</returns>
public unsafe bool TryGetExtension<T>(Device* device, out T ext) where T : NativeExtension<ALContext>
=> !((ext = IsExtensionPresent(device, ExtensionAttribute.GetExtensionAttribute(typeof(T)).Name)
? (T) Activator.CreateInstance(typeof(T), Context)
: null) is null);

/// <summary>
/// Gets an instance of the API of an extension to the API.
/// </summary>
/// <typeparam name="TContextExtension">The extension type.</typeparam>
/// <param name="device">The device the context is on.</param>
/// <returns>The extension.</returns>
[Obsolete
(
"This method has been deprecated and will be removed in Silk.NET 3.0. " +
"Please use TryGetExtension instead."
)]
public unsafe TContextExtension GetExtension<TContextExtension>(Device* device)
where TContextExtension : ContextExtensionBase
{
Expand Down
5 changes: 5 additions & 0 deletions src/OpenAL/Silk.NET.OpenAL/Extensions/ALExtensionLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace Silk.NET.OpenAL.Extensions
/// <summary>
/// A loader for OpenAL extensions.
/// </summary>
[Obsolete
(
"This class is deprecated and will be removed in Silk.NET 3.0. "+
"Please use the TryGetExtension method on ALContext."
)]
public static class ALExtensionLoader
{
/// <summary>
Expand Down