You can use instancing and a texture atlas to combine all the draw calls into a single one.
You only have a single 4 vertex VBO with the 4 corners 0,0 0,1 1,1 1,0
and an index buffer to draw them using GL_TRIANGLES
.
Then in a separate VBO you have the position and size of the quad (in a single vec4) and the position and size of the texture to use in the atlas (again as a vec4).
in vec2 coords;
in vec4 location;//x and y is the relative offset and z and w is the scaling factor
in vec4 textureLoc;
out vec2 texCoord;//0-1 as you would without the atlas
main(){
gl_Position = coords.xy*location.zw + location.xy;
texCoord = coords.xy*textureLoc.zw + textureLoc.xy;
}
Then during the rendering you fill the second VBO with position, size, texturePosition, textureSize
, set the attribute pointer as if they where one for each vertex and set the attribute Divisor to 1; draw with
void glDrawElementsInstanced(GL_TRIANGLES, 6, GL_Int, 0, numberQuads);