The Formation of Globular Clusters In A Cosmological Context