在渲染的ui-phase阶段,如下
public render (camera: Camera, renderPass: RenderPass) { const pipeline = this._pipeline; const device = pipeline.device; const cmdBuff = pipeline.commandBuffers[0]; const scene = camera.scene!; const batches = scene.batches; for (let i = 0; i < batches.length; i++) { const batch = batches[i]; 。。。 const count = batch.shaders.length; for (let j = 0; j < count; j++) { const pass = batch.passes[j]; if (pass.phase !== this._phaseID) continue; const shader = batch.shaders[j]; const inputAssembler = batch.inputAssembler!; const pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader, renderPass, inputAssembler); 。。。 cmdBuff.draw(inputAssembler); } } }
这里面的cmdBuff.draw就是一个drawcall;而scene.batches是在batcher2d的autoMergeBatches里面添加的,关键代码如下
const curDrawBatch = this._currStaticRoot ? this._currStaticRoot._requireDrawBatch() :this._drawBatchPool.alloc(); curDrawBatch.visFlags = this._currLayer; curDrawBatch.texture = this._currTexture!; curDrawBatch.sampler = this._currSampler; curDrawBatch.inputAssembler = ia; curDrawBatch.useLocalData = this._currTransform; curDrawBatch.textureHash = this._currTextureHash; curDrawBatch.samplerHash = this._currSamplerHash; curDrawBatch.fillPasses(mat, depthStencil, dssHash, null); this._batches.push(curDrawBatch);
串联起来看并没有减少drawcall不是吗?比如以两个连续节点都是sprite为例,按上面代码依旧产生2个DrawBatch,dc不还是2吗? 不知道哪个地方理解有误,感谢大佬指点!