Skip to main content

Backend Overview

iPlug2 IGraphics supports two drawing backends, selected at compile time:

NanoVG

Lightweight OpenGL/Metal vector graphics
  • Tiny footprint (~200KB)
  • Fast rendering
  • Minimal dependencies
  • Recommended for most plugins

Skia

Google’s 2D graphics library
  • Rich feature set
  • Advanced text layout
  • Better rendering quality
  • Larger binary size (~2-3MB)

Compile-Time Selection

Backends are selected using preprocessor definitions in your project configuration:
config.h
// Define the IGraphics backend
#define IGRAPHICS_NANOVG 1

// Define the graphics API (choose one)
#define IGRAPHICS_GL2 1      // OpenGL 2.1 (legacy)
// #define IGRAPHICS_GL3 1   // OpenGL 3.2+ (modern)
// #define IGRAPHICS_GLES2 1 // OpenGL ES 2.0 (mobile/web)
// #define IGRAPHICS_GLES3 1 // OpenGL ES 3.0 (mobile)
// #define IGRAPHICS_METAL 1 // Metal (macOS/iOS)

// OpenGL context creation
#define IGRAPHICS_GL 1       // Required for GL2/GL3/GLES variants
You must define exactly ONE graphics backend: either IGRAPHICS_NANOVG or IGRAPHICS_SKIA. Defining both or neither will cause a compilation error.

NanoVG Backend

Overview

NanoVG is a lightweight antialiased vector graphics rendering library built on top of OpenGL/Metal. It’s inspired by HTML5 canvas API.
When to use NanoVG:
  • Most audio plugins
  • Size-constrained scenarios
  • Fast rendering is priority
  • Basic text rendering is sufficient
  • No external dependencies desired

Features

Vector Graphics

Paths, curves, fills, strokes

Text Rendering

TrueType/OpenType fonts, single-line text

Images

PNG, JPEG, BMP loading and rendering

Fast Shadows

GPU-accelerated drop shadows

Graphics API Options

// OpenGL 2.1 - Maximum compatibility, legacy systems
#define IGRAPHICS_GL2 1

// OpenGL 3.2+ - Modern desktop, better performance
#define IGRAPHICS_GL3 1

// OpenGL ES 2.0 - Mobile devices, WebGL 1.0
#define IGRAPHICS_GLES2 1

// OpenGL ES 3.0 - Modern mobile, WebGL 2.0
#define IGRAPHICS_GLES3 1

// Metal - macOS 10.11+, iOS 8.0+, best performance on Apple
#define IGRAPHICS_METAL 1

Platform Recommendations

PlatformRecommended APINotes
macOSIGRAPHICS_METALBest performance, native Apple
iOSIGRAPHICS_METALRequired for iOS
WindowsIGRAPHICS_GL2 or GL3GL3 for newer systems
Web (WASM)IGRAPHICS_GLES2WebGL 1.0 support
LinuxIGRAPHICS_GL3Modern OpenGL

Code Example

class IGraphicsNanoVG : public IGraphics {
  // NanoVG-specific methods
  
  void DrawFastDropShadow(const IRECT& innerBounds, 
                          const IRECT& outerBounds, 
                          float xyDrop = 5.f, 
                          float roundness = 0.f, 
                          float blur = 10.f, 
                          IBlend* pBlend = nullptr);
  
  void DrawMultiLineText(const IText& text, const char* str, 
                         const IRECT& bounds, const IBlend* pBlend);
};

// Access NanoVG context directly
NVGcontext* nvg = static_cast<NVGcontext*>(pGraphics->GetDrawContext());

// Use NanoVG API
nvgBeginPath(nvg);
nvgRoundedRect(nvg, x, y, w, h, radius);
nvgFillColor(nvg, nvgRGBA(r, g, b, a));
nvgFill(nvg);

NanoVG Multi-Line Text

NanoVG supports basic multi-line text wrapping:
IText text(16.f, COLOR_WHITE);
const char* str = "This is a long text that will wrap to multiple lines";
IRECT bounds(10, 10, 200, 100);

pGraphics->DrawMultiLineText(text, str, bounds);
Multi-line text in NanoVG is basic. For complex paragraph layout, use Skia.

Skia Backend

Overview

Skia is Google’s comprehensive 2D graphics library used in Chrome, Android, and Flutter. It provides professional-grade rendering.
When to use Skia:
  • High-end plugin graphics
  • Advanced text layout needed
  • Best visual quality required
  • Larger binary size acceptable
  • Complex typography/internationalization

Features

Advanced Text

Paragraph layout, multi-line wrapping, bidirectional text

Image Filters

Blur, drop shadows, color matrices

High Quality

Excellent antialiasing and color management

Rich Features

