refactor to allow various gfx backends (work-in-progress)