I "color" my quads using 2 different ways, first is to supply the rgba color as a uniform:
// fragment shader
uniform sampler2D sampler2d;
uniform lowp vec4 color1;
varying mediump vec2 texCoordVar;
void main (void)
{
gl_FragColor = texture2D(sampler2d, texCoordVar) * color1;
}
Then, the quads are sorted according to color and then batched together, but if the color varies a lot then you end up with a lot of draw calls.
The other way is to use a vertex color attribute:
uniform highp mat4 matrixPVM;
attribute highp vec3 inVertex;
attribute lowp vec4 inColor;
attribute mediump vec2 texCoordAttr;
varying mediump vec2 texCoordVar;
varying lowp vec4 outColor;
void main(void)
{
gl_Position = matrixPVM * vec4(inVertex, 1.0);
texCoordVar = texCoordAttr.st;
outColor = inColor;
}
// fragement shader
uniform sampler2D sampler2d;
varying lowp vec4 outColor;
varying mediump vec2 texCoordVar;
void main (void)
{
gl_FragColor = texture2D(sampler2d, texCoordVar) * outColor;
}
This has much less draw call, but it's wastefull, because I only need a color attribute for each quad, not each vertex.
Maybe, there's a third way of doing this that I haven't thought of (but this is on OpenGL ES 2.0, so I can't use any fancy stuff).
Anyone have any suggestions?