render(_:to:commandBuffer:bounds:colorSpace:)
Renders a region of an image to a Metal texture.
Declaration
func render(_ image: CIImage, to texture: any MTLTexture, commandBuffer: (any MTLCommandBuffer)?, bounds: CGRect, colorSpace: CGColorSpace)Parameters
- image:
A Core Image image object.
- texture:
The destination Metal texture object.
- commandBuffer:
The Metal command buffer into which to schedule Core Image rendering tasks.
- bounds:
The rectangle in the destination texture to draw into.
- colorSpace:
The color space of the destination texture.
Discussion
If you specify nil for the commandBuffer parameter, Core Image manages its own Metal command buffer. To combine Core Image rendering with other Metal rendering tasks—for example, to use Core Image filters on textures whose content is generated by a Metal render-to-texture operation, or to use Core Image output later in the same Metal rendering pass—pass the same MTLCommandBuffer object you use for those tasks.
Rendering to a Metal texture requires a Metal-based context created with the init(mtlDevice:) or init(mtlDevice:options:) method. Calling this method on any other context raises an exception. This method renders only to Metal textures whose texture type is MTLTextureType.type2D and whose sampleCount value is 1.