Glasses are amorphous solids whose constituent particles are caged by their neighbours and thus cannot flow. This sluggishness is often ascribed to the free energy landscape containing multiple minima (basins) separated by high barriers. Here we show, using theory and numerical simulation, that the landscape is much rougher than is classically assumed. Deep in the glass, it undergoes a 'roughness transition' to fractal basins, which brings about isostaticity and marginal stability on approaching jamming. Critical exponents for the basin width, the weak force distribution and the spatial spread of quasi-contacts near jamming can be analytically determined. Their value is found to be compatible with numerical observations. This advance incorporates the jamming transition of granular materials into the framework of glass theory. Because temperature and pressure control what features of the landscape are experienced, glass mechanics and transport are expected to reflect the features of the topology we discuss here.