Factor out the texture copy code.