Work on Vega rendering.

Some nasty stuff in this commit that needs to be reorganised.