Bgfx.Net
0.11.0
See the version list below for details.
dotnet add package Bgfx.Net --version 0.11.0
NuGet\Install-Package Bgfx.Net -Version 0.11.0
<PackageReference Include="Bgfx.Net" Version="0.11.0" />
<PackageVersion Include="Bgfx.Net" Version="0.11.0" />
<PackageReference Include="Bgfx.Net" />
paket add Bgfx.Net --version 0.11.0
#r "nuget: Bgfx.Net, 0.11.0"
#:package Bgfx.Net@0.11.0
#addin nuget:?package=Bgfx.Net&version=0.11.0
#tool nuget:?package=Bgfx.Net&version=0.11.0
Bgfx.Net
Cross-platform .NET bindings for bgfx, a graphics rendering library that runs on Windows, Linux, macOS, and Android with Direct3D, Vulkan, OpenGL, OpenGL ES, and Metal backends.
Packages
| Package | Purpose |
|---|---|
Bgfx.Net |
Managed bindings + native bgfx shared library for all supported RIDs |
Bgfx.Net.Tools |
MSBuild integration that runs shaderc / texturec / geometryc at build time. Marked developmentDependency, so it doesn't propagate into consumer output. |
Supported platforms
| Platform | RIDs | Renderers | Minimum |
|---|---|---|---|
| Windows | win-x64, win-arm64 |
Direct3D 12, Direct3D 11, Vulkan, OpenGL, WebGPU | Windows 10 |
| Linux | linux-x64, linux-arm64 |
Vulkan, OpenGL, WebGPU, Direct3D 12 (WSL) | glibc 2.35 |
| macOS | osx-x64, osx-arm64 |
Metal, Vulkan (needs MoltenVK), WebGPU | macOS 11 |
| Android | android-arm64, android-x64 |
Vulkan, OpenGL ES | API 24 (Android 7.0) |
| iOS | ios-arm64, iossimulator-arm64 |
Metal | iOS 16, NativeAOT |
| Browser | browser-wasm |
WebGPU | A browser with WebGPU |
On Android the native libbgfx.so is shipped under runtimes/android-arm64/native
and runtimes/android-x64/native; a net*-android app that references the package
gets it bundled into the APK automatically. Two consumer-side notes:
- The app's effective Android
<RuntimeIdentifiers>must include the ABIs you want bundled — Release builds often resolve onlyandroid-arm64, so addandroid-x64if you also need the x86_64 emulator. - Supply bgfx the native window: set
Init.SwapChain.Nwhto theANativeWindow*obtained from the JavaSurfacevia JNI/NDK beforeInit.
On iOS bgfx ships as a static library that the app links directly, which only NativeAOT can
call: set PublishAot and publish the app, or pass -p:_IsPublishing=true to a simulator
build. Any other build warns with BGFXNET002 and throws DllNotFoundException on the first
bgfx call. Set Init.SwapChain.Nwh to a CAMetalLayer's handle before Init.
In the browser the WebGPU renderer cannot wait on its own adapter and device requests, so the
page resolves a GPUDevice before the .NET runtime starts and stores it in
Module.preinitializedWebGPUDevice. Set Init.PlatformData.Context to
Bgfx.ImportPageWebGpuDevice() before Init. The page chooses the device's features and limits
and handles device.lost; bgfx installs no callbacks on a device it was handed.
Quick start
The bindings mirror the bgfx C API, so entry points take pointers and the calling
code is unsafe.
using Bgfx.Net;
var init = default(Init);
Bgfx.InitCtor(&init);
init.Type = RendererType.Vulkan;
init.SwapChain.Nwh = nativeWindowHandle;
init.SwapChain.Width = 1280;
init.SwapChain.Height = 720;
init.Reset = (uint)ResetFlags.Vsync;
if (!Bgfx.Init(&init))
{
throw new InvalidOperationException("bgfx_init failed");
}
Bgfx.SetViewClear(0, (ushort)(ClearFlags.Color | ClearFlags.Depth), 0x303080ff, 1.0f, 0);
Bgfx.SetViewRect(0, 0, 0, 1280, 720, 0.0f, 1.0f);
while (running)
{
Bgfx.Touch(0);
Bgfx.Frame(0);
}
Bgfx.Shutdown();
See samples/Bgfx.Net.Sdl2Sample for a runnable version
that obtains nativeWindowHandle from SDL2.
Cloning
This repository uses git submodules for bgfx, bx, and bimg. bgfx points at
the bgfx.net branch of the vrimar/bgfx fork, which is upstream master plus the
fixes carried until they land upstream (see RELEASING.md):
git clone --recurse-submodules https://github.com/$USER/Bgfx.Net.git
# or, after a normal clone:
git submodule update --init --recursive
# or use the helper:
./build/bootstrap.sh
Building locally
Prerequisites: .NET SDK 10, plus a C++ toolchain for your platform
(MSVC on Windows, gcc/clang on Linux, Xcode CLT on macOS). On Windows the native
build still uses PowerShell (build-native-win.ps1). To cross-build the Android
native lib, install an NDK and run build-native-android.sh android-arm64
(or android-x64) with ANDROID_NDK_ROOT set.
./build/bootstrap.sh # init submodules, fetch genie
./build/build-native-unix.sh # or build-native-win.ps1 on Windows
./build/sync-bindings.sh # copies bgfx.cs into src/Bgfx.Net/Generated/
./build/run-generator.sh # produces bgfx.g.cs
dotnet build Bgfx.Net.sln
Caveats
- Shaders on Linux/macOS:
shaderccan produce GLSL/ESSL/Metal/SPIR-V on all platforms. DXBC also builds on a linux-x64 host withwineonPATH: shaderc runs Microsoft'sd3dcompiler_47.dll, whichBgfx.Net.Toolsships beside it, under Wine. SetWINEDLLOVERRIDES=d3dcompiler_47=nwhen invoking shaderc yourself, or Wine 11.10+ substitutes its own compiler. DXIL (viadxc) and DXBC on macOS or a linux-arm64 host still need additional tooling. - Threading: bgfx uses an API thread + render thread model selected at
Init. See bgfx's docs for the threading contract. - Pinned to a specific bgfx revision: The
Bgfx.Netassembly is built against exactly one bgfx commit. Read the pin at runtime viaBgfx.Net.BgfxBuildInfo.ApiVersionand.Revision(also embedded asBgfxApiVersion/BgfxRevisionassembly metadata). The package version itself is independent wrapper SemVer, not the bgfx revision — see RELEASING.md. Mixing the assembly with a differentbgfx.dllat runtime is unsupported.
License
BSD-2-Clause. See LICENSE for our code and THIRD-PARTY-NOTICES.md for upstream and 3rdparty attributions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bgfx.Net:
| Package | Downloads |
|---|---|
|
Tralys.Ui.Bgfx
Draws Tralys.Ui views through bgfx, with the Tralys.Ui shaders compiled for SPIR-V, D3D11, Metal and WGSL and embedded. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.12.0 | 63 | 11/25/2026 |
| 0.11.0 | 82 | 11/21/2026 |
| 0.10.0 | 138 | 11/16/2026 |
| 0.9.3 | 114 | 11/4/2026 |
| 0.9.2 | 183 | 11/4/2026 |
| 0.9.1 | 99 | 11/4/2026 |
| 0.9.0 | 135 | 10/30/2026 |
| 0.8.0 | 133 | 10/20/2026 |
| 0.7.1 | 125 | 10/17/2026 |
| 0.7.0 | 150 | 10/16/2026 |
| 0.6.2 | 126 | 10/10/2026 |
| 0.6.1 | 153 | 10/1/2026 |
| 0.6.0 | 134 | 9/23/2026 |
| 0.5.2 | 140 | 9/17/2026 |
| 0.5.1 | 144 | 9/17/2026 |
| 0.5.0 | 161 | 9/9/2026 |
| 0.4.0 | 211 | 7/4/2026 |
| 0.3.0 | 164 | 6/29/2026 |
| 0.2.0 | 172 | 6/11/2026 |
| 0.1.0 | 170 | 5/18/2026 |
Bundles bgfx API v170. Exact upstream commit recorded in assembly metadata (BgfxRevision).