<!--
{
  "availability" : [
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CompositorServices",
  "identifier" : "/documentation/CompositorServices/LayerRenderer/Drawable/addRenderContext(commandBuffer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Compositor Services",
      "CompositorServices"
    ],
    "preciseIdentifier" : "c:@F@cp_drawable_add_render_context"
  },
  "title" : "addRenderContext(commandBuffer:)"
}
-->

# addRenderContext(commandBuffer:)

Adds and returns a render context to a `LayerRenderer.Drawable` providing a metal command buffer.

```
func addRenderContext(commandBuffer cmd_buffer: any MTLCommandBuffer) -> LayerRenderer.Drawable.RenderContext
```

## Discussion

This object draws any content that the compositor needs to render in the app.
The [`LayerRenderer.Drawable.RenderContext`](/documentation/CompositorServices/LayerRenderer/Drawable/RenderContext) can only be used when the layer renderer is using layered layout or on platforms that only render one view, such as the Simulator.
The `RenderContext` makes use of the [`deviceAnchor`](/documentation/CompositorServices/LayerRenderer/Drawable/deviceAnchor) set in [`cp_drawable_set_device_anchor`](/documentation/CompositorServices/cp_drawable_set_device_anchor).
Only use the `deviceAnchor` in the layer renderer drawable before calling [`addRenderContext(commandBuffer:)`](/documentation/CompositorServices/LayerRenderer/Drawable/addRenderContext(commandBuffer:)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)