Move texture management function in a separate file.