'Wine glass', 'horse race' and 'race horse' are all examples of compound nouns.
When you have a compound noun made up of two words, the second word tells you what the object actually is - for example, a 'wine glass' is a kind of glass. The first word (wine) tells you what kind of glass it is. It's a glass which you drink wine out of.
Likewise, a 'race horse' is a type of horse. The first word (race) gives you more information about what type of horse it is.
By contrast, a 'horse race' is a sort of race. The first word (horse) specifies the sort of race that it is.
Here's a little exercise for you: Using the rule above, what would you call a glass you drink whisky out of, a horse that works on a farm, and a race involving bikes?
So, what's a 'glass of wine'? It's a glass containing wine. And what's the difference between a 'wine glass' and a 'glass of wine'? Simply, the first is empty and the second is full.