So, some improvements:
- The proposed SDK has changed to do linear typed arrays.
- The webGPU implementation does pass color, instead of changing a uniform, so it does not break the batch on color change. I think it uses a single value for all vertices and is passed as a colorData buffer with all four values the same, it is then used directly in the fragment shader to multiply the final color output. In the original description for the webGPU, Ashley mentioned that this implementation will not break the batch.
- As you saw, this is not the case in webgl renderer (though I think it could be and have a vague memory that it was similar to the final webGPU implementation at some point, but I haven't verified that and Ashley doesn't remember it.)
Yeah, I realized afterwards typed arrays are probably faster and also would be faster with built-in mesh rendering in future, as it could potentially just copy them directly to the GPU. So I've changed it to work with typed arrays like this:
const posArr = new Float32Array([
quad.p1.x + 50, quad.p1.y, 0,
quad.p2.x + 50, quad.p2.y, 0,
quad.p3.x, quad.p3.y, 0,
quad.p4.x, quad.p4.y, 0,
quad.p1.x + 250, quad.p1.y, 0,
quad.p2.x + 250, quad.p2.y, 0,
quad.p3.x + 200, quad.p3.y, 0,
quad.p4.x + 200, quad.p4.y, 0
]);
const uvArr = new Float32Array([
rcTex.left, rcTex.top,
rcTex.right, rcTex.top,
rcTex.right, rcTex.bottom,
rcTex.left, rcTex.bottom,
rcTex.left, rcTex.top,
rcTex.right, rcTex.top,
rcTex.right, rcTex.bottom,
rcTex.left, rcTex.bottom
]);
const indexArr = new Uint16Array([
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
]);
renderer.drawMesh(posArr, uvArr, indexArr);