This commit updates NanoVG's bgfx backend to match the original NanoVG's latest commit, which has significant changes about composite operation implementation as mentioned in pull request https://github.com/memononen/nanovg/pull/312.
This commit updates bgfx's NanoVG codebase to adapt the latest NanoVG commit since I've implemented blending support for the original NanoVG and there is no need of `nvgState()` anymore.
This commit updates nanovg's bgfx backend to adopt premultiplied alpha as the default blending mode just like the original nanovg. Both the fragment shader and the `glnvg__convertPaint()` function are updated to match the original nanovg counterpart.
However, the binary file of the fragment shader is built on Mac so DirectX support is missing.
This commit ports nanovg's helper functions for rendering stuff in framebuffer defined in `nanovg_gl_utils.h`. Also, a new `nvgState()` function is created for bgfx backend so it is possible to blend between framebuffers, which feature is long requested but not yet supported in original nanovg. The `nvgState()` function can be called between `nvgBeginFrame()` and `nvgEndFrame()`.
This commit fixes the bug that the bgfx does not respect the `devicePixelRatio` parameter passed to nanovg's `nvgBeginFrame()` function. The problem is caused by the `bgfx::setViewRect()` call defined in the `nvgRenderViewport()` function, as it should take size in consideration of the `devicePixelRatio` value.
However, this commit does not fix nanovg's example app because currently there is no easy way to pass the scale value to the `ExampleNanoVG::update()` method as it calls `nvgBeginFrame()`.
This commit moves the additional nanovg functions for bgfx to a separate header file, so it is possible to compile the original nanovg source files with bgfx in a custom build environment.
When a lot of lines are being drawn, this can overflow the vertex buffer, causing a crash in `nvgRenderFlush`. While the underlying code handles this case in an okay manner (truncating the vertex buffer instead of crashing), the `nvgRenderFlush` code is missing a check for this case, causing it to think it has more space than was allocated.
I tried to fix it with multiple buffers as mentioned in #160, however it seems more complex than it appears. This fix just makes it truncate the output according to the actual allocated amount of bytes in the vertex buffer, so it doesn't crash at least.
In our situation, the crash happened due to the view dimensions being reset to 0x0 after minimizing the window. This translated to fillCount of a path ending up at 0, which makes `fan` crash as it computes number of tris to -2 of fillCount. Since `numTris` is unsigned, this could lead to terrible things, but luckily it crashes soon.
There might be a cleaner fix for this further up the call stack, but this is a good solution in the meanwhile.