-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
render-shadowMap-batched-queue.ts
74 lines (67 loc) · 2.76 KB
/
render-shadowMap-batched-queue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @category pipeline
*/
import { GFXCommandBuffer } from '../gfx/command-buffer';
import { Pass } from '../renderer';
import { SubModel } from '../renderer/scene/submodel';
import { IRenderObject, SetIndex } from './define';
import { GFXDevice, GFXRenderPass, GFXBuffer, GFXShader } from '../gfx';
import { getPhaseID } from './pass-phase';
import { PipelineStateManager } from './pipeline-state-manager';
import { DSPool, ShaderPool, PassHandle, PassPool, PassView, SubModelPool, SubModelView, ShaderHandle } from '../renderer/core/memory-pools';
/**
* @zh
* 阴影渲染队列
*/
export class RenderShadowMapBatchedQueue {
private _subModelsArray: SubModel[] = [];
private _passArray: PassHandle[] = [];
private _shaderArray: GFXShader[] = [];
private _shadowMapBuffer: GFXBuffer | null = null;
private _phaseID = getPhaseID('shadow-add');
/**
* @zh
* clear ligth-Batched-Queue
*/
public clear (shadowMapBuffer: GFXBuffer) {
this._subModelsArray.length = 0;
this._shaderArray.length = 0;
this._passArray.length = 0;
this._shadowMapBuffer = shadowMapBuffer;
}
public add (renderObj: IRenderObject, subModelIdx: number, passIdx: number) {
const subModel = renderObj.model.subModels[subModelIdx];
const pass = subModel.passes[passIdx];
if (pass.phase === this._phaseID) {
if (this._shadowMapBuffer) {
const shader = ShaderPool.get(SubModelPool.get(subModel.handle, SubModelView.SHADER_0 + passIdx) as ShaderHandle);
this._subModelsArray.push(subModel);
this._shaderArray.push(shader);
this._passArray.push(pass.handle);
} else {
this._subModelsArray.length = 0;
this._shaderArray.length = 0;
this._passArray.length = 0;
}
}
}
/**
* @zh
* record CommandBuffer
*/
public recordCommandBuffer (device: GFXDevice, renderPass: GFXRenderPass, cmdBuff: GFXCommandBuffer) {
for (let i = 0; i < this._subModelsArray.length; ++i) {
const subModel = this._subModelsArray[i];
const shader = this._shaderArray[i];
const hPass = this._passArray[i];
const ia = subModel.inputAssembler!;
const pso = PipelineStateManager.getOrCreatePipelineState(device, hPass, shader, renderPass, ia);
const descriptorSet = DSPool.get(PassPool.get(hPass, PassView.DESCRIPTOR_SET));
cmdBuff.bindPipelineState(pso);
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, descriptorSet);
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, subModel.descriptorSet);
cmdBuff.bindInputAssembler(ia);
cmdBuff.draw(ia);
}
}
}