Child custody and visitation in Texas is governed by the "best interest" of the child. The Texas Family Code says "the best interest of the child shall always be the primary consideration of the court in determining issues of conservatorship and possession of and access to the child."
The Family Code sets the bar at "best interest" but does not tell you how to determine whether that bar is met or not. The decisions of Texas' appellate courts have ennumerated factors to consider in determing "best interest" in child custody and visitation cases. "Best Interest" is like beauty. It lies in the eye of the beholder, i.e. the finder of fact whether a jury or a judge. If a judge makes the decision, then the judge is bound only by his judicial discretion.
One1976 Texas Supreme Court case, Holley v. Adams, listed 14 non-exclusive factors which courts use to determine the best interests of the child. That list is too long to list here, but google the case if you wish. Its legal citation is 544 SW2d 367 (Tex.1976). The case will help you understand what is relevant and what is not in child custody and visitation.
There are factors the courts won't pay much attention to: infidelity, marital status of a parent; gender, racial issues, religion. In other words, it's pretty much a judgement call using common sense.