Tutorial 72: Choosing a Renderer

CNA Tutorials  ·  Architecture

ℹ

What you’ll learn

  • How CNA's 10 renderer identities group, and what each group is for.
  • Which renderers are platform-gated, which is the default where, and which never produce a pixel.
  • Selecting one renderer or compiling several for pre-device runtime selection.
  • Why SupportsCapability() is a summary and not a proof, and what the richer capability profile adds.

Before you start — Tutorial 20: Building and Running Your Game. The default remains a single renderer; Tutorial 126 covers the opt-in multi-renderer workflow in full.

In this snapshot (CNA 3b43bd86, a development snapshot after the 0.1.0 release) CNA exposes 10 renderer identities, implemented by 8 renderer families. The three GL-profile identities share one family, EasyGL. The default mode compiles one. An opt-in CNA_GRAPHICS_RENDERERS list can compile several compatible families; the application chooses one before the first graphics device is created, after which the choice latches. This is startup selection and optional fallback, not hot device switching.

The count is not a coverage claim. The 10 identities are not equally complete: two produce no pixels, one never presents to a window, and each carries a declared maturity (Production, Supported or Experimental) that is CNA's own classification, not a measurement. The set is curated: an identity earns a place only with meaningful platform coverage, compatibility value, architectural value or a capability the rest of the set does not cover. For reference-level capability and platform detail, see the Renderers guide.

Selecting a renderer

For the recommended single-renderer build, use either the named value or exactly one legacy boolean. Do not mix the two forms.

# Form 1 — name the renderer directly (case-sensitive)
cmake -S . -B build -DCNA_GRAPHICS_RENDERER=OPENGLES3

# Form 2 — switch exactly one CNA_RENDERER_<NAME> option ON
cmake -S . -B build -DCNA_RENDERER_OPENGLES3=ON

With form 2, turning on more than one option is a hard FATAL_ERROR: "Exactly one renderer option must be ON when using CNA_RENDERER_* options."

For a multi-renderer build, provide a semicolon-separated list and keep the singular value as the default member:

cmake -S . -B build-multi \
  -DCNA_GRAPHICS_RENDERERS="OPENGLES3;SDL_GPU;SOFTWARE" \
  -DCNA_GRAPHICS_RENDERER=OPENGLES3

Defaults when you pass nothing: Emscripten gets WEBGL2; Windows, macOS and iOS get SDL_GPU; every other system (Linux, Android, the BSDs) gets OPENGLES3. Because the Linux default is OPENGLES3, an ordinary Linux build needs the ../sharp-runtime (branch next for this snapshot), ../easy-gl (v0.1.1) and ../meta-gl (v0.4.1) sibling checkouts next to cna/ — they are separate repositories, not submodules, and the configure step checks their declared versions. The SDL_GPU default on Windows, macOS and iOS is CNA’s chosen modern path, but at this snapshot it is qualified on Linux and under Wine only, so test on the real target before you rely on it.

⚠

Names that are not accepted. EASYGL, D3D9 and ASCII are old spellings, not accepted values. Any name outside the 10 passed to CNA_GRAPHICS_RENDERER or listed in CNA_GRAPHICS_RENDERERS stops the configure in the root CMakeLists.txt, before any dependency is configured, with "unknown graphics renderer '<name>' (requested through <route>)" followed by the list of supported names. There are no aliases and no silent fallback on those two routes, and matching is case-sensitive (sdl_gpu is unknown; SDL_GPU is not). An old-style -DCNA_RENDERER_D3D9=ON switch is different: it is not read by anything and the default renderer is configured, so name the renderer with CNA_GRAPHICS_RENDERER. The old EASYGL is now one of three GL profiles, D3D9 became DIRECTX9, and ASCII is now the CNAEXT effect AsciiPostProcessEffect.

Group 1 — the OpenGL family (3 identities)

