Using Metal to Draw a View’s Contents
时间:2021-9-25
分类:Xcode,Metal开发,
针对人群:初学者,具备初级英语能力
来源:XCode帮助文件
Create a MetalKit view and a render pass to draw the view’s contents.
创建一个MetalKit视图和一个渲染通道来绘制视图内容。
Overview
In this sample, you’ll learn the basics of rendering graphics content with Metal.
You’ll use the MetalKit framework框架 to create a view that uses Metal to draw the contents of the view. Then, you’ll encode commands for a render pass that erases the view to a background color.
在这个例子中,你将学习用Metal渲染图形内容的基本操作。你会用MetalKit框架来创建一个视图,用Metal来绘制视图的内容。然后,你编码命令给一个渲染通道来“擦除”掉视图的背景颜色。
- Note: MetalKit automates windowing system tasks, loads textures, and handles 3D model data. See [MetalKit][MetalKit] for more information.
Prepare a MetalKit View to Draw
MetalKit provides a class called [MTKView
][MTKView], which is a subclass of [NSView
][NSView] (in macOS) or [UIView
][UIView] (in iOS and tvOS).
MTKView
handles many of the details related相关联的细节 to getting the content you draw with Metal onto the screen.
An MTKView
needs a reference引用(就是 C++中的指针) to a Metal device object in order to create resources internally, so your first step is to set the view’s device
property to an existing [MTLDevice
][MTLDevice].
_view.device = MTLCreateSystemDefaultDevice();
Other properties属性 on MTKView
allow you to control its behavior行为. To erase the contents of the view to a solid background color, you set its