metalkit

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package metalkit provides Go bindings for the MetalKit framework.

Build Metal apps quicker and easier using a common set of utility classes.

View Management

  • MTKView: A specialized view that creates, configures, and displays Metal objects.
  • MTKViewDelegate: Methods for responding to a MetalKit view’s drawing and resizing events.

Texture Loading

  • MTKTextureLoader: An object that creates textures from existing data in common image formats.

Model Handling

  • MTKMesh: A container for the vertex data of a Model I/O mesh, suitable for use in a Metal app.
  • MTKMeshBuffer: A buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.
  • MTKMeshBufferAllocator: An interface for allocating a MetalKit buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.
  • MTKSubmesh: A container for the index data of a Model I/O submesh, suitable for use in a Metal app.
  • Conversion Functions: Convert between Metal and Model I/O vertex representations.
  • Model Errors: Learn about errors thrown by model handling methods. (MTKModelError)

Key Types

  • MTKView - A specialized view that creates, configures, and displays Metal objects.
  • MTKTextureLoader - An object that creates textures from existing data in common image formats.
  • MTKMesh - A container for the vertex data of a Model I/O mesh, suitable for use in a Metal app.
  • MTKMeshBuffer - A buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.
  • MTKSubmesh - A container for the index data of a Model I/O submesh, suitable for use in a Metal app.
  • MTKMeshBufferAllocator - An interface for allocating a MetalKit buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.

Code generated from Apple documentation. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var MTKModelErrors struct {
	// Domain: The error domain used by MetalKit when returning mesh initialization errors.
	Domain MTKModelError
	// Key: The key used to retrieve an error string from an error object’s [userInfo](<doc://com.apple.documentation/documentation/Foundation/NSError/userInfo>) dictionary.
	Key MTKModelError
}

MTKModelErrors provides typed accessors for MTKModelError constants.

View Source
var MTKTextureLoaderErrors struct {
	// Domain: The error domain used by [MetalKit] when returning texture loading errors.
	Domain MTKTextureLoaderError
	// Key: The key used to retrieve an error string from an error object’s [userInfo](<doc://com.apple.documentation/documentation/Foundation/NSError/userInfo>) dictionary.
	Key MTKTextureLoaderError
}

MTKTextureLoaderErrors provides typed accessors for MTKTextureLoaderError constants.

View Source
var MTKTextureLoaderOptions struct {
	// AllocateMipmaps: A key used to specify whether the texture loader should allocate memory for mipmaps in the texture.
	AllocateMipmaps MTKTextureLoaderOption
	// CubeLayout: A key used to specify how cube texture data is arranged in the source image.
	CubeLayout MTKTextureLoaderOption
	// GenerateMipmaps: A key used to specify whether the texture loader should generate mipmaps for the texture.
	GenerateMipmaps MTKTextureLoaderOption
	LoadAsArray     MTKTextureLoaderOption
	// Origin: A key used to specify when to flip the pixel coordinates of the texture.
	Origin MTKTextureLoaderOption
	// SRGB: A key used to specify whether the texture data is stored as sRGB image data.
	SRGB MTKTextureLoaderOption
	// TextureCPUCacheMode: A key used to specify the CPU cache mode for the texture.
	TextureCPUCacheMode MTKTextureLoaderOption
	// TextureStorageMode: A key used to specify the storage mode for the texture.
	TextureStorageMode MTKTextureLoaderOption
	// TextureUsage: A key used to specify the intended usage of the texture.
	TextureUsage MTKTextureLoaderOption
}

MTKTextureLoaderOptions provides typed accessors for MTKTextureLoaderOption constants.

View Source
var MTKTextureLoaderOrigins struct {
	// BottomLeft: An option for specifying images that should be flipped only to put their origin in the bottom-left corner.
	BottomLeft MTKTextureLoaderOrigin
	// FlippedVertically: An option that specifies that images should always be flipped.
	FlippedVertically MTKTextureLoaderOrigin
	// TopLeft: An option for specifying images that should be flipped only to put their origin in the top-left corner.
	TopLeft MTKTextureLoaderOrigin
}

MTKTextureLoaderOrigins provides typed accessors for MTKTextureLoaderOrigin constants.

Functions

func MTKMetalVertexDescriptorFromModelIO

func MTKMetalVertexDescriptorFromModelIO(modelIODescriptor uintptr) *metal.MTLVertexDescriptor

MTKMetalVertexDescriptorFromModelIO returns a partially converted Metal vertex descriptor.

See: https://developer.apple.com/documentation/MetalKit/MTKMetalVertexDescriptorFromModelIO(_:)

func MTKMetalVertexDescriptorFromModelIOWithError

func MTKMetalVertexDescriptorFromModelIOWithError(modelIODescriptor uintptr, err *foundation.NSError) *metal.MTLVertexDescriptor

MTKMetalVertexDescriptorFromModelIOWithError returns a partially converted Metal vertex descriptor, reporting any error that occurs.

See: https://developer.apple.com/documentation/MetalKit/MTKMetalVertexDescriptorFromModelIOWithError

func MTKMetalVertexFormatFromModelIO added in v0.2.0

func MTKMetalVertexFormatFromModelIO(vertexFormat uintptr) metal.MTLVertexFormat

MTKMetalVertexFormatFromModelIO returns a converted Metal vertex format.

See: https://developer.apple.com/documentation/MetalKit/MTKMetalVertexFormatFromModelIO(_:)

func MTKModelIOVertexDescriptorFromMetal

func MTKModelIOVertexDescriptorFromMetal(metalDescriptor *metal.MTLVertexDescriptor) *objc.ID

MTKModelIOVertexDescriptorFromMetal returns a partially converted Model I/O vertex descriptor.

See: https://developer.apple.com/documentation/MetalKit/MTKModelIOVertexDescriptorFromMetal(_:)

func MTKModelIOVertexDescriptorFromMetalWithError

func MTKModelIOVertexDescriptorFromMetalWithError(metalDescriptor *metal.MTLVertexDescriptor, err *foundation.NSError) *objc.ID

MTKModelIOVertexDescriptorFromMetalWithError returns a partially converted Model I/O vertex descriptor, reporting any error that occurs.

See: https://developer.apple.com/documentation/MetalKit/MTKModelIOVertexDescriptorFromMetalWithError

func MTKModelIOVertexFormatFromMetal added in v0.2.0

func MTKModelIOVertexFormatFromMetal(vertexFormat metal.MTLVertexFormat) objectivec.IObject

MTKModelIOVertexFormatFromMetal returns a converted Model I/O vertex format.

See: https://developer.apple.com/documentation/MetalKit/MTKModelIOVertexFormatFromMetal(_:)

Types

type IMTKMesh

type IMTKMesh interface {
	objectivec.IObject

	// Initializes a MetalKit mesh and its submeshes from a Model I/O mesh.
	InitWithMeshDeviceError(mesh objectivec.IObject, device metal.MTLDevice) (MTKMesh, error)

	// An array of submeshes containing index buffers referencing the mesh vertices.
	Submeshes() []MTKSubmesh

	// An array of buffers in which mesh vertex data resides.
	VertexBuffers() []MTKMeshBuffer
	// The number of vertices in the vertex buffers.
	VertexCount() uint
	// A Model I/O vertex descriptor specifying the data layout in the vertex buffers.
	VertexDescriptor() objc.ID

	// The name of the mesh.
	Name() string
	SetName(value string)
}

An interface definition for the MTKMesh class.

Initialization

  • [IMTKMesh.InitWithMeshDeviceError]: Initializes a MetalKit mesh and its submeshes from a Model I/O mesh.

Submeshes

  • [IMTKMesh.Submeshes]: An array of submeshes containing index buffers referencing the mesh vertices.

Vertex Properties

  • [IMTKMesh.VertexBuffers]: An array of buffers in which mesh vertex data resides.
  • [IMTKMesh.VertexCount]: The number of vertices in the vertex buffers.
  • [IMTKMesh.VertexDescriptor]: A Model I/O vertex descriptor specifying the data layout in the vertex buffers.

Identifying Properties

  • [IMTKMesh.Name]: The name of the mesh.
  • [IMTKMesh.SetName]

See: https://developer.apple.com/documentation/MetalKit/MTKMesh

type IMTKMeshBuffer

type IMTKMeshBuffer interface {
	objectivec.IObject

	// The allocator object used to create this mesh buffer.
	Allocator() IMTKMeshBufferAllocator
	// The type of data contained in the originating Model I/O buffer.
	Type() objectivec.IObject

	// The Metal buffer backing all vertex and index data.
	Buffer() metal.MTLBuffer
	// The logical size of the Metal buffer, in bytes.
	Length() uint
	// The byte offset of the data within the Metal buffer.
	Offset() uint

	Zone(param1 objectivec.IObject) objectivec.IObject
}

An interface definition for the MTKMeshBuffer class.

Originating Objects

  • [IMTKMeshBuffer.Allocator]: The allocator object used to create this mesh buffer.
  • [IMTKMeshBuffer.Type]: The type of data contained in the originating Model I/O buffer.

Metal Buffer Properties

  • [IMTKMeshBuffer.Buffer]: The Metal buffer backing all vertex and index data.
  • [IMTKMeshBuffer.Length]: The logical size of the Metal buffer, in bytes.
  • [IMTKMeshBuffer.Offset]: The byte offset of the data within the Metal buffer.

Instance Methods

  • [IMTKMeshBuffer.Zone]

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer

type IMTKMeshBufferAllocator

