diff --git a/MetalScope.xcodeproj/project.pbxproj b/MetalScope.xcodeproj/project.pbxproj index 7d830cd..45d0d19 100644 --- a/MetalScope.xcodeproj/project.pbxproj +++ b/MetalScope.xcodeproj/project.pbxproj @@ -258,7 +258,7 @@ BFB8916F1E2E013400FA9129 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "eje Inc."; TargetAttributes = { BFB891771E2E013400FA9129 = { @@ -355,6 +355,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -362,6 +363,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -389,12 +391,13 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -414,6 +417,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -421,6 +425,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -442,10 +447,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -466,12 +472,13 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -488,11 +495,12 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme b/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme index acbc580..c6f619d 100644 --- a/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme +++ b/MetalScope.xcodeproj/xcshareddata/xcschemes/MetalScope.xcscheme @@ -1,6 +1,6 @@ Bool { diff --git a/Sources/RenderLoop.swift b/Sources/RenderLoop.swift index f95f829..5da6eec 100644 --- a/Sources/RenderLoop.swift +++ b/Sources/RenderLoop.swift @@ -19,7 +19,7 @@ public final class RenderLoop { private lazy var displayLink: CADisplayLink = { let link = CADisplayLink(target: self, selector: #selector(handleDisplayLink(_:))) - link.add(to: .main, forMode: .commonModes) + link.add(to: .main, forMode: RunLoop.Mode.common) link.isPaused = true return link }() diff --git a/Sources/StereoRenderer.swift b/Sources/StereoRenderer.swift index 3fd4208..2ef5723 100644 --- a/Sources/StereoRenderer.swift +++ b/Sources/StereoRenderer.swift @@ -51,9 +51,13 @@ internal final class StereoRenderer { ) eyeTextureDescriptor.usage = .renderTarget + guard let texture = device.makeTexture(descriptor: eyeTextureDescriptor) else { + fatalError("Failed to makeTexture") + } + eyeRenderingConfigurations = [ - .left: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)), - .right: EyeRenderingConfiguration(texture: device.makeTexture(descriptor: eyeTextureDescriptor)) + .left: EyeRenderingConfiguration(texture: texture), + .right: EyeRenderingConfiguration(texture: texture) ] } @@ -75,7 +79,10 @@ internal final class StereoRenderer { for (eye, configuration) in eyeRenderingConfigurations { semaphore.wait() - let commandBuffer = commandQueue.makeCommandBuffer() + guard + let commandBuffer = commandQueue.makeCommandBuffer(), + let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() + else { return } rendererDelegateProxy.currentRenderingEye = eye @@ -99,7 +106,6 @@ internal final class StereoRenderer { destinationOrigin = MTLOrigin(x: outputTexture.width / 2, y: 0, z: 0) } - let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() blitCommandEncoder.copy( from: texture, sourceSlice: 0, diff --git a/Sources/StereoScene.swift b/Sources/StereoScene.swift index 105ea48..bd11742 100644 --- a/Sources/StereoScene.swift +++ b/Sources/StereoScene.swift @@ -57,7 +57,7 @@ internal final class StereoScene: SCNScene { let mesh = SCNGeometry( sources: [ - SCNGeometrySource(vertices: vertices, count: vertices.count), + SCNGeometrySource(vertices: vertices), SCNGeometrySource(texcoord: texcoord), SCNGeometrySource(colors: colors) ], diff --git a/Sources/StereoView.swift b/Sources/StereoView.swift index 1819d76..6ae5829 100644 --- a/Sources/StereoView.swift +++ b/Sources/StereoView.swift @@ -144,7 +144,10 @@ public final class StereoView: UIView, SceneLoadable { height: Int(textureSize.height), mipmapped: true ) - let texture = device.makeTexture(descriptor: textureDescriptor) + + guard let texture = device.makeTexture(descriptor: textureDescriptor) else { + fatalError("Failed to makeTexture") + } self.init(stereoTexture: texture) diff --git a/Sources/StereoViewController.swift b/Sources/StereoViewController.swift index 71cb12a..9b2783f 100644 --- a/Sources/StereoViewController.swift +++ b/Sources/StereoViewController.swift @@ -344,7 +344,7 @@ open class StereoViewController: UIViewController, SceneLoadable { precondition(introductionViewUpdateTimer == nil) let timer = DispatchSource.makeTimerSource(queue: .main) - timer.scheduleRepeating(deadline: .now() + delay, interval: interval) + timer.schedule(deadline: .now() + delay, repeating: interval) timer.setEventHandler { [weak self] in guard self?.isViewLoaded == true, let _ = self?.introductionView else { return diff --git a/Sources/VideoScene.swift b/Sources/VideoScene.swift index 00fc5b9..7327cbd 100644 --- a/Sources/VideoScene.swift +++ b/Sources/VideoScene.swift @@ -75,7 +75,10 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene public init(renderer: PlayerRenderer) { self.renderer = renderer - commandQueue = renderer.device.makeCommandQueue() + guard let commandQueue = renderer.device.makeCommandQueue() else { + fatalError("Failed to makeCommandQueue()") + } + self.commandQueue = commandQueue super.init() renderLoop.resume() } @@ -110,12 +113,12 @@ public final class MonoSphericalVideoScene: MonoSphericalMediaScene, VideoScene updateTextureIfNeeded() - guard let texture = playerTexture else { - return - } + guard + let texture = playerTexture, + let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer() + else { return } do { - let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer() try renderer.render(atHostTime: time, to: texture, commandBuffer: commandBuffer) commandBuffer.commit() } catch let error as CVError { @@ -163,7 +166,10 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc public init(renderer: PlayerRenderer) { self.renderer = renderer - commandQueue = renderer.device.makeCommandQueue() + guard let commandQueue = renderer.device.makeCommandQueue() else { + fatalError("Failed to makeCommandQueue()") + } + self.commandQueue = commandQueue super.init() renderLoop.resume() } @@ -202,17 +208,16 @@ public final class StereoSphericalVideoScene: StereoSphericalMediaScene, VideoSc updateTexturesIfNeeded() - guard let playerTexture = playerTexture else { - return - } - - let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer() + guard + let playerTexture = playerTexture, + let commandBuffer = (commandQueue ?? self.commandQueue).makeCommandBuffer(), + let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() + else { return } do { try renderer.render(atHostTime: time, to: playerTexture, commandBuffer: commandBuffer) func copyPlayerTexture(region: MTLRegion, to sphereTexture: MTLTexture) { - let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder() blitCommandEncoder.copy( from: playerTexture, sourceSlice: 0,