From 6b8ddc2497e907f3be9e906e826eddbf0140df61 Mon Sep 17 00:00:00 2001 From: Pierre Renaux Date: Wed, 19 Jul 2017 02:56:08 +0800 Subject: [PATCH 1/3] Added .DS_Store to .gitignore ; --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c964cd8..07daa8f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ DerivedData # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control # #Pods/ +.DS_Store From f09fa30a8eda67d75b600539e9104dabcb4c0c7b Mon Sep 17 00:00:00 2001 From: Pierre Renaux Date: Wed, 19 Jul 2017 02:57:39 +0800 Subject: [PATCH 2/3] Updated samples to work correctly with Metal validation in Xcode 9 & iOS 11 ; --- objc/04-DrawingIn3D/DrawingIn3D/MBEMetalView.m | 3 ++- objc/05-Lighting/Lighting/MBEMetalView.m | 2 +- objc/06-Texturing/Texturing/MBEMetalView.m | 2 +- objc/07-Mipmapping/Mipmapping/MBERenderer.m | 1 + objc/08-CubeMapping/CubeMapping/MBERenderer.m | 1 + objc/10-AlphaBlending/AlphaBlending/MBERenderer.m | 1 + objc/11-InstancedDrawing/InstancedDrawing/MBERenderer.m | 1 + objc/12-TextRendering/TextRendering/MBERenderer.m | 1 + objc/14-ImageProcessing/ImageProcessing/MBEImageFilter.m | 1 + 9 files changed, 10 insertions(+), 3 deletions(-) diff --git a/objc/04-DrawingIn3D/DrawingIn3D/MBEMetalView.m b/objc/04-DrawingIn3D/DrawingIn3D/MBEMetalView.m index ef679f1..9726fb2 100644 --- a/objc/04-DrawingIn3D/DrawingIn3D/MBEMetalView.m +++ b/objc/04-DrawingIn3D/DrawingIn3D/MBEMetalView.m @@ -125,7 +125,8 @@ - (void)makeDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; - + desc.usage = MTLTextureUsageRenderTarget; + self.depthTexture = [self.metalLayer.device newTextureWithDescriptor:desc]; } } diff --git a/objc/05-Lighting/Lighting/MBEMetalView.m b/objc/05-Lighting/Lighting/MBEMetalView.m index ef679f1..846f367 100644 --- a/objc/05-Lighting/Lighting/MBEMetalView.m +++ b/objc/05-Lighting/Lighting/MBEMetalView.m @@ -125,7 +125,7 @@ - (void)makeDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; - + desc.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.metalLayer.device newTextureWithDescriptor:desc]; } } diff --git a/objc/06-Texturing/Texturing/MBEMetalView.m b/objc/06-Texturing/Texturing/MBEMetalView.m index ef679f1..846f367 100644 --- a/objc/06-Texturing/Texturing/MBEMetalView.m +++ b/objc/06-Texturing/Texturing/MBEMetalView.m @@ -125,7 +125,7 @@ - (void)makeDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; - + desc.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.metalLayer.device newTextureWithDescriptor:desc]; } } diff --git a/objc/07-Mipmapping/Mipmapping/MBERenderer.m b/objc/07-Mipmapping/Mipmapping/MBERenderer.m index eca5c25..e9c877d 100644 --- a/objc/07-Mipmapping/Mipmapping/MBERenderer.m +++ b/objc/07-Mipmapping/Mipmapping/MBERenderer.m @@ -138,6 +138,7 @@ - (void)buildDepthBuffer width:drawableSize.width height:drawableSize.height mipmapped:NO]; + depthTexDesc.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.device newTextureWithDescriptor:depthTexDesc]; } diff --git a/objc/08-CubeMapping/CubeMapping/MBERenderer.m b/objc/08-CubeMapping/CubeMapping/MBERenderer.m index a8118bf..3a85144 100644 --- a/objc/08-CubeMapping/CubeMapping/MBERenderer.m +++ b/objc/08-CubeMapping/CubeMapping/MBERenderer.m @@ -118,6 +118,7 @@ - (void)buildDepthBuffer width:drawableSize.width height:drawableSize.height mipmapped:NO]; + depthTexDesc.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.device newTextureWithDescriptor:depthTexDesc]; } diff --git a/objc/10-AlphaBlending/AlphaBlending/MBERenderer.m b/objc/10-AlphaBlending/AlphaBlending/MBERenderer.m index 9e774a0..146920c 100644 --- a/objc/10-AlphaBlending/AlphaBlending/MBERenderer.m +++ b/objc/10-AlphaBlending/AlphaBlending/MBERenderer.m @@ -203,6 +203,7 @@ - (void)buildDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; + descriptor.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.device newTextureWithDescriptor:descriptor]; [self.depthTexture setLabel:@"Depth Texture"]; } diff --git a/objc/11-InstancedDrawing/InstancedDrawing/MBERenderer.m b/objc/11-InstancedDrawing/InstancedDrawing/MBERenderer.m index 24da8d4..dd4e02d 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing/MBERenderer.m +++ b/objc/11-InstancedDrawing/InstancedDrawing/MBERenderer.m @@ -194,6 +194,7 @@ - (void)buildDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; + descriptor.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.device newTextureWithDescriptor:descriptor]; [self.depthTexture setLabel:@"Depth Texture"]; } diff --git a/objc/12-TextRendering/TextRendering/MBERenderer.m b/objc/12-TextRendering/TextRendering/MBERenderer.m index a79474e..47f12fc 100644 --- a/objc/12-TextRendering/TextRendering/MBERenderer.m +++ b/objc/12-TextRendering/TextRendering/MBERenderer.m @@ -174,6 +174,7 @@ - (void)buildDepthTexture width:drawableSize.width height:drawableSize.height mipmapped:NO]; + descriptor.usage = MTLTextureUsageRenderTarget; self.depthTexture = [self.device newTextureWithDescriptor:descriptor]; [self.depthTexture setLabel:@"Depth Texture"]; } diff --git a/objc/14-ImageProcessing/ImageProcessing/MBEImageFilter.m b/objc/14-ImageProcessing/ImageProcessing/MBEImageFilter.m index 7124b73..7f56925 100644 --- a/objc/14-ImageProcessing/ImageProcessing/MBEImageFilter.m +++ b/objc/14-ImageProcessing/ImageProcessing/MBEImageFilter.m @@ -47,6 +47,7 @@ - (void)applyFilter width:[inputTexture width] height:[inputTexture height] mipmapped:NO]; + textureDescriptor.usage = MTLTextureUsageShaderWrite|MTLTextureUsageShaderRead; self.internalTexture = [self.context.device newTextureWithDescriptor:textureDescriptor]; } From fed1c83e16e89cd85d04d4cd680d1596d93897d2 Mon Sep 17 00:00:00 2001 From: Warren Moore Date: Fri, 13 Oct 2017 14:27:43 -0700 Subject: [PATCH 3/3] Updated sample code to Xcode 9.0 and iOS SDK 11.0 --- .../ClearScreen.xcodeproj/project.pbxproj | 21 +++++++++++-- .../xcschemes/ClearScreen.xcscheme | 4 ++- .../AppIcon.appiconset/Contents.json | 30 ++++++++++++++++++ .../DrawingIn2D.xcodeproj/project.pbxproj | 31 ++++++++++++++----- .../xcschemes/DrawingIn2D.xcscheme | 4 ++- .../03-DrawingIn2D/DrawingIn2D/MBEMetalView.m | 22 +++++++++++++ .../DrawingIn3D.xcodeproj/project.pbxproj | 26 +++++++++++++--- .../Lighting.xcodeproj/project.pbxproj | 18 ++++++++++- .../Texturing.xcodeproj/project.pbxproj | 27 +++++++++++++--- .../06-Texturing/Texturing/MBETextureLoader.m | 1 + .../Mipmapping.xcodeproj/project.pbxproj | 25 ++++++++++++++- objc/07-Mipmapping/Mipmapping/Info.plist | 6 ++-- .../Mipmapping/MBEMatrixUtilities.h | 2 +- objc/07-Mipmapping/Mipmapping/MBERenderer.m | 10 ++++-- objc/07-Mipmapping/Mipmapping/Shaders.metal | 17 +++++----- .../CubeMapping.xcodeproj/project.pbxproj | 22 ++++++++++++- .../CubeMapping/MBEMatrixUtilities.h | 2 +- objc/08-CubeMapping/CubeMapping/Shaders.metal | 20 ++++++------ .../project.pbxproj | 20 +++++++++++- .../CompressedTextures/MBEMathUtilities.h | 2 +- .../CompressedTextures/MBETextureDataSource.m | 1 + .../AlphaBlending.xcodeproj/project.pbxproj | 24 ++++++++++++-- .../AlphaBlending/MBEMathUtilities.h | 2 +- .../AlphaBlending/MBETextureLoader.m | 1 + .../AlphaBlending/Shaders.metal | 18 +++++------ .../project.pbxproj | 22 ++++++++++++- .../xcschemes/InstancedDrawing.xcscheme | 4 ++- .../InstancedDrawing/Info.plist | 1 + .../InstancedDrawing/MBEMatrixUtilities.h | 2 +- .../InstancedDrawing/Shaders.metal | 14 ++++----- .../TextRendering.xcodeproj/project.pbxproj | 22 ++++++++++++- .../xcschemes/TextRendering.xcscheme | 4 ++- .../TextRendering/MBEMathUtilities.h | 2 +- .../TextRendering/MBERenderer.m | 1 + .../ImageProcessing.xcodeproj/project.pbxproj | 22 ++++++++++++- .../ImageProcessing/MBEGaussianBlur2DFilter.m | 3 +- .../ImageProcessing/MBEImageFilter.m | 2 +- .../MBEMainBundleTextureProvider.m | 1 + 38 files changed, 374 insertions(+), 82 deletions(-) diff --git a/objc/02-ClearScreen/ClearScreen.xcodeproj/project.pbxproj b/objc/02-ClearScreen/ClearScreen.xcodeproj/project.pbxproj index e8ddbfb..97237cc 100644 --- a/objc/02-ClearScreen/ClearScreen.xcodeproj/project.pbxproj +++ b/objc/02-ClearScreen/ClearScreen.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 833FBBB11BBE0B0E001EFE4D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 833FBBAF1BBE0B0E001EFE4D /* Main.storyboard */; }; 833FBBB31BBE0B0E001EFE4D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 833FBBB21BBE0B0E001EFE4D /* Assets.xcassets */; }; 833FBBB61BBE0B0E001EFE4D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 833FBBB41BBE0B0E001EFE4D /* LaunchScreen.storyboard */; }; - 833FBBBF1BBE0C19001EFE4D /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 833FBBBE1BBE0C19001EFE4D /* MBEMetalView.m */; settings = {ASSET_TAGS = (); }; }; + 833FBBBF1BBE0C19001EFE4D /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 833FBBBE1BBE0C19001EFE4D /* MBEMetalView.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -110,7 +110,7 @@ 833FBB9B1BBE0B0E001EFE4D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal by Example"; TargetAttributes = { 833FBBA21BBE0B0E001EFE4D = { @@ -191,13 +191,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -235,13 +243,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -308,6 +324,7 @@ 833FBBBC1BBE0B0E001EFE4D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/objc/02-ClearScreen/ClearScreen.xcodeproj/xcshareddata/xcschemes/ClearScreen.xcscheme b/objc/02-ClearScreen/ClearScreen.xcodeproj/xcshareddata/xcschemes/ClearScreen.xcscheme index bb09bf1..03bae38 100644 --- a/objc/02-ClearScreen/ClearScreen.xcodeproj/xcshareddata/xcschemes/ClearScreen.xcscheme +++ b/objc/02-ClearScreen/ClearScreen.xcodeproj/xcshareddata/xcschemes/ClearScreen.xcscheme @@ -1,6 +1,6 @@ @@ -45,6 +46,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/objc/02-ClearScreen/ClearScreen/Assets.xcassets/AppIcon.appiconset/Contents.json b/objc/02-ClearScreen/ClearScreen/Assets.xcassets/AppIcon.appiconset/Contents.json index 77c57de..269b146 100644 --- a/objc/02-ClearScreen/ClearScreen/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/objc/02-ClearScreen/ClearScreen/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -32,6 +42,16 @@ "filename" : "Icon@3x.png", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -63,6 +83,16 @@ "idiom" : "ipad", "filename" : "Icon~ipad@2x.png", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/project.pbxproj b/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/project.pbxproj index ab38b2f..d393a58 100644 --- a/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/project.pbxproj +++ b/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/project.pbxproj @@ -13,12 +13,12 @@ 83E2D7721BD188110006DDD8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D7701BD188110006DDD8 /* Main.storyboard */; }; 83E2D7741BD188110006DDD8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D7731BD188110006DDD8 /* Assets.xcassets */; }; 83E2D7771BD188110006DDD8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D7751BD188110006DDD8 /* LaunchScreen.storyboard */; }; - 83E2D7811BD188710006DDD8 /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D77F1BD188710006DDD8 /* MBEMetalView.m */; settings = {ASSET_TAGS = (); }; }; - 83E2D7821BD188710006DDD8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7801BD188710006DDD8 /* Shaders.metal */; settings = {ASSET_TAGS = (); }; }; + 83E2D7811BD188710006DDD8 /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D77F1BD188710006DDD8 /* MBEMetalView.m */; }; + 83E2D7821BD188710006DDD8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7801BD188710006DDD8 /* Shaders.metal */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 83E2D7641BD188110006DDD8 /* DrawingIn2D.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DrawingIn2D.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 83E2D7641BD188110006DDD8 /* DrawingIn2D.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DrawingIn2D.app; sourceTree = BUILT_PRODUCTS_DIR; }; 83E2D7681BD188110006DDD8 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 83E2D76A1BD188110006DDD8 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 83E2D76B1BD188110006DDD8 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -76,7 +76,7 @@ 83E2D7781BD188110006DDD8 /* Info.plist */, 83E2D7671BD188110006DDD8 /* Supporting Files */, ); - path = "DrawingIn2D"; + path = DrawingIn2D; sourceTree = ""; }; 83E2D7671BD188110006DDD8 /* Supporting Files */ = { @@ -102,8 +102,8 @@ ); dependencies = ( ); - name = "DrawingIn2D"; - productName = "DrawingIn2D"; + name = DrawingIn2D; + productName = DrawingIn2D; productReference = 83E2D7641BD188110006DDD8 /* DrawingIn2D.app */; productType = "com.apple.product-type.application"; }; @@ -113,7 +113,7 @@ 83E2D75C1BD188110006DDD8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal by Example"; TargetAttributes = { 83E2D7631BD188110006DDD8 = { @@ -195,13 +195,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -239,13 +247,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -312,6 +328,7 @@ 83E2D77D1BD188110006DDD8 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/xcshareddata/xcschemes/DrawingIn2D.xcscheme b/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/xcshareddata/xcschemes/DrawingIn2D.xcscheme index f7e44da..fc08a89 100644 --- a/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/xcshareddata/xcschemes/DrawingIn2D.xcscheme +++ b/objc/03-DrawingIn2D/DrawingIn2D.xcodeproj/xcshareddata/xcschemes/DrawingIn2D.xcscheme @@ -1,6 +1,6 @@ @@ -45,6 +46,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/objc/03-DrawingIn2D/DrawingIn2D/MBEMetalView.m b/objc/03-DrawingIn2D/DrawingIn2D/MBEMetalView.m index 07c6891..4528f72 100644 --- a/objc/03-DrawingIn2D/DrawingIn2D/MBEMetalView.m +++ b/objc/03-DrawingIn2D/DrawingIn2D/MBEMetalView.m @@ -57,6 +57,28 @@ - (void)didMoveToSuperview } } +- (void)setFrame:(CGRect)frame +{ + [super setFrame:frame]; + + // During the first layout pass, we will not be in a view hierarchy, so we guess our scale + CGFloat scale = [UIScreen mainScreen].scale; + + // If we've moved to a window by the time our frame is being set, we can take its scale as our own + if (self.window) + { + scale = self.window.screen.scale; + } + + CGSize drawableSize = self.bounds.size; + + // Since drawable size is in pixels, we need to multiply by the scale to move from points to pixels + drawableSize.width *= scale; + drawableSize.height *= scale; + + self.metalLayer.drawableSize = drawableSize; +} + - (CAMetalLayer *)metalLayer { return (CAMetalLayer *)self.layer; } diff --git a/objc/04-DrawingIn3D/DrawingIn3D.xcodeproj/project.pbxproj b/objc/04-DrawingIn3D/DrawingIn3D.xcodeproj/project.pbxproj index d375c72..6c4628b 100644 --- a/objc/04-DrawingIn3D/DrawingIn3D.xcodeproj/project.pbxproj +++ b/objc/04-DrawingIn3D/DrawingIn3D.xcodeproj/project.pbxproj @@ -13,10 +13,10 @@ 83E2D79A1BD597A30006DDD8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D7981BD597A30006DDD8 /* Main.storyboard */; }; 83E2D79C1BD597A30006DDD8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D79B1BD597A30006DDD8 /* Assets.xcassets */; }; 83E2D79F1BD597A30006DDD8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83E2D79D1BD597A30006DDD8 /* LaunchScreen.storyboard */; }; - 83E2D7B21BD598810006DDD8 /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7A71BD598810006DDD8 /* MBEMetalView.m */; settings = {ASSET_TAGS = (); }; }; - 83E2D7B51BD598810006DDD8 /* MBERenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7AC1BD598810006DDD8 /* MBERenderer.m */; settings = {ASSET_TAGS = (); }; }; - 83E2D7B61BD598810006DDD8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7AD1BD598810006DDD8 /* Shaders.metal */; settings = {ASSET_TAGS = (); }; }; - 83E2D7B81BD598810006DDD8 /* MBEMathUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7B11BD598810006DDD8 /* MBEMathUtilities.m */; settings = {ASSET_TAGS = (); }; }; + 83E2D7B21BD598810006DDD8 /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7A71BD598810006DDD8 /* MBEMetalView.m */; }; + 83E2D7B51BD598810006DDD8 /* MBERenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7AC1BD598810006DDD8 /* MBERenderer.m */; }; + 83E2D7B61BD598810006DDD8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7AD1BD598810006DDD8 /* Shaders.metal */; }; + 83E2D7B81BD598810006DDD8 /* MBEMathUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 83E2D7B11BD598810006DDD8 /* MBEMathUtilities.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -123,7 +123,7 @@ 83E2D7841BD597A30006DDD8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal by Example"; TargetAttributes = { 83E2D78B1BD597A30006DDD8 = { @@ -207,13 +207,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -251,13 +259,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; diff --git a/objc/05-Lighting/Lighting.xcodeproj/project.pbxproj b/objc/05-Lighting/Lighting.xcodeproj/project.pbxproj index d19286f..8219d7f 100644 --- a/objc/05-Lighting/Lighting.xcodeproj/project.pbxproj +++ b/objc/05-Lighting/Lighting.xcodeproj/project.pbxproj @@ -196,7 +196,7 @@ 839E18851BE31CDA00944528 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal by Example"; TargetAttributes = { 839E188C1BE31CDA00944528 = { @@ -285,13 +285,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -329,13 +337,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; diff --git a/objc/06-Texturing/Texturing.xcodeproj/project.pbxproj b/objc/06-Texturing/Texturing.xcodeproj/project.pbxproj index fa33f4c..331c2b0 100644 --- a/objc/06-Texturing/Texturing.xcodeproj/project.pbxproj +++ b/objc/06-Texturing/Texturing.xcodeproj/project.pbxproj @@ -183,7 +183,7 @@ 839E18C81BE348B800944528 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal by Example"; TargetAttributes = { 839E18CF1BE348B800944528 = { @@ -277,13 +277,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -305,7 +313,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -321,13 +329,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -343,7 +359,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -356,7 +372,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Texturing/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.metalbyexample.Texturing; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -368,7 +384,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Texturing/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.metalbyexample.Texturing; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -394,6 +410,7 @@ 839E18E91BE348B800944528 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/objc/06-Texturing/Texturing/MBETextureLoader.m b/objc/06-Texturing/Texturing/MBETextureLoader.m index f81902e..ac709c9 100644 --- a/objc/06-Texturing/Texturing/MBETextureLoader.m +++ b/objc/06-Texturing/Texturing/MBETextureLoader.m @@ -32,6 +32,7 @@ + (instancetype)sharedTextureLoader width:imageSize.width height:imageSize.height mipmapped:mipmapped]; + textureDescriptor.usage = MTLTextureUsageShaderRead; id texture = [[queue device] newTextureWithDescriptor:textureDescriptor]; [texture setLabel:imageName]; diff --git a/objc/07-Mipmapping/Mipmapping.xcodeproj/project.pbxproj b/objc/07-Mipmapping/Mipmapping.xcodeproj/project.pbxproj index 75b81a5..1bb1ac1 100644 --- a/objc/07-Mipmapping/Mipmapping.xcodeproj/project.pbxproj +++ b/objc/07-Mipmapping/Mipmapping.xcodeproj/project.pbxproj @@ -156,7 +156,7 @@ 83A1BDCE1A365434005638E2 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0610; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 83A1BDD51A365434005638E2 = { @@ -243,20 +243,30 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -285,13 +295,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -299,6 +317,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -318,7 +337,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Mipmapping/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -328,7 +349,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Mipmapping/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/objc/07-Mipmapping/Mipmapping/Info.plist b/objc/07-Mipmapping/Mipmapping/Info.plist index 048bdb0..7a92492 100644 --- a/objc/07-Mipmapping/Mipmapping/Info.plist +++ b/objc/07-Mipmapping/Mipmapping/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -22,6 +22,8 @@ 1 LSRequiresIPhoneOS + UIFileSharingEnabled + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -45,7 +47,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIFileSharingEnabled - diff --git a/objc/07-Mipmapping/Mipmapping/MBEMatrixUtilities.h b/objc/07-Mipmapping/Mipmapping/MBEMatrixUtilities.h index 506e4cd..838ab0f 100644 --- a/objc/07-Mipmapping/Mipmapping/MBEMatrixUtilities.h +++ b/objc/07-Mipmapping/Mipmapping/MBEMatrixUtilities.h @@ -1,6 +1,6 @@ @import simd; -matrix_float4x4 matrix_identity(); +matrix_float4x4 matrix_identity(void); matrix_float4x4 matrix_rotation(vector_float3 axis, float angle); diff --git a/objc/07-Mipmapping/Mipmapping/MBERenderer.m b/objc/07-Mipmapping/Mipmapping/MBERenderer.m index e9c877d..aaf28f9 100644 --- a/objc/07-Mipmapping/Mipmapping/MBERenderer.m +++ b/objc/07-Mipmapping/Mipmapping/MBERenderer.m @@ -54,14 +54,18 @@ - (void)buildMetal - (void)buildPipeline { MTLVertexDescriptor *vertexDescriptor = [MTLVertexDescriptor new]; - vertexDescriptor.attributes[0].bufferIndex = 0; vertexDescriptor.attributes[0].offset = 0; vertexDescriptor.attributes[0].format = MTLVertexFormatFloat4; - + vertexDescriptor.attributes[0].bufferIndex = 0; + vertexDescriptor.attributes[1].offset = sizeof(vector_float4); vertexDescriptor.attributes[1].format = MTLVertexFormatFloat4; vertexDescriptor.attributes[1].bufferIndex = 0; - + + vertexDescriptor.attributes[2].offset = 2 * sizeof(vector_float4); + vertexDescriptor.attributes[2].format = MTLVertexFormatFloat2; + vertexDescriptor.attributes[2].bufferIndex = 0; + vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex; vertexDescriptor.layouts[0].stepRate = 1; vertexDescriptor.layouts[0].stride = sizeof(MBEVertex); diff --git a/objc/07-Mipmapping/Mipmapping/Shaders.metal b/objc/07-Mipmapping/Mipmapping/Shaders.metal index 3f37b44..2bc5b3f 100644 --- a/objc/07-Mipmapping/Mipmapping/Shaders.metal +++ b/objc/07-Mipmapping/Mipmapping/Shaders.metal @@ -5,9 +5,9 @@ constant float3 kLightDirection(0, 0, -1); struct InVertex { - packed_float4 position [[attribute(0)]]; - packed_float4 normal [[attribute(1)]]; - packed_float2 texCoords [[attribute(2)]]; + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; + float2 texCoords [[attribute(2)]]; }; struct ProjectedVertex @@ -24,14 +24,13 @@ struct Uniforms float4x4 modelViewProjectionMatrix; }; -vertex ProjectedVertex vertex_project(constant InVertex *vertices [[buffer(0)]], - constant Uniforms &uniforms [[buffer(1)]], - ushort vid [[vertex_id]]) +vertex ProjectedVertex vertex_project(InVertex inVertex [[stage_in]], + constant Uniforms &uniforms [[buffer(1)]]) { ProjectedVertex outVert; - outVert.position = uniforms.modelViewProjectionMatrix * float4(vertices[vid].position); - outVert.normal = uniforms.normalMatrix * float4(vertices[vid].normal).xyz; - outVert.texCoords = vertices[vid].texCoords; + outVert.position = uniforms.modelViewProjectionMatrix * float4(inVertex.position); + outVert.normal = uniforms.normalMatrix * float4(inVertex.normal).xyz; + outVert.texCoords = inVertex.texCoords; return outVert; } diff --git a/objc/08-CubeMapping/CubeMapping.xcodeproj/project.pbxproj b/objc/08-CubeMapping/CubeMapping.xcodeproj/project.pbxproj index 5408c1b..1c1601c 100644 --- a/objc/08-CubeMapping/CubeMapping.xcodeproj/project.pbxproj +++ b/objc/08-CubeMapping/CubeMapping.xcodeproj/project.pbxproj @@ -195,7 +195,7 @@ 8362D1991A0D5BEB00A6D9A8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 8362D1A01A0D5BEB00A6D9A8 = { @@ -289,13 +289,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -304,6 +312,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -332,13 +341,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -346,6 +363,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -365,6 +383,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = CubeMapping/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -376,6 +395,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = CubeMapping/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/objc/08-CubeMapping/CubeMapping/MBEMatrixUtilities.h b/objc/08-CubeMapping/CubeMapping/MBEMatrixUtilities.h index 561f715..584911b 100644 --- a/objc/08-CubeMapping/CubeMapping/MBEMatrixUtilities.h +++ b/objc/08-CubeMapping/CubeMapping/MBEMatrixUtilities.h @@ -1,6 +1,6 @@ @import simd; -matrix_float4x4 identity(); +matrix_float4x4 identity(void); matrix_float4x4 rotation_about_axis(vector_float3 axis, float angle); diff --git a/objc/08-CubeMapping/CubeMapping/Shaders.metal b/objc/08-CubeMapping/CubeMapping/Shaders.metal index e2d38c4..5a7f709 100644 --- a/objc/08-CubeMapping/CubeMapping/Shaders.metal +++ b/objc/08-CubeMapping/CubeMapping/Shaders.metal @@ -11,8 +11,8 @@ constant float kEtaRatio = kEtaAir / kEtaGlass; struct Vertex { - packed_float4 position [[attribute(0)]]; - packed_float4 normal [[attribute(1)]]; + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; }; struct ProjectedVertex @@ -30,11 +30,11 @@ struct Uniforms float4 worldCameraPosition; }; -vertex ProjectedVertex vertex_skybox(device Vertex *vertices [[buffer(0)]], +vertex ProjectedVertex vertex_skybox(Vertex inVertex [[stage_in]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) { - float4 position = vertices[vid].position; + float4 position = inVertex.position; ProjectedVertex outVert; outVert.position = uniforms.modelViewProjectionMatrix * position; @@ -42,12 +42,12 @@ vertex ProjectedVertex vertex_skybox(device Vertex *vertices [[buffer(0)]], return outVert; } -vertex ProjectedVertex vertex_reflect(device Vertex *vertices [[buffer(0)]], +vertex ProjectedVertex vertex_reflect(Vertex inVertex [[stage_in]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) { - float4 modelPosition = vertices[vid].position; - float4 modelNormal = vertices[vid].normal; + float4 modelPosition = inVertex.position; + float4 modelNormal = inVertex.normal; float4 worldCameraPosition = uniforms.worldCameraPosition; float4 worldPosition = uniforms.modelMatrix * modelPosition; @@ -61,12 +61,12 @@ vertex ProjectedVertex vertex_reflect(device Vertex *vertices [[buffer(0)]], return outVert; } -vertex ProjectedVertex vertex_refract(device Vertex *vertices [[buffer(0)]], +vertex ProjectedVertex vertex_refract(Vertex inVertex [[stage_in]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) { - float4 modelPosition = vertices[vid].position; - float4 modelNormal = vertices[vid].normal; + float4 modelPosition = inVertex.position; + float4 modelNormal = inVertex.normal; float4 worldCameraPosition = uniforms.worldCameraPosition; float4 worldPosition = uniforms.modelMatrix * modelPosition; diff --git a/objc/09-CompressedTextures/CompressedTextures.xcodeproj/project.pbxproj b/objc/09-CompressedTextures/CompressedTextures.xcodeproj/project.pbxproj index 6acf11d..e59617b 100644 --- a/objc/09-CompressedTextures/CompressedTextures.xcodeproj/project.pbxproj +++ b/objc/09-CompressedTextures/CompressedTextures.xcodeproj/project.pbxproj @@ -159,7 +159,7 @@ 83419B751AE1B77500148DCA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 83419B7C1AE1B77500148DCA = { @@ -251,13 +251,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -296,13 +304,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -331,6 +347,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = CompressedTextures/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -342,6 +359,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = CompressedTextures/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/objc/09-CompressedTextures/CompressedTextures/MBEMathUtilities.h b/objc/09-CompressedTextures/CompressedTextures/MBEMathUtilities.h index f6b1e91..b82cbfc 100644 --- a/objc/09-CompressedTextures/CompressedTextures/MBEMathUtilities.h +++ b/objc/09-CompressedTextures/CompressedTextures/MBEMathUtilities.h @@ -8,7 +8,7 @@ float random_float(float min, float max); vector_float3 vector_orthogonal(vector_float3 v); /// Returns the identity matrix -matrix_float4x4 matrix_identity(); +matrix_float4x4 matrix_identity(void); /// Returns the matrix that rotates by `angle` radians about `axis` matrix_float4x4 matrix_rotation(vector_float3 axis, float angle); diff --git a/objc/09-CompressedTextures/CompressedTextures/MBETextureDataSource.m b/objc/09-CompressedTextures/CompressedTextures/MBETextureDataSource.m index 9286dc1..32e9fc0 100644 --- a/objc/09-CompressedTextures/CompressedTextures/MBETextureDataSource.m +++ b/objc/09-CompressedTextures/CompressedTextures/MBETextureDataSource.m @@ -960,6 +960,7 @@ - (BOOL)pixelFormatIsColorRenderable:(MTLPixelFormat)pixelFormat width:self.width height:self.height mipmapped:needMipStorage]; + texDescriptor.usage = MTLTextureUsageShaderRead; id texture = [[commandQueue device] newTextureWithDescriptor:texDescriptor]; __block NSInteger levelWidth = self.width; diff --git a/objc/10-AlphaBlending/AlphaBlending.xcodeproj/project.pbxproj b/objc/10-AlphaBlending/AlphaBlending.xcodeproj/project.pbxproj index 2a596ad..d95189c 100644 --- a/objc/10-AlphaBlending/AlphaBlending.xcodeproj/project.pbxproj +++ b/objc/10-AlphaBlending/AlphaBlending.xcodeproj/project.pbxproj @@ -217,7 +217,7 @@ 83DBFC0D1A3F5C0000630BA1 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 83DBFC141A3F5C0000630BA1 = { @@ -313,13 +313,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -328,6 +336,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -356,13 +365,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -370,6 +387,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -389,7 +407,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = AlphaBlending/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -401,7 +419,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = AlphaBlending/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/objc/10-AlphaBlending/AlphaBlending/MBEMathUtilities.h b/objc/10-AlphaBlending/AlphaBlending/MBEMathUtilities.h index 54551ce..e59a20c 100644 --- a/objc/10-AlphaBlending/AlphaBlending/MBEMathUtilities.h +++ b/objc/10-AlphaBlending/AlphaBlending/MBEMathUtilities.h @@ -7,7 +7,7 @@ float random_float(float min, float max); /// Returns a vector that is orthogonal to the input vector vector_float3 vector_orthogonal(vector_float3 v); -matrix_float4x4 matrix_identity(); +matrix_float4x4 matrix_identity(void); matrix_float4x4 matrix_rotation(vector_float3 axis, float angle); diff --git a/objc/10-AlphaBlending/AlphaBlending/MBETextureLoader.m b/objc/10-AlphaBlending/AlphaBlending/MBETextureLoader.m index 1bd8c6c..c13c612 100644 --- a/objc/10-AlphaBlending/AlphaBlending/MBETextureLoader.m +++ b/objc/10-AlphaBlending/AlphaBlending/MBETextureLoader.m @@ -26,6 +26,7 @@ + (instancetype)sharedTextureLoader width:imageSize.width height:imageSize.height mipmapped:mipmapped]; + textureDescriptor.usage = MTLTextureUsageShaderRead; id texture = [device newTextureWithDescriptor:textureDescriptor]; [texture setLabel:imageName]; diff --git a/objc/10-AlphaBlending/AlphaBlending/Shaders.metal b/objc/10-AlphaBlending/AlphaBlending/Shaders.metal index e883e7c..5d3e597 100644 --- a/objc/10-AlphaBlending/AlphaBlending/Shaders.metal +++ b/objc/10-AlphaBlending/AlphaBlending/Shaders.metal @@ -9,10 +9,10 @@ constant float kAlphaTestReferenceValue = 0.5; struct Vertex { - packed_float4 position [[attribute(0)]]; - packed_float4 normal [[attribute(1)]]; - packed_float4 diffuseColor [[attribute(2)]]; - packed_float2 texCoords [[attribute(3)]]; + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; + float4 diffuseColor [[attribute(2)]]; + float2 texCoords [[attribute(3)]]; }; struct ProjectedVertex @@ -34,7 +34,7 @@ struct InstanceUniforms float4x4 normalMatrix; }; -vertex ProjectedVertex project_vertex(constant Vertex *vertices [[buffer(0)]], +vertex ProjectedVertex project_vertex(Vertex vertexIn [[stage_in]], constant Uniforms &uniforms [[buffer(1)]], constant InstanceUniforms *instanceUniforms [[buffer(2)]], ushort vid [[vertex_id]], @@ -44,10 +44,10 @@ vertex ProjectedVertex project_vertex(constant Vertex *vertices [[buffer(0)]], float4x4 normalMatrix = instanceUniforms[iid].normalMatrix; ProjectedVertex outVert; - outVert.position = uniforms.viewProjectionMatrix * modelMatrix * float4(vertices[vid].position); - outVert.normal = normalMatrix * float4(vertices[vid].normal); - outVert.diffuseColor = vertices[vid].diffuseColor; - outVert.texCoords = vertices[vid].texCoords; + outVert.position = uniforms.viewProjectionMatrix * modelMatrix * float4(vertexIn.position); + outVert.normal = normalMatrix * float4(vertexIn.normal); + outVert.diffuseColor = vertexIn.diffuseColor; + outVert.texCoords = vertexIn.texCoords; return outVert; } diff --git a/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/project.pbxproj b/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/project.pbxproj index 4aa85da..7d8ec09 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/project.pbxproj +++ b/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/project.pbxproj @@ -223,7 +223,7 @@ 837F22FD1A2970BD006B7896 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 837F23041A2970BD006B7896 = { @@ -317,13 +317,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -332,6 +340,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -360,13 +369,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -374,6 +391,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -393,6 +411,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "$(SRCROOT)/InstancedDrawing/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = InstancedDrawing; @@ -404,6 +423,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "$(SRCROOT)/InstancedDrawing/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = InstancedDrawing; diff --git a/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/xcshareddata/xcschemes/InstancedDrawing.xcscheme b/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/xcshareddata/xcschemes/InstancedDrawing.xcscheme index 68a05ca..6304393 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/xcshareddata/xcschemes/InstancedDrawing.xcscheme +++ b/objc/11-InstancedDrawing/InstancedDrawing.xcodeproj/xcshareddata/xcschemes/InstancedDrawing.xcscheme @@ -1,6 +1,6 @@ @@ -45,6 +46,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/objc/11-InstancedDrawing/InstancedDrawing/Info.plist b/objc/11-InstancedDrawing/InstancedDrawing/Info.plist index 0f42155..f5017d4 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing/Info.plist +++ b/objc/11-InstancedDrawing/InstancedDrawing/Info.plist @@ -37,6 +37,7 @@ UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown UISupportedInterfaceOrientations~ipad diff --git a/objc/11-InstancedDrawing/InstancedDrawing/MBEMatrixUtilities.h b/objc/11-InstancedDrawing/InstancedDrawing/MBEMatrixUtilities.h index 506e4cd..838ab0f 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing/MBEMatrixUtilities.h +++ b/objc/11-InstancedDrawing/InstancedDrawing/MBEMatrixUtilities.h @@ -1,6 +1,6 @@ @import simd; -matrix_float4x4 matrix_identity(); +matrix_float4x4 matrix_identity(void); matrix_float4x4 matrix_rotation(vector_float3 axis, float angle); diff --git a/objc/11-InstancedDrawing/InstancedDrawing/Shaders.metal b/objc/11-InstancedDrawing/InstancedDrawing/Shaders.metal index f4691fb..d282d70 100644 --- a/objc/11-InstancedDrawing/InstancedDrawing/Shaders.metal +++ b/objc/11-InstancedDrawing/InstancedDrawing/Shaders.metal @@ -5,9 +5,9 @@ constant float3 kLightDirection(-0.43, -0.8, -0.43); struct InVertex { - packed_float4 position [[attribute(0)]]; - packed_float4 normal [[attribute(1)]]; - packed_float2 texCoords [[attribute(2)]]; + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; + float2 texCoords [[attribute(2)]]; }; struct ProjectedVertex @@ -28,7 +28,7 @@ struct PerInstanceUniforms float3x3 normalMatrix; }; -vertex ProjectedVertex vertex_project(device InVertex *vertices [[buffer(0)]], +vertex ProjectedVertex vertex_project(InVertex vertexIn [[stage_in]], constant Uniforms &uniforms [[buffer(1)]], constant PerInstanceUniforms *perInstanceUniforms [[buffer(2)]], ushort vid [[vertex_id]], @@ -38,9 +38,9 @@ vertex ProjectedVertex vertex_project(device InVertex *vertices [[buffer(0)]], float3x3 instanceNormalMatrix = perInstanceUniforms[iid].normalMatrix; ProjectedVertex outVert; - outVert.position = uniforms.viewProjectionMatrix * instanceModelMatrix * float4(vertices[vid].position); - outVert.normal = instanceNormalMatrix * float4(vertices[vid].normal).xyz; - outVert.texCoords = vertices[vid].texCoords; + outVert.position = uniforms.viewProjectionMatrix * instanceModelMatrix * float4(vertexIn.position); + outVert.normal = instanceNormalMatrix * float4(vertexIn.normal).xyz; + outVert.texCoords = vertexIn.texCoords; return outVert; } diff --git a/objc/12-TextRendering/TextRendering.xcodeproj/project.pbxproj b/objc/12-TextRendering/TextRendering.xcodeproj/project.pbxproj index ba51e81..3b2c9e7 100644 --- a/objc/12-TextRendering/TextRendering.xcodeproj/project.pbxproj +++ b/objc/12-TextRendering/TextRendering.xcodeproj/project.pbxproj @@ -140,7 +140,7 @@ 83D6DE911A853166003E9203 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Metal By Example"; TargetAttributes = { 83D6DE981A853166003E9203 = { @@ -227,13 +227,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -242,6 +250,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -270,13 +279,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -284,6 +301,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -303,6 +321,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = TextRendering/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -314,6 +333,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = TextRendering/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.metalbyexample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/objc/12-TextRendering/TextRendering.xcodeproj/xcshareddata/xcschemes/TextRendering.xcscheme b/objc/12-TextRendering/TextRendering.xcodeproj/xcshareddata/xcschemes/TextRendering.xcscheme index b57311d..354a560 100644 --- a/objc/12-TextRendering/TextRendering.xcodeproj/xcshareddata/xcschemes/TextRendering.xcscheme +++ b/objc/12-TextRendering/TextRendering.xcodeproj/xcshareddata/xcschemes/TextRendering.xcscheme @@ -1,6 +1,6 @@ texture = [context.device newTextureWithDescriptor:textureDescriptor]; MTLRegion region = MTLRegionMake2D(0, 0, width, height);