Instance Method

copy(from:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:to:destinationSlice:destinationLevel:destinationOrigin:)

Encodes a command to copy image data from a source buffer into a destination texture.

Required.

Declaration

func copy(from sourceBuffer: MTLBuffer, sourceOffset: Int, sourceBytesPerRow: Int, sourceBytesPerImage: Int, sourceSize: MTLSize, to destinationTexture: MTLTexture, destinationSlice: Int, destinationLevel: Int, destinationOrigin: MTLOrigin)

Parameters

sourceBuffer

The source buffer for the copy operation.

sourceOffset

The byte location in the source buffer where the copying starts. The location must be aligned to the size of the destination texture's pixel format. The value must be a multiple of the destination texture's pixel size, in bytes.

sourceBytesPerRow

This specifies the stride in bytes between rows of the source buffer memory. The value must be a multiple of the destination texture's pixel size, in bytes. The value must be less than or equal to 32,767 multiplied by the destination texture’s pixel size.

sourceBytesPerImage

For 3D textures and 2D array textures, the stride in bytes between 2D images of the source buffer memory. The value must be a multiple of the destination texture's pixel size, in bytes.

sourceSize

The number of source pixels, in width, height, and depth, to copy to the destination texture. When you copy to a 1D texture, height and depth must be 1. When you copy to a 2D texture, depth must be 1.

destinationTexture

The destination texture for the copy operation. The value must not be a isFramebufferOnly texture and must not have a PVRTC pixel format.

destinationSlice

The slice of the destination texture.

destinationLevel

The mipmap level of the destination texture.

destinationOrigin

The destination texture origin where the copying starts.

Discussion

Use destinationSlice and destinationLevel to select a single image of the destination texture.

If the texture’s pixel format is a compressed format, then sourceSize must be a multiple of the pixel format’s block size or be clamped to the edge of the texture if the block extends outside the bounds of a texture. For a compressed format, sourceBytesPerRow is the number of bytes from the start of one row of blocks to the start of the next row of blocks.

This method cannot be used if the destination texture has a PVRTC pixel format.

This method is equivalent to copy(from:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:to:destinationSlice:destinationLevel:destinationOrigin:options:) with options set to none.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software