gfx 各个类的源码解读(6) WebGL2CommandBuffer
gfx 各个类的源码解读(6) WebGL2CommandBuffer
WebGL2CommandBuffer 在 webgl2-command-buffer.ts
对WebGL2CmdPackage类命令填充和状态保存,
WebGL2CommandAllocator 负责cmd的alloc,
上面两个类实例在成员变量里,不是全局的
成员变量:
protected _cmdAllocator: WebGL2CommandAllocator = new WebGL2CommandAllocator();
protected _cmdAllocator: WebGL2CommandAllocator = new WebGL2CommandAllocator();
状态保存成员变量(后面用到会详细解读)
protected _curGPUPipelineState: IWebGL2GPUPipelineState | null = null;
protected _curGPUDescriptorSets: IWebGL2GPUDescriptorSet[] = [];
protected _curGPUInputAssembler: IWebGL2GPUInputAssembler | null = null;
protected _curDynamicOffsets: number[] = Array(8).fill(0);
protected _curDynamicStates: DynamicStates = new DynamicStates();
protected _isStateInvalied = false;
比如对WebGL2CmdBeginRenderPass命令的填充
public beginRenderPass (
renderPass: RenderPass,
framebuffer: Framebuffer,
renderArea: Rect,
clearColors: Color[],
clearDepth: number,
clearStencil: number,
) {
//pool alloc cmd
const cmd = this._cmdAllocator.beginRenderPassCmdPool.alloc(WebGL2CmdBeginRenderPass);
cmd.gpuRenderPass = (renderPass as WebGL2RenderPass).gpuRenderPass;
cmd.gpuFramebuffer = (framebuffer as WebGL2Framebuffer).gpuFramebuffer;
cmd.renderArea = renderArea;
for (let i = 0; i < clearColors.length; ++i) {
cmd.clearColors[i] = clearColors[i];
}
cmd.clearDepth = clearDepth;
cmd.clearStencil = clearStencil;
//cmdPackage装入cmd
this.cmdPackage装入cmd.beginRenderPassCmds.push(cmd);
this.cmdPackage.cmds.push(WebGL2Cmd.BEGIN_RENDER_PASS);
this._isInRenderPass = true;
}