Skip to content
Glitchless smooth window resizing in Metal
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
MetalTest2.xcodeproj Metal Layer view plus other improvements Jun 20, 2019
MetalTest2 Improve handling of .topLeft placement policy Jun 20, 2019
img Add gif to Readme Jun 20, 2019
.gitignore Add repo stuff Jun 20, 2019
LICENSE Add repo stuff Jun 20, 2019
Readme.md Readme title Jun 20, 2019

Readme.md

Metal Window Resizing Test Project

The goal of this project was to figure out a way to do glitchless smooth window resizing with Metal, I succeeded. MTKView has a problem where the redrawing is not synchronized with the window resize so it draws stretched frames, but there's a way to use CAMetalLayer to make it work.

This project draws views with a triangle with two vertices at fixed offsets from the left edge, and one vertex at a fixed offset from the right edge. It has three implementations that are displayed stacked vertically in the following order:

  1. MTKView. Which is supposed to be the easy view. Apple's Hello Triangle example uses this, and suffers terrible resize juddering. Code is in MetalView.swift.
  2. NSView. This is a benchmark implementation that draws the triangle with Core Graphics, it works perfectly. Code is in CocoaView.swift.
  3. CAMetalLayer. Implemented according to the top answer from this Stack Overflow question. Using just the Stack Overflow answer works better than MTKView but still glitches occasionally. It's also necessary to use presentsWithTransaction and follow the recommendations in the docs for that option regarding waitUntilScheduled, that delivers completely glitch-free results. Code is in MetalLayerView.swift.

GIF

Triangles are stacked in the order listed above, watch the top vertex of the top triangle:

Screen Recording

You can’t perform that action at this time.