Skip to content

Commit

Permalink
[modelio] Update for iOS 10.2 beta 1 (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentDondain authored and spouliot committed Nov 7, 2016
1 parent 7aa3a42 commit c198dc6
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 5 deletions.
38 changes: 38 additions & 0 deletions runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,44 @@ static IEnumerable<FunctionData> 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)",
Expand Down
37 changes: 37 additions & 0 deletions src/ModelIO/MDLNoiseTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#if XAMCORE_2_0 || !MONOMAC
using System;
using XamCore.ObjCRuntime;
using Vector2i = global::OpenTK.Vector2i;

namespace XamCore.ModelIO {

[iOS (9,0), Mac (10,11, onlyOn64 : true)]
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)
{
}

[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
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
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ MODELIO_CORE_SOURCES = \

MODELIO_SOURCES = \
ModelIO/MDLAsset.cs \
ModelIO/MDLNoiseTexture.cs \
ModelIO/MDLVertexDescriptor.cs \
ModelIO/MDLMesh.cs \

Expand Down
48 changes: 43 additions & 5 deletions src/modelio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 ();

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -763,6 +773,12 @@ NSMutableArray<MDLSubmesh> 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")]
Expand All @@ -772,6 +788,11 @@ NSMutableArray<MDLSubmesh> 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);
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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:")]
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1929,6 +1963,10 @@ 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);

[NullAllowed, Export ("faceTopology", ArgumentSemantic.Retain)]
IMDLMeshBuffer FaceTopology { get; set; }

Expand Down
7 changes: 7 additions & 0 deletions tests/introspection/ApiSelectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:":
Expand Down
77 changes: 77 additions & 0 deletions tests/monotouch-test/ModelIO/MDLNoiseTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// MDLNoiseTexture Unit Tests
//
// Authors:
// Vincent Dondain <vidondai@microsoft.com>
//
// 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__

0 comments on commit c198dc6

Please sign in to comment.