copy(sourceTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:destinationBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:)
Encodes a command that copies image data from a slice of a texture instance to a buffer, with options for special texture formats.
Declaration
func copy(sourceTexture: any MTLTexture, sourceSlice: Int, sourceLevel: Int, sourceOrigin: MTLOrigin, sourceSize: MTLSize, destinationBuffer: any MTLBuffer, destinationOffset: Int, destinationBytesPerRow: Int, destinationBytesPerImage: Int, options: MTLBlitOption = [])Parameters
- sourceTexture:
An Mtltexture texture that the command copies data from. To read the source texture contents, you need to set its Isframebufferonly property to False prior to drawing into it.
- sourceSlice:
A slice within
sourceTexturethe command uses as a starting point to copy data from. Set this to0ifsourceTextureisn’t a texture array or a cube texture. - sourceLevel:
A mipmap level within
sourceTexture. - sourceOrigin:
An Mtlorigin instance that represents a location within
sourceTexturethat the command begins copying data from. Assign0to each dimension that’s not relevant tosourceTexture. - sourceSize:
An Mtlsize instance that represents the size of the region, in pixels, that the command copies from
sourceTexture, starting atsourceOrigin. Assign1to each dimension that’s not relevant tosourceTexture. IfsourceTextureuses a compressed pixel format, setsourceSizeto a multiple of thesourceTexture'sPixelformat block size. If the block extends outside the bounds of the texture, clampsourceSizeto the edge of the texture. - destinationBuffer:
An Mtlbuffer instance the command copies data to.
- destinationOffset:
A byte offset within
destinationBufferthe command copies to. The value you provide as this argument needs to be a multiple ofsourceTexture'spixel size, in bytes. - destinationBytesPerRow:
The number of bytes between adjacent rows of pixels in
destinationBuffer. This value must be a multiple ofsourceTexture'spixel size, in bytes, and less than or equal to the product ofsourceTexture'spixel size, in bytes, and the largest pixel widthsourceTexture’stype allows. IfsourceTextureuses a compressed pixel format, setdestinationBytesPerRowto the number of bytes between the starts of two row blocks. - destinationBytesPerImage:
The number of bytes between each 2D image of a 3D texture. This value must be a multiple of
sourceTexture'spixel size, in bytes. Set this value to0ifsourceSize'sDepth value is1. - options:
A Mtlblitoption value that applies to textures with applicable pixel formats, such as combined depth/stencil or PVRTC formats. If
sourceTexture'sPixelformat is a combined depth/stencil format, setoptionsto either Depthfromdepthstencil or Stencilfromdepthstencil, but not both. IfsourceTexture'sPixelformat is a PVRTC format, setoptionsto Rowlinearpvrtc.