Skip to content

Instantly share code, notes, and snippets.

@schwa
schwa / splat-formats.md
Last active September 3, 2026 17:42
splat-formats.md

Splat formats

Bytes per splat is measured on a test file: an interior scan of a room, 711,677 splats, with degree-3 spherical harmonics.

Format Source Year B/splat Lossy SH Extensible Fixed order
.ply INRIA convention (reference) 2023 248.0 no yes yes[^ply] no
.splat antimatter15 2023 32.0 yes no[^splatsh] no no
.sog PlayCanvas 2025 17.4 yes yes unofficial[^sog] yes[^sogorder]
@schwa
schwa / functions.swift
Created September 18, 2025 19:05
Metal Visible Functions:
// https://developer.apple.com/videos/play/wwdc2020/10013
// Using Metal Visible Functions:
// 1. Define a function pointer type alias in the kernel (e.g., `using OperationFunction = float(float, constant void *)`)
// 2. Kernel takes a `visible_function_table<FunctionType>` parameter
// 3. Mark functions as `[[visible]]` in Metal shader code
// 4. Use MTLLinkedFunctions to link visible functions when creating the compute pipeline
// 5. Create MTLVisibleFunctionTable and populate with function handles from the pipeline
// 6. Pass the visible function table to compute encoder with setVisibleFunctionTable()
// 7. Access functions in kernel via table index: `operationFunctions[index]`
@schwa
schwa / XForms.swift
Created June 12, 2024 06:18
XForms.swift
import SwiftUI
struct XForm <Content>: View where Content: View {
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
//
// ContentView.swift
// HotOrNot
//
// Created by Jonathan Wight on 6/10/24.
//
import SwiftUI
import Vision
@schwa
schwa / ScreenSaver.swift
Created March 20, 2024 19:52
Silly Swift Screen Saver Sample Source
import SwiftUI
struct Point {
var position: CGPoint
var velocity: CGPoint
}
struct ContentView: View {
@State
var lines: [[Point]] = []
@schwa
schwa / SwiftUI for macOS Missing Features.md
Last active January 31, 2024 02:45
SwiftUI for macOS Missing Features

https://mastodon.social/@schwa/111801520286334341

My list:

  • Tap location for contextual menus. A lot of apps need to know exactly where a context menu is being triggered from (e.g. canvas style editors etc).
  • Modifier key observation during button presses/gestures etc.
  • Cursor support
  • Native Undo Manager support (SwiftUI has Environment.undoManager but it just exposes Cocoa's UndoManager which doesn't feel very SwiftUI like).
  • Expanded File Dialog options (e.g. adding buttons to the dialog).
  • The outline variant of List (List(… children: …)) is missing a lot of the flexibility of NSOutlineView (TODO: flesh this out with concrete example).
@schwa
schwa / SharedWindow.swift
Created December 15, 2023 19:28
SwiftUI example showing how to make a Shared Content Window…
import SwiftUI
import Observation
import os
/// A trick in SwiftUI to have a singls shared global window.
/// We want the user to be able to show and hide this window, and change the content in it. Hitting show multiply times should NOT open multiple windows but instead should bring the shared window forward.
/// The trick is to use a dummy Singleton type (here we embed it with the shared content) that we can pass to open/dismissWindow and the WindowGroup. The dummy SIngleton type must contain no properties and merely exists to trick SwiftUI into only ever showing one window for the type at a time.
@Observable
class SharedContent {
@schwa
schwa / ImmersiveSpaceHelper.swift
Created October 16, 2023 18:05
SwiftUI helpers to make dealing with ImmsersiveSpaces less annoying.
/// Create an ``ImmersiveSpaceState`` in your view, wrap it with `@State` and modify your view content with ``immersiveSpaceHelper()``.
/// Example:
/// ```swift
/// struct MyView: View {
/// @State
/// var immersiveSpaceState = ImmersiveSpaceState(id: "my-immersive-space-id")
///
/// var body: some View {
/// Toggle("Show/Hide Immersive Space", isOn: $immersiveSpaceState.show)
/// .immersiveSpaceHelper($immersiveSpaceState)
@schwa
schwa / Devices.md
Created September 15, 2023 03:22
Metal 3 Availablity & GPU Family Table

Metal 3 Availablity & GPU Family Table

Device OS SOC Metal GPU Family
iPhone 6S & 6S Plus iOS 15 A8 2 Apple2
iPhone SE (1st generation) iOS 15 A9 2 Apple3
iPhone 7 & 7 Plus iOS 15 A10 Fusion 2 Apple3
iPod Touch (7th generation) iOS 15 A10 Fusion 2 Apple3
iPhone 8 & 8 Plus iOS 15, 16 A11 Bionic 2 Apple4
iPhone X iOS 15, 16 A11 Bionic 2 Apple4