Making nanovg run in emscripten didn't require any changes except for 2 bugs:
- the many glGetError calls killed performance, especially on Chrome; a define which turns glnvg__checkError into a no-op would be nice
- the icon textures are non-POT, and need GL_TEXTURE_WRAP_S/GL_TEXTURE_WRAP_T set to GL_CLAMP_TO_EDGE in order to be rendered (this may have been GL state spilling over from my engine though, but I think nanovg should override this state)
- emscripten and NaCl don't allow synchronous IO (fopen/fread/fclose) during the render loop, but both have emulations for fopen which require to preload files into memory, so these loader functions make sense for some scenarios even when running in the web browser
- in my case I'm not using fopen/fclose but my engine's IO system which calls platform-specific HTTP APIs, and then call nanovg's create-from-memory functions for fonts and images
- images and fonts are loaded asynchronously, creation and rendering is deferred until the required files are loaded (but my implementation of this is a bit hacky at the moment)
- this means in my case the fopen functions are useless, and I added a NANOVG_NO_STDIO define to conditionally remove them (similar to stb_image's STBI_NO_STDIO)
- it would be good to find ways to reduce the number of GL calls, because in WebGL even simple functions come with overhead (for instance, there's a lot of glUniform1f and glUniform2f calls, may be these can be merged into fewer glUniform4f, or maybe even provide the shader parameters with a single glUniform4fv?)
- in stb_image.h and stb_truetype.h: PNaCl doesn't have the memory.h header, instead memcpy is defined in string.h
- I was a bit confused by the nvgCreateFontMem function because the function takes ownership of the provided memory chunk, and there's no nvgDeleteFont function
- it would be cool to have a way to override the malloc/free calls, or (if even possible) to remove dynamic allocation inside the lib completely