Gradients, patterns, effects, advanced blending

Dependencies

Skia requires building the Skia library:
1

Download Skia

Clone the Skia repository or download prebuilt binaries
2

Build Skia

Follow iPlug2’s build instructions in Dependencies/Build/README.md
3

Configure paths

Point your project to the Skia include and library directories
# iPlug2 includes scripts to build Skia
cd $IPLUG2_ROOT/Dependencies/Build
./build-skia-mac.sh  # macOS
# or build-skia-win.bat  # Windows
Skia adds ~2-3MB to your plugin binary size. Consider this for distribution.

Code Example

class IGraphicsSkia : public IGraphics {
  // Skia-specific features
  
  void DrawFastDropShadow(const IRECT& innerBounds, 
                          const IRECT& outerBounds, 
                          float xyDrop, float roundness, 
                          float blur, IBlend* pBlend);
  
  void DrawMultiLineText(const IText& text, const char* str, 
                         const IRECT& bounds, const IBlend* pBlend);
  
  void ApplyLayerDropShadow(ILayerPtr& layer, const IShadow& shadow);
};

// Access Skia canvas directly
SkCanvas* canvas = static_cast<SkCanvas*>(pGraphics->GetDrawContext());

// Use Skia API
SkPaint paint;
paint.setColor(SK_ColorRED);
paint.setAntiAlias(true);
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, w, h), r, r);
canvas->drawRRect(rrect, paint);

Advanced Text Layout

Skia provides sophisticated text layout with the Paragraph API:
// Multi-line text with proper wrapping and alignment
IText text(16.f, COLOR_WHITE);
text.mAlign = EAlign::Near;
text.mVAlign = EVAlign::Top;

const char* longText = 
  "Skia handles complex text layout including line breaking, "
  "justification, and bidirectional text. Perfect for plugin "
  "documentation or rich text displays.";

IRECT bounds(10, 10, 300, 200);
pGraphics->DrawMultiLineText(text, longText, bounds);

Feature Comparison

Drawing Primitives

FeatureNanoVGSkiaNotes
PathsBoth excellent
StrokesSkia has more dash options
FillsBoth support gradients
CurvesCubic & quadratic beziers
TransformsRotate, scale, skew

Text Rendering

FeatureNanoVGSkiaNotes
Basic textBoth work well
Multi-line⚠️ Basic✅ AdvancedSkia has paragraph API
Font features⚠️ Limited✅ FullOpenType features
BidirectionalRTL/LTR text
Text shaping⚠️ Basic✅ AdvancedComplex scripts

Images & Effects

FeatureNanoVGSkiaNotes
Bitmap loadingPNG, JPEG, etc.
SVG supportVia nanosvg/Skia SVG
Blur effects⚠️ Drop shadow onlySkia has full filters
Image filtersColor matrix, etc.
Layer effects⚠️ BasicAdvanced compositing

Performance

MetricNanoVGSkiaNotes
Binary size~200KB~2-3MBNanoVG much smaller
Memory usageLowModerateSkia uses more RAM
Rendering speedFastModerateNanoVG slightly faster
Startup timeInstantFastMinimal difference

Backend-Specific Code

When you need backend-specific features:
#if defined IGRAPHICS_NANOVG
  // NanoVG-specific code
  NVGcontext* nvg = static_cast<NVGcontext*>(pGraphics->GetDrawContext());
  nvgBeginPath(nvg);
  nvgCircle(nvg, x, y, r);
  nvgFillColor(nvg, nvgRGBA(255, 0, 0, 255));
  nvgFill(nvg);
  
#elif defined IGRAPHICS_SKIA
  // Skia-specific code
  SkCanvas* canvas = static_cast<SkCanvas*>(pGraphics->GetDrawContext());
  SkPaint paint;
  paint.setColor(SK_ColorRED);
  canvas->drawCircle(x, y, r, paint);
#endif
Backend-specific code reduces portability. Use IGraphics abstraction when possible.

Switching Backends

To switch between backends:
1

Update config.h

Change IGRAPHICS_NANOVG to IGRAPHICS_SKIA (or vice versa)
2

Update graphics API defines

Ensure appropriate GL/Metal defines for the new backend
3

Add/remove dependencies

Add Skia libraries if switching to Skia, or remove them for NanoVG
4

Test thoroughly

Some subtle rendering differences may exist
Most IGraphics code is backend-agnostic and will work unchanged.

Best Practices

  • Targeting older systems/web
  • Want minimal dependencies
  • Building most audio plugins

Troubleshooting

Next Steps

Controls Library

Works identically on both backends

Custom Controls

Draw using backend-agnostic API

Getting Started

Set up your first UI

Responsive UI

Handle scaling and resizing