Can't you use the "Painter's Algorithm"? Or maybe I don't know what the problem is