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
32 changes: 32 additions & 0 deletions runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,15 @@ static IEnumerable<FunctionData> GetFunctionData ()
}
);

data.Add (
new FunctionData {
Comment = " // NMatrix4x3 func ()",
Prefix = "simd__",
Variants = Variants.All,
ReturnType = Types.NMatrix4x3,
}
);

// We must expand functions with native types to their actual type as well.
for (int i = data.Count - 1; i >= 0; i--) {
if (!data [i].HasNativeType)
Expand Down Expand Up @@ -2362,6 +2371,13 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
writer.WriteLine ("\t\t{0}{2}columns [i].d = {1}.columns [i] [3];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t}");
break;
case "NMatrix4x3":
writer.WriteLine ("\tfor (int i = 0; i < 4; i++) {");
writer.WriteLine ("\t\t{0}{2}columns [i].a = {1}.columns [i] [0];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t\t{0}{2}columns [i].b = {1}.columns [i] [1];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t\t{0}{2}columns [i].c = {1}.columns [i] [2];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t}");
break;
case "MDLAxisAlignedBoundingBox":
writer.WriteLine ("\t{0}{2}maxBounds.a = {1}.maxBounds [0];", managedVariable, nativeVariable, accessor);
writer.WriteLine ("\t{0}{2}maxBounds.b = {1}.maxBounds [1];", managedVariable, nativeVariable, accessor);
Expand Down Expand Up @@ -2482,6 +2498,13 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
writer.WriteLine ("\t\t{0}.columns [i][3] = {1}{2}columns [i].d;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t}");
break;
case "NMatrix4x3":
writer.WriteLine ("\tfor (int i = 0; i < 4; i++) {");
writer.WriteLine ("\t\t{0}.columns [i][0] = {1}{2}columns [i].a;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t\t{0}.columns [i][1] = {1}{2}columns [i].b;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t\t{0}.columns [i][2] = {1}{2}columns [i].c;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t}");
break;
case "MDLAxisAlignedBoundingBox":
writer.WriteLine ("\t{0}.maxBounds [0] = {1}{2}maxBounds.a;", nativeVariable, managedVariable, accessor);
writer.WriteLine ("\t{0}.maxBounds [1] = {1}{2}maxBounds.b;", nativeVariable, managedVariable, accessor);
Expand Down Expand Up @@ -3046,6 +3069,15 @@ public static class Types {
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData NMatrix4x3 = new TypeData {
ManagedType = "NMatrix4x3",
NativeType = "matrix_float4x3",
NativeWrapperType = "struct NMatrix4x3",
RequireMarshal = true,
IsARMStret = true,
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData Double = new TypeData {
ManagedType = "Double",
NativeType = "double",
Expand Down
6 changes: 6 additions & 0 deletions runtime/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef __attribute__((__ext_vector_type__(4))) float vector_float4;
typedef struct { vector_float2 columns[2]; } matrix_float2x2;
typedef struct { vector_float3 columns[3]; } matrix_float3x3;
typedef struct { vector_float4 columns[4]; } matrix_float4x4;
typedef struct { vector_float3 columns[4]; } matrix_float4x3;

typedef struct { vector_float4 vector; } simd_quatf;

Expand Down Expand Up @@ -178,6 +179,11 @@ struct NMatrix4 {
Vector4f columns [4];
};

struct NMatrix4x3 {
// Use Vector4f here, since the managed version has padding to match accordingly.
Vector4f columns [4];
};

struct QuatF {
Vector4f vector;
};
Expand Down
187 changes: 187 additions & 0 deletions src/Simd/MatrixFloat4x3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
//
// Authors:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright (c) 2017 Microsoft Inc
//

//
// This represents the native matrix_float4x3 type (3 rows and 4 columns)
//

using System;
using System.Runtime.InteropServices;

using VectorFloat4=global::OpenTK.Vector4;

namespace OpenTK
{
[StructLayout (LayoutKind.Sequential)]
public struct NMatrix4x3 : IEquatable<NMatrix4x3>
{
public float M11;
public float M21;
public float M31;
float dummy1;

public float M12;
public float M22;
public float M32;
float dummy2;

public float M13;
public float M23;
public float M33;
float dummy3;

public float M14;
public float M24;
public float M34;
float dummy4;

public NMatrix4x3 (
float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34)
{
M11 = m11;
M21 = m21;
M31 = m31;
M12 = m12;
M22 = m22;
M32 = m32;
M13 = m13;
M23 = m23;
M33 = m33;
M14 = m14;
M24 = m24;
M34 = m34;
dummy1 = 0;
dummy2 = 0;
dummy3 = 0;
dummy4 = 0;
}

public NVector3 Column0 {
get {
return new NVector3 (M11, M21, M31);
}
set {
M11 = value.X;
M21 = value.Y;
M31 = value.Z;
}
}

public NVector3 Column1 {
get {
return new NVector3 (M12, M22, M32);
}
set {
M12 = value.X;
M22 = value.Y;
M32 = value.Z;
}
}

public NVector3 Column2 {
get {
return new NVector3 (M13, M23, M33);
}
set {
M13 = value.X;
M23 = value.Y;
M33 = value.Z;
}
}

public NVector3 Column3 {
get {
return new NVector3 (M14, M24, M34);
}
set {
M14 = value.X;
M24 = value.Y;
M34 = value.Z;
}
}

public Vector4 Row0 {
get {
return new Vector4 (M11, M12, M13, M14);
}
set {
M11 = value.X;
M12 = value.Y;
M13 = value.Z;
M14 = value.W;
}
}

public Vector4 Row1 {
get {
return new Vector4 (M21, M22, M23, M24);
}
set {
M21 = value.X;
M22 = value.Y;
M23 = value.Z;
M24 = value.W;
}
}

public Vector4 Row2 {
get {
return new Vector4 (M31, M32, M33, M34);
}
set {
M31 = value.X;
M32 = value.Y;
M33 = value.Z;
M34 = value.W;
}
}

public static bool operator == (NMatrix4x3 left, NMatrix4x3 right)
{
return left.Equals (right);
}

public static bool operator != (NMatrix4x3 left, NMatrix4x3 right)
{
return !left.Equals (right);
}

public override string ToString ()
{
return
$"({M11}, {M12}, {M13}, {M14})\n" +
$"({M21}, {M22}, {M23}, {M24})\n" +
$"({M31}, {M32}, {M33}, {M34})";
}

public override int GetHashCode ()
{
return
M11.GetHashCode () ^ M12.GetHashCode () ^ M13.GetHashCode () ^ M14.GetHashCode () ^
M21.GetHashCode () ^ M22.GetHashCode () ^ M23.GetHashCode () ^ M24.GetHashCode () ^
M31.GetHashCode () ^ M32.GetHashCode () ^ M33.GetHashCode () ^ M34.GetHashCode ();
}

public override bool Equals (object obj)
{
if (!(obj is NMatrix4x3))
return false;

return Equals ((NMatrix4x3) obj);
}

public bool Equals (NMatrix4x3 other)
{
return
M11 == other.M11 && M12 == other.M12 && M13 == other.M13 && M14 == other.M14 &&
M21 == other.M21 && M22 == other.M22 && M23 == other.M23 && M24 == other.M24 &&
M31 == other.M31 && M32 == other.M32 && M33 == other.M33 && M34 == other.M34;
}
}
}
6 changes: 2 additions & 4 deletions src/avfoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7874,15 +7874,13 @@ interface AVVideoCompositionCoreAnimationTool {
interface AVCameraCalibrationData
{
[Export ("intrinsicMatrix")]
Matrix3 GetIntrinsicMatrix { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get;}
NMatrix3 IntrinsicMatrix { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get; }

[Export ("intrinsicMatrixReferenceDimensions")]
CGSize IntrinsicMatrixReferenceDimensions { get; }

/*
[Export ("extrinsicMatrix")]
Matrix4 GetExtrinsicMatrix { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get;}; // should be a matrix 4x3
*/
NMatrix4x3 ExtrinsicMatrix { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get; }

[Export ("pixelSize")]
float PixelSize { get; }
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,7 @@ SHARED_CORE_SOURCES = \
ObjCRuntime/Selector.cs \
Simd/MatrixFloat2x2.cs \
Simd/MatrixFloat3x3.cs \
Simd/MatrixFloat4x3.cs \
Simd/MatrixFloat4x4.cs \
Simd/VectorFloat3.cs \

Expand Down
13 changes: 13 additions & 0 deletions tests/bindings-test/StructsAndEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using MatrixFloat2x2 = global::OpenTK.NMatrix2;
using MatrixFloat3x3 = global::OpenTK.NMatrix3;
using MatrixFloat4x3 = global::OpenTK.NMatrix4x3;
using MatrixFloat4x4 = global::OpenTK.NMatrix4;

namespace Bindings.Test
Expand All @@ -27,6 +28,9 @@ public static class CFunctions {
[DllImport ("__Internal")]
public static extern void x_get_matrix_float4x4 (IntPtr self, string sel, out float r0c0, out float r0c1, out float r0c2, out float r0c3, out float r1c0, out float r1c1, out float r1c2, out float r1c3, out float r2c0, out float r2c1, out float r2c2, out float r2c3, out float r3c0, out float r3c1, out float r3c2, out float r3c3);

[DllImport ("__Internal")]
public static extern void x_get_matrix_float4x3 (IntPtr self, string sel, out float r0c0, out float r0c1, out float r0c2, out float r0c3, out float r1c0, out float r1c1, out float r1c2, out float r1c3, out float r2c0, out float r2c1, out float r2c2, out float r2c3);

public static MatrixFloat2x2 GetMatrixFloat2x2 (NSObject obj, string selector)
{
float r0c0, r0c1, r1c0, r1c1;
Expand Down Expand Up @@ -58,6 +62,15 @@ public static MatrixFloat4x4 GetMatrixFloat4x4 (NSObject obj, string selector)
r3c0, r3c1, r3c2, r3c3);
}

public static MatrixFloat4x3 GetMatrixFloat4x3 (NSObject obj, string selector)
{
float r0c0, r0c1, r0c2, r0c3, r1c0, r1c1, r1c2, r1c3, r2c0, r2c1, r2c2, r2c3;
x_get_matrix_float4x3 (obj.Handle, selector, out r0c0, out r0c1, out r0c2, out r0c3, out r1c0, out r1c1, out r1c2, out r1c3, out r2c0, out r2c1, out r2c2, out r2c3);
return new MatrixFloat4x3 (
r0c0, r0c1, r0c2, r0c3,
r1c0, r1c1, r1c2, r1c3,
r2c0, r2c1, r2c2, r2c3);
}

#if !__WATCHOS__
[DllImport ("__Internal")]
Expand Down
33 changes: 33 additions & 0 deletions tests/monotouch-test/Asserts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using OpenTK;
using MatrixFloat2x2 = global::OpenTK.NMatrix2;
using MatrixFloat3x3 = global::OpenTK.NMatrix3;
using MatrixFloat4x3 = global::OpenTK.NMatrix4x3;
using MatrixFloat4x4 = global::OpenTK.NMatrix4;
using VectorFloat3 = global::OpenTK.NVector3;
using NUnit.Framework;
Expand Down Expand Up @@ -370,5 +371,37 @@ public static void AreEqual (MatrixFloat4x4 expected, Matrix4 actual, string mes
AreEqual (expected.M34, actual.M34, message + " (M34)");
AreEqual (expected.M44, actual.M44, message + " (M44)");
}

public static void AreEqual (MatrixFloat4x3 expected, MatrixFloat4x3 actual, float delta, string message)
{
AreEqual (expected.M11, actual.M11, delta, message + " (M11)");
AreEqual (expected.M21, actual.M21, delta, message + " (M21)");
AreEqual (expected.M31, actual.M31, delta, message + " (M31)");
AreEqual (expected.M12, actual.M12, delta, message + " (M12)");
AreEqual (expected.M22, actual.M22, delta, message + " (M22)");
AreEqual (expected.M32, actual.M32, delta, message + " (M32)");
AreEqual (expected.M13, actual.M13, delta, message + " (M13)");
AreEqual (expected.M23, actual.M23, delta, message + " (M23)");
AreEqual (expected.M33, actual.M33, delta, message + " (M33)");
AreEqual (expected.M14, actual.M14, delta, message + " (M14)");
AreEqual (expected.M24, actual.M24, delta, message + " (M24)");
AreEqual (expected.M34, actual.M34, delta, message + " (M34)");
}

public static void AreEqual (MatrixFloat4x3 expected, MatrixFloat4x3 actual, string message)
{
AreEqual (expected.M11, actual.M11, message + " (M11)");
AreEqual (expected.M21, actual.M21, message + " (M21)");
AreEqual (expected.M31, actual.M31, message + " (M31)");
AreEqual (expected.M12, actual.M12, message + " (M12)");
AreEqual (expected.M22, actual.M22, message + " (M22)");
AreEqual (expected.M32, actual.M32, message + " (M32)");
AreEqual (expected.M13, actual.M13, message + " (M13)");
AreEqual (expected.M23, actual.M23, message + " (M23)");
AreEqual (expected.M33, actual.M33, message + " (M33)");
AreEqual (expected.M14, actual.M14, message + " (M14)");
AreEqual (expected.M24, actual.M24, message + " (M24)");
AreEqual (expected.M34, actual.M34, message + " (M34)");
}
}

Loading