All three share one internal implementation, called EasyGL, which lives in the ../easy-gl sibling library (itself needing ../meta-gl). "EasyGL" is the implementation's name; it is not a selectable renderer value. Selecting any of the three compiles the same tree and adds a CNA_GL_PROFILE_* define.

ValueWhat it isPlatform
OPENGLES3OpenGL ES 3.0 (GLSL ES 3.00) via EasyGL. The default on Linux, Android and the BSDs. Declared Production.Native hosts (not Emscripten)
OPENGL33Desktop OpenGL 3.3 core profile via EasyGL. Declared Production. On macOS it runs on Apple’s OpenGL 4.1 core context; CNA recorded its full test tree passing there on a physical Mac mini M4 in an early-October campaign that predates this snapshot and was not repeated.Native hosts (not Emscripten)
WEBGL2WebGL 2 via EasyGL. The Emscripten default. Declared Supported.Emscripten only

OPENGLES3 is the renderer CNA develops against day to day, and the one its Linux CI runs the full default suite on. It is the safe answer if you have no reason to pick another. Tutorial 102 walks the family in detail.

Group 2 — modern GPU APIs (2 identities)

Two renderers drive a modern explicit GPU API, both through a portable layer. Neither picks the native API itself: SDL chooses its Vulkan, Direct3D 12 or Metal GPU driver underneath SDL_GPU, and wgpu-native or the browser chooses underneath WEBGPU. CNA has no compute-shader, storage-buffer, indirect-draw or GPU-timer API on any renderer; what these two implement is ordinary graphics — stock effects, PBR, image-based lighting, shadows, float render targets, instancing and compiled effects.

ValueWhat it isPlatform
SDL_GPUCNA’s modern native path: XNA 4.0 mapped onto SDL3's GPU API (SPIR-V; SDL selects its GPU driver). Declared Supported. Custom ShaderEffect only where libshaderc exists (Linux and Android builds; compiled out on Windows, Apple and Emscripten); no occlusion queries; base-instance drawing. See Tutorial 131.Wherever SDL3's GPU API has a device; needs the SDL3 platform. The default on Windows, macOS and iOS; qualified on Linux (Vulkan) and under Wine (Direct3D 12) only
WEBGPUWebGPU through the pinned native wgpu-native (WGSL shaders) and through the Emscripten emdawnwebgpu port in the browser. Declared Supported (since 17 October 2026). See Tutorial 132.Native desktop hosts and the browser; verified on Linux x86_64 and in headless Chrome only

Running on Vulkan, Direct3D 12 or Metal hardware therefore means running SDL_GPU (or FNA3D, whose own SDL_GPU driver reaches the same APIs); the native driver is SDL’s choice, not a CNA identity. On Apple, CI has a gating macOS smoke leg for SDL_GPU on SDL’s Metal driver that had not recorded a run at this snapshot, and non-gating iOS legs; SDL_GPU has never been built for iOS. iOS admits SOFTWARE and SDL_GPU; no physical iPhone or iPad has run either, and tvOS remains unsupported.

Group 3 — translation layers (3 identities)

Three identities do not talk to one native API themselves but adapt another library, which then picks its own native API; CNA classes them as its TranslationLayer category. The extra layer is the point — and also the risk, because CNA's coverage of each is narrower than the wrapped library itself. Two of the three appear in Group 2; the one whose whole identity is an adapter of an XNA-shaped library is FNA3D.

ValueWhat it adaptsNotes
FNA3DFNA-XNA's FNA3D C library, which chooses its SDL_GPU, Direct3D 11 or OpenGL driver at runtime (override with FNA3D_FORCE_DRIVER), plus MojoShader. Declared Experimental. See Tutorial 108.Cannot compile custom shaders at all; it executes compiled Direct3D 9 Effect Framework binaries, which are always on, and shades the stock and PBR effects through its own shaders. Its whole-corpus oracle CTest gates only that scenes render, not pixel equality. Needs SDL3.
SDL_GPUSDL3's GPU APIGroup 2.
WEBGPUWebGPU (wgpu-native or emdawnwebgpu)Group 2.

