Currently I'm trying to render a TileMap using OpenGL 2.1, GLSL 1.2. I would like to draw every tile in just one draw call. I use a single texture with all tiles, identifying each one by an index.
The vertex data per tile is:
vec2 worldPos; // the position to transform the tile Quad in world coordinates vec2 texCoord; // the uv coordinates, calculated using the tile index, by CPU (top-left corner).
But I can't find a way to draw everything with one draw call: - The uv coordinates can't be calculated in shader because the vertex shader don't know which corner of the quad it is processing. - Can't draw by element because my quad vertex data only contains 4 vertices, store repeated vertices is a memory waste. Only if I could use a separate element buffer just for the vertex (0, 1, 2, 3, 0, 1, ...).
Does someone have any suggestion about how should I proceed? Thanks!