Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
s1ddok committed Nov 26, 2019
1 parent 4854be1 commit 308e76b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 90 deletions.
8 changes: 0 additions & 8 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
18B1A088231E7867000A9BAB /* SwitchDataFormatEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B1A086231E7867000A9BAB /* SwitchDataFormatEncoder.swift */; };
4FBA92F23EE96BEC3B50A6F4 /* Pods_AlloyTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2C9B19EDEBD9C61E5137353 /* Pods_AlloyTests.framework */; };
63F9C6B2B8704ABC4263F909 /* Pods_DemoAppTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A47635EFD74A558403F5CB4 /* Pods_DemoAppTests.framework */; };
930654D121D55DF700ACD3D7 /* BrightnessEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 930654D021D55DF700ACD3D7 /* BrightnessEncoder.swift */; };
9348719F21B3D39A00733E6A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9348719E21B3D39A00733E6A /* AppDelegate.swift */; };
934871A121B3D39A00733E6A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 934871A021B3D39A00733E6A /* ViewController.swift */; };
934871A321B3D39B00733E6A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 934871A221B3D39B00733E6A /* Assets.xcassets */; };
934871A621B3D39B00733E6A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 934871A421B3D39B00733E6A /* Main.storyboard */; };
93AFAC0E21B434C000C23181 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 93AFAC0D21B434C000C23181 /* Shaders.metal */; };
93AFAC3021BAFBFB00C23181 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93AFAC2F21BAFBFB00C23181 /* Metal.framework */; };
93B3E24021F505E1008835A0 /* AlloyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93B3E23F21F505E1008835A0 /* AlloyTests.swift */; };
93B3E24821F50722008835A0 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 93B3E24721F50722008835A0 /* Shaders.metal */; };
Expand Down Expand Up @@ -70,15 +68,13 @@
5F11945128CA3F5B062C9782 /* Pods-DemoAppTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoAppTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-DemoAppTests/Pods-DemoAppTests.release.xcconfig"; sourceTree = "<group>"; };
7A47635EFD74A558403F5CB4 /* Pods_DemoAppTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoAppTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9072BB7C76F22B60656C7DC4 /* Pods_DemoApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
930654D021D55DF700ACD3D7 /* BrightnessEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrightnessEncoder.swift; sourceTree = "<group>"; };
9348719B21B3D39A00733E6A /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
9348719E21B3D39A00733E6A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
934871A021B3D39A00733E6A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
934871A221B3D39B00733E6A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
934871A521B3D39B00733E6A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
934871A721B3D39B00733E6A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
934871A821B3D39B00733E6A /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = "<group>"; };
93AFAC0D21B434C000C23181 /* Shaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
93AFAC2F21BAFBFB00C23181 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
93B3E23D21F505E1008835A0 /* AlloyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AlloyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
93B3E23F21F505E1008835A0 /* AlloyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlloyTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,8 +208,6 @@
934871A421B3D39B00733E6A /* Main.storyboard */,
934871A721B3D39B00733E6A /* Info.plist */,
934871A821B3D39B00733E6A /* Demo.entitlements */,
93AFAC0D21B434C000C23181 /* Shaders.metal */,
930654D021D55DF700ACD3D7 /* BrightnessEncoder.swift */,
);
path = Demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -596,10 +590,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
93AFAC0E21B434C000C23181 /* Shaders.metal in Sources */,
934871A121B3D39A00733E6A /* ViewController.swift in Sources */,
9348719F21B3D39A00733E6A /* AppDelegate.swift in Sources */,
930654D121D55DF700ACD3D7 /* BrightnessEncoder.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
7 changes: 4 additions & 3 deletions Demo/Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -619,7 +620,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
Expand Down
41 changes: 0 additions & 41 deletions Demo/Demo/BrightnessEncoder.swift

This file was deleted.

23 changes: 0 additions & 23 deletions Demo/Demo/Shaders.metal

This file was deleted.

30 changes: 23 additions & 7 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import Cocoa
import Alloy
import AVFoundation
import SwiftMath

class ViewController: NSViewController {

@IBOutlet weak var imageView: NSImageView!
@IBOutlet weak var slider: NSSlider!

let context = MTLContext(device: Metal.lowPowerDevice!)
var brightnessEncoder: BrightnessEncoder!
var affineCropEncoder: TextureAffineCropEncoder!

let image = NSImage(named: "flower")!

Expand All @@ -25,7 +26,7 @@ class ViewController: NSViewController {

self.imageView.image = self.image

self.brightnessEncoder = BrightnessEncoder(context: self.context)
self.affineCropEncoder = try! TextureAffineCropEncoder(context: self.context)
}

@IBAction func sliderDragged(_ sender: NSSlider) {
Expand All @@ -40,19 +41,34 @@ class ViewController: NSViewController {
else { return }


let cropTextureDescriptor = texture.descriptor
cropTextureDescriptor.usage.insert(.shaderWrite)
cropTextureDescriptor.width = 200
cropTextureDescriptor.height = 100

let transform = Matrix3x3f.translate(tx: 0.5, ty: 0.5)
* Matrix3x3f.rotate(angle: Angle(radians: sender.floatValue))
* Matrix3x3f.scale(sx: 1.9, sy: 0.2)
* Matrix3x3f.translate(tx: -0.5, ty: -0.5)

let cropTexture = context.device.makeTexture(descriptor: cropTextureDescriptor)!

try? self.context.scheduleAndWait { buffer in
self.brightnessEncoder.intensity = sender.floatValue
self.brightnessEncoder.encode(input: texture,
in: buffer)
buffer.compute { encoder in
self.affineCropEncoder.encode(sourceTexture: texture,
destinationTexture: cropTexture,
affineTransform: simd_float3x3(transform),
using: encoder)
}

// For Mac applications (doesn't actually do anything, serves as an example)
if case .managed = texture.storageMode {
buffer.blit { encoder in
encoder.synchronize(resource: texture)
encoder.synchronize(resource: cropTexture)
}
}
}

self.imageView.image = texture.image
self.imageView.image = cropTexture.image
}
}
1 change: 1 addition & 0 deletions Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target 'Demo' do
pod 'Alloy', :path => '../'
pod 'Alloy/Shaders', :path => '../'
pod 'Alloy/ML', :path => '../'
pod 'SwiftMath', :path => '../../SwiftMath'
end

target 'AlloyTests' do
Expand Down
21 changes: 13 additions & 8 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
PODS:
- Alloy (0.10.6):
- Alloy/Core (= 0.10.6)
- Alloy/Core (0.10.6)
- Alloy/ML (0.10.6):
- Alloy (0.10.13):
- Alloy/Core (= 0.10.13)
- Alloy/Core (0.10.13)
- Alloy/ML (0.10.13):
- Alloy/Core
- Alloy/Shaders (0.10.6):
- Alloy/Shaders (0.10.13):
- Alloy/Core
- SwiftMath (3.1.5)

DEPENDENCIES:
- Alloy (from `../`)
- Alloy/ML (from `../`)
- Alloy/Shaders (from `../`)
- SwiftMath (from `../../SwiftMath`)

EXTERNAL SOURCES:
Alloy:
:path: "../"
SwiftMath:
:path: "../../SwiftMath"

SPEC CHECKSUMS:
Alloy: 1bdb714ea3a55350e4e2f6aea3396242aa0b5059
Alloy: 4b975976e4175ab6c3b3714b7f3c3d63ac9f33b1
SwiftMath: bed522f2a3c1b262da0507a9aab6cc139bc02416

PODFILE CHECKSUM: 54f7eb14bb7ebbe7105dd3dec05e031a395a1e79
PODFILE CHECKSUM: bbb877a35edabb939d8eaf9251095a90f65d7433

COCOAPODS: 1.7.5
COCOAPODS: 1.8.1

0 comments on commit 308e76b

Please sign in to comment.