Book Image

Application Development with Swift

By : Hossam Ghareeb
Book Image

Application Development with Swift

By: Hossam Ghareeb

Overview of this book

Table of Contents (14 chapters)

Getting started with Metal


Now I think you have enough background knowledge to get started with Metal. Let's start building our demo together.

  1. Open Xcode, create new project, and choose the Game template.

  2. Then, write the name of the MetalDemo project, choose Swift as a language, and select Metal in the Game Technology options list.

  3. Now, build and run in your device. You should see a beautiful triangle moving in 3D.

We will go through the code together and explain the most important parts of it in how to draw this triangle.

Devices and CAMetalLayers

Open GameViewController.swift, and you will see that we have to first import Metal framework. Then, if you checked the first two attributes, you should see something like this:

    let device = { MTLCreateSystemDefaultDevice() }()
    let metalLayer = { CAMetalLayer() }()

Creating devices is considered the first step in your Metal code. Devices are the abstractions over GPU in your iOS device. Devices conform to protocol MTLDevice, and you can consider...