refactor gl temporary buffer code