https://github.com/bigmat18/bgfx-lines
Implementation of algorithms to draw lines in different shape a size without using any primitive in API but with bgfx
https://github.com/bigmat18/bgfx-lines
cmake cpp rendering shaders
Last synced: 27 days ago
JSON representation
Implementation of algorithms to draw lines in different shape a size without using any primitive in API but with bgfx
- Host: GitHub
- URL: https://github.com/bigmat18/bgfx-lines
- Owner: bigmat18
- Created: 2024-05-30T15:07:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-25T00:29:39.000Z (9 months ago)
- Last Synced: 2025-09-25T02:38:20.540Z (9 months ago)
- Topics: cmake, cpp, rendering, shaders
- Language: C++
- Homepage: https://www.canva.com/design/DAGf9IzYEwI/3owBkRHI0qNNT_RI0JQX9Q/edit?utm_content=DAGf9IzYEwI&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton
- Size: 1.29 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BGFX Lines Rendering
## 1. Introduction
BGFX Lines is an **open-source**, **general-purpose**, **multi-platform** C++ library for
rendering lines and polylines with variable thickness, custom caps, joins, and
advanced visual effects—without relying on native API line primitives.
Developed as part of my Bachelor’s degree final exam, the project leverages the
bgfx cross-platform rendering library and demonstrates multiple algorithms for
efficient and high-quality line rendering.
- No API line primitives used (fully custom)
- Supports variable thickness, caps, joins, borders
- Multiple CPU/GPU implementations including instancing and compute
## 2. Papers, Libraries, and Requirements
### Papers & References
- bgfx: Cross-platform rendering library — https://github.com/bkaradzic/bgfx
- bx — https://github.com/bkaradzic/bx
- bimg (optional) — https://github.com/bkaradzic/bimg
- https://www.labri.fr/perso/nrougier/python-opengl/#rendering-lines
- https://www.yumpu.com/en/document/read/55443281/opengl-blueprint-rendering
- https://jcgt.org/published/0002/02/08/
- https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-22-fast-prefiltered-lines
### Requirements
- C++17 or newer
- CMake ≥ 3.15
- Supported OS: Windows, Linux, macOS (others may work)
- GPU backend supported by bgfx (OpenGL, Direct3D, Vulkan, Metal)
- Shader model and compute support required for GPU-generated paths
## 3. Features
- Variable-width lines and polylines
- Caps (butt/round/square), joins (miter/bevel/round), borders/outlines
- Anti-aliased rendering strategies
- Five rendering approaches:
- CPU-Generated: buffers generated on CPU, classical draw
- GPU-Generated: buffers generated via compute shaders, then drawn
- CPU Instancing: CPU data + instanced rendering
- GPU Instancing: GPU compute + instanced rendering
- Texture Instancing: instance data via texture buffer (TBO/SSBO)
- General-purpose, multi-platform, bgfx-based
- Modular design for easy integration into existing engines/tools
## 4. Installation and Usage
### 4.1. Getting the Source
```bash
git clone --recursive https://github.com/youruser/bgfx-lines.git
cd bgfx-lines
```
If you forgot `--recursive`, run:
```bash
git submodule update --init --recursive
```
### 4.2. Building
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
```
Artifacts:
- Static/dynamic library target(s) for integration
- Example/demo executables (if enabled)
Optional CMake options (create as needed):
- `-DLINES_BUILD_EXAMPLES=ON`
- `-DLINES_BUILD_TESTS=ON`
### 4.3. Minimal Usage Example
```cpp
std::vector points;
generatePointsInCube(points, 3, 100);
line = std::make_unique(points);
line->settings().setThickness(5);
line->settings().setBorder(2);
line->settings().setAntialias(0);
line->settings().setLeftCap(lines::LineCap::TRIANGLE_CAP);
line->settings().setRigthCap(lines::LineCap::ROUND_CAP);
line->settings().setColorToUse(lines::LineColorToUse::PER_VERTEX_COLOR);
line->settings().setGeneralColor(lines::LinesVertex::COLOR(1, 0, 1, 1));
while (running) {
// ... bgfx frame prep ...
bgfx::touch(0);
line->draw(0);
bgfx::frame();
}
// Cleanup lines and bgfx...
```
See the `examples/` folder for fully working samples per backend.
## 5. Results

Rendering of 500.000 lines visual effect and update each 1.0 sec

Rendering of a Graph using custom lines and polylines system with visual effects

Rendering of a model wireframe using custom lines with 5px thickness
## 6. Benchmark and Performance Analysis

Delta Time absulute value with static buffers (no-updates)

Delta Time compared with reference implementation with static buffers (no-updates)

Delta Time absulute value with dynamic buffers (updates)

Delta Time compared with reference implementation with dynamic buffers (updates)