summaryrefslogtreecommitdiffstatsci
path: root/README.md
blob: 9ecbe3d0b27232d469ede96593778b4940ac5330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<h1 align="center">
  <br>
  <a href="https://github.com/jpbruyere/vkvg/blob/master/vkvg.svg">
	<img src="https://github.com/jpbruyere/vkvg/blob/master/vkvg.svg?sanitize=true" alt="vkvg" width="140">
  </a>
  <br>
	<br>
  Vulkan Vector Graphics
  <br>
<p align="center">
  <a href="https://github.com/jpbruyere/vkvg/actions/workflows/cmake.yml">
     <img src="https://github.com/jpbruyere/vkvg/actions/workflows/cmake.yml/badge.svg">
  </a>
  <img src="https://img.shields.io/github/license/jpbruyere/vkvg.svg?style=flat-square">
  <a href="https://www.paypal.me/GrandTetraSoftware">
    <img src="https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square">
  </a>
  <a href="https://matrix.to/#/#vkvg:matrix.org">
    <img src="https://matrix.to/img/matrix-badge.svg">
  </a>
</p>
<p align="center">
  <a href="https://aur.archlinux.org/packages/vkvg">
    <img src="https://img.shields.io/aur/version/vkvg">
  </a>
  <a href="https://mpr.hunterwittenborn.com/packages/vkvg">
    <img src="https://img.shields.io/badge/mpr-v0.3.0--beta-blue">
  </a>
</p>
</h1>

