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
26 changes: 26 additions & 0 deletions src/SceneKit/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using System;

using Foundation;
using ObjCRuntime;

using Vector3 = global::OpenTK.Vector3;
Expand Down Expand Up @@ -364,6 +365,7 @@ public enum SCNRenderingApi : ulong
{
Metal,
#if !MONOMAC
[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
OpenGLES2,
#else
OpenGLLegacy,
Expand Down Expand Up @@ -458,4 +460,28 @@ public enum SCNNodeFocusBehavior : long
Occluding,
Focusable,
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
public enum SCNLightProbeType : long
{
Irradiance = 0,
Radiance = 1,
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
public enum SCNLightProbeUpdateType : long
{
Never = 0,
Realtime = 1,
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
public enum SCNLightAreaType : long
{
Rectangle = 1,
Polygon = 4,
}
}
195 changes: 194 additions & 1 deletion src/scenekit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

using NMatrix4 = global::OpenTK.NMatrix4;
using NVector3 = global::OpenTK.NVector3;
using Vector3 = global::OpenTK.NVector3;
using Vector4 = global::OpenTK.Vector4;
using Quaternion = global::OpenTK.Quaternion;

Expand Down Expand Up @@ -597,8 +598,39 @@ interface SCNCamera : SCNAnimatable, SCNTechniqueSupport, NSCopying, NSSecureCod
[Watch (4, 0), TV (11, 0), Mac (10, 13), iOS (11, 0)]
[Export ("screenSpaceAmbientOcclusionNormalThreshold")]
nfloat ScreenSpaceAmbientOcclusionNormalThreshold { get; set; }

#endif

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("projectionTransformWithViewportSize:")]
SCNMatrix4 GetProjectionTransform (CGSize viewportSize);

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("bloomIterationCount")]
nint BloomIterationCount { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("bloomIterationSpread")]
nfloat BloomIterationSpread { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("grainIntensity")]
nfloat GrainIntensity { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("grainScale")]
nfloat GrainScale { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("grainIsColored")]
bool GrainIsColored { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("whiteBalanceTemperature")]
nfloat WhiteBalanceTemperature { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("whiteBalanceTint")]
nfloat WhiteBalanceTint { get; set; }
}