Two identities need SDL3 directly — SDL_GPU and FNA3D. Every windowed renderer takes its window and GL context from the SDL3 platform, CNA’s one windowing platform; a build with CNA_ENABLE_SDL=OFF is windowless (CNA_PLATFORM=HEADLESS or TERMINAL).

Group 4 — Windows: DIRECTX9 and the SDL_GPU default

One renderer is hard-gated to Windows: configuring DIRECTX9 anywhere else is a FATAL_ERROR, not a warning. It is real Direct3D 9 — the API XNA 4.0 itself ran on — through its genuine COM interfaces. The Windows default, SDL_GPU, is not Windows-only: on Windows SDL picks its Direct3D 12 driver underneath it.

ValueWhat it targets
DIRECTX9Direct3D 9. Compiles custom HLSL at runtime with D3DCompile for SpriteBatch effects. Declared Production. The pixel-exactness renderer — see below.
SDL_GPUSDL’s Direct3D 12 driver on Windows (Group 2). The Windows default; custom ShaderEffect is compiled out of Windows builds.
⚠

Windows evidence is Wine evidence. CNA validates DIRECTX9 through MinGW-w64 cross builds run under Wine with DXVK, and SDL_GPU’s Direct3D 12 driver under Wine with vkd3d-proton. A native-Windows MSVC workflow (d3d-windows-ci.yml: the DIRECTX9 suite and an SDL_GPU Direct3D 12 smoke leg) exists as manual dispatch only; CNA’s handoff records the SDL_GPU leg as not run yet and no current real-Windows hardware validation. Verify native-hardware behaviour yourself before shipping. Tutorial 103 covers both.

Pixel-exactness is a DIRECTX9 statement, and only that. CNA's XNA oracle corpus is 39 scenes (256×256, HiDef) with reference images captured from the genuine Microsoft XNA 4.0 runtime under Wine with DXVK on Linux. DIRECTX9, run through the same Wine+DXVK stack, is recorded in the repository as matching all 39 at tolerance 0; that run is not part of CI and has not been repeated on native Windows. No other renderer is held to that bar: EasyGL and SOFTWARE are gated on two line scenes only (the EasyGL test fails on any pixel difference; the SOFTWARE test only if a scene does not render), and FNA3D's corpus test only checks that scenes render. If bit-identical XNA 4.0 output is the goal, DIRECTX9 is the answer and nothing else is.

Group 5 — the browser (WebGL 2 and WebGPU)

Two identities run in the browser: WEBGL2 (the EasyGL profile of Group 1, Emscripten-only and the Emscripten default) and WEBGPU (Group 2), whose browser route goes through the emdawnwebgpu port. On the Emscripten side CI builds one WebAssembly bundle containing WEBGL2 and WEBGPU and checks that both renderers and the JavaScript selection surface are in it; it does not run the bundle.

In the browser the renderer can also be chosen at page load, without a rebuild, when several are compiled in: set Module.cnaPreferredRenderer (for example var Module = { cnaPreferredRenderer: "WEBGPU" };) before the runtime starts. It sits at the environment variable's precedence. Tutorial 105 covers the group.

⚠

Three web caveats apply to every browser build, WEBGL2 and WEBGPU alike. StorageDevice saves persist in the browser’s IndexedDB, which CNA mounts and restores before main() — except in a threaded build, which uses WasmFS by default and needs -DCNA_EMSCRIPTEN_USE_WASMFS=OFF for persistence. There is no video decoder: Video/VideoPlayer compile and link, but decoding throws NotSupportedException (the FFmpeg backend is never built for Emscripten). And Game::Run() blocks on the caller's stack through Asyncify, so external consumers must link CNA::EmscriptenAsyncify (automatic for CNA-owned app executables); the old “heap-allocate your Game” rule no longer applies. Tutorial 81 covers the web build.

