Reapply https://github.com/libgdx/libgdx/commit/6f4728fa87c9862a66d3f93657091c8b0b51e616