type IMTKMeshBufferAllocator interface {
	objectivec.IObject

	// Initializes a new allocator object.
	InitWithDevice(device metal.MTLDevice) MTKMeshBufferAllocator

	// The device used to create Metal objects.
	Device() metal.MTLDevice
}

An interface definition for the MTKMeshBufferAllocator class.

Initialization

  • [IMTKMeshBufferAllocator.InitWithDevice]: Initializes a new allocator object.

Device

  • [IMTKMeshBufferAllocator.Device]: The device used to create Metal objects.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBufferAllocator

type IMTKSubmesh

type IMTKSubmesh interface {
	objectivec.IObject

	// The parent mesh containing the vertex data of this submesh.
	Mesh() IMTKMesh

	// The index buffer used to render the submesh object.
	IndexBuffer() IMTKMeshBuffer
	// The number of indices in the index buffer.
	IndexCount() uint
	// The type of index data in the index buffer.
	IndexType() unsafe.Pointer
	// The primitive type with which to draw the submesh object.
	PrimitiveType() unsafe.Pointer

	// The name of the submesh.
	Name() string
	SetName(value string)
}

An interface definition for the MTKSubmesh class.

Parent Mesh

  • [IMTKSubmesh.Mesh]: The parent mesh containing the vertex data of this submesh.

Properties used to Draw Indexed Primitives

  • [IMTKSubmesh.IndexBuffer]: The index buffer used to render the submesh object.
  • [IMTKSubmesh.IndexCount]: The number of indices in the index buffer.
  • [IMTKSubmesh.IndexType]: The type of index data in the index buffer.
  • [IMTKSubmesh.PrimitiveType]: The primitive type with which to draw the submesh object.

Identifying Properties

  • [IMTKSubmesh.Name]: The name of the submesh.
  • [IMTKSubmesh.SetName]

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh

type IMTKTextureLoader