2D games run on every renderer that draws

No identity is 2D-only at this snapshot. Every renderer that produces pixels draws both 2D and 3D, so a SpriteBatch-only game runs on any of them, and the platform default is a good choice. If a 2D game needs to run where no GPU exists, SOFTWARE (Group 6) draws the same sprites on the CPU.

Group 6 — CPU-only and no-output (3 identities)

ValueWhat it is
SOFTWAREA genuine CPU rasteriser that owns its framebuffer. Off-screen by default — you read pixels back with GetBackBufferData() — except on CNA_PLATFORM=TERMINAL attached to a TTY, where finished frames are presented (and on iOS, through the platform’s surface presenter). It reports CustomEffects false and, if you construct a custom ShaderEffect anyway, keeps it for resource compatibility without ever executing its source — its own fixed CPU shading path renders instead. Compiled effects are an opt-in build option. Declared Experimental. See Tutorial 107.
HEADLESSNo GPU and no window. It validates arguments and counts or traces calls (CNA_HEADLESS_MODE) and records custom shader submissions rather than executing them. Built for fast CI of game logic; selected by GraphicsAdapter.UseNullDevice.
STUBA no-op renderer. No pixel output of any kind, all 17 capabilities false, no bookkeeping. The default of the dev, unit and release-modules presets.

CNA_PLATFORM=TERMINAL accepts only these three; of them only SOFTWARE actually displays anything there.

Which renderers produce no picture

Two renderers — HEADLESS and STUB — produce no pixel output at all. STUB also reports ThreeD false, but it is a no-op renderer, not a 2D one: its draw calls do nothing. SOFTWARE renders real pixels but does not present them to a window (except on a terminal and on iOS). Where a 3D resource cannot exist — a Texture3D on STUB or HEADLESS, for example — the outcome is the Unsupported3DGraphicsCallBehavior setting: Throw (the default) raises an error naming the renderer and the method, while WarnAndStub logs one warning per operation and returns a safe null object. WarnAndStub changes no SupportsCapability() answer.

Which renderers execute custom shaders

A custom ShaderEffect (see Tutorial 52) genuinely executes on the three GL profile identities and WEBGPU, on SDL_GPU in Linux and Android builds that have libshaderc (or when you hand it SPIR-V), and on DIRECTX9 for SpriteBatch effects written in HLSL (its 3D draws use the stock effects). HEADLESS records the submission without executing it.

Everywhere else you get one of three different outcomes, and the difference matters:

  • SOFTWARE accepts the effect and silently ignores the source. It reports CustomEffects false, but construction does not fail and nothing tells you at draw time — this is the one to watch for.
  • SDL_GPU outside Linux and Android compiles the custom-effect path out: on Windows, Apple and Emscripten builds it reports CustomEffects false, because no runtime GLSL → SPIR-V → DXIL/MSL path exists.
  • FNA3D has no custom-effect path (no effect renderer is created). FNA3D can still run compiled XNA effects; see below. STUB runs nothing at all.

The shading language also varies: GLSL on the GL family, SPIR-V on SDL_GPU, HLSL compiled at runtime on DIRECTX9, and WGSL on WEBGPU. One source string is not portable across all of them; Tutorial 151 shows how to ship one variant per dialect.

Separately, compiled XNA effects (Direct3D 9 Effect Framework bytecode, .fxb) run on six renderer families (8 identities): FNA3D always, and five opt-in build options — CNA_EASYGL_COMPILED_EFFECTS (all three GL profiles), CNA_WEBGPU_COMPILED_EFFECTS, CNA_SOFTWARE_COMPILED_EFFECTS, CNA_DIRECTX9_COMPILED_EFFECTS and CNA_SDL_GPU_COMPILED_EFFECTS. All five default to OFF, so a default configure reports CompiledEffects false on 9 of the 10 identities; HEADLESS and STUB never run them.

SupportsCapability() fails open

⚠

