Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Swift Package Manager for super easy installation :) #22

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# Swift package manager
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "MetalNanoVG",
platforms: [
.macOS(.v10_11), .iOS(.v8)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "MetalNanoVG",
targets: ["MetalNanoVG"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "MetalNanoVG",
dependencies: []),
.testTarget(
name: "MetalNanoVGTests",
dependencies: ["MetalNanoVG"]),
]
)
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,40 @@ Advantages

* Shared buffers between CPU and GPU.
* Various Metal states are cached whenever possible.
* Low overheads compared to OpenGL.
* Low overhead compared to OpenGL.
* Pre-compiled shaders. (no need to compile shaders at runtime)
* Seamless integration with powerful Metal features such as [Metal Performance Shaders](https://developer.apple.com/documentation/metalperformanceshaders).

Installation
============

1. Download both `NanoVG` and `MetalNanoVG` source codes.
2. Add both `NanoVG` and `MetalNanoVG`'s `src` directories to the header search
path.
3. Add `NanoVG`'s `src/nanovg.c` and `MetalNanoVG`'s `src/nanovg_mtl.m` to
the `Compile Sources` section in Xcode.
4. Link the `Metal` and `QuartzCore` frameworks.
5. For best performance, disable *GPU Frame Capture* and *Metal API Validation* as described [here](https://developer.apple.com/library/content/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Dev-Technique/Dev-Technique.html#//apple_ref/doc/uid/TP40014221-CH8-SW3).
## Swift Package Manager (requires Xcode 11 or later)

1. In Xcode, Select File -> Swift Packages -> Add Package Depedency
1. Enter `https://github.com/ollix/MetalNanoVG` for the URL.
1. For best performance, disable *GPU Frame Capture* and *Metal API Validation* as described [here](https://developer.apple.com/library/content/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Dev-Technique/Dev-Technique.html#//apple_ref/doc/uid/TP40014221-CH8-SW3).

Done.

Usage
=====

## Swift

1. Import.

```Swift
import MetalNanoVG
```
2. Pass the `CAMetalLayer` object when creating the NanoVG context.

```Swift
let layer = CAMetalLayer()
let nvg = nvgCreateMTL(Unmanaged.passUnretained(layer).toOpaque(), Int32(NVG_ANTIALIAS.rawValue))
```

## Objective-C

1. Include the headers.

```C
Expand Down
Loading