Culling occluded geometry using the visibility result buffer
At a glance
| Item | Summary |
|---|---|
| Purpose | Draw a scene without rendering hidden geometry by checking whether each object in the scene is visible. |
| App architecture | A C/Objective-C header, Metal, Objective-C sample with the source-visible chain main → AAPLViewController → AAPLRenderer → metal_stdlib APIs. |
| Main patterns | Delegate or data-source callbacks |
| Project style | 11 scanned source file(s) across C/Objective-C header, Metal, 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 | Foundation, metal_stdlib, simd; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Application/
│ ├── main.m
│ ├── AAPLAppDelegate.h
│ ├── AAPLAppDelegate.m
│ ├── AAPLViewController.h
│ ├── AAPLViewController.m
│ ├── WindowSceneDelegate.h
│ ├── WindowSceneDelegate.m
│ └── iOS/
│ └── Base.lproj/
│ └── Main.storyboard
└── Renderer/
├── AAPLRenderer.h
├── AAPLRenderer.m
├── AAPLShaders.metal
└── AAPLShaderTypes.h
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.
- The verified tree contains 9 project/configuration file(s) and 6 source declaration(s).
Overall architecture
flowchart LR
N1["main"]
N2["AAPLViewController"]
N3["AAPLRenderer"]
N4["metal_stdlib APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Application/main.m:12 — architecture anchor
#if defined(TARGET_MACOS)
int main(int argc, const char * argv[])
{
@autoreleasepool {
return NSApplicationMain(argc, argv);
}
}
#endifInterpretation
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
classDiagram
AAPLAppDelegate o-- PlatformWindow : window
WindowSceneDelegate o-- UIWindow : window
AAPLRenderer o-- size_t : numVisibleFragments
AAPLRenderer o-- size_t : numSpheresDrawn
Ownership evidence
Application/AAPLAppDelegate.h:27 — stored dependency or nearest verified ownership anchor
#if defined(TARGET_MACOS)
@property (strong, nonatomic) PlatformWindow *window;
#endif| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AAPLAppDelegate |
PlatformWindow (window) |
retains or copies an assigned value | Header-visible collaborators |
WindowSceneDelegate |
UIWindow (window) |
retains or copies an assigned value | Header-visible collaborators |
AAPLRenderer |
size_t (numVisibleFragments) |
stores or receives | The declaring implementation writes; property clients read |
AAPLRenderer |
size_t (numSpheresDrawn) |
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 | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLShaderTypes.h:14 |
| Source import | metal_stdlib |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLShaders.metal:8 |
| Source import | simd |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLShaderTypes.h: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:24 — representative type boundary
@interface AAPLAppDelegate : PlatformAppDelegate
#if defined(TARGET_MACOS)
@property (strong, nonatomic) PlatformWindow *window;
#endif
@end| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AAPLAppDelegate |
Receives callback-driven events | PlatformAppDelegate |
AAPLViewController |
View lifecycle, callbacks, and feature coordination | PlatformViewController, MTKViewDelegate |
WindowSceneDelegate |
Receives callback-driven events | UIResponder, UIWindowSceneDelegate |
AAPLRenderer |
Owns drawing, GPU, or presentation processing | NSObject |
RasterizerData |
Represents feature data | Concrete collaborators/imported frameworks |
MeshIndexData |
Represents feature data | 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/AAPLAppDelegate.h:27) |
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. |
window (Application/WindowSceneDelegate.h:15) |
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. |
numVisibleFragments (Renderer/AAPLRenderer.h:19) |
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. |
numSpheresDrawn (Renderer/AAPLRenderer.h:20) |
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
Application/AAPLAppDelegate.h:27 — representative boundary
#if defined(TARGET_MACOS)
@property (strong, nonatomic) PlatformWindow *window;
#endifSwift 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 | 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. |
| Owns drawing, GPU, or presentation processing | AAPLRenderer |
The source’s Renderer suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | Application/AAPLAppDelegate.h:24 |
Callback protocols invert event delivery back into the sample’s owner. |
Main application flow
sequenceDiagram
participant AAPLViewController
participant _renderer
participant NSString
participant _modeDisplay
participant _numDisplay
AAPLViewController->>_renderer: drawInMTKView()
AAPLViewController->>NSString: initWithFormat()
AAPLViewController->>NSString: initWithFormat()
AAPLViewController->>_modeDisplay: setStringValue()
AAPLViewController->>_numDisplay: setStringValue()
AAPLViewController->>_modeDisplay: setText()
AAPLViewController->>_numDisplay: setText()
Reference code
Application/AAPLViewController.m:121 — drawInMTKView()
- (void) drawInMTKView:(nonnull MTKView*) view
{
#if defined(TARGET_TVOS)
// The sample animates the position variable for lack of a slider control.
_renderer.position = sin(CACurrentMediaTime() / 5.0);
#endif
[_renderer drawInMTKView:view];
// Set the label and value depending on the mode of the app.
NSString* label = @"";
NSString* value = @"";
if(_renderer.visibilityTestingMode == AAPLFragmentCountingMode)
{
label = @"Fragment count:";
value = [[NSString alloc] initWithFormat:@"%lu", _renderer.numVisibleFragments];
}
else if(_renderer.visibilityTestingMode == AAPLOcclusionCullingMode)
{
label = @"Spheres drawn:";
value = [[NSString alloc] initWithFormat:@"%lu / %u", _renderer.numSpheresDrawn, AAPLNumObjectsXYZ];
}
#if defined(TARGET_MACOS)
[_modeDisplay setStringValue:label];
[_numDisplay setStringValue:value];
#elif defined(TARGET_IOS) || defined(TARGET_TVOS)
[_modeDisplay setText:label];
[_numDisplay setText:value];
#endif
}Naming conventions
- Types: Controller: AAPLViewController; Delegate: AAPLAppDelegate, WindowSceneDelegate; Renderer: AAPLRenderer.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
application,viewDidLoad,optionChanged,modeChanged,toggleMode,drawInMTKView,mtkView,scene. - Files:
Application/AAPLAppDelegate.h,Application/AAPLAppDelegate.m,Application/AAPLViewController.h,Application/AAPLViewController.m,Application/WindowSceneDelegate.h,Application/WindowSceneDelegate.m.
Architecture takeaways
mainis the main source-visible entry or composition anchor for this sample.- Framework work reaches metal_stdlib, simd 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/AAPLAppDelegate.h |
Cited implementation, AAPLAppDelegate, window |
Application/WindowSceneDelegate.h |
window, WindowSceneDelegate |
Renderer/AAPLRenderer.h |
numVisibleFragments, numSpheresDrawn, AAPLRenderer |
Renderer/AAPLShaderTypes.h |
Foundation, simd, Feature implementation |
Renderer/AAPLShaders.metal |
metal_stdlib, RasterizerData, MeshIndexData |
Application/AAPLAppDelegate.m |
AAPLAppDelegate |
Application/AAPLViewController.h |
AAPLViewController |
Application/AAPLViewController.m |
AAPLViewController |
Application/WindowSceneDelegate.m |
WindowSceneDelegate |
Renderer/AAPLRenderer.m |
AAPLRenderer |