GraphicsCapability has 17 members (the 14 of alpha.1 plus FloatRenderTargets, HalfFloatRenderTargets and HalfFloatTextureLinearFiltering). The renderer-interface default still returns true for the original members except stencil (delegated to the renderer), multi-stream input and compiled effects (false unless the renderer opts in), and the two float render-target answers (false). Only DIRECTX9 supplies no override at all and relies on those inherited defaults wholesale; SDL_GPU has a switch with no permissive default arm, STUB answers false to everything, while WEBGPU, HEADLESS, SOFTWARE, the GL profiles and FNA3D mix explicit answers with a default: true. At the device level, six answers are derived separately (compiled effects, float and half-float render targets, half-float linear filtering, and multiple render targets and Texture3D, which are limited by the graphics profile). Treat a true as "not known to be unsupported", not as a guarantee, and test the renderer you ship.

For a richer answer, ask the device for its renderer capability profile: 33 named features, 8 numeric limits, per-format usage for all 27 SurfaceFormat members and a readable report, each feature answering Unknown, Unsupported, Supported or Restricted. Tutorial 101 and Tutorial 133 show the calls.

One gap worth knowing before you design around it

Cube faces inside a multiple-render-target set are refused on two otherwise-capable 3D renderers: DIRECTX9 throws NotSupportedException (“cube faces in a multi-target set are not implemented by this CNA renderer”), and WEBGPU refuses with its own message. Plain 2D MRT works on the renderers that report multiple render targets; binding a RenderTargetCube face as one slot of an MRT set is the case to check on your renderer before you depend on it (the GL family, SOFTWARE, SDL_GPU and FNA3D implement it, and HEADLESS accepts it without rasterizing anything). See Tutorial 62.

Decision table

SituationChoose
Not sure / just startingThe platform default; on Linux that is OPENGLES3 — CNA's day-to-day development renderer
Pure 2D game, maximum portabilityThe platform default: every pixel-producing renderer draws SpriteBatch content; SOFTWARE needs no GPU at all
3D game on LinuxOPENGLES3 or OPENGL33; SDL_GPU (on SDL’s Vulkan driver) for a modern explicit API
3D game on WindowsSDL_GPU (the default, on SDL’s Direct3D 12 driver; no native Windows run recorded yet), DIRECTX9, or OPENGL33
Bit-identical XNA 4.0 outputDIRECTX9 (Windows-only) — the only renderer recorded in the repository as matching all 39 oracle scenes
macOSSDL_GPU (the default, on SDL’s Metal driver; not re-qualified on Apple hardware at this snapshot) or SOFTWARE, the renderer macOS CI exercises; see Tutorial 109
Browser, 3D or 2DWEBGL2 (the Emscripten default). Read the web caveats above first.
Browser with WebGPUWEBGPU — Tutorial 105
CI without a GPU, game logic onlyHEADLESS (or STUB)
Deterministic, GPU-free pixel comparisonSOFTWARE (read back with GetBackBufferData())
Running an FNA-shaped compiled-effect workflowFNA3D (always-on compiled effects; no custom shaders) — Tutorial 108
Anything that needs a custom shaderNot FNA3D, SOFTWARE (silently ignored) or STUB, and not SDL_GPU outside Linux and Android builds

Setting the renderer in CMake

# Configure and build with the SDL_GPU renderer
cmake -S . -B build-sdlgpu -DCNA_GRAPHICS_RENDERER=SDL_GPU
cmake --build build-sdlgpu --target CnaTests

# Equivalent, using the per-renderer option form
cmake -S . -B build-sdlgpu -DCNA_RENDERER_SDL_GPU=ON

# The Windows-only renderer needs a Windows toolchain (MSVC, or MinGW-w64 from Linux)
cmake -S . -B build-d3d9 \
      -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw-w64.cmake \
      -DCNA_GRAPHICS_RENDERER=DIRECTX9