interface ISCNCameraControlConfiguration {}
Expand Down Expand Up @@ -1135,6 +1167,10 @@ interface SCNHitTest {
[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
[Field ("SCNHitTestOptionSearchMode")]
NSString SearchModeKey { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Field ("SCNHitTestOptionIgnoreLightArea")]
NSString IgnoreLightAreaKey { get; }
}

[Watch (3,0)]
Expand Down Expand Up @@ -1177,6 +1213,8 @@ interface SCNHitTestResult {

#if MONOMAC
[iOS (8,0)]
[Deprecated (PlatformName.MacOSX, 10, 14, message: "OpenGL API deprecated, please use Metal instead.")]
[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
[BaseType (typeof (CAOpenGLLayer))]
interface SCNLayer : SCNSceneRenderer, SCNTechniqueSupport {
// We already pull in the Scene property from the SCNSceneRenderer protocol, no need to redefine it here.
Expand Down Expand Up @@ -1340,6 +1378,83 @@ interface SCNLight : SCNAnimatable, SCNTechniqueSupport, NSCopying, NSSecureCodi
[Export ("lightWithMDLLight:")]
SCNLight FromModelLight (MDLLight mdllight);
#endif

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("probeType", ArgumentSemantic.Assign)]
SCNLightProbeType ProbeType { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("probeUpdateType", ArgumentSemantic.Assign)]
SCNLightProbeUpdateType ProbeUpdateType { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("probeExtents", ArgumentSemantic.Assign)]
Vector3 ProbeExtents {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noob question - What does the MarshalDirective do here? Does NativePrefix = "xamarin_simd__" mean that this binding has something to do AOT compilation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarshalDirective is a workaround we have to work around a calling convention limitation with P/Invokes.

The problem is that certain native types (such as Vector3) are not put in the normal registers when used as parameters to methods, instead they're passed in special SIMD registers. Unfortunately managed code (i.e. P/Invokes) doesn't know about this, so we can't call these native methods using P/Invokes because the arguments would be in the wrong registers.

Our workaround is a bit involved: we generate a native wrapper method where the parameters are passed in the expected registers, and that calls the actual native function, so that the native compiler puts the arguments in the right registers. The MarshalDirective attribute tells the generator that it should generate a call to the wrapper method instead of the normal P/Invoke (and that the name of the wrapper method is the name of the native function prefixed by xamarin_simd__, and the library where the wrapper method is located - __Internal means the executable itself).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 (takes it in slowly)
Thanks! 😃

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("probeOffset", ArgumentSemantic.Assign)]
Vector3 ProbeOffset {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("parallaxCorrectionEnabled")]
bool ParallaxCorrectionEnabled { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("parallaxExtentsFactor", ArgumentSemantic.Assign)]
Vector3 ParallaxExtentsFactor {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("parallaxCenterOffset", ArgumentSemantic.Assign)]
Vector3 ParallaxCenterOffset {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[NullAllowed, Export ("probeEnvironment")]
SCNMaterialProperty ProbeEnvironment { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("areaType", ArgumentSemantic.Assign)]
SCNLightAreaType AreaType { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("areaExtents", ArgumentSemantic.Assign)]
Vector3 AreaExtents {
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
get;
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")]
set;
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[NullAllowed, Export ("areaPolygonVertices", ArgumentSemantic.Copy)]
NSValue[] AreaPolygonVertices { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("drawsArea")]
bool DrawsArea { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("doubleSided")]
bool DoubleSided { get; set; }
}

[Watch (3,0)]
Expand All @@ -1365,6 +1480,10 @@ interface SCNLightType {
[TV (10, 0), Mac (10, 12), iOS (10, 0)]
[Field ("SCNLightTypeProbe")]
NSString Probe { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Field ("SCNLightTypeArea")]
NSString Area { get; }
}

#if MONOMAC
Expand Down Expand Up @@ -1413,6 +1532,10 @@ interface SCNLightingModel {
[TV (10, 0), Mac (10, 12), iOS (10, 0)]
[Field ("SCNLightingModelPhysicallyBased")]
NSString PhysicallyBased { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Field ("SCNLightingModelShadowOnly")]
NSString ShadowOnly { get; }
}

[Watch (3,0)]
Expand Down Expand Up @@ -1525,6 +1648,18 @@ interface SCNMaterial : SCNAnimatable, SCNShadable, NSCopying, NSSecureCoding {
SCNColorMask ColorBufferWriteMask { get; set; }

#endif

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("clearCoat")]
SCNMaterialProperty ClearCoat { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("clearCoatRoughness")]
SCNMaterialProperty ClearCoatRoughness { get; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("clearCoatNormal")]
SCNMaterialProperty ClearCoatNormal { get; }
}

[Watch (3,0)]
Expand Down Expand Up @@ -1552,6 +1687,7 @@ interface SCNMaterialProperty : SCNAnimatable, NSSecureCoding {

[Deprecated (PlatformName.iOS, 10, 0)]
[Deprecated (PlatformName.MacOSX, 10, 12)]
[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
[NoWatch, NoTV]
[NullAllowed, Export ("borderColor", ArgumentSemantic.Retain)]
NSObject BorderColor { get; set; }
Expand Down Expand Up @@ -1625,6 +1761,8 @@ interface SCNHitTestOptions {
bool IgnoreHiddenNodes { get; set; }
SCNNode RootNode { get; set; }
SCNHitTestSearchMode SearchMode { get; set; }
[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
bool IgnoreLightArea { get; set; }
}

[Watch (3,0)]
Expand Down Expand Up @@ -2362,6 +2500,7 @@ interface SCNProgramDelegate {
[NoTV, NoWatch]
#endif
[Availability (Deprecated = Platform.Mac_10_10, Message = "Use the SCNProgram's Opaque property instead.")]
[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
[Export ("programIsOpaque:")]
bool IsProgramOpaque (SCNProgram program);
#endif
Expand Down Expand Up @@ -2418,6 +2557,7 @@ interface SCNRenderer : SCNSceneRenderer, SCNTechniqueSupport {
[Export ("render")]
[Deprecated (PlatformName.MacOSX, 10, 11)]
[Deprecated (PlatformName.iOS, 9, 0)]
[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
void Render ();

[Mac (10,10)]
Expand Down Expand Up @@ -2620,6 +2760,22 @@ bool WriteToUrl (NSUrl url,
[Export ("sceneWithMDLAsset:")]
SCNScene FromAsset (MDLAsset asset);
#endif

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("wantsScreenSpaceReflection")]
bool WantsScreenSpaceReflection { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("screenSpaceReflectionSampleCount")]
nint ScreenSpaceReflectionSampleCount { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("screenSpaceReflectionMaximumDistance")]
nfloat ScreenSpaceReflectionMaximumDistance { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("screenSpaceReflectionStride")]
nfloat ScreenSpaceReflectionStride { get; set; }
}

interface ISCNSceneExportDelegate { }
Expand Down Expand Up @@ -3082,6 +3238,27 @@ interface SCNSceneRenderer {
[NullAllowed, Export ("audioListener", ArgumentSemantic.Retain)]
[DebuggerBrowsable (DebuggerBrowsableState.Never)]
SCNNode AudioListener { get; set; }

#if XAMCORE_4_0
[Abstract] // this protocol existed before iOS 9 (or OSX 10.11) and we cannot add abstract members to it (breaking changes)
#endif
[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("temporalAntialiasingEnabled")]
bool TemporalAntialiasingEnabled { [Bind ("isTemporalAntialiasingEnabled")] get; set; }

#if XAMCORE_4_0
[Abstract] // this protocol existed before iOS 9 (or OSX 10.11) and we cannot add abstract members to it (breaking changes)
#endif
[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("currentViewport")]
CGRect CurrentViewport { get; }

#if XAMCORE_4_0
[Abstract] // this protocol existed before iOS 9 (or OSX 10.11) and we cannot add abstract members to it (breaking changes)
#endif
[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("usesReverseZ")]
bool UsesReverseZ { get; set; }
}

[Watch (3,0)]
Expand Down Expand Up @@ -3287,6 +3464,7 @@ interface SCNTube {
[Internal] // we'll make it public if there's a need for them (beside the strong dictionary we provide)
interface SCNRenderingOptionsKeys {

[Unavailable (PlatformName.MacCatalyst)][Advice ("This API is not available when using UIKit on macOS.")]
[Field ("SCNPreferredRenderingAPIKey")]
NSString RenderingApiKey { get; }

Expand Down Expand Up @@ -3329,12 +3507,16 @@ interface SCNView : SCNSceneRenderer, SCNTechniqueSupport {
bool AllowsCameraControl { get; set; }

#if MONOMAC
[Deprecated (PlatformName.MacOSX, 10, 14, message: "OpenGL API deprecated, please use Metal instead.")]
[Export ("openGLContext", ArgumentSemantic.Retain)]
NSOpenGLContext OpenGLContext { get; set; }

[Deprecated (PlatformName.MacOSX, 10, 14, message: "OpenGL API deprecated, please use Metal instead.")]
[Export ("pixelFormat", ArgumentSemantic.Retain)]
NSOpenGLPixelFormat PixelFormat { get; set; }
#elif !WATCH
[Deprecated (PlatformName.iOS, 12, 0, message: "OpenGL API deprecated, please use Metal instead.")]
[Deprecated (PlatformName.TvOS, 12, 0, message: "OpenGL API deprecated, please use Metal instead.")]
[Export ("eaglContext", ArgumentSemantic.Retain)]
#if XAMCORE_2_0
EAGLContext EAGLContext { get; set; }
Expand Down Expand Up @@ -3388,6 +3570,10 @@ interface SCNView : SCNSceneRenderer, SCNTechniqueSupport {
[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
[Export ("rendersContinuously")]
bool RendersContinuously { get; set; }

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
[Export ("drawableResizesAsynchronously")]
bool DrawableResizesAsynchronously { get; set; }
}

#if XAMCORE_4_0
Expand Down Expand Up @@ -3894,6 +4080,13 @@ interface SCNTechnique : SCNAnimatable, NSCopying, NSSecureCoding {
[iOS (9,0)][Mac (10,11)]
[Internal, Export ("setObject:forKeyedSubscript:")]
void _SetObject ([NullAllowed] NSObject obj, INSCopying key);

#if XAMCORE_2_0 // Metal is 64 bit only

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is XAMCORE_2_0 now, so this #if is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True it's redundant but the PR is mergeable right now so I'm not gonna rebuild it (:
Will avoid next time.

[NoWatch]
[TV (13,0), Mac (10,15), iOS (13,0)]
[NullAllowed, Export ("library", ArgumentSemantic.Strong)]
IMTLLibrary Library { get; set; }
#endif
}

[Watch (3,0)]
Expand Down
10 changes: 10 additions & 0 deletions tests/xtro-sharpie/common-SceneKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
!incorrect-protocol-member! SCNSceneRenderer::depthPixelFormat is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::device is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::stencilPixelFormat is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::currentViewport is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::isTemporalAntialiasingEnabled is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::setTemporalAntialiasingEnabled: is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::setUsesReverseZ: is REQUIRED and should be abstract
!incorrect-protocol-member! SCNSceneRenderer::usesReverseZ is REQUIRED and should be abstract

## same for SCNActionable, it is required member of a protocol added to XAMCORE_4_0
!incorrect-protocol-member! SCNActionable::actionKeys is REQUIRED and should be abstract
Expand Down Expand Up @@ -80,6 +85,11 @@
!missing-selector! SCNNode::simdWorldRight not bound
!missing-selector! SCNNode::simdWorldTransform not bound
!missing-selector! SCNNode::simdWorldUp not bound
!missing-selector! SCNHitTestResult::simdLocalCoordinates not bound
!missing-selector! SCNHitTestResult::simdLocalNormal not bound
!missing-selector! SCNHitTestResult::simdModelTransform not bound
!missing-selector! SCNHitTestResult::simdWorldCoordinates not bound
!missing-selector! SCNHitTestResult::simdWorldNormal not bound

## untyped enum (SceneKitTypes.h) but described as the value of `code` for `NSError` which is an NSInteger
!unknown-native-enum! SCNErrorCode bound
Loading