gfx 各個類的原始碼解讀(6) WebGL2CommandBuffer
阿新 • • 發佈:2022-04-08
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; }