# The Emscripten-only renderer refuses to configure for a native target
emcmake cmake -S . -B build-webgl2 -DCNA_GRAPHICS_RENDERER=WEBGL2
⚠

cmake --build ... --target CNA no longer works. CNA is an add_library(CNA INTERFACE) umbrella with no sources, so it is not a buildable target. Build CnaTests, a demo target, or simply cmake --build build.

CTest labels follow the renderer names too: ctest -L DIRECTX9 works, ctest -L D3D9 matches nothing.

Compile-time defines in game code

The selected (default) renderer emits a CNA_RENDERER_<NAME> preprocessor define project-wide. The three GL profiles are the one exception: they all emit CNA_RENDERER_EASYGL (the shared implementation identity) plus a CNA_GL_PROFILE_<NAME> define naming the profile. In a multi-renderer build only the default's macro is defined, and CNA_MULTI_RENDERER is added.

#if defined(CNA_RENDERER_SDL_GPU)
    // SDL_GPU-specific startup work
#elif defined(CNA_RENDERER_EASYGL)
    // Any of OPENGLES3 / OPENGL33 / WEBGL2.
    // Narrow it further when the profile actually matters:
    #if defined(CNA_GL_PROFILE_WEBGL2)
        // Browser build: keep the particle budget small.
        maxParticles_ = 2000;
    #endif
#elif defined(CNA_RENDERER_DIRECTX9)
    // Windows-only native Direct3D 9 path
#endif

Prefer a run-time capability query over a compile-time define wherever the behaviour depends on what the device can do rather than on which renderer was compiled; in a multi-renderer build the define names only the default.

Runtime selection in a multi-renderer build

GraphicsRendererSelection::SetPreferred() has highest precedence, followed by the CNA_GRAPHICS_RENDERER environment variable (in an Emscripten build, the page property Module.cnaPreferredRenderer at the same precedence) and finally the compiled default. Selection must happen before the first graphics device is successfully created, and then latches: a failed attempt does not latch, so a game may catch the error and retry with another configuration. Unknown, retired or uncompiled identities throw. Fallback is opt-in; a failed preferred renderer is otherwise a hard failure, and automatic fallback tries the renderers that show a picture before HEADLESS. Two device flags also pick a renderer: GraphicsAdapter.UseNullDevice requires HEADLESS and UseReferenceDevice requires SOFTWARE.

Not every list is legal: CMake rejects identities from different platform partitions (the Windows-only DIRECTX9 and the Emscripten-only WEBGL2 cannot share a build, and OPENGLES3/OPENGL33 are refused under Emscripten), and CNA_PLATFORM=TERMINAL accepts only SOFTWARE, HEADLESS and STUB. Several EasyGL identities may coexist within one partition. Multi-renderer builds also carry every selected dependency and increase build and binary size. See Tutorial 126 and Runtime Renderer Selection.

What CI actually covers

This snapshot contains 18 workflow files, 16 of which run automatically. Automatic (push/PR) lanes cover OPENGLES3 (the full default suite under Xvfb), the SDL3 platform contract on Linux with OPENGLES3, SDL_GPU (on lavapipe), WEBGPU and SOFTWARE, windowless HEADLESS and TERMINAL cells, glTF stride legs, a HEADLESS;SOFTWARE;STUB multi-renderer build, SOFTWARE on macOS with a bundle smoke app and an iOS Simulator smoke app, a gating SDL_GPU-on-Metal smoke leg on macOS and non-gating iOS SDL_GPU legs, and a WebAssembly bundle build of WEBGL2;WEBGPU. The Windows lane (DIRECTX9 and an SDL_GPU Direct3D 12 smoke leg) is manual-dispatch only. No workflow names FNA3D or OPENGL33, there is no Android job, and the macOS SDL_GPU leg had not recorded a run at this snapshot. That is build and smoke coverage, not coverage of every one of the 10 identities, every valid combination, physical iOS hardware, or the full GPU pixel/oracle matrix.