Skip to content

Commit

Permalink
Add metal demo (#38)
Browse files Browse the repository at this point in the history
* Add metal demo

* Remove Vulkan import
  • Loading branch information
ctreffs authored Jun 30, 2023
1 parent 0e8b963 commit dcdbf0a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
7 changes: 0 additions & 7 deletions Demos/CPUBackendDemoApp/main.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// main.swift
// Fireblade PAL
//
// Copyright © 2018-2023 Fireblade Team. All rights reserved.
// Licensed under MIT License. See LICENSE file for details.

import FirebladePAL

Platform.initialize()
Expand Down
39 changes: 39 additions & 0 deletions Demos/MetalBackendDemoApp/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#if FRB_GRAPHICS_METAL

import FirebladePAL
import Metal

Platform.initialize()
print("Platform version: \(Platform.version)")

func makeMTLSurface(in window: Window) throws -> MTLWindowSurface {
let surface = try MTLWindowSurface(in: window, device: MTLCreateSystemDefaultDevice())
surface.mtlLayer?.backgroundColor = .init(red: 1.0, green: 0.0, blue: 1.0, alpha: 1.0)
return surface
}

let props = WindowProperties(title: "Metal Window", frame: .init(0, 0, 800, 600))

let window = try Window(properties: props,
surface: makeMTLSurface)

var event = Event()
var quit = false

while !quit {
Events.pumpEvents()

while Events.pollEvent(&event) {
switch event.variant {
case .userQuit:
quit = true

default:
break
}
}
}

Platform.quit()

#endif
9 changes: 1 addition & 8 deletions Demos/VulkanBackendDemoApp/main.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// main.swift
// Fireblade PAL
//
// Copyright © 2018-2023 Fireblade Team. All rights reserved.
// Licensed under MIT License. See LICENSE file for details.

#if FRB_GRAPHICS_VULKAN

import FirebladePAL
Expand All @@ -17,7 +10,7 @@
return try VLKWindowSurface(in: window, instance: vulkanInstance)
}

let props = WindowProperties(title: "Title", frame: .init(0, 0, 800, 600))
let props = WindowProperties(title: "Vulkan Window", frame: .init(0, 0, 800, 600))

let window = try Window(properties: props,
surface: makeVLKSurface)
Expand Down
6 changes: 6 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ let package = Package(
path: "Demos/VulkanBackendDemoApp",
swiftSettings: swiftSettings
),
.executableTarget(
name: "MetalBackendDemoApp",
dependencies: ["FirebladePAL"],
path: "Demos/MetalBackendDemoApp",
swiftSettings: swiftSettings
),
.testTarget(name: "FirebladePALTests",
dependencies: ["FirebladePAL"]),
]
Expand Down
10 changes: 5 additions & 5 deletions Sources/FirebladePAL/Platform/SDL/SDLWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@

public var sizeInPixels: Size<Int> {
#if os(macOS) || os(iOS) || os(tvOS)
var w: Int32 = 0, h: Int32 = 0
SDL_GetWindowSizeInPixels(_window, &w, &h)
return Size(width: Int(w), height: Int(h))
var w: Int32 = 0, h: Int32 = 0
SDL_GetWindowSizeInPixels(_window, &w, &h)
return Size(width: Int(w), height: Int(h))
#else
#warning("Requires SDL 2.26.0 - falling back to `size`.")
return size
#warning("Requires SDL 2.26.0 - falling back to `size`.")
return size
#endif
}

Expand Down

0 comments on commit dcdbf0a

Please sign in to comment.