Instance Method

copy(from:sourceSlice:sourceLevel:sourceOrigin:sourceSize:to:destinationSlice:destinationLevel:destinationOrigin:)

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

Required.

Declaration

func copy(from sourceTexture: MTLTexture, sourceSlice: Int, sourceLevel: Int, sourceOrigin: MTLOrigin, sourceSize: MTLSize, to destinationTexture: MTLTexture, destinationSlice: Int, destinationLevel: Int, destinationOrigin: MTLOrigin)

Parameters

sourceTexture

The source texture for the copy operation. The value must not be a isFramebufferOnly texture.

sourceSlice

The slice of the source texture.

For a cube texture, slice is a value between 0 and 5, inclusive, that defines which cube face is the source.

For a texture array, slice is the index for the array element.

For a cube texture array, slice is a value that defines both a cube face and an array index. The general equation for determining the correct value of slice is:

slice=cubeFace+arrayIndex*6

For example, the third face of a fifth cube is equal to (3-1) + (5-1)*6 = 26.

If the texture type is neither an array nor a cube, use 0.

sourceLevel

The mipmap level of the source texture.

sourceOrigin

The origin of the portion of the source texture where the copying starts.

sourceSize

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

destinationTexture

The destination texture for the copy operation. The value must not be a isFramebufferOnly texture.

destinationSlice

The slice of the destination texture.

For a cube texture, slice is a value between 0 and 5, inclusive, that defines which cube face is the destination.

For a texture array, slice is the index for the array element.

For a cube texture array, slice is a value that defines both a cube face and an array index. The general equation for determining the correct value of slice is:

slice=cubeFace+arrayIndex*6

For example, the third face of a fifth cube is equal to (3-1) + (5-1)*6 = 26.

If the texture type is neither an array nor a cube, use 0.

destinationLevel

The mipmap level of the destination texture.

destinationOrigin

The destination texture origin where the copying starts.

Discussion

Use sourceSlice and sourceLevel together to select a single image of the source texture. Use destinationSlice and destinationLevel to select a single image of the destination texture.

The source and destination textures must have the same pixel format and the same sample count. For compressed pixel formats, align the copy region to that pixel format's block size. Overlapping regions within a single texture produce undefined results.

This method cannot be used with a subregion of a texture that has a PVRTC pixel format. The method can be used if you are copying an entire texture with a PVRTC pixel format.

See Also

Copying Data Between Textures

func copy(from: MTLTexture, to: MTLTexture)

Encodes a command to copy a texture's data to another texture.

Required.