Skip to content

Commit 9fd76c2

Browse files
committed
Implement macOS view, view controller, storyboard and renderer changes.
Add all relevant files to mac target.
1 parent 1e12f8f commit 9fd76c2

File tree

16 files changed

+292
-126
lines changed

16 files changed

+292
-126
lines changed

objc/06-Texturing/Texturing-Mac/Base.lproj/Main.storyboard

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
56
</dependencies>
67
<scenes>
78
<!--Application-->
@@ -673,7 +674,7 @@
673674
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
674675
</connections>
675676
</application>
676-
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider=""/>
677+
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
677678
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
678679
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
679680
</objects>
@@ -688,7 +689,7 @@
688689
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
689690
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
690691
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
691-
<connections>
692+
<connections>
692693
<outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/>
693694
</connections>
694695
</window>
@@ -703,8 +704,8 @@
703704
<!--View Controller-->
704705
<scene sceneID="hIz-AP-VOD">
705706
<objects>
706-
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
707-
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
707+
<viewController id="XfG-lQ-9wD" customClass="ViewController" sceneMemberID="viewController">
708+
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl" customClass="MBEMetalViewMac">
708709
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
709710
<autoresizingMask key="autoresizingMask"/>
710711
</view>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// MBEMetalViewMac.h
3+
// DrawingIn3D-Mac
4+
//
5+
// Created by Brent Gulanowski on 2018-06-18.
6+
// Copyright © 2018 Metal by Example. All rights reserved.
7+
//
8+
9+
@import Cocoa;
10+
11+
#import "MBEMetalView.h"
12+
13+
@interface MBEMetalViewMac : MBEMetalView
14+
15+
@end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// MBEMetalViewMac.m
3+
// DrawingIn3D-Mac
4+
//
5+
// Created by Brent Gulanowski on 2018-06-18.
6+
// Copyright © 2018 Metal by Example. All rights reserved.
7+
//
8+
9+
#import "MBEMetalViewMac.h"
10+
11+
@interface MBEMetalViewMac()
12+
@property (nonatomic) CVDisplayLinkRef displayLink;
13+
@property (nonatomic, strong) CAMetalLayer *metalLayer;
14+
@end
15+
16+
static NSTimeInterval C3DTimeIntervalFromTimeStamp(const CVTimeStamp *timeStamp) {
17+
return 1.0 / (timeStamp->rateScalar * (double)timeStamp->videoTimeScale / (double)timeStamp->videoRefreshPeriod);
18+
}
19+
20+
static CVReturn C3DViewDisplayLink(CVDisplayLinkRef displayLink,
21+
const CVTimeStamp *inNow,
22+
const CVTimeStamp *inOutputTime,
23+
CVOptionFlags flagsIn,
24+
CVOptionFlags *flagsOut,
25+
void *view) {
26+
@autoreleasepool {
27+
[(__bridge MBEMetalView *)view renderWithDuration:C3DTimeIntervalFromTimeStamp(inOutputTime)];
28+
}
29+
30+
return kCVReturnSuccess;
31+
}
32+
33+
@implementation MBEMetalViewMac
34+
35+
@synthesize metalLayer=_metalLayer;
36+
37+
- (CALayer *)makeBackingLayer
38+
{
39+
CAMetalLayer *layer = [[CAMetalLayer alloc] init];
40+
_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
41+
_metalLayer = layer;
42+
return layer;
43+
}
44+
45+
- (CGSize)drawableSize {
46+
return self.bounds.size;
47+
}
48+
49+
- (void)viewDidMoveToSuperview
50+
{
51+
[super viewDidMoveToSuperview];
52+
53+
if (self.metalLayer.device == nil) {
54+
self.metalLayer.device = MTLCreateSystemDefaultDevice();
55+
}
56+
if (self.depthTexture == nil) {
57+
[self makeDepthTexture];
58+
}
59+
60+
if (self.superview) {
61+
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
62+
CVDisplayLinkSetOutputCallback(_displayLink, C3DViewDisplayLink, (__bridge void *)(self));
63+
CVDisplayLinkStart(_displayLink);
64+
}
65+
else {
66+
CVDisplayLinkStop(_displayLink);
67+
CVDisplayLinkRelease(_displayLink);
68+
_displayLink = NULL;
69+
}
70+
}
71+
72+
@end

objc/06-Texturing/Texturing-Mac/ViewController.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

objc/06-Texturing/Texturing-Mac/ViewController.m

Lines changed: 0 additions & 27 deletions
This file was deleted.

