Fix some depth-buffer related bugs