mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 14:08:25 +01:00
Update Slang, Vulkan, Gltf and ImGui. Offload natives to sub-packages.
Public-PR: https://github.com/ahwootech/BRUTAL/pull/9 Public-PR: https://github.com/ahwootech/BRUTAL/pull/15 Public-PR: https://github.com/ahwootech/BRUTAL/pull/21 Fixes: ahwootech/BRUTAL#8 Fixes: ahwootech/BRUTAL#22 Co-authored-by: Laurens de Voogd <laurens@devoogd.be> Co-authored-by: sGo7-Dev <goulax16@gmail.com> Co-authored-by: Capsup <capsup@live.dk>
This commit is contained in:
parent
a25cdf80b2
commit
4ac91e105e
1 changed files with 2034 additions and 318 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
|
||||
namespace Brutal.GltfApi;
|
||||
|
||||
|
|
@ -9,8 +10,31 @@ public interface IExtensionGltfObject
|
|||
|
||||
public static class GltfExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an extension object by name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Under trimming or Native AOT, <typeparamref name="T"/> must be one of the extension types this library
|
||||
/// defines; for your own extension types use the overload that takes a <see cref="JsonTypeInfo{T}"/>.
|
||||
/// </remarks>
|
||||
public static T? GetExtension<T>(this IExtensionGltfObject obj, string extensionName)
|
||||
where T : class
|
||||
{
|
||||
return GetExtensionCore<T>(obj, extensionName, jsonTypeInfo: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an extension object by name, reading it with the given source-generated metadata.
|
||||
/// </summary>
|
||||
public static T? GetExtension<T>(this IExtensionGltfObject obj, string extensionName, JsonTypeInfo<T> jsonTypeInfo)
|
||||
where T : class
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(jsonTypeInfo);
|
||||
return GetExtensionCore(obj, extensionName, jsonTypeInfo);
|
||||
}
|
||||
|
||||
private static T? GetExtensionCore<T>(IExtensionGltfObject obj, string extensionName, JsonTypeInfo<T>? jsonTypeInfo)
|
||||
where T : class
|
||||
{
|
||||
var extensionMap = obj.Extensions;
|
||||
if (extensionMap == null || !extensionMap.TryGetValue(extensionName, out var extObj))
|
||||
|
|
@ -19,8 +43,10 @@ public static class GltfExtensions
|
|||
// from deserialization hold the raw JsonElement.
|
||||
if (extObj is T typed)
|
||||
return typed;
|
||||
// Metadata is resolved only here: for an unregistered T it throws under Native AOT, and in JIT builds
|
||||
// for types System.Text.Json can't describe, which must not break lookups that never deserialize.
|
||||
if (extObj is JsonElement je)
|
||||
return je.Deserialize<T>(GltfUtility.JsonOptions);
|
||||
return je.Deserialize(jsonTypeInfo ?? (JsonTypeInfo<T>)GltfUtility.JsonOptions.GetTypeInfo(typeof(T)));
|
||||
throw new InvalidCastException(
|
||||
$"Extension '{extensionName}' holds a {extObj.GetType()}, expected {typeof(T)} or JsonElement"
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue