cupertino-sample-code/metal-drawing-a-triangle-with-metal-4
Mihaela Mihaljevic 2e932c3330 data: refresh sample-code from .cupertino/sample-code/
Bulk update of extracted Apple sample-code archives from
/Users/mmj/.cupertino/sample-code/, the source the v1.0.0 / v1.0.1
release database bundles indexed.

627 source zips processed:
- 619 extracted successfully
- 8 invalid zips skipped (samplecode.zip, accessibility.zip,
  appintents.zip, ios-ipados-release-notes.zip, watchos-release-notes.zip,
  visionos-release-notes-visionos-release-notes.zip, updates.zip,
  technologyoverviews-.zip — all corrupt downloads, not real samples,
  cupertino crawler #TBD).

Result: 632 sample directories (was 606). 1,166 file-level changes:
139 new, 582 modified, 445 deleted. Sample directories whose zips
extracted byte-identical to the previous version produce zero git
changes.
2026-05-09 13:33:22 +02:00
..
Application data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
Configuration Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
Documentation Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
Hello Triangle.xcodeproj data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
Metal 4 renderer data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
Metal renderer data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
Renderer common data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
Shaders Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
UI data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
View controller data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
.gitignore Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
LICENSE.txt data: refresh sample-code from .cupertino/sample-code/ 2026-05-09 13:33:22 +02:00
README.md Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00

Drawing a triangle with Metal 4

Render a colorful, rotating 2D triangle by running draw commands with a render pipeline on a GPU.

Overview

This sample demonstrates how to render imagery by sending commands to the GPU with the Metal 4 API, and relates to WWDC25 session 205: Discover Metal 4.

Multiple times a second, the sample's app displays a colorful triangle by:

  1. Updating the vertex data for the triangle
  2. Encoding draw commands as a frame of visual content
  3. Running the draw commands on a Metal device that represents an Apple silicon GPU
  4. Updating the display after the GPU finishes rendering that frame

Apps can give a person the impression of motion by rendering and displaying frames at a sufficient frequency, typically at 60 frames or more per second.

The renderer encodes one frame at a time, and has three frames of content in flight at the same time. Starting when the first frame is visible on the display, the renderer is continually managing three frames at once:

  • The first frame is in its final lifetime phase as the frame that's visible to a person on the device's display.
  • The second frame is in its second lifetime phase where the GPU renders it in a render pass, which is the collection of render commands that draw the triangle.
  • The third frame is in its first lifetime phase where the renderer encodes the draw commands for the next render pass by using the Metal API on the CPU.

The renderer manages the frames as each progresses through its three lifetime phases. The diagram below illustrates how the first frames move through time, where each column represents a snapshot of the app's current frames and their states:

A timeline diagram that shows how frames progress through their lifetime phases by dividing time into vertical columns, each of which represents a snapshot in time as they flow from left to right. The first column has one box with the label "encode frame 1". The second column has two boxes with the labels "encode frame 2" and "execute frame 1". The third column has three boxes with the labels "encode frame 3", "execute frame 2" and "display frame 1". The next two columns continue the pattern with three boxes each, where column five has the labels "encode frame 5", "execute frame 4", and "display frame 3". The final, right-most column has three boxes, each with an ellipsis that indicates the pattern continues indefinitely.

For more information about the app and how it works, see Drawing a triangle with Metal 4 in the developer documentation.