st/mesa: consolidate and clean-up texture memory allocation code