MetalNanoVG is the native Metal port of NanoVG that tries to get the most out of Apple's Graphics APIs.
If you found this project useful, please consider donating to show your support ❤️
- Works only on macOS 10.11+, tvOS 9.0+ and iOS 8.0+.
- Simulator support is available since iOS 13 and requires Xcode 11+ running on macOS 10.15+.
- Not all Apple hardwares are supported even if meets the OS requirement.
- ARC is required.
- Shared buffers between CPU and GPU.
- Various Metal states are cached whenever possible.
- Low overheads compared to OpenGL.
- Pre-compiled shaders. (no need to compile shaders at runtime)
- Seamless integration with powerful Metal features such as Metal Performance Shaders.
- Download both
NanoVG
andMetalNanoVG
source codes. - Add both
NanoVG
andMetalNanoVG
'ssrc
directories to the header search path. - Add
NanoVG
'ssrc/nanovg.c
andMetalNanoVG
'ssrc/nanovg_mtl.m
to theCompile Sources
section in Xcode. - Link the
Metal
andQuartzCore
frameworks. - For best performance, disable GPU Frame Capture and Metal API Validation as described here.
Done.
- Include the headers.
#include "nanovg.h"
#include "nanovg_mtl.h"
- Pass the
CAMetalLayer
object when creating the NanoVG context.
NVGcontext* ctx = nvgCreateMTL(metalLayer, NVG_ANTIALIAS | NVG_STENCIL_STROKES);
The following table depicts a simple CPU usage benchmark of running the NanoVG demo app on iOS devices with full Retina resolution. Both Metal and OpenGL ES2 implementations get constant 60 FPS.
iPhone 6s+ | iPad Pro 12.7" (2015) | |
---|---|---|
Resolution | 1080 x 1920 | 2732 * 2048 |
Metal | 20% | 20% |
OpenGL ES2 | 35% | 33% |
MetalNanoVG was originally created to improve the performance of the iOS app Fog of World.