Hi guys,
Yes I know that we are going to support automatic batching to "Reduce" the number of draw calls
but there is a way to make the number of draw calls to 1. yes 1, how?
While ago we were investigating the possibility of inserting a sprite into a batch node sprites, so that it renders in-between the batch node sprites.
this was not possible, because its 2 different draw calls.
and this was limited by a draw call must bind a single texture.
What we found is that we could bind multiple texture into a single draw call.
By using multi texture in a single draw, we could potentially bind all texture to a single call, thus everything can be drawn in 1 batch
here is the shader (all credit to Dingping (David) lv)
precision lowp float;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
varying float v_texIndex;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
uniform sampler2D CC_Texture4;
uniform sampler2D CC_Texture5;
uniform sampler2D CC_Texture6;
uniform sampler2D CC_Texture7;
void main()
{
gl_FragColor = v_fragmentColor * texture2D(CC_Texture[texIndex], v_texCoord);}
};
OpenGL specification states that multi texture supports at least 8 textures.
We have not tried this approach on C++ and real devices yet, we have only tried it in webGL.
It works but the only caveat is that in webGL, you cannot use array index like CC_Texture[texIndex], you must use if else which slows it down a little.
I theory, this should work fine on c++, real device, and should really speed up drawing process by a lot, it also simplifies your render queue sorting process
Carlo could you investigate this further? and what do you guys think?
Regards
Hao