Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3374a7d

Browse files
adding macos instructions
1 parent 79baf0d commit 3374a7d

7 files changed

Lines changed: 124 additions & 2 deletions

02_Development_environment.md

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ As mentioned before, Vulkan by itself is a platform agnostic API and does not
6262
include tools for creating a window to display the rendered results. To benefit
6363
from the cross-platform advantages of Vulkan and to avoid the horrors of Win32,
6464
we'll use the [GLFW library](http://www.glfw.org/) to create a window, which
65-
supports both Windows and Linux. There are other libraries available for this
65+
supports Windows, Linux and MacOS. There are other libraries available for this
6666
purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that
6767
it also abstracts away some of the other platform-specific things in Vulkan
6868
besides just window creation.
@@ -266,7 +266,7 @@ As mentioned before, Vulkan by itself is a platform agnostic API and does not
266266
include tools for creation a window to display the rendered results. To benefit
267267
from the cross-platform advantages of Vulkan and to avoid the horrors of X11,
268268
we'll use the [GLFW library](http://www.glfw.org/) to create a window, which
269-
supports both Windows and Linux. There are other libraries available for this
269+
supports Windows, Linux and MacOS. There are other libraries available for this
270270
purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that
271271
it also abstracts away some of the other platform-specific things in Vulkan
272272
besides just window creation.
@@ -487,3 +487,125 @@ offline version of the entire Vulkan specification. Feel free to explore the
487487
other files, but we won't need them for this tutorial.
488488

