-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from gadirom/Dedicated-shaders
Dedicated shaders
- Loading branch information
Showing
29 changed files
with
964 additions
and
224 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
Example/Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1410" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "0055B518288CDCDA008580B0" | ||
BuildableName = "Example.app" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
enableThreadSanitizer = "YES" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "0055B518288CDCDA008580B0" | ||
BuildableName = "Example.app" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "0055B518288CDCDA008580B0" | ||
BuildableName = "Example.app" | ||
BlueprintName = "Example" | ||
ReferencedContainer = "container:Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 19 additions & 5 deletions
24
Sources/MetalBuilder/MetalBuilderRenderer/MetalBuilderRenderingContext.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import MetalKit | ||
|
||
/// Class that is passed to the MetalContent closure and contain useful values. | ||
/// Use these values in CPU code or pass them into shaders. | ||
/// Class that is passed to the MetalContent closure and contain useful values and methods. | ||
/// Use the values in CPU code or pass them into shaders. | ||
public final class MetalBuilderRenderingContext{ | ||
/// Viewport size that can be used in a shader | ||
/// Viewport size that can be used in a shader. | ||
@MetalState(metalName: "viewportSize") public var viewportSize: simd_uint2 = [0,0] | ||
/// Scale factor of the view. Used to convert point coordinates into pixel coordinates | ||
/// Scale factor of the view. Used to convert point coordinates into pixel coordinates. | ||
@MetalState(metalName: "scaleFactor") public var scaleFactor: Float = 1 | ||
/// Render time. Starts at zero and pauses when the app is in a background phase | ||
/// Render time. Starts at zero and pauses when the app is in a background phase. | ||
/// | ||
/// You can manually pause and start the timer using `pauseTime` and `resumeTime` methods. | ||
@MetalState(metalName: "time") public var time: Float = 0 | ||
|
||
|
||
weak var timer: MetalBuilderTimer? | ||
|
||
/// Pauses the timer. | ||
public func pauseTime(){ | ||
timer?.manualPause() | ||
} | ||
/// Resumes the timer. | ||
public func resumeTime(){ | ||
timer?.manualResume() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
Sources/MetalBuilder/MetalBuilderRenderer/MetalBuilderTimer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import AVFoundation | ||
|
||
class MetalBuilderTimer{ | ||
|
||
public var time: Float{ | ||
_time | ||
} | ||
|
||
private var _time: Float = 0 | ||
private var startTime: Double = 0 | ||
private var pausedTime: Double = 0 | ||
private var justStarted = true | ||
private var paused = true | ||
|
||
private var manualPaused = false | ||
|
||
// private let timerQueue = DispatchQueue(label: "MetalBuilderTimer_Queue", | ||
// qos: .userInitiated) | ||
|
||
func count(){ | ||
//timerQueue.sync { | ||
if justStarted { | ||
startTime = CFAbsoluteTimeGetCurrent() | ||
justStarted = false | ||
paused = false | ||
} | ||
if paused { return } | ||
_time = Float(CFAbsoluteTimeGetCurrent()-startTime) | ||
//} | ||
} | ||
//Pause and resume manually by the client | ||
func manualPause(){ | ||
manualPaused = true | ||
pauseTime() | ||
} | ||
func manualResume(){ | ||
manualPaused = false | ||
resumeTime() | ||
} | ||
//Pause and resume for going in and from background | ||
func backgroundPause(){ | ||
pauseTime() | ||
} | ||
func backgroundResume(){ | ||
if manualPaused { return } | ||
resumeTime() | ||
} | ||
|
||
private func pauseTime(){ | ||
guard !justStarted | ||
else{return} | ||
guard !paused | ||
else{return} | ||
pausedTime = CFAbsoluteTimeGetCurrent() | ||
paused = true | ||
print("time paused!") | ||
} | ||
private func resumeTime(){ | ||
guard !justStarted | ||
else{return} | ||
guard paused | ||
else{return} | ||
startTime += CFAbsoluteTimeGetCurrent()-pausedTime | ||
paused = false | ||
print("time resumed!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.