ctx – flexible scalable graphics for microcontrollers, GEGL and more

A new single-header C(/C++ compatible) library with an API inspired by cairo and HTML5 canvas' 2D rendering context, called ctx. Follow the link for some more information and a video demonstration. It works on 32bit microcontrollers like ESP32 and ARM-CortexM4; and is devised to scale to networked/remote and threaded software rendering

It is a work in progress, but already has the ability to render to 1bit, 2bit, 4bit and 8bit integer and 32bit floating point grayscale, as well as 8bpc, floating point RGBA and a couple of variants of 16bit 565RGB framebuffers, for the floating point formats I plan to make it very generic before considering performance so that grayscale, RGB, CMYK as well as spectral or multi-ink scenarios are well supported in a way that will work well with GEGL.

The way the API works; it is designed to be used with a split front-end and backend the communicate with a binary drawlist/renderstream. In the initial prototyping device the card10 badge from this years Chaos Communications Camp, the "user core" creates the renderstream (from C or micropython), and the system core does the rendering. This part of the architecture might open up some interesting way of doing interactive networked vector graphics, it makes parallelization with threading easy, as well as possible doing front-to-back rather than back-to-front rendering. This structuring of the rendering also permits trading of performance for memory use by not having a full-sized framebuffer on a microcontroller, the buffer for the renderstream replaces the framebuffer - and pixels are made on demand as one uploads chunks of pixels or scanlines over SPI, making it feasible to drive displays with high pixel count without needing to use scarce microcontroller RAM.

During the technological investigations that have led to ctx I stumbled across a couple of somewhat related projects. A small OpenGL(ES) rendererer with similar API in nanovg as well as small3dlib which packs a performant software only OpenGL like implementation into less than a handful thousand lines of C.