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

Rendering a scene with deferred lighting in C++

At a glance

Item Summary
Purpose Avoid expensive lighting calculations by implementing a deferred lighting renderer optimized for immediate mode and tile-based deferred renderer GPUs.
App architecture A C++, C/Objective-C header, Metal, Objective-C, Objective-C++, Python sample bundle with entry-bearing project variants Application, metal-cpp, each leading to Metal / metal_stdlib APIs.
Main patterns View-controller organization, Delegate or data-source callbacks, Adapter
Project style 33 scanned source file(s) across C++, C/Objective-C header, Metal, Objective-C, Objective-C++, Python, 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 Metal, metal_stdlib, simd, MetalKit, QuartzCore; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Application/
│   ├── main.m
│   ├── AAPLAppDelegate.h
│   ├── AAPLAppDelegate.m
│   ├── AAPLViewController.h
│   ├── AAPLViewController.mm
│   ├── WindowSceneDelegate.h
│   └── WindowSceneDelegate.m
└── Renderer/
    ├── AAPLViewAdapter.h
    ├── AAPLRenderer.cpp
    ├── AAPLBufferExaminationManager.h
    ├── AAPLMesh.h
    └── AAPLRenderer.h

Structure observations

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

Overall architecture

Reference code

Application/main.m:19 — architecture anchor

#if defined(TARGET_IOS) || defined(TARGET_TVOS)
int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AAPLAppDelegate class]));
    }
}
#endif

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

Application/WindowSceneDelegate.h:17 — stored dependency or nearest verified ownership anchor

#if defined(TARGET_IOS) || defined(TARGET_TVOS)
@property (nonatomic, strong) UIWindow *window;
#endif
Owner Object or state Relationship Mutation authority
WindowSceneDelegate UIWindow (window) retains or copies an assigned value Header-visible collaborators

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 Metal The cited file imports this module; runtime use and architectural role are not inferred. Renderer/AAPLBufferExaminationManager.h:14
Source import metal_stdlib The cited file imports this module; runtime use and architectural role are not inferred. Renderer/Shaders/AAPLBufferExamination.metal:7
Source import simd The cited file imports this module; runtime use and architectural role are not inferred. Renderer/AAPLBufferExaminationManager.cpp:15
Source import MetalKit The cited file imports this module; runtime use and architectural role are not inferred. Application/AAPLViewController.h:16
Source import QuartzCore The cited file imports this module; runtime use and architectural role are not inferred. Renderer/AAPLBufferExaminationManager.cpp:17
Source import stdlib.h The cited file imports this module; runtime use and architectural role are not inferred. Renderer/AAPLMathUtilities.cpp:21

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

Application/AAPLAppDelegate.h:12 — representative type boundary

#if defined(TARGET_IOS) || defined(TARGET_TVOS)
@interface AAPLAppDelegate : UIResponder <UIApplicationDelegate>

@end
#endif
Type Responsibility Depends on or conforms to
AAPLAppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AAPLViewAdapter Translates one interface or representation into another Concrete collaborators/imported frameworks
Renderer Owns drawing, GPU, or presentation processing Concrete collaborators/imported frameworks
BufferExaminationManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
AAPLViewController View lifecycle, callbacks, and feature coordination PlatformViewController, MTKViewDelegate
WindowSceneDelegate Receives callback-driven events UIResponder, UIWindowSceneDelegate
Renderer Owns drawing, GPU, or presentation processing Concrete collaborators/imported frameworks
MetalDrawable Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
Texture Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
RenderPassDescriptor Describes an operation or framework input Concrete collaborators/imported frameworks

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
window (Application/WindowSceneDelegate.h:17) 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.
MakeSingleHeader (metal-cpp/SingleHeader/MakeSingleHeader.py:249) language/file boundary Visibility follows the language’s file, module, and export rules rather than Swift access modifiers. Inference: the language’s file or module boundary is sufficient for this sample collaboration.

Reference code

Application/WindowSceneDelegate.h:17 — representative boundary

#if defined(TARGET_IOS) || defined(TARGET_TVOS)
@property (nonatomic, strong) UIWindow *window;
#endif

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
Translates one interface or representation into another AAPLViewAdapter The source’s Adapter suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination AAPLViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AAPLAppDelegate, WindowSceneDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination BufferExaminationManager The source’s Manager suffix makes this role explicit.
Owns drawing, GPU, or presentation processing Renderer The source’s Renderer suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Application/AAPLViewController.h:19 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks Application/AAPLAppDelegate.h:12 Callback protocols invert event delivery back into the sample’s owner.
Adapter Renderer/AAPLViewAdapter.h:25 An adapter-named type translates interfaces or representations.

Naming conventions

  • Types: Adapter: AAPLViewAdapter; Controller: AAPLViewController; Delegate: AAPLAppDelegate, WindowSceneDelegate; Manager: BufferExaminationManager; Renderer: Renderer.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: application, applicationShouldTerminateAfterLastWindowClosed, viewDidLoad, _setupView, dealloc, mtkView, drawInMTKView, touchesBegan.
  • Files: Application/AAPLAppDelegate.h, Renderer/AAPLViewAdapter.h, Application/AAPLAppDelegate.m, Application/AAPLViewController.h, Application/AAPLViewController.mm, Application/WindowSceneDelegate.h.

Architecture takeaways

  • main is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Metal, metal_stdlib, simd, MetalKit 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
Application/main.m Cited implementation, Feature implementation
Application/WindowSceneDelegate.h Cited implementation, window, WindowSceneDelegate
Application/AAPLAppDelegate.h AAPLAppDelegate, Cited implementation
metal-cpp/SingleHeader/MakeSingleHeader.py Cited implementation, HeaderPrefix, SingleHeader
Application/AAPLViewController.h AAPLViewController, MetalKit
Renderer/AAPLViewAdapter.h AAPLViewAdapter, MetalDrawable, Texture, RenderPassDescriptor
Renderer/AAPLBufferExaminationManager.h Metal, Renderer, BufferExaminationManager
Renderer/Shaders/AAPLBufferExamination.metal metal_stdlib, LightInfoData, RenderTextureData
Renderer/AAPLBufferExaminationManager.cpp simd, QuartzCore, Feature implementation
Renderer/AAPLMathUtilities.cpp stdlib.h, Feature implementation
Renderer/AAPLRenderer.cpp Feature implementation
Application/AAPLAppDelegate.m AAPLAppDelegate
Application/AAPLViewController.mm AAPLViewController
Application/WindowSceneDelegate.m WindowSceneDelegate
Renderer/AAPLMesh.h MeshVertex, MeshBuffer, Submesh, Mesh
Renderer/AAPLRenderer.h Renderer