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. |
||
|---|---|---|
| .. | ||
| Application | ||
| Configuration | ||
| Documentation | ||
| Hello Triangle.xcodeproj | ||
| Metal 4 renderer | ||
| Metal renderer | ||
| Renderer common | ||
| Shaders | ||
| UI | ||
| View controller | ||
| .gitignore | ||
| LICENSE.txt | ||
| README.md | ||
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:
- Updating the vertex data for the triangle
- Encoding draw commands as a frame of visual content
- Running the draw commands on a Metal device that represents an Apple silicon GPU
- 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:
For more information about the app and how it works, see Drawing a triangle with Metal 4 in the developer documentation.