489489
You are now all set for [the real adventure](!Drawing_a_triangle/Setup/Base_code).
490+
491+
## MacOS
492+
493+
These instructions will assume you are using Xcode and the [Homebrew package manager](https://brew.sh/). Also, keep in mind that you will need at least MacOS version 10.11, and your device needs to support the [Metal API](https://en.wikipedia.org/wiki/Metal_(API)#Supported_GPUs).
494+
495+
### MoltenVK
496+
497+
For MacOS what we will be using to develop Vulkan application is [MoltenVK](https://moltengl.com/). This is a library that maps Vulkan to Apple's Metal graphics framework, with this you can take advantage of debugging and performance benefits of Apple's Metal framework.
498+
499+
To install and build MoltenVK go the the project's [github repository](https://github.com/KhronosGroup/MoltenVK) and follow the instructions. By the end you should have built one of the runtime distribution packages, either the Release or the Debug configuration. To make sure everything was done successfully, we will run one of the examples from the repository. Go to the folder where you cloned the repository, find and open the file `../MoltenVK/Demos/Demos.xcworkspace`. Now all the projects should open on Xcode, select the application `Cube-macOS`, build and run it. You should see the following:
500+
501+
![](/images/cube_demo_mac.png)
502+
503+
### GLFW
504+
505+
As mentioned before, Vulkan by itself is a platform agnostic API and does not include tools for creation a window to display the rendered results. To benefit from the cross-platform advantages of Vulkan and to avoid the horrors of X11, we'll use the [GLFW library](http://www.glfw.org/) to create a window, which supports Windows, Linux and MacOS. There are other libraries available for this purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that it also abstracts away some of the other platform-specific things in Vulkan besides just window creation.
506+
507+
To install GLFW on MacOS you can follow the same instructions to install it on Linux, so please refer to that topic on this chapter.
508+
509+
### GLM
510+
511+
Unlike DirectX 12, Vulkan does not include a library for linear algebra
512+
operations, so we'll have to download one. [GLM](http://glm.g-truc.net/) is a
513+
nice library that is designed for use with graphics APIs and is also commonly
514+
used with OpenGL.
515+
516+
It is a header-only library that can be installed from the `glm` package:
517+
518+
```bash
519+
brew install glm
520+
```
521+
522+
### Setting up Xcode
523+
524+
Now that all the dependencies are installed we can set up a basic Xcode project for Vulkan. Most of the instructions here are essentially a lot of "plumbing" so we can get all the dependencies linked to the project.
525+
526+
Start Xcode and create a new Xcode project. On the window that will open select Application > Command Line Tool.
527+
528+
![](/images/xcode_new_project.png)
529+
530+
Select `Next`, write a name for the project and for `Language` select `C++`.
531+
532+
![](/images/xcode_new_project_2.png)
533+
534+
Press `Next` and the project should have been created. Now, let's change the code on the generated `main.cpp` file to the following code:
535+
536+
```c++
537+
#include <vulkan/vulkan.h>
538+
#include <GLFW/glfw3.h>
539+
540+
#define GLM_FORCE_RADIANS
541+
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
542+
#include <glm/vec4.hpp>
543+
#include <glm/mat4x4.hpp>
544+
545+
#include <iostream>
546+
547+
int main() {
548+
glfwInit();
549+
550+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
551+
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
552+
553+
uint32_t extensionCount = 0;
554+
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
555+
556+
std::cout << extensionCount << " extensions supported" << std::endl;
557+
558+
glm::mat4 matrix;
559+
glm::vec4 vec;
560+
auto test = matrix * vec;
561+
562+
while(!glfwWindowShouldClose(window)) {
563+
glfwPollEvents();
564+
}
565+
566+
glfwDestroyWindow(window);
567+
568+
glfwTerminate();
569+
570+
return 0;
571+
}
572+
```
573+
574+
Xcode should already be complaining of errors such as libraries it cannot find. We will now start configuring the project to get rid of those errors. On the *Project Navigator* panel select your project. Open the *Build Settings* tab and then:
575+
576+
* Find the **Framework Search Paths** field and add a link to the `../MoltenVK/macOS` folder (which should be in the folder you clonned the MoltenVK project).
577+
* Find the **Header Search Paths** field and add a link to `/usr/local/include` (this is where Homebrew install libraries, so the glm header files should be there), a link to `../glfw-3.2.1/include` for the glfw headers, and finally a link to `../MoltenVK/Package/Release/MoltenVK/include` for the Vulkan headers (in this example I built the framework for the Release configuration).
578+
* Find the **Library Search Paths** field and add a link to `../glfw-3.2.1/src`.
579+
580+
It should look like so (obviously, paths will be different depending on where you placed on your files):
581+
582+
![](/images/xcode_paths.png)
583+
584+
Above I have added the values for the Release configurations because it's the one I'm using, you just need to add the paths on the configuration that you picked.
585+
586+
Now, on the *General* tab, on **Linked Frameworks and Libraries** you will need to add the following frameworks:
587+
588+
* libc++.tbd
589+
* libglfw3.a
590+
* Should be at `../glfw-3.2.1/src/libglfw3.a`.
591+
* MoltenVK.framework
592+
* Should be at `../MoltenVK/Package/Release/MoltenVK/macOS/MoltenVK.framework`.
593+
* Metal.framework
594+
* IOSurface.framework
595+
* QuartzCore.framework
596+
* IOKit.framework
597+
* Foundation.framework
598+
* Cocoa.framework
599+
* CoreVideo.framework
600+
601+
Should look like:
602+
603+
![](/images/xcode_frameworks.png)
604+
605+
Finally, you should be all set! Now if you run the project (remembering to setting the build configuration to Debug or Release depending on the configuration you chose) you should see the following:
606+
607+
![](/images/xcode_output.png)
608+
609+
The number of extensions should be non-zero. The other logs are from the libraries, you might get different messages from those depending on tour configuration.
610+
611+
You are now all set for [the real thing](!Drawing_a_triangle/Setup/Base_code).

images/cube_demo_mac.png

65.7 KB
Loading

images/xcode_frameworks.png

48.4 KB
Loading

images/xcode_new_project.png

70.2 KB
Loading

images/xcode_new_project_2.png

39.3 KB
Loading

images/xcode_output.png

104 KB
Loading

images/xcode_paths.png

44.4 KB
Loading

0 commit comments

Comments
 (0)