Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Migrating OpenGL code to Metal

At a glance

Item Summary
Purpose Replace your app’s deprecated OpenGL code with Metal.
App architecture A C/Objective-C header, Metal, Objective-C, Objective-C++ sample with the source-visible chain mainAAPLMetalViewControllerAAPLMetalRenderersimd / OpenGLES APIs.
Main patterns View-controller organization, Delegate or data-source callbacks
Project style 21 scanned source file(s) across C/Objective-C header, Metal, Objective-C, Objective-C++, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages simd, OpenGLES, Foundation, OpenGL, UIKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Common/
│   ├── main.m
│   ├── AAPLAppDelegate.h
│   ├── AAPLMeshData.h
│   ├── AAPLAppDelegate.m
│   ├── WindowSceneDelegate.h
│   └── WindowSceneDelegate.m
├── Metal/
│   ├── AAPLMetalRenderer.m
│   ├── AAPLMetalRenderer.h
│   └── AAPLMetalViewController.h
└── OpenGL/
    ├── AAPLOpenGLRenderer.m
    ├── AAPLOpenGLViewController.h
    └── AAPLOpenGLViewController.m

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C/Objective-C header, Metal, Objective-C, Objective-C++.
  • The verified tree contains 9 project/configuration file(s) and 14 source declaration(s).

Overall architecture

Reference code

Common/main.m:19 — architecture anchor

#if defined(TARGET_IOS) || defined(TARGET_TVOS)
int main(int argc, char * argv[]) {
    // ...
#error Metal is not supported in this version of Simulator.
    // ...
}
#endif

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Metal.

Ownership and state

Ownership evidence

Common/AAPLMeshData.h:22 — stored dependency or nearest verified ownership anchor

@interface AAPLSubmeshData : NSObject
// ...
@property (nonatomic, readonly, nonnull) uint32_t *indexData;
// ...
@end
Owner Object or state Relationship Mutation authority
AAPLVertexData uint32_t (indexData) stores or receives The declaring implementation writes; property clients read
AAPLVertexData NSUInteger (indexCount) stores or receives The declaring implementation writes; property clients read
AAPLVertexData NSURL (baseColorMapURL) stores or receives The declaring implementation writes; property clients read
AAPLVertexData AAPLVertexData (vertexData) stores or receives The declaring implementation writes; property clients read

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
Source import simd The cited file imports this module; runtime use and architectural role are not inferred. Common/AAPLCommonDefinitions.h:10
Source import OpenGLES The cited file imports this module; runtime use and architectural role are not inferred. OpenGL/AAPLGLHeaders.h:19
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Common/AAPLMeshData.h:9
Source import OpenGL The cited file imports this module; runtime use and architectural role are not inferred. OpenGL/AAPLGLHeaders.h:13
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. Common/AAPLAppDelegate.h:8
Source import stdlib.h The cited file imports this module; runtime use and architectural role are not inferred. Common/AAPLMathUtilities.h:8

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

Common/AAPLAppDelegate.h:10 — representative type boundary

@interface AAPLAppDelegate : UIResponder <UIApplicationDelegate>

@end
Type Responsibility Depends on or conforms to
AAPLAppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AAPLOpenGLView User-interface presentation and input forwarding PlatformViewBase
AAPLOpenGLViewController View lifecycle, callbacks, and feature coordination PlatformViewController
WindowSceneDelegate Receives callback-driven events UIResponder, UIWindowSceneDelegate
AAPLMetalRenderer Owns drawing, GPU, or presentation processing NSObject, MTKViewDelegate
AAPLMetalViewController View lifecycle, callbacks, and feature coordination PlatformViewController
AAPLOpenGLRenderer Owns drawing, GPU, or presentation processing NSObject
AAPLVertexData Represents feature data Concrete collaborators/imported frameworks
AAPLSubmeshData Represents feature data NSObject
AAPLMeshData Represents feature data NSObject

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
indexData (Common/AAPLMeshData.h:22) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
indexCount (Common/AAPLMeshData.h:24) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
baseColorMapURL (Common/AAPLMeshData.h:26) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
AAPLVertexData (Common/AAPLMeshData.h:37) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.

Reference code

Common/AAPLMeshData.h:22 — representative boundary

@interface AAPLSubmeshData : NSObject
// ...
@property (nonatomic, readonly, nonnull) uint32_t *indexData;
// ...
@end

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
View lifecycle, callbacks, and feature coordination AAPLMetalViewController, AAPLOpenGLViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AAPLAppDelegate, WindowSceneDelegate The source’s Delegate suffix makes this role explicit.
Owns drawing, GPU, or presentation processing AAPLMetalRenderer, AAPLOpenGLRenderer The source’s Renderer suffix makes this role explicit.
User-interface presentation and input forwarding AAPLOpenGLView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Metal/AAPLMetalViewController.h:20 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks Common/AAPLAppDelegate.h:10 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: AAPLMetalViewController, AAPLOpenGLViewController; Delegate: AAPLAppDelegate, WindowSceneDelegate; Renderer: AAPLMetalRenderer, AAPLOpenGLRenderer; View: AAPLOpenGLView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: initWithURL, initWithMetalKitView, buildTempleObjects, buildReflectiveQuadObjects, updateFrameState, mtkView, drawInMTKView, initWithDefaultFBOName.
  • Files: Common/AAPLAppDelegate.h, Common/AAPLMeshData.h, Metal/AAPLMetalRenderer.m, OpenGL/AAPLOpenGLRenderer.m, OpenGL/AAPLOpenGLViewController.h, OpenGL/AAPLOpenGLViewController.m.

Architecture takeaways

  • main is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches simd, OpenGLES, OpenGL, UIKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
Common/main.m Cited implementation, Feature implementation
Common/AAPLMeshData.h Cited implementation, indexData, indexCount, baseColorMapURL, vertexData, Foundation, AAPLVertexData, AAPLSubmeshData, AAPLMeshData
Common/AAPLAppDelegate.h AAPLAppDelegate, Cited implementation, UIKit
Metal/AAPLMetalViewController.h AAPLMetalViewController
Common/AAPLCommonDefinitions.h simd, Feature implementation
OpenGL/AAPLGLHeaders.h OpenGLES, OpenGL, Feature implementation
Common/AAPLMathUtilities.h stdlib.h, Feature implementation
Metal/AAPLMetalRenderer.m AAPLMetalRenderer, AAPLVertexData
OpenGL/AAPLOpenGLRenderer.m AAPLOpenGLRenderer, AAPLVertexData
OpenGL/AAPLOpenGLViewController.h AAPLOpenGLView, AAPLOpenGLViewController
OpenGL/AAPLOpenGLViewController.m AAPLOpenGLView, AAPLOpenGLViewController
Common/AAPLAppDelegate.m AAPLAppDelegate
Common/WindowSceneDelegate.h WindowSceneDelegate
Common/WindowSceneDelegate.m WindowSceneDelegate
Metal/AAPLMetalRenderer.h AAPLMetalRenderer
Metal/AAPLMetalViewController.m AAPLMetalViewController