objc/06-Texturing/Texturing.xcodeproj/project.pbxproj

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,24 @@
2727
839E19191BE3583B00944528 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 839E19181BE3583B00944528 /* Shaders.metal */; };
2828
839E191C1BE3596D00944528 /* MBETextureLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E191B1BE3596D00944528 /* MBETextureLoader.m */; };
2929
8451833420D918BA00BF473E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8451833320D918BA00BF473E /* AppDelegate.m */; };
30-
8451833720D918BA00BF473E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8451833620D918BA00BF473E /* ViewController.m */; };
3130
8451833920D918BB00BF473E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8451833820D918BB00BF473E /* Assets.xcassets */; };
3231
8451833C20D918BB00BF473E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8451833A20D918BB00BF473E /* Main.storyboard */; };
3332
8451833F20D918BB00BF473E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8451833E20D918BB00BF473E /* main.m */; };
33+
8451834420D919E200BF473E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18DA1BE348B800944528 /* ViewController.m */; };
34+
8451834520D919F100BF473E /* moo.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 839E19041BE349AC00944528 /* moo.aiff */; };
35+
8451834620D91A6E00BF473E /* spot.obj in Resources */ = {isa = PBXBuildFile; fileRef = 839E19061BE349AC00944528 /* spot.obj */; };
36+
8451834720D91A7A00BF473E /* spot_texture.png in Resources */ = {isa = PBXBuildFile; fileRef = 839E19091BE349AD00944528 /* spot_texture.png */; };
37+
8451834820D91A9300BF473E /* MBEMathUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18EB1BE3495400944528 /* MBEMathUtilities.m */; };
38+
8451834920D91A9300BF473E /* MBEMaterial.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E19011BE3497A00944528 /* MBEMaterial.m */; };
39+
8451834A20D91A9300BF473E /* MBEMesh.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18ED1BE3495400944528 /* MBEMesh.m */; };
40+
8451834B20D91A9300BF473E /* MBETextureLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E191B1BE3596D00944528 /* MBETextureLoader.m */; };
41+
8451834C20D91A9300BF473E /* MBEOBJGroup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 839E18F11BE3495400944528 /* MBEOBJGroup.mm */; };
42+
8451834D20D91A9300BF473E /* MBEOBJMesh.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18F31BE3495400944528 /* MBEOBJMesh.m */; };
43+
8451834E20D91A9300BF473E /* MBEOBJModel.mm in Sources */ = {isa = PBXBuildFile; fileRef = 839E18F51BE3495400944528 /* MBEOBJModel.mm */; };
44+
8451834F20D91A9300BF473E /* MBERenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18F71BE3495400944528 /* MBERenderer.m */; };
45+
8451835020D91A9E00BF473E /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 839E19181BE3583B00944528 /* Shaders.metal */; };
46+
8451835320D91D9700BF473E /* MBEMetalViewMac.m in Sources */ = {isa = PBXBuildFile; fileRef = 8451835220D91D9700BF473E /* MBEMetalViewMac.m */; };
47+
8451835420D91DAF00BF473E /* MBEMetalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 839E18EF1BE3495400944528 /* MBEMetalView.m */; };
3448
/* End PBXBuildFile section */
3549

3650
/* Begin PBXFileReference section */
@@ -75,13 +89,13 @@
7589
8451833020D918BA00BF473E /* Texturing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Texturing.app; sourceTree = BUILT_PRODUCTS_DIR; };
7690
8451833220D918BA00BF473E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7791
8451833320D918BA00BF473E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
78-
8451833520D918BA00BF473E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
79-
8451833620D918BA00BF473E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
8092
8451833820D918BB00BF473E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
8193
8451833B20D918BB00BF473E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
8294
8451833D20D918BB00BF473E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8395
8451833E20D918BB00BF473E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
8496
8451834020D918BB00BF473E /* Texturing_Mac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Texturing_Mac.entitlements; sourceTree = "<group>"; };
97+
8451835120D91D9700BF473E /* MBEMetalViewMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBEMetalViewMac.h; sourceTree = "<group>"; };
98+
8451835220D91D9700BF473E /* MBEMetalViewMac.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBEMetalViewMac.m; sourceTree = "<group>"; };
8599
/* End PBXFileReference section */
86100