**vkvg** is an open-source *2D graphics library* written in **C** using [Vulkan](https://www.khronos.org/vulkan/) as backend.
The **API** follows the same pattern as [Cairo](https://www.cairographics.org/), but new functions and original drawing mechanics may be added.

**vkvg** is in alpha development stage and the core api is mostly stabilized. All contributions are welcome.

In progress API documentation is available online at http://vkvg.org.

<p align="center">
  <a href="https://github.com/jpbruyere/vkvg/blob/master/vkvg-tiger.png">
	<kbd><img src="https://github.com/jpbruyere/vkvg/blob/master/vkvg-tiger.png" height="260"></kbd>
  </a>
  <a href="https://github.com/jpbruyere/vkvg/blob/master/screenshot3.png">
	<kbd><img src="https://raw.githubusercontent.com/jpbruyere/vkvg/master/screenshot3.png" height="260"></kbd>
  </a>
  <a href="https://github.com/jpbruyere/vkvg/blob/master/screenshot1.png">
	<kbd><img src="https://github.com/jpbruyere/vkvg/blob/master/screenshot1.png" height="260"></kbd>
  </a>
</p>

## Performance comparison

<p align="center">
  <a href="https://github.com/jpbruyere/vgperf/blob/master/vgperf.png">
	<kbd><img src="https://raw.githubusercontent.com/jpbruyere/vgperf/master/vgperf.png" height="300"></kbd>
  </a>
   <br>major libs perf comparison</br>
</p>

## Current status:

- Fill (stencil even-odd, non-zero).
- Stroke.
- Basic painting operation.
- Font system with caching operational.
- Linear/Radial Gradients.
- Line caps and joins.
- Dashes.
- Context should be thread safe, extensive tests required.
- Image loading and writing with [stb lib](https://github.com/nothings/stb)
- Test includes svg rendering either with built-in renderer or [nanoSVG](https://github.com/memononen/nanosvg)

## Requirements:

- [CMake](https://cmake.org/): version >= 3.16
- [Vulkan](https://www.khronos.org/vulkan/): version >= 1.1
- [FontConfig](https://www.freedesktop.org/wiki/Software/fontconfig/): optional, without fontconfig, use `vkvg_load_font_from_path`.
- [Freetype](https://www.freetype.org/): optional, stb_truetype as alternative.
- [Harfbuzz](https://www.freedesktop.org/wiki/Software/HarfBuzz/): optional, without complex text shaping may be wrong.
- GLSLC: spirv compiler, included in [LunarG SDK](https://www.lunarg.com/vulkan-sdk/): compile shader to spir-V (building only, optional)
- [xxd](https://linux.die.net/man/1/xxd): generate headers with precompiled shaders (building only, optional)
- [GLFW](http://www.glfw.org/): optional, if present tests are built.

if `glslc` or `xxd` are not present, a precompiled version of the shaders is stored in the git tree.

## Building

<a href="https://aur.archlinux.org/packages/vkvg"><img src="https://img.shields.io/aur/version/vkvg"></a>
<a href="https://mpr.hunterwittenborn.com/packages/vkvg"><img src="https://img.shields.io/badge/mpr-v0.3.0--beta-blue"></a>

```bash
#fetch sources from github
git clone --recursive https://github.com/jpbruyere/vkvg.git
cd vkvg
# Create build directory
mkdir build
cd build
# Run CMake configuration
cmake ..
```
If you work on your own fork of vkvg, due to the relative paths in `.gitmodules`, you may ends with remote not found if you
didn't fork the submodules as well. To overcome the problem, you may set a fallback url for submodules with the following command:

```bash
git config submodule.vkh.url https://github.com/jpbruyere/vkhelpers.git
git config submodule.glutess.url https://github.com/jpbruyere/glutess.git
git config submodule.vkvg-svg.url https://github.com/jpbruyere/vkvg-svg.git
```

### CMake configure options

##### Core library options:

* `-DVKVG_USE_GLUTESS=true`: Use embedded glu tesselator to fill polygones in NON-ZERO mode. If false, a simple ear clipping algorithm is used.
* `-DVKVG_SVG=true`: Enable experimental svg renderer. If false, use nanoSVG.
* `-DVKVG_RECORDING=true`: Enable experimental draw commands recording infrastructure.
* `-DVKVG_BUILD_DOCS=true`: Build documentation if doxygen is found.

##### Vulkan Features:

* `-DVKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT=true`: Enable `VK_EXT_scalar_block_layout` that reduce structure padding for gpu.
* `-VKVG_ENABLE_VK_TIMELINE_SEMAPHORE=true`: Enable experimental work syncing with `VK_KHR_timeline_semaphore` instead of Fences.

##### Text rendering libraries:

Those libraries are enabled by default, but disabled if not found.
* `-DVKVG_USE_FONTCONFIG=true`: enable FontConfig to resolve font's names.
* `-DVKVG_USE_FREETYPE=true`: enable FreeType to render glyphs, if false glyphs are rendered with stb_truetype.
* `-DVKVG_USE_HARFBUZZ=true`: enable harfbuzz for text shaping.

##### Tests options:

* `-DVKVG_BUILD_TESTS=true`: build all tests in the tests forlder.
* `-DVKVG_TEST_DIRECT_DRAW=true`: enable drawing directly on the swapchain images.

##### Debugging options:

If vkvg is compiled with `CMAKE_BUILD_TYPE=Debug`, several additional options are made available to help debugging:
* `-DENABLE_VALIDATION=true`: enable vulkan validation layer.
* `-DENABLE_DBG_UTILS=true`: enable various vulkan debug utils extensions features.
* `-DENABLE_RENDERDOC=true`: enable renderdoc layer.
* `-DENABLE_WIRED_FILL=true`: enable rendering in wired mode, current mode is controled with the global variable `vkvg_wired_debug`.
* `-DENABLE_PROFILING=true`: add -pg to the compile options.
* `-DVKVG_DBG_STATS=true`: store various context statistics fetchable with `vkvg_device_get_stats()`

```bash
cmake --build .
```
A [detailed tutorial](doc/windows_build_tutorial.md) is available for Windows.

## Running tests

Append the `-h` option to see available command line parameters.

## Contributing

See the [contribution guide](https://github.com/jpbruyere/vkvg/blob/master/CONTRIBUTING.md) for more information.

Join us on [matrix](https://matrix.to/#/#vkvg:matrix.org) for any question.

## Addtitional Credits

- vkvg use the [AGG project](http://antigrain.com/)'s recursive bezier algorithm which is kindly exposed [here](http://agg.sourceforge.net/antigrain.com/research/adaptive_bezier/index.html).
- I've learned Vulkan with the help of the excellent [Sacha Willems's vulkan examples](https://github.com/SaschaWillems/Vulkan).
- The 2d affine matrix implementation follows Cairo's one.

## Change log

* v0.2.0
	- radial gradients.
	- better stroke joins handling.
	- png saved in srgb format.
	- doxygen cmake target and style

## To Do

- [x] Use Scissor where possible.
- [x] Improve stroke algorithms.
- [x] Radial gradients.
- [x] Dashed lines.
- [ ] Operators.
- [x] Optimize vulkan memory allocations by sub-allocating from a single shared memory chunk per type.
- [x] Optimize command submissions.
- [x] Test SDF font rendering.
- [x] Avoid line joins inside curves and arc.
- [ ] Structured unit testing.
- [x] Perf and memory checks.
- [ ] Code cleanup and comments.
- [ ] Documentations.