Ported texture load function to Swift