Files
cocos4/cocos/core/pipeline/render-batched-queue.ts
T
pandamicro 95813e2a92 API translation for core/pipeline (#6753)
* API translation for core/pipeline

* Complete

* Improve
2020-06-18 23:05:55 +08:00

59 lines
1.8 KiB
TypeScript

/**
* @category pipeline
*/
import { GFXCommandBuffer } from '../gfx/command-buffer';
import { BatchedBuffer } from './batched-buffer';
/**
* @en The render queue for dynamic batching
* @zh 渲染合批队列。
*/
export class RenderBatchedQueue {
/**
* @en A set of dynamic batched buffer
* @zh 动态合批缓存集合。
*/
public queue = new Set<BatchedBuffer>();
/**
* @en Clear the render queue
* @zh 清空渲染队列。
*/
public clear () {
const it = this.queue.values(); let res = it.next();
while (!res.done) {
res.value.clear();
res = it.next();
}
this.queue.clear();
}
/**
* @en Record command buffer for the current queue
* @zh 记录命令缓冲。
* @param cmdBuff The command buffer to store the result
*/
public recordCommandBuffer (cmdBuff: GFXCommandBuffer) {
const it = this.queue.values(); let res = it.next();
while (!res.done) {
let boundPSO = false;
for (let b = 0; b < res.value.batches.length; ++b) {
const batch = res.value.batches[b];
if (!batch.mergeCount) { continue; }
for (let v = 0; v < batch.vbs.length; ++v) {
batch.vbs[v].update(batch.vbDatas[v]);
}
batch.vbIdx.update(batch.vbIdxData.buffer);
batch.ubo.update(batch.uboData.view);
if (!boundPSO) { cmdBuff.bindPipelineState(batch.pso); boundPSO = true; }
cmdBuff.bindBindingLayout(batch.pso.pipelineLayout.layouts[0]);
cmdBuff.bindInputAssembler(batch.ia);
cmdBuff.draw(batch.ia);
}
res = it.next();
}
}
}