It turns out you only have to identify yourself if you are under arrest, not merely detained. That’s surprising. If you want to read the statute, turn to Penal Code 38.02.