<!--
{
  "availability" : [
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ParavirtualizedGraphics",
  "identifier" : "/documentation/ParavirtualizedGraphics/PGDisplay/encodeCurrentFrame(to:texture:region:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Paravirtualized Graphics"
    ],
    "preciseIdentifier" : "c:objc(pl)PGDisplay(im)encodeCurrentFrameToCommandBuffer:texture:region:"
  },
  "title" : "encodeCurrentFrame(to:texture:region:)"
}
-->

# encodeCurrentFrame(to:texture:region:)

Encodes Metal commands to process the current frame and write it to a texture.

```
func encodeCurrentFrame(to commandBuffer: any MTLCommandBuffer, texture: any MTLTexture, region: MTLRegion) -> Bool
```

## Parameters

`commandBuffer`

The Metal command buffer for encoding the processing of the new frame.

`texture`

The destination texture.

`region`

The region within the Metal texture for the frame data to land in.

## Return Value

Returns <doc://com.apple.documentation/documentation/Swift/true> if the method encoded the commands successfully; otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

This method encodes Metal commands to process the new frame, dealing with color matching, gamma, and other factors. The GPU writes data to a region inside the destination texture, linearly scaled as necessary to fit in the specified region. The encoded commands won’t change any texture data outside the specified region.

The texture and command buffer must share the same Metal device object that you used to create the virtual graphics device. The destination texture must specify all of the usage bits that the display’s [`minimumTextureUsage`](/documentation/ParavirtualizedGraphics/PGDisplay/minimumTextureUsage) property provides, but can specify additional flags.

Typically, you encode frame processing in response to a call to the frame event handler you specified when you created the display object. See [`newFrameEventHandler`](/documentation/ParavirtualizedGraphics/PGDisplayDescriptor/newFrameEventHandler) for more information.

---

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)