From 6fe54db6898888d3d458fd38526c1d672345a4ea Mon Sep 17 00:00:00 2001 From: Vincent Dondain Date: Fri, 4 Nov 2016 21:08:50 +0100 Subject: [PATCH 1/2] [modelio] Update for iOS 10.2 beta 1 --- runtime/bindings-generator.cs | 38 +++++++++ src/ModelIO/MDLNoiseTexture.cs | 35 +++++++++ src/frameworks.sources | 1 + src/modelio.cs | 47 +++++++++-- tests/introspection/ApiSelectorTest.cs | 7 ++ .../monotouch-test/ModelIO/MDLNoiseTexture.cs | 77 +++++++++++++++++++ 6 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 src/ModelIO/MDLNoiseTexture.cs create mode 100644 tests/monotouch-test/ModelIO/MDLNoiseTexture.cs diff --git a/runtime/bindings-generator.cs b/runtime/bindings-generator.cs index ef3fa09f2fa2..7e12d5957a80 100644 --- a/runtime/bindings-generator.cs +++ b/runtime/bindings-generator.cs @@ -512,6 +512,44 @@ static IEnumerable GetFunctionData () } ); + data.Add ( + new FunctionData { + Comment = " // IntPtr func (float, Vector2, nuint, nuint, nuint, int, bool, IntPtr)", + Prefix = "simd__", + Variants = Variants.NonStret, + ReturnType = Types.IntPtr, + Parameters = new ParameterData[] { + new ParameterData { TypeData = Types.Float }, + new ParameterData { TypeData = Types.Vector2 }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.Int32 }, + new ParameterData { TypeData = Types.Bool }, + new ParameterData { TypeData = Types.IntPtr }, + }, + } + ); + + data.Add ( + new FunctionData { + Comment = " // IntPtr func (float, Vector2, nuint, nuint, nuint, Int64, bool, IntPtr)", + Prefix = "simd__", + Variants = Variants.NonStret, + ReturnType = Types.IntPtr, + Parameters = new ParameterData[] { + new ParameterData { TypeData = Types.Float }, + new ParameterData { TypeData = Types.Vector2 }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.NUInt }, + new ParameterData { TypeData = Types.Int64 }, + new ParameterData { TypeData = Types.Bool }, + new ParameterData { TypeData = Types.IntPtr }, + }, + } + ); + data.Add ( new FunctionData { Comment = " // bool func (Vector2i, IntPtr, IntPtr, IntPtr, IntPtr)", diff --git a/src/ModelIO/MDLNoiseTexture.cs b/src/ModelIO/MDLNoiseTexture.cs new file mode 100644 index 000000000000..7160b12f9425 --- /dev/null +++ b/src/ModelIO/MDLNoiseTexture.cs @@ -0,0 +1,35 @@ +#if XAMCORE_2_0 || !MONOMAC +using System; +using XamCore.ObjCRuntime; +using Vector2i = global::OpenTK.Vector2i; + +namespace XamCore.ModelIO { + + public enum MDLNoiseTextureType { + Vector, + Cellular, + } + + public partial class MDLNoiseTexture { + [iOS (9,0), Mac (10,11, onlyOn64 : true)] + public MDLNoiseTexture (float input, string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding) : this (input, name, textureDimensions, channelEncoding, MDLNoiseTextureType.Vector) + { + } + + public MDLNoiseTexture (float input, string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding, MDLNoiseTextureType type) + { + // two different `init*` would share the same C# signature + switch (type) { + case MDLNoiseTextureType.Vector: + Handle = InitVectorNoiseWithSmoothness (input, name, textureDimensions, channelEncoding); + break; + case MDLNoiseTextureType.Cellular: + Handle = InitCellularNoiseWithFrequency (input, name, textureDimensions, channelEncoding); + break; + default: + throw new ArgumentException ("type"); + } + } + } +} +#endif \ No newline at end of file diff --git a/src/frameworks.sources b/src/frameworks.sources index e1a4bcb24b34..7f005c2ac409 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -945,6 +945,7 @@ MODELIO_CORE_SOURCES = \ MODELIO_SOURCES = \ ModelIO/MDLAsset.cs \ + ModelIO/MDLNoiseTexture.cs \ ModelIO/MDLVertexDescriptor.cs \ ModelIO/MDLMesh.cs \ diff --git a/src/modelio.cs b/src/modelio.cs index 6b4b0ee4ed3e..eb6bbf6781ec 100644 --- a/src/modelio.cs +++ b/src/modelio.cs @@ -37,6 +37,8 @@ namespace XamCore.ModelIO { + delegate void MDLObjectHandler (MDLObject mdlObject, ref bool stop); + [iOS (9,0)][Mac(10,11, onlyOn64 : true)] [BaseType (typeof(MDLPhysicallyPlausibleLight))] [DisableDefaultCtor] @@ -415,6 +417,10 @@ interface MDLMaterial : MDLNamed, INSFastEnumeration [return: NullAllowed] MDLMaterialProperty GetProperty (MDLMaterialSemantic semantic); + [iOS (10,2), Mac (10,12,1)] + [Export ("propertiesWithSemantic:")] + MDLMaterialProperty[] GetProperties (MDLMaterialSemantic semantic); + [Export ("removeAllProperties")] void RemoveAllProperties (); @@ -645,7 +651,11 @@ nuint VertexCount { } [Export ("vertexBuffers", ArgumentSemantic.Retain)] - IMDLMeshBuffer[] VertexBuffers { get; } + IMDLMeshBuffer[] VertexBuffers { + get; + [iOS (10,2), Mac (10,12,1), TV (10,1)] + set; + } [NullAllowed] [Export ("submeshes", ArgumentSemantic.Copy)] @@ -763,6 +773,12 @@ NSMutableArray Submeshes { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] MDLMesh CreateCylindroid (float height, Vector2 radii, nuint radialSegments, nuint verticalSegments, MDLGeometryType geometryType, bool inwardNormals, [NullAllowed] IMDLMeshBufferAllocator allocator); + [Static] + [iOS (10,2), Mac (12,1,1), TV (10,1)] + [Export ("newCapsuleWithHeight:radii:radialSegments:verticalSegments:hemisphereSegments:geometryType:inwardNormals:allocator:")] + [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] + MDLMesh CreateCapsule (float height, Vector2 radii, nuint radialSegments, nuint verticalSegments, nuint hemisphereSegments, MDLGeometryType geometryType, bool inwardNormals, [NullAllowed] IMDLMeshBufferAllocator allocator); + [Static] [Export ("newEllipticalConeWithHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:")] [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] @@ -772,6 +788,11 @@ NSMutableArray Submeshes { [Export ("newIcosahedronWithRadius:inwardNormals:allocator:")] MDLMesh CreateIcosahedron (float radius, bool inwardNormals, [NullAllowed] IMDLMeshBufferAllocator allocator); + [Static] + [iOS (10,2), Mac (12,1,1), TV (10,1)] + [Export ("newIcosahedronWithRadius:inwardNormals:geometryType:allocator:")] + MDLMesh CreateIcosahedron (float radius, bool inwardNormals, MDLGeometryType geometryType, [NullAllowed] IMDLMeshBufferAllocator allocator); + [Static] [Export ("newSubdividedMesh:submeshIndex:subdivisionLevels:")] MDLMesh CreateSubdividedMesh (MDLMesh mesh, nuint submeshIndex, nuint subdivisionLevels); @@ -932,13 +953,20 @@ interface MDLNoiseTexture [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] IntPtr Constructor ([NullAllowed] NSData pixelData, bool topLeftOrigin, [NullAllowed] string name, Vector2i dimensions, nint rowStride, nuint channelCount, MDLTextureChannelEncoding channelEncoding, bool isCube); + [Internal] [Export ("initVectorNoiseWithSmoothness:name:textureDimensions:channelEncoding:")] [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] - IntPtr Constructor (float smoothness, [NullAllowed] string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding); + IntPtr InitVectorNoiseWithSmoothness (float smoothness, [NullAllowed] string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding); [Export ("initScalarNoiseWithSmoothness:name:textureDimensions:channelCount:channelEncoding:grayscale:")] [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] IntPtr Constructor (float smoothness, [NullAllowed] string name, Vector2i textureDimensions, int channelCount, MDLTextureChannelEncoding channelEncoding, bool grayscale); + + [Internal] + [iOS (10,2), Mac (12,1,1)] + [Export ("initCellularNoiseWithFrequency:name:textureDimensions:channelEncoding:")] + [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] + IntPtr InitCellularNoiseWithFrequency (float frequency, [NullAllowed] string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding); } [iOS (9,0), Mac(10,11, onlyOn64 : true)] @@ -986,6 +1014,10 @@ interface MDLObject : MDLNamed [Export ("objectAtPath:")] MDLObject GetObject (string path); + [iOS (10,2), Mac (12,1,1), TV (10,1)] + [Export ("enumerateChildObjectsOfClass:root:usingBlock:stopPointer:")] + void EnumerateChildObjects (Class objectClass, MDLObject root, MDLObjectHandler handler, ref bool stop); + [NullAllowed, Export ("transform", ArgumentSemantic.Retain)] IMDLTransformComponent Transform { get; set; } @@ -1304,7 +1336,11 @@ interface MDLSubmesh : MDLNamed MDLMaterial Material { get; set; } [NullAllowed, Export ("topology", ArgumentSemantic.Retain)] - MDLSubmeshTopology Topology { get; } + MDLSubmeshTopology Topology { + get; + [iOS (10,2), Mac (12,1,1), TV (10,1)] + set; + } [Static] [Export ("submeshWithSCNGeometryElement:")] @@ -1739,8 +1775,6 @@ interface MDLVertexDescriptor : NSCopying interface MDLVoxelArray { - [Deprecated (PlatformName.MacOSX, 10, 12, message: "Use new MDLVoxelArray (MDLAsset, int, float)")] - [Obsoleted (PlatformName.iOS, 10, 0, message: "Use new MDLVoxelArray (MDLAsset, int, float)")] [Export ("initWithAsset:divisions:interiorShells:exteriorShells:patchRadius:")] IntPtr Constructor (MDLAsset asset, int divisions, int interiorShells, int exteriorShells, float patchRadius); @@ -1929,6 +1963,9 @@ interface MDLVertexBufferLayout : NSCopying [iOS (9,0)][Mac(10,11, onlyOn64 : true)] [BaseType (typeof (NSObject))] interface MDLSubmeshTopology { + [Export ("initWithSubmesh:")] + IntPtr Constructor (MDLSubmesh submesh); + [NullAllowed, Export ("faceTopology", ArgumentSemantic.Retain)] IMDLMeshBuffer FaceTopology { get; set; } diff --git a/tests/introspection/ApiSelectorTest.cs b/tests/introspection/ApiSelectorTest.cs index 5fa3219ce0da..9c13c9b16745 100644 --- a/tests/introspection/ApiSelectorTest.cs +++ b/tests/introspection/ApiSelectorTest.cs @@ -176,6 +176,13 @@ protected virtual bool Skip (Type type, string selectorName) return true; } break; + case "MDLNoiseTexture": + switch (selectorName) { + case "initCellularNoiseWithFrequency:name:textureDimensions:channelEncoding:": + case "initVectorNoiseWithSmoothness:name:textureDimensions:channelEncoding:": + return true; + } + break; case "NSImage": switch (selectorName) { case "initByReferencingFile:": diff --git a/tests/monotouch-test/ModelIO/MDLNoiseTexture.cs b/tests/monotouch-test/ModelIO/MDLNoiseTexture.cs new file mode 100644 index 000000000000..e9339aba0b3e --- /dev/null +++ b/tests/monotouch-test/ModelIO/MDLNoiseTexture.cs @@ -0,0 +1,77 @@ +// +// MDLNoiseTexture Unit Tests +// +// Authors: +// Vincent Dondain +// +// Copyright 2016 Microsoft +// + +#if !__WATCHOS__ + +using System; +#if XAMCORE_2_0 +using Foundation; +using ModelIO; +using ObjCRuntime; +#else +using MonoTouch.Foundation; +using MonoTouch.ModelIO; +using MonoTouch.ObjCRuntime; +#endif +using OpenTK; +using NUnit.Framework; + +namespace MonoTouchFixtures.ModelIO +{ + + [TestFixture] + // we want the test to be available if we use the linker + [Preserve (AllMembers = true)] + public class MDLNoiseTextureTest + { + [TestFixtureSetUp] + public void Setup () + { + TestRuntime.AssertXcodeVersion (8, 2); + + if (Runtime.Arch == Arch.SIMULATOR && IntPtr.Size == 4) { + // There's a bug in the i386 version of objc_msgSend where it doesn't preserve SIMD arguments + // when resizing the cache of method selectors for a type. So here we call all selectors we can + // find, so that the subsequent tests don't end up producing any cache resize (radar #21630410). + object dummy; + using (var obj = new MDLNoiseTexture (1.0f, "texture", Vector2i.Zero, MDLTextureChannelEncoding.Float16)) { + dummy = obj.ChannelCount; + dummy = obj.ChannelEncoding; + dummy = obj.Dimensions; + dummy = obj.IsCube; + dummy = obj.MipLevelCount; + dummy = obj.Name; + dummy = obj.RowStride; + obj.GetTexelDataWithBottomLeftOrigin (); + obj.GetTexelDataWithBottomLeftOrigin (1, false); + obj.GetTexelDataWithTopLeftOrigin (); + obj.GetTexelDataWithTopLeftOrigin (1, false); + } + using (var obj = new MDLTexture ()) { + } + } + } + + [Test] + public void Ctor () + { + var V2 = new Vector2i (123, 456); + + using (var obj = new MDLNoiseTexture (1.0f, "texture", V2, MDLTextureChannelEncoding.Float16, MDLNoiseTextureType.Cellular)) { + Asserts.AreEqual (V2, obj.Dimensions, "dimensions"); + } + + using (var obj = new MDLNoiseTexture (1.0f, "texture", V2, MDLTextureChannelEncoding.Float16, MDLNoiseTextureType.Vector)) { + Asserts.AreEqual (V2, obj.Dimensions, "dimensions"); + } + } + } +} + +#endif // !__WATCHOS__ From 5adfa90cd453e067bfa74d998731a159639fca2e Mon Sep 17 00:00:00 2001 From: Vincent Dondain Date: Mon, 7 Nov 2016 18:00:20 +0100 Subject: [PATCH 2/2] [modelio] Add missing availability attributes --- src/ModelIO/MDLNoiseTexture.cs | 2 ++ src/modelio.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/ModelIO/MDLNoiseTexture.cs b/src/ModelIO/MDLNoiseTexture.cs index 7160b12f9425..ac04ed81953e 100644 --- a/src/ModelIO/MDLNoiseTexture.cs +++ b/src/ModelIO/MDLNoiseTexture.cs @@ -5,6 +5,7 @@ namespace XamCore.ModelIO { + [iOS (9,0), Mac (10,11, onlyOn64 : true)] public enum MDLNoiseTextureType { Vector, Cellular, @@ -16,6 +17,7 @@ public MDLNoiseTexture (float input, string name, Vector2i textureDimensions, MD { } + [iOS (10,2), Mac (10,12, onlyOn64 : true)] public MDLNoiseTexture (float input, string name, Vector2i textureDimensions, MDLTextureChannelEncoding channelEncoding, MDLNoiseTextureType type) { // two different `init*` would share the same C# signature diff --git a/src/modelio.cs b/src/modelio.cs index eb6bbf6781ec..e1bc9153cb37 100644 --- a/src/modelio.cs +++ b/src/modelio.cs @@ -1963,6 +1963,7 @@ interface MDLVertexBufferLayout : NSCopying [iOS (9,0)][Mac(10,11, onlyOn64 : true)] [BaseType (typeof (NSObject))] interface MDLSubmeshTopology { + [iOS (10,2), Mac (10,12)] [Export ("initWithSubmesh:")] IntPtr Constructor (MDLSubmesh submesh);