Skip to content

Commit

Permalink
[C] Clear OpenTK namespace
Browse files Browse the repository at this point in the history
fixes #13160

- removes unused types
- use System.Numerics when possible
- move own created types from OpenTK namespace to CoreGraphics
- create missing types in CoreGraphics namespace
  • Loading branch information
StephaneDelcroix committed Jan 25, 2022
1 parent eb3015b commit d79ae8f
Show file tree
Hide file tree
Showing 142 changed files with 1,651 additions and 282 deletions.
100 changes: 93 additions & 7 deletions runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ static IEnumerable<FunctionData> GetFunctionData (bool isDotNet = false)
var data = new List<FunctionData> ();

Types.NativeHandleType = isDotNet ? Types.NativeHandle : Types.IntPtr;
Types.Vector2d = isDotNet ? Types.NVector2d : Types.OpenTK_Vector2d;
Types.Vector4d = isDotNet ? Types.NVector4d : Types.OpenTK_Vector4d;
Types.Vector2i = isDotNet ? Types.NVector2i : Types.OpenTK_Vector2i;
Types.Vector3i = isDotNet ? Types.NVector3i : Types.OpenTK_Vector3i;
Types.Vector4i = isDotNet ? Types.NVector4i : Types.OpenTK_Vector4i;
Types.Matrix4f = isDotNet ? Types.Numerics_Matrix4f : Types.OpenTK_Matrix4f;
Types.QuatD = isDotNet ? Types.NQuaterniond : Types.OpenTK_QuatD;

data.Add (
new FunctionData {
Expand Down Expand Up @@ -1759,6 +1766,17 @@ static IEnumerable<FunctionData> GetFunctionData (bool isDotNet = false)
}
);

data.Add (
new FunctionData {
Comment = " // void func (NVector3d)",
Prefix = "simd__",
Variants = Variants.NonStret,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.NVector3d },
},
}
);

