# Examples

Most of the examples require shader/texture/mesh data to be loaded. When running examples your current directory should be examples/runtime.

    <bgfx_path>/examples/runtime $ ../../.build/<config>/bin/example-00-helloworldDebug

## 00-helloworld

Initialization and debug text.

## 01-cubes

Rendering simple static mesh.

## 02-metaballs

Rendering with transient buffers and embedding shaders.

Downloading...

## 03-raymarch

Updating shader uniforms.

## 04-mesh

Loading meshes.

## 05-instancing

Geometry instancing.

## 06-bump

Loading textures.

## 07-callback

Implementing application specific callbacks for taking screen shots, caching OpenGL binary shaders, and video capture.

## 08-update

Updating textures.

## 09-hdr

Using multiple views with frame buffers, and view order remapping.

## 10-font

Use the font system to display text and styled text.

## 11-fontsdf

Use a single distance field font to render text of various size.

## 12-lod

Mesh LOD transitions.

## 13-stencil

Stencil reflections and shadows.

## 14-shadowvolumes

Shadow volumes.

## 15-shadowmaps-simple

## 16-shadowmaps

## 17-drawstress

### 60Hz

Draw stress is CPU stress test to show what is the maximum number of draw calls while maintaining 60Hz frame rate. bgfx currently has default limit of 64K draw calls per frame. You can increase this limit by changing `BGFX_CONFIG_MAX_DRAW_CALLS`.

