Updated generateMipmaps implementation