As you know, the Genitive case has lots of uses in Russian.
One of them expresses an amount of something:
With mass nouns it is also used to express "some" unspecified amount of that stuff when used instead of the Accusative:
Note that this usage is only characteristic for situations when you ask or hypothesize about using "some or other amount" of a substance. You cannot actually say that you are drinking "воды" right now—but you can say that you want some (or that you sipped some in the past—with a perfective¹, of course).
«Чай» has an alternative Partitive form «чаю»:
It is optional. Actually, many short masculine nouns that denote substances used to have such form. However, «чай» is, probably, the only one where the form is immensely popular in spoken speech and does not sound old-fashioned or downright archaic.
Russian differentiates between a number of drinking vessels. Стака́н is what you call a "glass" in English: typically, a cylindrical vessel made of glass, with no handle. However, if you mean a measurement unit (quite popular in cooking), it corresponds to the English word "cup". In Russian you use not a cup or rice or flour but a "glass" of rice or flower.