The processes involved in the formation of gametes. Gametes are normally formed by meiosis but sometimes by mitosis (as in the gametophyte generation of the ferns). In mammals gametogenesis in the female is known as oogenesis and occurs in the ovaries; in the male it is known as spermatogenesis and occurs in the testes.