87101
/* Begin PBXFrameworksBuildPhase section */
@@ -185,12 +199,12 @@
185199
children = (
186200
8451833220D918BA00BF473E /* AppDelegate.h */,
187201
8451833320D918BA00BF473E /* AppDelegate.m */,
188-
8451833520D918BA00BF473E /* ViewController.h */,
189-
8451833620D918BA00BF473E /* ViewController.m */,
190202
8451833820D918BB00BF473E /* Assets.xcassets */,
191-
8451833A20D918BB00BF473E /* Main.storyboard */,
192203
8451833D20D918BB00BF473E /* Info.plist */,
193204
8451833E20D918BB00BF473E /* main.m */,
205+
8451833A20D918BB00BF473E /* Main.storyboard */,
206+
8451835120D91D9700BF473E /* MBEMetalViewMac.h */,
207+
8451835220D91D9700BF473E /* MBEMetalViewMac.m */,
194208
8451834020D918BB00BF473E /* Texturing_Mac.entitlements */,
195209
);
196210
path = "Texturing-Mac";
@@ -288,8 +302,11 @@
288302
isa = PBXResourcesBuildPhase;
289303
buildActionMask = 2147483647;
290304
files = (
305+
8451834720D91A7A00BF473E /* spot_texture.png in Resources */,
306+
8451834620D91A6E00BF473E /* spot.obj in Resources */,
291307
8451833920D918BB00BF473E /* Assets.xcassets in Resources */,
292308
8451833C20D918BB00BF473E /* Main.storyboard in Resources */,
309+
8451834520D919F100BF473E /* moo.aiff in Resources */,
293310
);
294311
runOnlyForDeploymentPostprocessing = 0;
295312
};
@@ -320,9 +337,20 @@
320337
isa = PBXSourcesBuildPhase;
321338
buildActionMask = 2147483647;
322339
files = (
323-
8451833720D918BA00BF473E /* ViewController.m in Sources */,
340+
8451835020D91A9E00BF473E /* Shaders.metal in Sources */,
341+
8451835420D91DAF00BF473E /* MBEMetalView.m in Sources */,
342+
8451834F20D91A9300BF473E /* MBERenderer.m in Sources */,
343+
8451834920D91A9300BF473E /* MBEMaterial.m in Sources */,
344+
8451834420D919E200BF473E /* ViewController.m in Sources */,
345+
8451834C20D91A9300BF473E /* MBEOBJGroup.mm in Sources */,
324346
8451833F20D918BB00BF473E /* main.m in Sources */,
347+
8451834E20D91A9300BF473E /* MBEOBJModel.mm in Sources */,
325348
8451833420D918BA00BF473E /* AppDelegate.m in Sources */,
349+
8451834820D91A9300BF473E /* MBEMathUtilities.m in Sources */,
350+
8451835320D91D9700BF473E /* MBEMetalViewMac.m in Sources */,
351+
8451834B20D91A9300BF473E /* MBETextureLoader.m in Sources */,
352+
8451834A20D91A9300BF473E /* MBEMesh.m in Sources */,
353+
8451834D20D91A9300BF473E /* MBEOBJMesh.m in Sources */,
326354
);
327355
runOnlyForDeploymentPostprocessing = 0;
328356
};

objc/06-Texturing/Texturing/MBEMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import UIKit;
1+
@import Foundation;
22
@import Metal;
33

44
@interface MBEMesh : NSObject

objc/06-Texturing/Texturing/MBEMetalView.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
#import <TargetConditionals.h>
2+
3+
#if TARGET_OS_IPHONE
14
@import UIKit;
5+
#define NSUIView UIView;
6+
#else
7+
@import AppKit;
8+
#define NSUIView NSView;
9+
#endif
210
@import Metal;
311
@import QuartzCore.CAMetalLayer;
412

513
@protocol MBEMetalViewDelegate;
614

7-
@interface MBEMetalView : UIView
15+
@interface MBEMetalView : NSUIView
816

917
/// The delegate of this view, responsible for drawing
1018
@property (nonatomic, weak) id<MBEMetalViewDelegate> delegate;
@@ -36,6 +44,19 @@
3644
/// size as its depth attachment's texture
3745
@property (nonatomic, readonly) MTLRenderPassDescriptor *currentRenderPassDescriptor;
3846

47+
// Subclass override points
48+
@property (nonatomic, readonly) CGSize drawableSize;
49+
50+
- (void)makeDepthTexture;
51+
- (void)renderWithDuration:(NSTimeInterval)duration;
52+
53+
@end
54+
55+
// For subclasses
56+
@interface MBEMetalView ()
57+
@property (assign) NSTimeInterval frameDuration;
58+
@property (strong) id<CAMetalDrawable> currentDrawable;
59+
@property (strong) id<MTLTexture> depthTexture;
3960
@end
4061

4162
@protocol MBEMetalViewDelegate <NSObject>

0 commit comments

Comments
 (0)