Why did Robert McNamara become a critic of American intervention in Vietnam?

Robert McNamara served as secretary of defense from 1961-1968. Throughout his time in office Robert McNamara was a die-hard defender of the Vietnam War. McNamara was so vocal in his support that some people began calling Vietnam McNamaras War. After he left office Robert McNamara became a critic of America's intervention in Vietnam. Why did Robert McNamaras opinion about Vietnam change?