Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store

# Xcode
# this ignores dummy workspace files in xcodeproj dir
ParticleCam.xcodeproj/*
!ParticleCam.xcodeproj/project.pbxproj
35 changes: 33 additions & 2 deletions ParticleCam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@
3EA930931B75BFFA0067276D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0700;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Simon Gladman";
TargetAttributes = {
3EA9309A1B75BFFA0067276D = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = ZBFYF9JG5V;
DevelopmentTeam = 6CFA54MQCP;
LastSwiftMigration = 1010;
ProvisioningStyle = Manual;
};
};
};
Expand Down Expand Up @@ -206,13 +208,23 @@
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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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";
Expand Down Expand Up @@ -251,13 +263,23 @@
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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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";
Expand All @@ -276,6 +298,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
TARGETED_DEVICE_FAMILY = 2;
VALIDATE_PRODUCT = YES;
};
Expand All @@ -287,11 +310,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 6CFA54MQCP;
INFOPLIST_FILE = ParticleCam/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = uk.co.flexmonkey.ParticleCam;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "(dan jan 16) Dev Any App";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -302,11 +329,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = ParticleCam/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = uk.co.flexmonkey.ParticleCam;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

29 changes: 1 addition & 28 deletions ParticleCam/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

2 changes: 2 additions & 0 deletions ParticleCam/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Camera access is used to get live video feed for particle processing</string>
</dict>
</plist>
28 changes: 14 additions & 14 deletions ParticleCam/ParticleLab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ import MetalPerformanceShaders

class ParticleCamFilter: MetalImageFilter
{
let particleCount = ParticleCount.OneMillion.rawValue
let particleCount = ParticleCount.oneMillion.rawValue
let alignment:Int = 0x4000
let particlesMemoryByteSize:Int

var particlesMemory:UnsafeMutablePointer<Void> = nil
let particlesVoidPtr: COpaquePointer
var particlesMemory:UnsafeMutableRawPointer? = nil
let particlesVoidPtr: OpaquePointer
let particlesParticlePtr: UnsafeMutablePointer<Particle>
let particlesParticleBufferPtr: UnsafeMutableBufferPointer<Particle>

lazy var particlesBufferNoCopy: MTLBuffer =
{
[unowned self] in

return self.device.newBufferWithBytesNoCopy(self.particlesMemory,
return self.device.makeBuffer(bytesNoCopy: self.particlesMemory!,
length: Int(self.particlesMemoryByteSize),
options: .CPUCacheModeDefaultCache,
deallocator: nil)
options: MTLResourceOptions(),
deallocator: nil)!
}()

let particleSize = sizeof(Particle)
let particleSize = MemoryLayout<Particle>.size

// MARK: Initialisation

init()
{
particlesMemoryByteSize = particleCount * sizeof(Particle)
particlesMemoryByteSize = particleCount * MemoryLayout<Particle>.size

posix_memalign(&particlesMemory, alignment, particlesMemoryByteSize)

particlesVoidPtr = COpaquePointer(particlesMemory)
particlesVoidPtr = OpaquePointer(particlesMemory!)
particlesParticlePtr = UnsafeMutablePointer<Particle>(particlesVoidPtr)
particlesParticleBufferPtr = UnsafeMutableBufferPointer(start: particlesParticlePtr, count: particleCount)

Expand Down Expand Up @@ -109,11 +109,11 @@ class ParticleCamFilter: MetalImageFilter

enum ParticleCount: Int
{
case QuarterMillion = 262144
case HalfMillion = 524288
case OneMillion = 1048576
case TwoMillion = 2097152
case FourMillion = 4194304
case quarterMillion = 262144
case halfMillion = 524288
case oneMillion = 1048576
case twoMillion = 2097152
case fourMillion = 4194304
}

// Particles use x and y for position and z and w for velocity
Expand Down
4 changes: 2 additions & 2 deletions ParticleCam/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ViewController: UIViewController, CameraCaptureHelperDelegate
{
let imageView = MetalImageView()

let cameraCaptureHelper = CameraCaptureHelper(cameraPosition: .Front)
let cameraCaptureHelper = CameraCaptureHelper(cameraPosition: .front)

let particleCamFilter = ParticleCamFilter()

Expand All @@ -36,7 +36,7 @@ class ViewController: UIViewController, CameraCaptureHelperDelegate
}


func newCameraImage(cameraCaptureHelper: CameraCaptureHelper, image: CIImage)
func newCameraImage(_ cameraCaptureHelper: CameraCaptureHelper, image: CIImage)
{
particleCamFilter.inputImage = image

Expand Down
Loading