CPU | Renderer | GPU | Arch/Compiler/OS | Dim | Calls
--- | --- | --- | --- | --- | ---
i7-4770K 4.2 | GL2.1 | 2xGTX780 | x64/VS2013/Win 8.1 | 51 | 132651
i7-4770K 4.2 | DX11 | 2xGTX780 | x64/VS2013/Win 8.1 | 50 | 125000
i7-4790K 4.0 | GL2.1 | GTX970 | x64/VS2015/Win 10 | 47 | 103823
i7-4790K 4.0 | DX11 | GTX970 | x64/VS2015/Win 10 | 45 | 91125
i7-4790K 4.0 | DX9 | GTX970 | x64/VS2013/Win 10 | 40 | 64000
i5-3570 3.8 | NV 331.49 | GTX560Ti | x64/GCC/Linux | 40 | 64000+
i7-920 2.66 | GL2.1 | GTX650Ti | x64/VS2008/Win 7 | 38 | 54872
i7-920 2.66 | GL2.1 | GTX650Ti | x86/VS2008/Win 7 | 38 | 54872
i7-6700K 4.0 | GL2.1 | Skylake GT2 | x64/GCC/Win 10 | 38 | 54872
i7-4790K 4.0 | DX11 | R7 240 | x64/VS2015/Win 10 | 36 | 46656
i7-920 2.66 | NV 331.113 | GTX650Ti | x64/GCC/Linux | 34 | 39304
i7-6700K 4.0 | DX11 | Skylake GT2 | x64/GCC/Win 10 | 34 | 39304
i7-4790K 4.0 | DX9 | R7 240 | x64/VS2015/Win 10 | 32 | 32768
i7-920 2.66 | DX9 | GTX650Ti | x64/GCC/Win 7 | 32 | 32768
i7-920 2.66 | DX9 | GTX650Ti | x64/VS2008/Win 7 | 32 | 32768
i7-920 2.66 | DX9 | GTX650Ti | x86/GCC/Win 7 | 30 | 27000
i7-920 2.66 | DX9 | GTX650Ti | x86/VS2008/Win 7 | 30 | 27000
i5-6200U 2.3 | DX11 | Intel 520 | x64/GCC/Win 10 | 30 | 27000
i5-4250U 1.3 | GL2.1 | HD5000 | x64/Clang/OSX 10.9 | 28 | 21852
Q8200 2.33 | NV 319.32 | GTX260 | x64/GCC/Linux | 27 | 19683
i7-6700K 4.0 | GL2.1 | Skylake GT2 | x64/GCC/Linux | 27 | 19683
i7-2600K 3.4 | DX9 | AMD6800 | x64/VS2012/Win 7 | 27 | 19683
i7-2600K 3.4 | GL2.1 | AMD6800 | x64/VS2012/Win 7 | 26 | 17576
i7-4770R 3.2 | Mesa 10.5.9 | HD5200 | x64/GCC/Linux | 26 | 17576
i5-6200U 2.3 | GL | Intel 520 | x64/GCC/Win 10 | 26 | 17576
i7-920 2.66 | DX9-Wine | GTX650Ti | x64/GCC/Linux | 24 | 13824
i5-6200U 2.3 | Mesa 10.5.9 | Intel 520 | x64/GCC/Linux | 23 | 12167
i7-4750HQ 2.0 | Mesa 10.0.1 | HD5200 | x64/GCC/Linux | 22 | 10648
i7-4750HQ 2.0 | Mesa 10.1.3 | HD5200 | x64/GCC/Linux | 21 | 9261
i7-920 2.66 | ES2-ANGLE | GTX650Ti | x86/VS2008/Win 7 | 21 | 9261
Q8200 2.33 | Gallium 0.4 | AMD5770 | x64/GCC/Linux | 21 | 9261
i5-4250U 1.3 | ES2 | HD5000 | JIT/Clang/PNaCl 31 | 21 | 9261
i5-4250U 1.3 | ES2 | HD5000 | x86/GCC/NaCl 31 | 20 | 8000
Q8200 2.33 | Gallium 0.4 | GTX260 | x64/GCC/Linux | 19 | 6859
i5-2450M 2.5 | Mesa 10.2.0 | HD3000 | x64/GCC/Linux | 19 | 6859
i7-920 2.66 | ES2-PowerVR | GTX650Ti | x86/VS2008/Win 7 | 18 | 5832
i7-920 2.66 | FF27-GL | GTX650Ti | JIT/Clang/W7-asm.js | 17 | 4913
i7-6700K 4.0 | DX9 | Skylake GT2 | x64/GCC/Win 10 | 16 | 4096
i7-4750HQ 2.0 | Mesa 8.0.5 | LLVMPIPE | x64/GCC/Linux | 16 | 4096
i5-6200U 2.3 | DX9 | Intel 520 | x64/GCC/Win 10 | 16 | 4096
i7-920 2.66 | ES2-Qualcomm | GTX650Ti | x86/VS2008/Win 7 | 15 | 3375
i7-920 2.66 | ES2 | GTX650Ti | x64/GCC/NaCl 31 | 15 | 3375
i7-920 2.66 | ES2 | GTX650Ti | JIT/Clang/PNaCl 31 | 15 | 3375
Q8200 2.33 | NV 319.32 | GTX260 | x64/GCC/NaCl 31 | 15 | 3375
Q8200 2.33 | NV 319.32 | GTX260 | x64/GCC/PNaCl 31 | 15 | 3375
‘12 Nexus 7 | ES2 | Tegra3 | ARM/GCC/Android | 15 | 3375
i5-4250U 1.3 | ES2-FF27 | HD5000 | JIT/Clang/OSX-asm.js | 15 | 3375
i5-4250U 1.3 | Chrome33 | HD5000 | JIT/Clang/OSX-asm.js | 15 | 3375
iPad mini 2 | ES2 | PVR G6430 | ARM64/Clang/iOS7 | 15 | 3375
i7-920 2.66 | Chrome33 | GTX650Ti | JIT/Clang/W7-asm.js | 14 | 2744
i7-920 2.66 | FF27-ANGLE | GTX650Ti | JIT/Clang/W7-asm.js | 14 | 2744
‘13 Nexus 10 | ES2 | Mali T604 | ARM/GCC/Android | 13 | 2197
iPhone 5 | ES2 | PVR SGX543 | ARM/Clang/iOS7 | 13 | 2197
‘13 Nexus 7 | ES2 | S4 Pro | ARM/GCC/Android | 12 | 1728
iPad 2 | ES2 | PVR SGX543 | ARM/Clang/iOS6 | 12 | 1728
AMD A4-5000 | Gallium 0.4 | HD8330/Kabini | x64/GCC/Linux | 12 | 1728
Xperia Z | ES2 | Adreno320 | ARM/GCC/Android | 11 | 1331
iPod 4 | ES2 | PVR SGX535 | ARM/Clang/iOS6 | 7 | 343
i7-920 2.66 | ES2-Mali | GTX650Ti | x86/VS2008/Windows7 | 6 | 216
Creator CI20 | ES2 | PVR SGX540 | MIPS/GCC/Debian8 | 7 | 343
i5-6200U 2.3 | ES2 | SwiftShader | x64/GCC/Linux | 6 | 216
RaspberryPi | ES2 | VC IV | ARM/GCC/Raspbian | 6 | 216

To test browsers in 60Hz mode following changes were made:

- Firefox 27 about:config adjustments: `webgl.prefer-native-gl true` (on Windows), and `layout.frame_rate 500`.

- Chrome 33 command line option: `--disable-gpu-vsync`.

### 30Hz (test for browsers)

By default browsers are using vsync, and don’t have option to turn it off programmatically.

