Merge upstream revisions 12629-12701. Also undo my loadtexture change and implement upstream changes. They seem to have fixed the problem in a more correct manner.