data.Add (
new FunctionData {
Comment = " // void func (float, Vector2i)",
Expand Down Expand Up @@ -2637,14 +2655,17 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
{
var accessor = isRef ? "->" : ".";
switch (type.ManagedType) {
case "NVector2d":
case "Vector2d":
case "NVector2i":
case "Vector2i":
case "Vector2":
writer.WriteLine ("\t{0}{2}a = {1} [0];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t{0}{2}b = {1} [1];", managedVariable, nativeVariable, accessor);
break;
case "Vector3d":
case "Vector3i":
case "NVector3i":
case "Vector3":
writer.WriteLine ("\t{0}{2}a = {1} [0];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t{0}{2}b = {1} [1];", managedVariable, nativeVariable, accessor);
Expand All @@ -2657,7 +2678,9 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
writer.WriteLine ("\t{0}{2}c = {1} [2];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t{0}{1}d = 0;", managedVariable, accessor);
break;
case "NVector4d":
case "Vector4d":
case "NVector4i":
case "Vector4i":
case "Vector4":
if (type.NativeType == "vector_float3") {
Expand Down Expand Up @@ -2690,6 +2713,7 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
writer.WriteLine ("\t}");
break;
case "Matrix4":
case "Matrix4x4":
case "NMatrix4":
case "NMatrix4d":
writer.WriteLine ("\tfor (int i = 0; i < 4; i++) {");
Expand Down Expand Up @@ -2736,6 +2760,7 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
writer.WriteLine ("\t}");
break;
case "Quaternion":
case "NQuaterniond":
case "Quaterniond":
writer.WriteLine ("\t{0}{2}vector.a = {1}.vector [0];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t{0}{2}vector.b = {1}.vector [1];", managedVariable, nativeVariable, accessor);
Expand Down Expand Up @@ -2783,13 +2808,16 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
{
var accessor = isRef ? "->" : ".";
switch (type.ManagedType) {
case "NVector2d":
case "Vector2d":
case "NVector2i":
case "Vector2i":
case "Vector2":
writer.WriteLine ("\t{0} [0] = {1}{2}a;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t{0} [1] = {1}{2}b;", nativeVariable, managedVariable, accessor);
break;
case "Vector3d":
case "NVector3i":
case "Vector3i":
case "Vector3":
case "NVector3":
Expand All @@ -2798,7 +2826,9 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
writer.WriteLine ("\t{0} [1] = {1}{2}b;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t{0} [2] = {1}{2}c;", nativeVariable, managedVariable, accessor);
break;
case "NVector4d":
case "Vector4d":
case "NVector4i":
case "Vector4i":
case "Vector4":
if (type.NativeType == "vector_float3") {
Expand Down Expand Up @@ -2830,6 +2860,7 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
writer.WriteLine ("\t}");
break;
case "Matrix4":
case "Matrix4x4":
case "NMatrix4":
case "NMatrix4d":
writer.WriteLine ("\tfor (int i = 0; i < 4; i++) {");
Expand Down Expand Up @@ -2876,6 +2907,7 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
writer.WriteLine ("\t}");
break;
case "Quaternion":
case "NQuaterniond":
case "Quaterniond":
writer.WriteLine ("\t{0}.vector [0] = {1}{2}vector.a;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t{0}.vector [1] = {1}{2}vector.b;", nativeVariable, managedVariable, accessor);
Expand Down Expand Up @@ -3334,31 +3366,60 @@ public static class Types {
NativeWrapperType = "struct Vector4f",
RequireMarshal = true,
};
public static TypeData Vector2i = new TypeData {
public static TypeData Vector2i;
public static TypeData OpenTK_Vector2i = new TypeData {
ManagedType = "Vector2i",
NativeType = "vector_int2",
NativeWrapperType = "struct Vector2i",
RequireMarshal = true,
IsX86Stret = true,
};
public static TypeData Vector3i = new TypeData {
public static TypeData NVector2i = new TypeData {
ManagedType = "NVector2i",
NativeType = "vector_int2",
NativeWrapperType = "struct Vector2i",
RequireMarshal = true,
IsX86Stret = true,
};
public static TypeData Vector3i;
public static TypeData OpenTK_Vector3i = new TypeData {
ManagedType = "Vector3i",
NativeType = "vector_int3",
NativeWrapperType = "struct Vector3i",
RequireMarshal = true,
};
public static TypeData Vector4i = new TypeData {
public static TypeData NVector3i = new TypeData {
ManagedType = "NVector3i",
NativeType = "vector_int3",
NativeWrapperType = "struct Vector3i",
RequireMarshal = true,
};
public static TypeData Vector4i;
public static TypeData OpenTK_Vector4i = new TypeData {
ManagedType = "Vector4i",
NativeType = "vector_int4",
NativeWrapperType = "struct Vector4i",
RequireMarshal = true,
};
public static TypeData Vector2d = new TypeData {
public static TypeData NVector4i = new TypeData {
ManagedType = "NVector4i",
NativeType = "vector_int4",
NativeWrapperType = "struct Vector4i",
RequireMarshal = true,
};
public static TypeData Vector2d;
public static TypeData OpenTK_Vector2d = new TypeData {
ManagedType = "Vector2d",
NativeType = "vector_double2",
NativeWrapperType = "struct Vector2d",
RequireMarshal = true
};
public static TypeData NVector2d = new TypeData {
ManagedType = "NVector2d",
NativeType = "vector_double2",
NativeWrapperType = "struct Vector2d",
RequireMarshal = true
};
public static TypeData Vector3d = new TypeData {
ManagedType = "Vector3d",
NativeType = "vector_double3",
Expand All @@ -3371,12 +3432,19 @@ public static class Types {
NativeWrapperType = "struct Vector4d", // Yes, Vector4d, since NVector3d has 4 doubles.
RequireMarshal = true,
};
public static TypeData Vector4d = new TypeData {
public static TypeData Vector4d;
public static TypeData OpenTK_Vector4d = new TypeData {
ManagedType = "Vector4d",
NativeType = "vector_double4",
NativeWrapperType = "struct Vector4d",
RequireMarshal = true,
};
public static TypeData NVector4d = new TypeData {
ManagedType = "NVector4d",
NativeType = "vector_double4",
NativeWrapperType = "struct Vector4d",
RequireMarshal = true,
};
public static TypeData Matrix2f = new TypeData {
ManagedType = "Matrix2",
NativeType = "matrix_float2x2",
Expand Down Expand Up @@ -3413,7 +3481,8 @@ public static class Types {
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData Matrix4f = new TypeData {
public static TypeData Matrix4f;
public static TypeData OpenTK_Matrix4f = new TypeData {
ManagedType = "Matrix4",
NativeType = "matrix_float4x4",
NativeWrapperType = "struct Matrix4f",
Expand All @@ -3422,6 +3491,15 @@ public static class Types {
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData Numerics_Matrix4f = new TypeData {
ManagedType = "Matrix4x4",
NativeType = "matrix_float4x4",
NativeWrapperType = "struct Matrix4f",
RequireMarshal = true,
IsARMStret = true,
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData NMatrix4 = new TypeData {
ManagedType = "NMatrix4",
NativeType = "matrix_float4x4",
Expand Down Expand Up @@ -3601,13 +3679,21 @@ public static class Types {
RequireMarshal = true,
};

public static TypeData QuatD = new TypeData {
public static TypeData QuatD;
public static TypeData OpenTK_QuatD = new TypeData {
ManagedType = "Quaterniond",
NativeType = "simd_quatd",
NativeWrapperType = "struct QuatD",
RequireMarshal = true,
IsX64Stret = true,
};
public static TypeData NQuaterniond = new TypeData {
ManagedType = "NQuaterniond",
NativeType = "simd_quatd",
NativeWrapperType = "struct QuatD",
RequireMarshal = true,
IsX64Stret = true,
};

public static TypeData MPSImageHistogramInfo = new TypeData {
ManagedType = "MPSImageHistogramInfo",
Expand Down
6 changes: 5 additions & 1 deletion src/ARKit/ARCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
//

using System;
#if NET
using Vector2 = global::System.Numerics.Vector2;
using Vector3 = global::CoreGraphics.NVector3;
#else
using Vector2 = global::OpenTK.Vector2;
using Vector3 = global::OpenTK.NVector3;

#endif
#nullable enable

namespace ARKit {
Expand Down
5 changes: 5 additions & 0 deletions src/ARKit/ARFaceGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

using System;
using System.Runtime.InteropServices;
#if NET
using Vector2 = global::System.Numerics.Vector2;
using Vector3 = global::CoreGraphics.NVector3;
#else
using Vector2 = global::OpenTK.Vector2;
using Vector3 = global::OpenTK.NVector3;
#endif

#nullable enable

Expand Down
5 changes: 5 additions & 0 deletions src/ARKit/ARPlaneGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

using System;
using System.Runtime.InteropServices;
#if NET
using Vector2 = global::System.Numerics.Vector2;
using Vector3 = global::CoreGraphics.NVector3;
#else
using Vector2 = global::OpenTK.Vector2;
using Vector3 = global::OpenTK.NVector3;
#endif

#nullable enable

Expand Down
5 changes: 4 additions & 1 deletion src/ARKit/ARPointCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

using System;
using System.Runtime.InteropServices;
#if NET
using Vector3 = global::CoreGraphics.NVector3;
#else
using Vector3 = global::OpenTK.NVector3;

#endif
#nullable enable

namespace ARKit {
Expand Down
4 changes: 4 additions & 0 deletions src/ARKit/ARSkeleton2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

using System;
using System.Runtime.InteropServices;
#if NET
using Vector2 = global::System.Numerics.Vector2;
#else
using Vector2 = global::OpenTK.Vector2;
#endif

#nullable enable

Expand Down
4 changes: 4 additions & 0 deletions src/ARKit/ARSkeleton3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

using System;
using System.Runtime.InteropServices;
#if NET
using Matrix4 = global::CoreGraphics.NMatrix4;
#else
using Matrix4 = global::OpenTK.NMatrix4;
#endif

#nullable enable

Expand Down
1 change: 0 additions & 1 deletion src/AVFoundation/AVCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.ComponentModel;
using OpenTK;
using CoreMedia;
using Foundation;
using ObjCRuntime;
Expand Down
1 change: 0 additions & 1 deletion src/AVFoundation/AVOutputSettingsAssistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using ObjCRuntime;
using CoreAnimation;
using CoreLocation;
using OpenTK;

namespace AVFoundation {

Expand Down
8 changes: 6 additions & 2 deletions src/AVFoundation/AVTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
using System.Runtime.Versioning;

#if !COREBUILD
using OpenTK;
#endif
#if NET
using Vector3 = global::System.Numerics.Vector3;
#else
using Vector3 = global::OpenTK.Vector3;
#endif // NET
#endif // !COREBUILD
using CoreGraphics;
using ObjCRuntime;

Expand Down
Loading

0 comments on commit d79ae8f

Please sign in to comment.