mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-07 03:52:41 +08:00
77186a5c5b
* lightmap instancing * fix planar shadow instancing
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
/**
|
|
* @category pipeline
|
|
*/
|
|
|
|
import { GFXCommandBuffer } from '../gfx/command-buffer';
|
|
import { InstancedBuffer } from './instanced-buffer';
|
|
|
|
/**
|
|
* @en Render queue for instanced batching
|
|
* @zh 渲染合批队列。
|
|
*/
|
|
export class RenderInstancedQueue {
|
|
|
|
/**
|
|
* @en A set of instanced buffer
|
|
* @zh Instance 合批缓存集合。
|
|
*/
|
|
public queue = new Set<InstancedBuffer>();
|
|
|
|
/**
|
|
* @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) {
|
|
const { instances } = res.value;
|
|
if (instances.length > 0) {
|
|
res.value.uploadBuffers();
|
|
for (let b = 0; b < instances.length; ++b) {
|
|
const instance = instances[b];
|
|
if (!instance.count) { continue; }
|
|
cmdBuff.bindPipelineState(instance.pso);
|
|
cmdBuff.bindBindingLayout(instance.pso.pipelineLayout.layouts[0]);
|
|
cmdBuff.bindInputAssembler(instance.ia);
|
|
cmdBuff.draw(instance.ia);
|
|
}
|
|
}
|
|
res = it.next();
|
|
}
|
|
}
|
|
}
|