CPU | Renderer | GPU | Arch/Compiler/OS | Dim | Calls
--- | --- | --- | --- | --- | ---
i7-920 2.66 | GL2.1 | GTX650Ti | x64/VS2008/Win7 | 38 | 64000+
i5-4250U 1.3 | GL2.1 | HD5000 | x64/Clang/OSX 10.9 | 36 | 46656
i5-4250U 1.3 | Chrome34 | HD5000 | JIT/Clang/OSX-PNaCl 31 | 28 | 21952
i5-4250U 1.3 | Chrome33 | HD5000 | JIT/Clang/OSX-PNaCl 31 | 27 | 19683
i5-4250U 1.3 | FF28 | HD5000 | JIT/Clang/OSX-asm.js | 25 | 15625
i5-4250U 1.3 | FF36 | HD5000 | JIT/Clang/OSX-asm.js | 25 | 15625
i5-4250U 1.3 | Chrome41 | HD5000 | x64/GCC/OSX-NaCl 41 | 24 | 13824
i5-4250U 1.3 | FF37 | HD5000 | JIT/Clang/OSX-asm.js | 23 | 12167
i5-4250U 1.3 | FF27 | HD5000 | JIT/Clang/OSX-asm.js | 20 | 8000
i7-920 2.66 | Chrome33 | GTX650Ti | JIT/Clang/W7-PNaCl 31 | 20 | 8000
i7-920 2.66 | Chrome34 | GTX650Ti | JIT/Clang/W7-asm.js | 18 | 5832
i7-920 2.66 | Chrome33 | GTX650Ti | JIT/Clang/W7-asm.js | 18 | 5832
i7-920 2.66 | FF28 | GTX650Ti | JIT/Clang/W7-asm.js | 18 | 5832
i7-920 2.66 | FF27 | GTX650Ti | JIT/Clang/W7-asm.js | 18 | 5832
i5-4250U 1.3 | Safari7 | HD5000 | JIT/Clang/OSX-asm.js | 15 | 3375

## 18-ibl

Image-based lighting.

## 19-oit

Weighted, Blended Order-Independent Transparency

## 20-nanovg

NanoVG is small antialiased vector graphics rendering library.

## 21-deferred

MRT rendering and deferred shading.

## 22-windows

Rendering into multiple windows.

## 23-vectordisplay

Rendering lines as oldschool vectors.

## 24-nbody

N-body simulation with compute shaders using buffers.

## 25-c99

Initialization and debug text with C99 API.

## 26-occlusion

Using occlusion query for conditional rendering.

## 27-terrain

Terrain painting example.

## 28-wireframe

Drawing wireframe mesh.

## 29-debugdraw

Debug draw.

## 30-picking

Mouse picking via GPU readback.

## 31-rsm

Global Illumination with Reflective Shadow Map.

## 32-particles

Particles.

## 33-pom

Parallax occlusion mapping.

Reference(s):

  - Exploring bump mapping with WebGL

## 34-mvs

Multiple vertex streams.

## 35-dynamic

Dynamic buffers update.

## 36-sky

Perez dynamic sky model.

## 37-gpudrivenrendering

GPU-Driven Rendering.

Reference(s):

  - Experiments in GPU-based occlusion culling,

  - Experiments in GPU-based occlusion culling part 2: MultiDrawIndirect and mesh lodding,

  - Porting GPU driven occlusion culling to bgfx.

## 38-bloom

Bloom.

Reference(s):

  - Next Generation Post Processing in Call of Duty: Advanced Warfare.

## 39-assao

Adaptive Screen Space Ambient Occlusion.

Reference(s):

  - Adaptive Screen Space Ambient Occlusion.

## 40-svt

Sparse Virtual Textures.

## 41-tess

Adaptive GPU Tessellation with Compute Shaders

Reference(s):

  - Adaptive GPU Tessellation with Compute Shaders by Jad Khoury, Jonathan Dupuy, and Christophe Riccio.

## 42-bunnylod

Simple Polygon Reduction

Reference(s):

  - Simple Polygon Reduction.

  - A Simple, Fast,and Effective Polygon Reduction Algorithm.

## 43-denoise

Denoise

Reference(s):

  - Spatiotemporal Variance-Guided Filtering: Real-Time Reconstruction for Path-Traced Global Illumination..

  - Streaming G-Buffer Compression for Multi-Sample Anti-Aliasing.

  - Edge-Avoiding À-Trous Wavelet Transform for fast Global Illumination Filtering.

## 44-sss

Screen-Space Shadows

## 45-bokeh

Bokeh Depth of Field

Reference(s):

  - Bokeh depth of field in a single pass.

## 46-fsr

AMD FidelityFX Super Resolution - high-quality solution for producing high resolution frames from lower resolution inputs.

## 47-pixelformats

Pixel Formats

View and test texture formats

## 48-drawindirect

Draw Indirect

Simple example of indirect rendering + an implementation of multidraw indirect

Reference(s):

  - OpenGL MultiDrawIndirect with per-instance textures.

  - Indirect Rendering - A way to a million draw calls.

## 49-hextile

Realtime Hex-Tiling

Simple example of how to use Hex-tiling in real time, ported from https://github.com/mmikk/hextile-demo

Reference(s):

  - Hex-Tiling demo.

  - Paper explaining concepts -.

## 50-headless

Demonstrate running bgfx in headless mode. Initialize bgfx without window, render into frame buffer, and output result into an image.