type IMTKTextureLoader interface {
	objectivec.IObject

	// Initializes a new texture loader object.
	InitWithDevice(device metal.MTLDevice) MTKTextureLoader
	// The device object that the texture loader uses to create textures.
	Device() metal.MTLDevice

	// Synchronously loads image data and creates a new Metal texture from a given URL.
	NewTextureWithContentsOfURLOptionsError(URL foundation.INSURL, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously loads image data and creates a new Metal texture from a given URL.
	NewTextureWithContentsOfURLOptionsCompletionHandler(URL foundation.INSURL, options foundation.INSDictionary, completionHandler ErrorHandler)
	// Synchronously loads image data and creates new Metal textures from the specified list of URLs.
	NewTexturesWithContentsOfURLsOptionsError(URLs []foundation.NSURL, options foundation.INSDictionary) ([]objectivec.IObject, error)
	// Asynchronously loads image data and creates new Metal textures from the specified list of URLs.
	NewTexturesWithContentsOfURLsOptionsCompletionHandler(URLs []foundation.NSURL, options foundation.INSDictionary, completionHandler ErrorHandler)

	// Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
	NewTextureWithNameScaleFactorBundleOptionsError(name string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
	NewTextureWithNameScaleFactorBundleOptionsCompletionHandler(name string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)
	// Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.
	NewTexturesWithNamesScaleFactorBundleOptionsCompletionHandler(names []string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)
	// Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog, using a specified display gamut.
	NewTextureWithNameScaleFactorDisplayGamutBundleOptionsError(name string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
	NewTextureWithNameScaleFactorDisplayGamutBundleOptionsCompletionHandler(name string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)
	// Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.
	NewTexturesWithNamesScaleFactorDisplayGamutBundleOptionsCompletionHandler(names []string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)

	// Synchronously loads image data and creates a new Metal texture from a given bitmap image.
	NewTextureWithCGImageOptionsError(cgImage coregraphics.CGImageRef, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously loads image data and creates a new Metal texture from a given bitmap image.
	NewTextureWithCGImageOptionsCompletionHandler(cgImage coregraphics.CGImageRef, options foundation.INSDictionary, completionHandler ErrorHandler)

	// Synchronously creates a new Metal texture from an in-memory representation of the texture’s data.
	NewTextureWithDataOptionsError(data foundation.INSData, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously creates a new Metal texture from an in-memory representation of the texture’s data.
	NewTextureWithDataOptionsCompletionHandler(data foundation.INSData, options foundation.INSDictionary, completionHandler ErrorHandler)

	// Synchronously loads image data and creates a Metal texture from the specified Model I/O texture.
	NewTextureWithMDLTextureOptionsError(texture objectivec.IObject, options foundation.INSDictionary) (metal.MTLTexture, error)
	// Asynchronously loads image data and creates a Metal texture from the specified Model I/O texture.
	NewTextureWithMDLTextureOptionsCompletionHandler(texture objectivec.IObject, options foundation.INSDictionary, completionHandler ErrorHandler)
}

An interface definition for the MTKTextureLoader class.

Creating a Texture Loader

  • [IMTKTextureLoader.InitWithDevice]: Initializes a new texture loader object.
  • [IMTKTextureLoader.Device]: The device object that the texture loader uses to create textures.

Loading Textures from URLs

  • [IMTKTextureLoader.NewTextureWithContentsOfURLOptionsError]: Synchronously loads image data and creates a new Metal texture from a given URL.
  • [IMTKTextureLoader.NewTextureWithContentsOfURLOptionsCompletionHandler]: Asynchronously loads image data and creates a new Metal texture from a given URL.
  • [IMTKTextureLoader.NewTexturesWithContentsOfURLsOptionsError]: Synchronously loads image data and creates new Metal textures from the specified list of URLs.
  • [IMTKTextureLoader.NewTexturesWithContentsOfURLsOptionsCompletionHandler]: Asynchronously loads image data and creates new Metal textures from the specified list of URLs.

Loading Textures from Asset Catalogs

  • [IMTKTextureLoader.NewTextureWithNameScaleFactorBundleOptionsError]: Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
  • [IMTKTextureLoader.NewTextureWithNameScaleFactorBundleOptionsCompletionHandler]: Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
  • [IMTKTextureLoader.NewTexturesWithNamesScaleFactorBundleOptionsCompletionHandler]: Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.
  • [IMTKTextureLoader.NewTextureWithNameScaleFactorDisplayGamutBundleOptionsError]: Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog, using a specified display gamut.
  • [IMTKTextureLoader.NewTextureWithNameScaleFactorDisplayGamutBundleOptionsCompletionHandler]: Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.
  • [IMTKTextureLoader.NewTexturesWithNamesScaleFactorDisplayGamutBundleOptionsCompletionHandler]: Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.

Loading Textures from Core Graphics Images

  • [IMTKTextureLoader.NewTextureWithCGImageOptionsError]: Synchronously loads image data and creates a new Metal texture from a given bitmap image.
  • [IMTKTextureLoader.NewTextureWithCGImageOptionsCompletionHandler]: Asynchronously loads image data and creates a new Metal texture from a given bitmap image.

Loading Textures from In-Memory Data Representations

  • [IMTKTextureLoader.NewTextureWithDataOptionsError]: Synchronously creates a new Metal texture from an in-memory representation of the texture’s data.
  • [IMTKTextureLoader.NewTextureWithDataOptionsCompletionHandler]: Asynchronously creates a new Metal texture from an in-memory representation of the texture’s data.

Loading Textures from Model I/O Representations

  • [IMTKTextureLoader.NewTextureWithMDLTextureOptionsError]: Synchronously loads image data and creates a Metal texture from the specified Model I/O texture.
  • [IMTKTextureLoader.NewTextureWithMDLTextureOptionsCompletionHandler]: Asynchronously loads image data and creates a Metal texture from the specified Model I/O texture.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader

type IMTKView

type IMTKView interface {
	appkit.INSView

	// Initializes a view with the specified frame rectangle and Metal device.
	InitWithFrameDevice(frameRect corefoundation.CGRect, device metal.MTLDevice) MTKView

	// The view’s delegate.
	Delegate() MTKViewDelegate
	SetDelegate(value MTKViewDelegate)

	// The device object the view uses to create its Metal objects.
	Device() metal.MTLDevice
	SetDevice(value metal.MTLDevice)
	// The device object that the system recommends using for this view.
	PreferredDevice() metal.MTLDevice

	// The color pixel format for the current drawable’s texture.
	ColorPixelFormat() unsafe.Pointer
	SetColorPixelFormat(value metal.MTLPixelFormat)
	// The color space of the rendered content.
	Colorspace() coregraphics.CGColorSpaceRef
	SetColorspace(value coregraphics.CGColorSpaceRef)
	// A Boolean value that determines whether the drawable’s textures are used only for rendering.
	FramebufferOnly() bool
	SetFramebufferOnly(value bool)
	// The current size of drawable textures.
	DrawableSize() corefoundation.CGSize
	SetDrawableSize(value corefoundation.CGSize)
	// The recommended dimensions of the drawable.
	PreferredDrawableSize() corefoundation.CGSize
	// A Boolean value that controls whether to resize the drawable as the view changes size.
	AutoResizeDrawable() bool
	SetAutoResizeDrawable(value bool)
	// The color to use to clear the color target when creating a render pass descriptor.
	ClearColor() metal.MTLClearColor
	SetClearColor(value metal.MTLClearColor)

	// The format used to generate the [depthStencilTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/depthStencilTexture>) object.
	DepthStencilPixelFormat() unsafe.Pointer
	SetDepthStencilPixelFormat(value metal.MTLPixelFormat)
	// The texture usage characteristics that the view uses when creating the depth and stencil textures.
	DepthStencilAttachmentTextureUsage() unsafe.Pointer
	SetDepthStencilAttachmentTextureUsage(value metal.MTLTextureUsage)
	// The depth value to use to clear the depth target when creating a render pass descriptor.
	ClearDepth() float64
	SetClearDepth(value float64)
	// The stencil value to use to clear the stencil target when creating a render pass descriptor.
	ClearStencil() uint32
	SetClearStencil(value uint32)

	// The sample count used to generate the [multisampleColorTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/multisampleColorTexture>) object.
	SampleCount() uint
	SetSampleCount(value uint)
	// The texture usage characteristics that the view uses when creating multisample textures.
	MultisampleColorAttachmentTextureUsage() unsafe.Pointer
	SetMultisampleColorAttachmentTextureUsage(value metal.MTLTextureUsage)

	// A render pass descriptor to draw into the current drawable.
	CurrentRenderPassDescriptor() metal.MTLRenderPassDescriptor
	// The drawable to use for the current frame.
	CurrentDrawable() quartzcore.CAMetalDrawable
	// A packed depth and stencil texture associated with the current drawable object’s texture.
	DepthStencilTexture() metal.MTLTexture
	// The storage mode that the packed depth and stencil texture use.
	DepthStencilStorageMode() unsafe.Pointer
	SetDepthStencilStorageMode(value metal.MTLStorageMode)
	// The multisample color sample texture to render into.
	MultisampleColorTexture() metal.MTLTexture

	// The rate at which the view redraws its contents.
	PreferredFramesPerSecond() int
	SetPreferredFramesPerSecond(value int)
	// A Boolean value that indicates whether the draw loop is paused.
	Paused() bool
	SetPaused(value bool)
	// A Boolean value that indicates whether the view responds to [setNeedsDisplay()](<doc://com.apple.documentation/documentation/UIKit/UIView/setNeedsDisplay()>).
	EnableSetNeedsDisplay() bool
	SetEnableSetNeedsDisplay(value bool)
	// Redraws the view’s contents immediately.
	Draw()
	// A Boolean value that determines whether the view presents its content using a Core Animation transaction.
	PresentsWithTransaction() bool
	SetPresentsWithTransaction(value bool)

	// Releases the [depthStencilTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/depthStencilTexture>) and [multisampleColorTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/multisampleColorTexture>) objects.
	ReleaseDrawables()

	CurrentMTL4RenderPassDescriptor() metal.MTL4RenderPassDescriptor
}

An interface definition for the MTKView class.

Creating a View

  • [IMTKView.InitWithFrameDevice]: Initializes a view with the specified frame rectangle and Metal device.

Configuring the Delegate

  • [IMTKView.Delegate]: The view’s delegate.
  • [IMTKView.SetDelegate]

Configuring the Metal Device

  • [IMTKView.Device]: The device object the view uses to create its Metal objects.
  • [IMTKView.SetDevice]
  • [IMTKView.PreferredDevice]: The device object that the system recommends using for this view.

Configuring the Color Render Target

  • [IMTKView.ColorPixelFormat]: The color pixel format for the current drawable’s texture.
  • [IMTKView.SetColorPixelFormat]
  • [IMTKView.Colorspace]: The color space of the rendered content.
  • [IMTKView.SetColorspace]
  • [IMTKView.FramebufferOnly]: A Boolean value that determines whether the drawable’s textures are used only for rendering.
  • [IMTKView.SetFramebufferOnly]
  • [IMTKView.DrawableSize]: The current size of drawable textures.
  • [IMTKView.SetDrawableSize]
  • [IMTKView.PreferredDrawableSize]: The recommended dimensions of the drawable.
  • [IMTKView.AutoResizeDrawable]: A Boolean value that controls whether to resize the drawable as the view changes size.
  • [IMTKView.SetAutoResizeDrawable]
  • [IMTKView.ClearColor]: The color to use to clear the color target when creating a render pass descriptor.
  • [IMTKView.SetClearColor]

Configuring the Render Target Properties

  • [IMTKView.DepthStencilPixelFormat]: The format used to generate the [depthStencilTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/depthStencilTexture>) object.
  • [IMTKView.SetDepthStencilPixelFormat]
  • [IMTKView.DepthStencilAttachmentTextureUsage]: The texture usage characteristics that the view uses when creating the depth and stencil textures.
  • [IMTKView.SetDepthStencilAttachmentTextureUsage]
  • [IMTKView.ClearDepth]: The depth value to use to clear the depth target when creating a render pass descriptor.
  • [IMTKView.SetClearDepth]
  • [IMTKView.ClearStencil]: The stencil value to use to clear the stencil target when creating a render pass descriptor.
  • [IMTKView.SetClearStencil]

Configuring Multisampling

  • [IMTKView.SampleCount]: The sample count used to generate the [multisampleColorTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/multisampleColorTexture>) object.
  • [IMTKView.SetSampleCount]
  • [IMTKView.MultisampleColorAttachmentTextureUsage]: The texture usage characteristics that the view uses when creating multisample textures.
  • [IMTKView.SetMultisampleColorAttachmentTextureUsage]

Retrieving Render Target Information

  • [IMTKView.CurrentRenderPassDescriptor]: A render pass descriptor to draw into the current drawable.
  • [IMTKView.CurrentDrawable]: The drawable to use for the current frame.
  • [IMTKView.DepthStencilTexture]: A packed depth and stencil texture associated with the current drawable object’s texture.
  • [IMTKView.DepthStencilStorageMode]: The storage mode that the packed depth and stencil texture use.
  • [IMTKView.SetDepthStencilStorageMode]
  • [IMTKView.MultisampleColorTexture]: The multisample color sample texture to render into.

Configuring Drawing Behavior

  • [IMTKView.PreferredFramesPerSecond]: The rate at which the view redraws its contents.
  • [IMTKView.SetPreferredFramesPerSecond]
  • [IMTKView.Paused]: A Boolean value that indicates whether the draw loop is paused.
  • [IMTKView.SetPaused]
  • [IMTKView.EnableSetNeedsDisplay]: A Boolean value that indicates whether the view responds to [setNeedsDisplay()](<doc://com.apple.documentation/documentation/UIKit/UIView/setNeedsDisplay()>).
  • [IMTKView.SetEnableSetNeedsDisplay]
  • [IMTKView.Draw]: Redraws the view’s contents immediately.
  • [IMTKView.PresentsWithTransaction]: A Boolean value that determines whether the view presents its content using a Core Animation transaction.
  • [IMTKView.SetPresentsWithTransaction]

Releasing Memory

  • [IMTKView.ReleaseDrawables]: Releases the [depthStencilTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/depthStencilTexture>) and [multisampleColorTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/multisampleColorTexture>) objects.

Instance Properties

  • [IMTKView.CurrentMTL4RenderPassDescriptor]

See: https://developer.apple.com/documentation/MetalKit/MTKView

type MTKMesh

type MTKMesh struct {
	objectivec.Object
}

A container for the vertex data of a Model I/O mesh, suitable for use in a Metal app.

Initialization

Submeshes

  • MTKMesh.Submeshes: An array of submeshes containing index buffers referencing the mesh vertices.

Vertex Properties

Identifying Properties

See: https://developer.apple.com/documentation/MetalKit/MTKMesh

func MTKMeshFromID

func MTKMeshFromID(id objc.ID) MTKMesh

MTKMeshFromID constructs a MTKMesh from an objc.ID.

A container for the vertex data of a Model I/O mesh, suitable for use in a Metal app.

func NewMTKMesh

func NewMTKMesh() MTKMesh

NewMTKMesh creates a new MTKMesh instance.

func NewMeshWithMeshDeviceError

func NewMeshWithMeshDeviceError(mesh objectivec.IObject, device metal.MTLDevice) (MTKMesh, error)

Initializes a MetalKit mesh and its submeshes from a Model I/O mesh.

mesh: The source Model I/O mesh from which to create this MetalKit mesh.

device: The Metal device on which to create MetalKit mesh resources.

Return Value

A new MetalKit mesh object, or `nil` if an error occured.

Discussion

This initializer does initialize any children meshes of the Model I/O mesh.

All vertex buffers in the source Model I/O mesh and the index buffer of each of its submeshes must have been created with a MTKMeshBufferAllocator object.

A Model I/O submesh may have its index type and/or geometric primitive type converted to a corresponding Metal type as listed in the tables below. If the geometric primitive type cannot be converted, an error is returned through `error`.

[Table data omitted]

[Table data omitted]

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/init(mesh:device:)

func (MTKMesh) Autorelease

func (m MTKMesh) Autorelease() MTKMesh

Autorelease adds the receiver to the current autorelease pool.

func (MTKMesh) Init

func (m MTKMesh) Init() MTKMesh

Init initializes the instance.

func (MTKMesh) InitWithMeshDeviceError

func (m MTKMesh) InitWithMeshDeviceError(mesh objectivec.IObject, device metal.MTLDevice) (MTKMesh, error)

Initializes a MetalKit mesh and its submeshes from a Model I/O mesh.

mesh: The source Model I/O mesh from which to create this MetalKit mesh.

device: The Metal device on which to create MetalKit mesh resources.

Return Value

A new MetalKit mesh object, or `nil` if an error occured.

Discussion

This initializer does initialize any children meshes of the Model I/O mesh.

All vertex buffers in the source Model I/O mesh and the index buffer of each of its submeshes must have been created with a MTKMeshBufferAllocator object.

A Model I/O submesh may have its index type and/or geometric primitive type converted to a corresponding Metal type as listed in the tables below. If the geometric primitive type cannot be converted, an error is returned through `error`.

[Table data omitted]

[Table data omitted]

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/init(mesh:device:)

func (MTKMesh) Name

func (m MTKMesh) Name() string

The name of the mesh.

Discussion

Your application can use this value to identify the mesh in a scene.

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/name

func (MTKMesh) SetName

func (m MTKMesh) SetName(value string)

func (MTKMesh) Submeshes

func (m MTKMesh) Submeshes() []MTKSubmesh

An array of submeshes containing index buffers referencing the mesh vertices.

Discussion

Submeshes may also contain texture materials to apply when rendering the mesh object.

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/submeshes

func (MTKMesh) VertexBuffers

func (m MTKMesh) VertexBuffers() []MTKMeshBuffer

An array of buffers in which mesh vertex data resides.

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/vertexBuffers

func (MTKMesh) VertexCount

func (m MTKMesh) VertexCount() uint

The number of vertices in the vertex buffers.

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/vertexCount

func (MTKMesh) VertexDescriptor

func (m MTKMesh) VertexDescriptor() objc.ID

A Model I/O vertex descriptor specifying the data layout in the vertex buffers.

Discussion

This is a convenience property. The MTKMesh class does not use this descriptor, but your application may use this object to determine rendering state or create a MTLVertexDescriptor object to build a MTLRenderPipelineState object capable of interpreting the data in [VertexBuffers].

See: https://developer.apple.com/documentation/MetalKit/MTKMesh/vertexDescriptor

type MTKMeshBuffer

type MTKMeshBuffer struct {
	objectivec.Object
}

A buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.

Originating Objects

Metal Buffer Properties

Instance Methods

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer

func MTKMeshBufferFromID

func MTKMeshBufferFromID(id objc.ID) MTKMeshBuffer

MTKMeshBufferFromID constructs a MTKMeshBuffer from an objc.ID.

A buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.

func NewMTKMeshBuffer

func NewMTKMeshBuffer() MTKMeshBuffer

NewMTKMeshBuffer creates a new MTKMeshBuffer instance.

func (MTKMeshBuffer) Allocator

func (m MTKMeshBuffer) Allocator() IMTKMeshBufferAllocator

The allocator object used to create this mesh buffer.

Discussion

The allocator uses Model I/O for copy and re-layout operations, such as when a new vertex descriptor is applied to an existing vertex buffer.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer/allocator

func (MTKMeshBuffer) Autorelease

func (m MTKMeshBuffer) Autorelease() MTKMeshBuffer

Autorelease adds the receiver to the current autorelease pool.

func (MTKMeshBuffer) Buffer

func (m MTKMeshBuffer) Buffer() metal.MTLBuffer

The Metal buffer backing all vertex and index data.

Discussion

Many MTKMeshBuffer objects may reference the same MTLBuffer object, in which case each MTKMeshBuffer object will have its own unique [Offset] value.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer/buffer

func (MTKMeshBuffer) Init

func (m MTKMeshBuffer) Init() MTKMeshBuffer

Init initializes the instance.

func (MTKMeshBuffer) Length

func (m MTKMeshBuffer) Length() uint

The logical size of the Metal buffer, in bytes.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer/length

func (MTKMeshBuffer) Offset

func (m MTKMeshBuffer) Offset() uint

The byte offset of the data within the Metal buffer.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer/offset

func (MTKMeshBuffer) Type

func (m MTKMeshBuffer) Type() objectivec.IObject

The type of data contained in the originating Model I/O buffer.

Discussion

A MDLMeshBuffer object can contain Model I/O mesh vertex data or submesh index data.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBuffer/type

type MTKMeshBufferAllocator

type MTKMeshBufferAllocator struct {
	objectivec.Object
}

An interface for allocating a MetalKit buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.

Initialization

Device

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBufferAllocator

func MTKMeshBufferAllocatorFromID

func MTKMeshBufferAllocatorFromID(id objc.ID) MTKMeshBufferAllocator

MTKMeshBufferAllocatorFromID constructs a MTKMeshBufferAllocator from an objc.ID.

An interface for allocating a MetalKit buffer that backs the vertex data of a Model I/O mesh, suitable for use in a Metal app.

func NewMTKMeshBufferAllocator

func NewMTKMeshBufferAllocator() MTKMeshBufferAllocator

NewMTKMeshBufferAllocator creates a new MTKMeshBufferAllocator instance.

func NewMeshBufferAllocatorWithDevice

func NewMeshBufferAllocatorWithDevice(device metal.MTLDevice) MTKMeshBufferAllocator

Initializes a new allocator object.

device: The Metal device on which to create buffers.

Return Value

An initialized allocator object.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBufferAllocator/init(device:)

func (MTKMeshBufferAllocator) Autorelease

Autorelease adds the receiver to the current autorelease pool.

func (MTKMeshBufferAllocator) Device

The device used to create Metal objects.

Discussion

A Metal device must be specialized at initialization.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBufferAllocator/device

func (MTKMeshBufferAllocator) Init

Init initializes the instance.

func (MTKMeshBufferAllocator) InitWithDevice

Initializes a new allocator object.

device: The Metal device on which to create buffers.

Return Value

An initialized allocator object.

See: https://developer.apple.com/documentation/MetalKit/MTKMeshBufferAllocator/init(device:)

type MTKMeshBufferAllocatorClass

type MTKMeshBufferAllocatorClass struct {
	// contains filtered or unexported fields
}

func GetMTKMeshBufferAllocatorClass

func GetMTKMeshBufferAllocatorClass() MTKMeshBufferAllocatorClass

GetMTKMeshBufferAllocatorClass returns the class object for MTKMeshBufferAllocator.

func (MTKMeshBufferAllocatorClass) Alloc

Alloc allocates memory for a new instance of the class.

type MTKMeshBufferClass

type MTKMeshBufferClass struct {
	// contains filtered or unexported fields
}

func GetMTKMeshBufferClass

func GetMTKMeshBufferClass() MTKMeshBufferClass

GetMTKMeshBufferClass returns the class object for MTKMeshBuffer.

func (MTKMeshBufferClass) Alloc

func (mc MTKMeshBufferClass) Alloc() MTKMeshBuffer

Alloc allocates memory for a new instance of the class.

type MTKMeshClass

type MTKMeshClass struct {
	// contains filtered or unexported fields
}

func GetMTKMeshClass

func GetMTKMeshClass() MTKMeshClass

GetMTKMeshClass returns the class object for MTKMesh.

func (MTKMeshClass) Alloc

func (mc MTKMeshClass) Alloc() MTKMesh

Alloc allocates memory for a new instance of the class.

type MTKModelError

type MTKModelError = string

MTKModelError is constants used to declare Model Errors.

See: https://developer.apple.com/documentation/MetalKit/MTKModelError

type MTKSubmesh

type MTKSubmesh struct {
	objectivec.Object
}

A container for the index data of a Model I/O submesh, suitable for use in a Metal app.

Overview

The MTKSubmesh class provides a container for a segment of mesh data that can be rendered in a single draw call. A submesh can only be initialized as part of a MTKMesh object. Each submesh contains an index buffer with which the parent’s mesh data can be rendered. Actual submesh vertex data resides in the submesh’s parent mesh. For more information on Model I/O submeshes, see MDLSubmesh.

Parent Mesh

  • MTKSubmesh.Mesh: The parent mesh containing the vertex data of this submesh.

Properties used to Draw Indexed Primitives

Identifying Properties

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh

func MTKSubmeshFromID

func MTKSubmeshFromID(id objc.ID) MTKSubmesh

MTKSubmeshFromID constructs a MTKSubmesh from an objc.ID.

A container for the index data of a Model I/O submesh, suitable for use in a Metal app.

func NewMTKSubmesh

func NewMTKSubmesh() MTKSubmesh

NewMTKSubmesh creates a new MTKSubmesh instance.

func (MTKSubmesh) Autorelease

func (s MTKSubmesh) Autorelease() MTKSubmesh

Autorelease adds the receiver to the current autorelease pool.

func (MTKSubmesh) IndexBuffer

func (s MTKSubmesh) IndexBuffer() IMTKMeshBuffer

The index buffer used to render the submesh object.

Discussion

Use this object for the `indexBuffer` parameter in a call to drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:).

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/indexBuffer

func (MTKSubmesh) IndexCount

func (s MTKSubmesh) IndexCount() uint

The number of indices in the index buffer.

Discussion

Use this value for the `indexCount` parameter in a call to drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:).

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/indexCount

func (MTKSubmesh) IndexType

func (s MTKSubmesh) IndexType() unsafe.Pointer

The type of index data in the index buffer.

Discussion

Use this value for the `indexType` parameter in a call to drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:).

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/indexType

func (MTKSubmesh) Init

func (s MTKSubmesh) Init() MTKSubmesh

Init initializes the instance.

func (MTKSubmesh) Mesh

func (s MTKSubmesh) Mesh() IMTKMesh

The parent mesh containing the vertex data of this submesh.

Discussion

The buffer of this parent mesh should be set in the encoder before a call to drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:) is made.

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/mesh

func (MTKSubmesh) Name

func (s MTKSubmesh) Name() string

The name of the submesh.

Discussion

Your application can use this value to identify the mesh in a scene.

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/name

func (MTKSubmesh) PrimitiveType

func (s MTKSubmesh) PrimitiveType() unsafe.Pointer

The primitive type with which to draw the submesh object.

Discussion

Use this value for the `primitiveType` parameter in a call to drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:).

See: https://developer.apple.com/documentation/MetalKit/MTKSubmesh/primitiveType

func (MTKSubmesh) SetName

func (s MTKSubmesh) SetName(value string)

type MTKSubmeshClass

type MTKSubmeshClass struct {
	// contains filtered or unexported fields
}

func GetMTKSubmeshClass

func GetMTKSubmeshClass() MTKSubmeshClass

GetMTKSubmeshClass returns the class object for MTKSubmesh.

func (MTKSubmeshClass) Alloc

func (mc MTKSubmeshClass) Alloc() MTKSubmesh

Alloc allocates memory for a new instance of the class.

type MTKTextureLoader

type MTKTextureLoader struct {
	objectivec.Object
}

An object that creates textures from existing data in common image formats.

Overview

Use the MTKTextureLoader class to create a Metal texture from existing image data.

This class supports common file formats, like PNG, JPEG, and TIFF. It also loads image data from KTX and PVR files, asset catalogs, Core Graphics images, and other sources. It infers the output texture format and pixel format from the image data.

You create textures synchronously or asynchronously using MTKTextureLoader methods that return MTLTexture instances. Pass options to these methods that customize the image-loading and texture-creation process.

First create an MTKTextureLoader instance, passing the device that it uses to create textures. Then use one of the texture loader’s methods to create a texture. The code example below synchronously creates a texture from data at a URL, using the default options:

If you use custom data formats, or change the image data at runtime, use MTLTexture methods instead. For more information, see Creating and sampling textures.

Creating a Texture Loader

Loading Textures from URLs

Loading Textures from Asset Catalogs

Loading Textures from Core Graphics Images

Loading Textures from In-Memory Data Representations

Loading Textures from Model I/O Representations

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader

func MTKTextureLoaderFromID

func MTKTextureLoaderFromID(id objc.ID) MTKTextureLoader

MTKTextureLoaderFromID constructs a MTKTextureLoader from an objc.ID.

An object that creates textures from existing data in common image formats.

func NewMTKTextureLoader

func NewMTKTextureLoader() MTKTextureLoader

NewMTKTextureLoader creates a new MTKTextureLoader instance.

func NewTextureLoaderWithDevice

func NewTextureLoaderWithDevice(device metal.MTLDevice) MTKTextureLoader

Initializes a new texture loader object.

device: The Metal device to create Metal textures with.

Return Value

An initialized texture loader object.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/init(device:)

func (MTKTextureLoader) Autorelease

func (t MTKTextureLoader) Autorelease() MTKTextureLoader

Autorelease adds the receiver to the current autorelease pool.

func (MTKTextureLoader) Device

func (t MTKTextureLoader) Device() metal.MTLDevice

The device object that the texture loader uses to create textures.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/device

func (MTKTextureLoader) Init

Init initializes the instance.

func (MTKTextureLoader) InitWithDevice

func (t MTKTextureLoader) InitWithDevice(device metal.MTLDevice) MTKTextureLoader

Initializes a new texture loader object.

device: The Metal device to create Metal textures with.

Return Value

An initialized texture loader object.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/init(device:)

func (MTKTextureLoader) NewTextureWithCGImageOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithCGImageOptionsCompletionHandler(cgImage coregraphics.CGImageRef, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates a new Metal texture from a given bitmap image.

cgImage: The [CGImage] from which to load image data. // [CGImage]: https://developer.apple.com/documentation/CoreGraphics/CGImage

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(cgImage:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithCGImageOptionsError

func (t MTKTextureLoader) NewTextureWithCGImageOptionsError(cgImage coregraphics.CGImageRef, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously loads image data and creates a new Metal texture from a given bitmap image.

cgImage: The [CGImage] from which to load image data. // [CGImage]: https://developer.apple.com/documentation/CoreGraphics/CGImage

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(cgImage:options:)

func (MTKTextureLoader) NewTextureWithContentsOfURLOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithContentsOfURLOptionsCompletionHandler(URL foundation.INSURL, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates a new Metal texture from a given URL.

URL: The URL of the file to load.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(URL:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithContentsOfURLOptionsError

func (t MTKTextureLoader) NewTextureWithContentsOfURLOptionsError(URL foundation.INSURL, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously loads image data and creates a new Metal texture from a given URL.

URL: The URL of the file to load.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(URL:options:)

func (MTKTextureLoader) NewTextureWithDataOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithDataOptionsCompletionHandler(data foundation.INSData, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously creates a new Metal texture from an in-memory representation of the texture’s data.

data: The [NSData] object containing image data. // [NSData]: https://developer.apple.com/documentation/Foundation/NSData

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(data:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithDataOptionsError

func (t MTKTextureLoader) NewTextureWithDataOptionsError(data foundation.INSData, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously creates a new Metal texture from an in-memory representation of the texture’s data.

data: The [NSData] object containing image data. // [NSData]: https://developer.apple.com/documentation/Foundation/NSData

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(data:options:)

func (MTKTextureLoader) NewTextureWithMDLTextureOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithMDLTextureOptionsCompletionHandler(texture objectivec.IObject, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates a Metal texture from the specified Model I/O texture.

texture: A Model I/O texture object containing image data from which to create the texture.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(texture:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithMDLTextureOptionsError

func (t MTKTextureLoader) NewTextureWithMDLTextureOptionsError(texture objectivec.IObject, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously loads image data and creates a Metal texture from the specified Model I/O texture.

texture: A Model I/O texture object containing image data from which to create the texture.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(texture:options:)

func (MTKTextureLoader) NewTextureWithNameScaleFactorBundleOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithNameScaleFactorBundleOptionsCompletionHandler(name string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

name: The name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

bundle: The resource bundle containing the asset catalog to load the texture from.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:bundle:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithNameScaleFactorBundleOptionsError

func (t MTKTextureLoader) NewTextureWithNameScaleFactorBundleOptionsError(name string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

name: The name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

bundle: The resource bundle containing the asset catalog to load textures from.

options: A dictionary describing any additional texture loading steps. See [Texture Loading Options].

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [Texture Loading Options]: https://developer.apple.com/documentation/GLKit/texture-loading-options [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:bundle:options:)

func (MTKTextureLoader) NewTextureWithNameScaleFactorDisplayGamutBundleOptionsCompletionHandler

func (t MTKTextureLoader) NewTextureWithNameScaleFactorDisplayGamutBundleOptionsCompletionHandler(name string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

name: The name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

displayGamut: The version of the texture based on the trait in Xcode.

To determine the appropriate parameter value, pass the widest [NSDisplayGamut] value that returns [true] when queried against the “ method of [NSWindow]. // [true]: https://developer.apple.com/documentation/Swift/true

bundle: The resource bundle containing the asset catalog to load the texture from.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

completionHandler: A block called when the texture has been loaded and fully initialized.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:displayGamut:bundle:options:completionHandler:)

func (MTKTextureLoader) NewTextureWithNameScaleFactorDisplayGamutBundleOptionsError

func (t MTKTextureLoader) NewTextureWithNameScaleFactorDisplayGamutBundleOptionsError(name string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary) (metal.MTLTexture, error)

Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog, using a specified display gamut.

name: The name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

displayGamut: The version of the texture based on the trait in Xcode.

To determine the appropriate parameter value, pass the widest [NSDisplayGamut] value that returns [true] when queried against the “ method of [NSWindow]. // [true]: https://developer.apple.com/documentation/Swift/true

bundle: The resource bundle containing the asset catalog to load textures from.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

Return Value

A fully loaded and initialized Metal texture, or `nil` if an error occurred.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:displayGamut:bundle:options:)

func (MTKTextureLoader) NewTexturesWithContentsOfURLsOptionsCompletionHandler

func (t MTKTextureLoader) NewTexturesWithContentsOfURLsOptionsCompletionHandler(URLs []foundation.NSURL, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates new Metal textures from the specified list of URLs.

URLs: An array of URLs referencing files to load.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

completionHandler: A block called after all URLs have been processed. See the MTKTextureLoaderArrayCallback signature to determine whether each texture has successfully loaded.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTextures(URLs:options:completionHandler:)

func (MTKTextureLoader) NewTexturesWithContentsOfURLsOptionsError

func (t MTKTextureLoader) NewTexturesWithContentsOfURLsOptionsError(URLs []foundation.NSURL, options foundation.INSDictionary) ([]objectivec.IObject, error)

Synchronously loads image data and creates new Metal textures from the specified list of URLs.

URLs: An array of URLs referencing files to load.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

error: If all textures were fully loaded and initialized, this pointer is `nil` on output. If an error occurs while loading any of the specified URLs, this pointer refers to an [NSError] object describing the failure. (Which element in the [URLs] array the error corresponds to is undefined.) // [NSError]: https://developer.apple.com/documentation/Foundation/NSError

Return Value

An array of Metal textures, each corresponding to a URL listed in the [URLs] parameter. If an error occurs while loading a texture, the corresponding array element is an NSNull object.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTextures(URLs:options:error:)

func (MTKTextureLoader) NewTexturesWithNamesScaleFactorBundleOptionsCompletionHandler

func (t MTKTextureLoader) NewTexturesWithNamesScaleFactorBundleOptionsCompletionHandler(names []string, scaleFactor float64, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.

names: An array of strings, each the name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

bundle: The resource bundle containing the asset catalog to load textures from.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

completionHandler: A block called after all assets have been processed. See the MTKTextureLoaderArrayCallback signature to determine whether each texture has successfully loaded.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTextures(names:scaleFactor:bundle:options:completionHandler:)

func (MTKTextureLoader) NewTexturesWithNamesScaleFactorDisplayGamutBundleOptionsCompletionHandler

func (t MTKTextureLoader) NewTexturesWithNamesScaleFactorDisplayGamutBundleOptionsCompletionHandler(names []string, scaleFactor float64, displayGamut appkit.NSDisplayGamut, bundle foundation.NSBundle, options foundation.INSDictionary, completionHandler ErrorHandler)

Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.

names: An array of strings, each the name of a texture in an asset catalog.

scaleFactor: The scale factor of texture to request.

In iOS and tvOS, pass the [contentsScale] value of the view where you plan to display texture content.

In macOS, pass the [backingScaleFactor] value of the window where you plan to display texture content. // [backingScaleFactor]: https://developer.apple.com/documentation/AppKit/NSWindow/backingScaleFactor [contentsScale]: https://developer.apple.com/documentation/QuartzCore/CALayer/contentsScale

displayGamut: The version of the texture based on the trait in Xcode.

To determine the appropriate parameter value, pass the widest [NSDisplayGamut] value that returns [true] when queried against the “ method of [NSWindow]. // [true]: https://developer.apple.com/documentation/Swift/true

bundle: The resource bundle containing the asset catalog to load textures from.

options: A dictionary describing any additional texture loading steps. See `Texture Loading Options`.

When using this method, the texture loader ignores the [generateMipmaps], [SRGB], [cubeLayout], and [origin] options. // [SRGB]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/SRGB [cubeLayout]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/cubeLayout [generateMipmaps]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/generateMipmaps [origin]: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option/origin

completionHandler: A block called after all assets have been processed. See the MTKTextureLoaderArrayCallback signature to determine whether each texture has successfully loaded.

Discussion

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/newTextures(names:scaleFactor:displayGamut:bundle:options:completionHandler:)

type MTKTextureLoaderArrayCallback

type MTKTextureLoaderArrayCallback = func([]objectivec.IObject, foundation.NSError)

MTKTextureLoaderArrayCallback is the signature for the block executed after an asynchronous loading operation for multiple textures has completed.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/ArrayCallback

type MTKTextureLoaderCallback

type MTKTextureLoaderCallback = func(metal.MTLTexture, foundation.NSError)

MTKTextureLoaderCallback is the signature for the block executed after an asynchronous loading operation for a single texture has completed.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Callback

type MTKTextureLoaderClass

type MTKTextureLoaderClass struct {
	// contains filtered or unexported fields
}

func GetMTKTextureLoaderClass

func GetMTKTextureLoaderClass() MTKTextureLoaderClass

GetMTKTextureLoaderClass returns the class object for MTKTextureLoader.

func (MTKTextureLoaderClass) Alloc

Alloc allocates memory for a new instance of the class.

type MTKTextureLoaderCubeLayout

type MTKTextureLoaderCubeLayout = string

MTKTextureLoaderCubeLayout is options for specifying how cube texture data is arranged in the source image.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/CubeLayout

var (
	// MTKTextureLoaderCubeLayoutVertical is specifies that the source 2D image is a vertical arrangement of six cube faces.
	//
	// See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/CubeLayout/vertical
	MTKTextureLoaderCubeLayoutVertical MTKTextureLoaderCubeLayout
)

type MTKTextureLoaderError

type MTKTextureLoaderError = string

MTKTextureLoaderError is errors returned by the texture loader.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Error

type MTKTextureLoaderOption

type MTKTextureLoaderOption = string

MTKTextureLoaderOption is keys and values used to specify loading options.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Option

type MTKTextureLoaderOrigin

type MTKTextureLoaderOrigin = string

MTKTextureLoaderOrigin is options for specifying when to flip the pixel coordinates of the texture.

See: https://developer.apple.com/documentation/MetalKit/MTKTextureLoader/Origin

type MTKView

type MTKView struct {
	appkit.NSView
}

A specialized view that creates, configures, and displays Metal objects.

Overview

The MTKView class provides a default implementation of a Metal-aware view that you can use to render graphics using Metal and display them onscreen. When asked, the view provides a MTLRenderPassDescriptor object that points at a texture for you to render new contents into. Optionally, an MTKView can create depth and stencil textures for you and any intermediate textures needed for antialiasing. The view uses a CAMetalLayer to manage the Metal drawable objects.

The view requires a MTLDevice object to manage the Metal objects it creates for you. You must set the MTKView.Device property and, optionally, modify the view’s drawable properties before drawing.

Configuring the Drawing Behavior

The MTKView class supports three drawing modes:

- Timed updates: The view redraws its contents based on an internal timer. In this case, which is the default behavior, both MTKView.Paused and MTKView.EnableSetNeedsDisplay are set to false. Use this mode for games and other animated content that’s regularly updated. - Draw notifications: The view redraws itself when something invalidates its contents, usually because of a call to setNeedsDisplay() or some other view-related behavior. In this case, set MTKView.Paused and MTKView.EnableSetNeedsDisplay to true. Use this mode for apps with a more traditional workflow, where updates happen when data changes, but not on a regular timed interval. - Explicit drawing: The view redraws its contents only when you explicitly call the MTKView.Draw method. In this case, set MTKView.Paused to true and MTKView.EnableSetNeedsDisplay to false. Use this mode to create your own custom workflow.

Drawing the View’s Contents

Regardless of drawing mode, when the view needs to update its contents, it calls the draw(_:) method when that method has been overridden by a subclass, or [DrawInMTKView] on the view’s delegate if the subclass doesn’t override it. You should either subclass MTKView or provide a delegate, but not both.

In your drawing method, you obtain a render pass descriptor from the view, render into it, and then present the associated drawable.

Obtaining a Drawable from a MetalKit View

Each MTKView is backed by a CAMetalLayer. In your renderer, implement the MTKViewDelegate protocol to interact with a MetalKit view. Call the MetalKit view’s MTKView.CurrentRenderPassDescriptor property to obtain a render pass descriptor configured for the current frame:

When you read this property, Core Animation implicitly obtains a drawable for the current frame and stores it in the MTKView.CurrentDrawable property. It then configures a render pass descriptor to draw into that drawable, including any depth, stencil, and antialiasing textures as necessary. The view configures this render pass using the default store and load actions. You can adjust the descriptor further before using it to create a MTLRenderCommandEncoder.

Obtain drawables as late as possible; preferably, immediately before encoding your onscreen render pass.

Registering the Drawable’s Presentation

After rendering the contents, you must present the drawable to update the view’s contents. The most convenient way to present the content is to call the present(_:) method on the command buffer. Then, call the commit() method to submit the command buffer to a GPU:

When a command queue schedules a command buffer for execution, the drawable tracks all render or write requests on itself in that command buffer. The operating system doesn’t present the drawable onscreen until the commands have finished executing. By asking the command buffer to present the drawable, you guarantee that presentation happens after the command queue has scheduled this command buffer. Don’t wait for the command buffer to finish executing before registering the drawable’s presentation.

Creating a View

Configuring the Delegate

Configuring the Metal Device

Configuring the Color Render Target

Configuring the Render Target Properties

Configuring Multisampling

Retrieving Render Target Information

Configuring Drawing Behavior

Releasing Memory

  • MTKView.ReleaseDrawables: Releases the [depthStencilTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/depthStencilTexture>) and [multisampleColorTexture](<doc://com.apple.metalkit/documentation/MetalKit/MTKView/multisampleColorTexture>) objects.

Instance Properties

See: https://developer.apple.com/documentation/MetalKit/MTKView

func MTKViewFromID

func MTKViewFromID(id objc.ID) MTKView

MTKViewFromID constructs a MTKView from an objc.ID.

A specialized view that creates, configures, and displays Metal objects.

func NewMTKView

func NewMTKView() MTKView

NewMTKView creates a new MTKView instance.

func NewViewWithCoder

func NewViewWithCoder(coder foundation.INSCoder) MTKView

Initializes a view from data in a given unarchiver.

coder: An unarchiver object.

Return Value

An initialized view object.

See: https://developer.apple.com/documentation/MetalKit/MTKView/init(coder:)

func NewViewWithFrameDevice

func NewViewWithFrameDevice(frameRect corefoundation.CGRect, device metal.MTLDevice) MTKView

Initializes a view with the specified frame rectangle and Metal device.

frameRect: The frame rectangle for the view.

device: The Metal device object to use.

Return Value

An initialized view object.

See: https://developer.apple.com/documentation/MetalKit/MTKView/init(frame:device:)

func (MTKView) AutoResizeDrawable

func (v MTKView) AutoResizeDrawable() bool

A Boolean value that controls whether to resize the drawable as the view changes size.

Discussion

If the value is true, the view automatically resizes its underlying color, depth, stencil, and multisample textures when the view is resized. If the value is false, you must explicitly set [DrawableSize] to change the size of these objects.

The default value is true.

See: https://developer.apple.com/documentation/MetalKit/MTKView/autoResizeDrawable

func (MTKView) Autorelease

func (v MTKView) Autorelease() MTKView

Autorelease adds the receiver to the current autorelease pool.

func (MTKView) ClearColor

func (v MTKView) ClearColor() metal.MTLClearColor

The color to use to clear the color target when creating a render pass descriptor.

Discussion

When the view creates a render pass, it sets the load action for the color render target to MTLLoadAction.clear and uses this color as the clear color. The default value is `(0.0, 0.0, 0.0, 1.0)`.

See: https://developer.apple.com/documentation/MetalKit/MTKView/clearColor

func (MTKView) ClearDepth

func (v MTKView) ClearDepth() float64

The depth value to use to clear the depth target when creating a render pass descriptor.

Discussion

If you specified that you want a depth texture, the view configures any render passes to use the depth texture, with a load action of MTLLoadAction.clear and the value of this property as the value to clear it to. The default value is `1.0`.

See: https://developer.apple.com/documentation/MetalKit/MTKView/clearDepth

func (MTKView) ClearStencil

func (v MTKView) ClearStencil() uint32

The stencil value to use to clear the stencil target when creating a render pass descriptor.

Discussion

If you specified that you want a stencil texture, the view configures any render passes to use the stencil texture, with a load action of MTLLoadAction.clear and the value of this property as the value to clear it to. The default value is `0`.

See: https://developer.apple.com/documentation/MetalKit/MTKView/clearStencil

func (MTKView) ColorPixelFormat

func (v MTKView) ColorPixelFormat() unsafe.Pointer

The color pixel format for the current drawable’s texture.

Discussion

The pixel format must be one that the underlying CAMetalLayer can use. See pixelFormat.

The default value is MTLPixelFormat.bgra8Unorm.

See: https://developer.apple.com/documentation/MetalKit/MTKView/colorPixelFormat

func (MTKView) Colorspace

func (v MTKView) Colorspace() coregraphics.CGColorSpaceRef

The color space of the rendered content.

Discussion

The default value is `nil`, indicating that the rendered content isn’t color-matched. If you set this to a different color space, Core Animation performs any necessary color transformations when compositing the view’s contents.

See: https://developer.apple.com/documentation/MetalKit/MTKView/colorspace

func (MTKView) CurrentDrawable

func (v MTKView) CurrentDrawable() quartzcore.CAMetalDrawable

The drawable to use for the current frame.

Discussion

If all drawable objects are in use, the value of this property is `nil`. Your app should check that [CurrentDrawable] isn’t `nil` before attempting to draw. The view changes the value of this property only after returning from a drawing function, either draw(_:) from a subclassed instance of the view, or [DrawInMTKView] from the view’s delegate.

Use a MTLRenderCommandEncoder object to render into the drawable’s texture and present it for display (typically registered using the present(_:) method of a command buffer). Try to minimize the time between when you fetch the drawable and when you submit the command buffer that uses it. For more information, see CAMetalLayer.

See: https://developer.apple.com/documentation/MetalKit/MTKView/currentDrawable

func (MTKView) CurrentMTL4RenderPassDescriptor

func (v MTKView) CurrentMTL4RenderPassDescriptor() metal.MTL4RenderPassDescriptor

Discussion

A render pass descriptor generated from the currentDrawable’s texture and the view’s depth, stencil, and sample buffers and clear values.

This is a convience property. The view does not use this descriptor and there is no requirement for an app to use this descriptor.

See: https://developer.apple.com/documentation/MetalKit/MTKView/currentMTL4RenderPassDescriptor

func (MTKView) CurrentRenderPassDescriptor

func (v MTKView) CurrentRenderPassDescriptor() metal.MTLRenderPassDescriptor

A render pass descriptor to draw into the current drawable.

Discussion

Reading this property creates and returns a new render pass descriptor to render into the current drawable’s texture. MTKView doesn’t use this descriptor, and there’s no requirement for your application to use it.

This property is `nil` if the view’s [Device] property isn’t set or if [CurrentDrawable] is `nil`. Your app should check that [CurrentRenderPassDescriptor] isn’t `nil` before attempting to use it.

The view configures the render pass as follows:

- If multisampling isn’t enabled—The color attachment at index 0 of the render pass descriptor points to the texture assigned to the current drawable, with a load action of MTLLoadAction.clear and a store action of MTLStoreAction.store. - If you’ve enabled multisampling—The color attachment at index 0 of the render pass descriptor points to the multisample texture, the resolve texture points to the texture assigned to the current drawable, and the attachment has a load action of MTLLoadAction.clear and a store action of MTLStoreAction.multisampleResolve. - If you’ve specified a depth or stencil target—The render pass configures the appropriate targets, with a load action of MTLLoadAction.clear and a store action of MTLStoreAction.dontCare.

See: https://developer.apple.com/documentation/MetalKit/MTKView/currentRenderPassDescriptor

func (MTKView) Delegate

func (v MTKView) Delegate() MTKViewDelegate

The view’s delegate.

Discussion

A delegate is optional. If you provide one, the view calls the delegate when it needs to update its contents. You should either provide a delegate or subclass the view to override the draw(_:) method, but not both.

See: https://developer.apple.com/documentation/MetalKit/MTKView/delegate

func (MTKView) DepthStencilAttachmentTextureUsage

func (v MTKView) DepthStencilAttachmentTextureUsage() unsafe.Pointer

The texture usage characteristics that the view uses when creating the depth and stencil textures.

Discussion

The default value is renderTarget.

See: https://developer.apple.com/documentation/MetalKit/MTKView/depthStencilAttachmentTextureUsage

func (MTKView) DepthStencilPixelFormat

func (v MTKView) DepthStencilPixelFormat() unsafe.Pointer

The format used to generate the [DepthStencilTexture] object.

Discussion

The default value is MTLPixelFormat.invalid, which means that the view doesn’t create a depth and stencil texture. If you set it to a different format, the view automatically creates those textures for you and configures them as part of any render passes that the view creates.

See: https://developer.apple.com/documentation/MetalKit/MTKView/depthStencilPixelFormat

func (MTKView) DepthStencilStorageMode

func (v MTKView) DepthStencilStorageMode() unsafe.Pointer

The storage mode that the packed depth and stencil texture use.

Discussion

The default value is MTLStorageMode.private.

See: https://developer.apple.com/documentation/MetalKit/MTKView/depthStencilStorageMode

func (MTKView) DepthStencilTexture

func (v MTKView) DepthStencilTexture() metal.MTLTexture

A packed depth and stencil texture associated with the current drawable object’s texture.

Discussion

The value of [DepthStencilPixelFormat] determines the format of this texture.

The default value is `nil`. This value is also `nil` if the specified pixel format is MTLPixelFormat.invalid.

See: https://developer.apple.com/documentation/MetalKit/MTKView/depthStencilTexture

func (MTKView) Device

func (v MTKView) Device() metal.MTLDevice

The device object the view uses to create its Metal objects.

Discussion

The default value is `nil`. You must explicitly set the device object.

See: https://developer.apple.com/documentation/MetalKit/MTKView/device

func (MTKView) Draw

func (v MTKView) Draw()

Redraws the view’s contents immediately.

Discussion

This method manually tells the view to redraw its contents. Calling this method causes the view to call either the [DrawInMTKView] method of the view’s [Delegate], or the draw(_:) method of the MTKView subclass. Never call this method inside either drawing function.

See: https://developer.apple.com/documentation/MetalKit/MTKView/draw()

func (MTKView) DrawableSize

func (v MTKView) DrawableSize() corefoundation.CGSize

The current size of drawable textures.

Discussion

Changing this value adjusts the size of any color, depth, stencil, and multisampling textures created by the view. If [AutoResizeDrawable] is true, this property is updated automatically whenever the view’s size changes. If [AutoResizeDrawable] is false, set this value to change the size of the texture objects.

The default value is derived from the current view’s size, in native pixels.

See: https://developer.apple.com/documentation/MetalKit/MTKView/drawableSize

func (MTKView) EnableSetNeedsDisplay

func (v MTKView) EnableSetNeedsDisplay() bool

A Boolean value that indicates whether the view responds to setNeedsDisplay().

Discussion

If this value and the value of [Paused] are true, the view behaves similarly to a UIView object, responding to calls to setNeedsDisplay(). In this case, the view’s internal draw loop is paused and updates are event-driven instead.

The default value is false.

See: https://developer.apple.com/documentation/MetalKit/MTKView/enableSetNeedsDisplay

func (MTKView) FramebufferOnly

func (v MTKView) FramebufferOnly() bool

A Boolean value that determines whether the drawable’s textures are used only for rendering.

Discussion

If the value is true (the default), the underlying CAMetalLayer object allocates its textures with only the renderTarget usage flag. Core Animation can then optimize the textures for display purposes. However, you may not sample, read from, or write to those textures. If the value is false, you can sample or perform read/write operations on the textures, but at a cost to performance.

See: https://developer.apple.com/documentation/MetalKit/MTKView/framebufferOnly

func (MTKView) Init

func (v MTKView) Init() MTKView

Init initializes the instance.

func (MTKView) InitWithFrameDevice

func (v MTKView) InitWithFrameDevice(frameRect corefoundation.CGRect, device metal.MTLDevice) MTKView

Initializes a view with the specified frame rectangle and Metal device.

frameRect: The frame rectangle for the view.

device: The Metal device object to use.

Return Value

An initialized view object.

See: https://developer.apple.com/documentation/MetalKit/MTKView/init(frame:device:)

func (MTKView) MultisampleColorAttachmentTextureUsage

func (v MTKView) MultisampleColorAttachmentTextureUsage() unsafe.Pointer

The texture usage characteristics that the view uses when creating multisample textures.

Discussion

The default value is renderTarget.

See: https://developer.apple.com/documentation/MetalKit/MTKView/multisampleColorAttachmentTextureUsage

func (MTKView) MultisampleColorTexture

func (v MTKView) MultisampleColorTexture() metal.MTLTexture

The multisample color sample texture to render into.

Discussion

The format of this texture is determined by the value of the [ColorPixelFormat] and [SampleCount] properties.

The default value is `nil`. This value is also `nil` if the specified pixel format is MTLPixelFormat.invalid, or if [SampleCount] is less than or equal to 1.

See: https://developer.apple.com/documentation/MetalKit/MTKView/multisampleColorTexture

func (MTKView) Paused

func (v MTKView) Paused() bool

A Boolean value that indicates whether the draw loop is paused.

Discussion

If the value is false, the view periodically redraws the contents, at a frame rate set by the value of [PreferredFramesPerSecond].

The default value is false.

See: https://developer.apple.com/documentation/MetalKit/MTKView/isPaused

func (MTKView) PreferredDevice

func (v MTKView) PreferredDevice() metal.MTLDevice

The device object that the system recommends using for this view.

Discussion

On systems with a single GPU, this method returns the default Metal system device; see MTLCreateSystemDefaultDevice(). On systems with more than one GPU, this method returns the MTLDevice that was last used to composite and present the view’s contents. This device object usually corresponds to the GPU associated with the screen that’s displaying the view. If you set the view’s [Device] property to this device object, you reduce the number of cross-GPU texture copies that Core Animation must make to present the view’s contents onscreen.

See: https://developer.apple.com/documentation/MetalKit/MTKView/preferredDevice

func (MTKView) PreferredDrawableSize

func (v MTKView) PreferredDrawableSize() corefoundation.CGSize

The recommended dimensions of the drawable.

See: https://developer.apple.com/documentation/MetalKit/MTKView/preferredDrawableSize

func (MTKView) PreferredFramesPerSecond

func (v MTKView) PreferredFramesPerSecond() int

The rate at which the view redraws its contents.

Discussion

When your application sets its preferred frame rate, the view chooses a frame rate as close to that as possible based on the capabilities of the screen the view is displayed on. To provide a consistent frame rate, the actual frame rate chosen is usually a factor of the maximum refresh rate of the screen. For example, if the maximum refresh rate of the screen is `60` frames per second, that’s also the highest frame rate the view sets as the actual frame rate. However, if you ask for a lower frame rate, the view might choose `30`, `20`, or `15` frames per second, or another factor, as the actual frame rate.

Your application should choose a frame rate that it can consistently maintain. The default value is `60` frames per second.

See: https://developer.apple.com/documentation/MetalKit/MTKView/preferredFramesPerSecond

func (MTKView) PresentsWithTransaction

func (v MTKView) PresentsWithTransaction() bool

A Boolean value that determines whether the view presents its content using a Core Animation transaction.

Discussion

This property mirrors the value on the underlying CAMetalLayer object, and determines whether the view synchronizes updates to its own contents with other content changes in Core Animation. For more information about how this property affects your rendering code, see presentsWithTransaction.

See: https://developer.apple.com/documentation/MetalKit/MTKView/presentsWithTransaction

func (MTKView) ReleaseDrawables

func (v MTKView) ReleaseDrawables()

Releases the [DepthStencilTexture] and [MultisampleColorTexture] objects.

Discussion

Call this method when your app is moving to the background or when the view won’t display content for a significant period of time. The texture objects that this class creates consume a large amount of memory, so freeing them makes that memory available to other parts of your app.

See: https://developer.apple.com/documentation/MetalKit/MTKView/releaseDrawables()

func (MTKView) SampleCount

func (v MTKView) SampleCount() uint

The sample count used to generate the [MultisampleColorTexture] object.

Discussion

Support for different sample count values varies by device object. Call the supportsTextureSampleCount(_:) method to determine if the device object supports the sample count you want.

The default value is `1`. When you set a value greater than `1`, the view creates and configures an intermediate set of multisample textures. The pixel format is the same as the one specified for the drawable; see [ColorPixelFormat]. When the view creates a render pass descriptor, the render pass uses those intermediate textures as the color render targets, with a store action to resolve these multisample textures into the drawable’s texture (MTLStoreAction.multisampleResolve).

See: https://developer.apple.com/documentation/MetalKit/MTKView/sampleCount

func (MTKView) SetAutoResizeDrawable

func (v MTKView) SetAutoResizeDrawable(value bool)

func (MTKView) SetClearColor

func (v MTKView) SetClearColor(value metal.MTLClearColor)

func (MTKView) SetClearDepth

func (v MTKView) SetClearDepth(value float64)

func (MTKView) SetClearStencil

func (v MTKView) SetClearStencil(value uint32)

func (MTKView) SetColorPixelFormat

func (v MTKView) SetColorPixelFormat(value metal.MTLPixelFormat)

func (MTKView) SetColorspace

func (v MTKView) SetColorspace(value coregraphics.CGColorSpaceRef)

func (MTKView) SetDelegate

func (v MTKView) SetDelegate(value MTKViewDelegate)

func (MTKView) SetDepthStencilAttachmentTextureUsage

func (v MTKView) SetDepthStencilAttachmentTextureUsage(value metal.MTLTextureUsage)

func (MTKView) SetDepthStencilPixelFormat

func (v MTKView) SetDepthStencilPixelFormat(value metal.MTLPixelFormat)

func (MTKView) SetDepthStencilStorageMode

func (v MTKView) SetDepthStencilStorageMode(value metal.MTLStorageMode)

func (MTKView) SetDevice

func (v MTKView) SetDevice(value metal.MTLDevice)

func (MTKView) SetDrawableSize

func (v MTKView) SetDrawableSize(value corefoundation.CGSize)

func (MTKView) SetEnableSetNeedsDisplay

func (v MTKView) SetEnableSetNeedsDisplay(value bool)

func (MTKView) SetFramebufferOnly

func (v MTKView) SetFramebufferOnly(value bool)

func (MTKView) SetMultisampleColorAttachmentTextureUsage

func (v MTKView) SetMultisampleColorAttachmentTextureUsage(value metal.MTLTextureUsage)

func (MTKView) SetPaused

func (v MTKView) SetPaused(value bool)

func (MTKView) SetPreferredFramesPerSecond

func (v MTKView) SetPreferredFramesPerSecond(value int)

func (MTKView) SetPresentsWithTransaction

func (v MTKView) SetPresentsWithTransaction(value bool)

func (MTKView) SetSampleCount

func (v MTKView) SetSampleCount(value uint)

type MTKViewClass

type MTKViewClass struct {
	// contains filtered or unexported fields
}

func GetMTKViewClass

func GetMTKViewClass() MTKViewClass

GetMTKViewClass returns the class object for MTKView.

func (MTKViewClass) Alloc

func (mc MTKViewClass) Alloc() MTKView

Alloc allocates memory for a new instance of the class.

type MTKViewDelegate

type MTKViewDelegate interface {
	objectivec.IObject

	// Updates the view’s contents upon receiving a change in layout, resolution, or size.
	//
	// See: https://developer.apple.com/documentation/MetalKit/MTKViewDelegate/mtkView(_:drawableSizeWillChange:)
	MtkViewDrawableSizeWillChange(view IMTKView, size corefoundation.CGSize)

	// Draws the view’s contents.
	//
	// See: https://developer.apple.com/documentation/MetalKit/MTKViewDelegate/draw(in:)
	DrawInMTKView(view IMTKView)
}

Methods for responding to a MetalKit view’s drawing and resizing events.

See: https://developer.apple.com/documentation/MetalKit/MTKViewDelegate

type MTKViewDelegateConfig

type MTKViewDelegateConfig struct {

	// Other Methods
	// DrawInMTKView — Draws the view’s contents.
	DrawInMTKView func(view MTKView)
}

MTKViewDelegateConfig holds optional typed callbacks for MTKViewDelegate methods. Set non-nil fields to register the corresponding Objective-C delegate method. Methods with nil callbacks are not registered, so [NSObject.RespondsToSelector] returns false for them — matching the Objective-C delegate pattern exactly.

See Apple Documentation for protocol details.

type MTKViewDelegateObject

type MTKViewDelegateObject struct {
	objectivec.Object
}

MTKViewDelegateObject wraps an existing Objective-C object that conforms to the MTKViewDelegate protocol.

func MTKViewDelegateObjectFromID

func MTKViewDelegateObjectFromID(id objc.ID) MTKViewDelegateObject

MTKViewDelegateObjectFromID constructs a MTKViewDelegateObject from an objc.ID. The object is determined to conform to the protocol at runtime.

func NewMTKViewDelegate

func NewMTKViewDelegate(config MTKViewDelegateConfig) MTKViewDelegateObject

NewMTKViewDelegate creates an Objective-C object implementing the MTKViewDelegate protocol.

Each call registers a unique Objective-C class containing only the methods set in config. This means [NSObject.RespondsToSelector] works correctly for optional delegate methods — only non-nil callbacks are registered.

The returned MTKViewDelegateObject satisfies the MTKViewDelegate interface and can be passed directly to SetDelegate and similar methods.

See Apple Documentation for protocol details.

func (MTKViewDelegateObject) BaseObject

func (o MTKViewDelegateObject) BaseObject() objectivec.Object

func (MTKViewDelegateObject) DrawInMTKView

func (o MTKViewDelegateObject) DrawInMTKView(view IMTKView)

Draws the view’s contents.

view: The view requesting that its contents be redrawn.

Discussion

This method is called on the delegate when it is asked to render into the view.

See: https://developer.apple.com/documentation/MetalKit/MTKViewDelegate/draw(in:)

func (MTKViewDelegateObject) MtkViewDrawableSizeWillChange

func (o MTKViewDelegateObject) MtkViewDrawableSizeWillChange(view IMTKView, size corefoundation.CGSize)

Updates the view’s contents upon receiving a change in layout, resolution, or size.

view: The view requesting that its contents be updated.

size: The view’s new drawable size.

Discussion

Use this method to recompute any view or projection matrices, or to regenerate any buffers to be compatible with the view’s new size.

See: https://developer.apple.com/documentation/MetalKit/MTKViewDelegate/mtkView(_:drawableSizeWillChange:)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL