diff --git a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts index 85ef3c0523..36fd97ad2d 100644 --- a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts @@ -154,25 +154,6 @@ export const graphicsAssembler: IAssembler = { }, end (graphics: Graphics) { - const impl = graphics.impl; - if (!impl) { - return; - } - - const renderDataList = impl.getRenderDataList(); - if (renderDataList.length <= 0 || !graphics.model) { - return; - } - - const subModelCount = graphics.model.subModels.length; - const listLength = renderDataList.length; - const delta = listLength - subModelCount; - if (delta > 0) { - for (let k = subModelCount; k < listLength; k++) { - graphics.activeSubModel(k); - } - } - graphics.markForUpdateRenderData(); }, diff --git a/cocos/2d/components/graphics.ts b/cocos/2d/components/graphics.ts index 6129181567..9433774463 100644 --- a/cocos/2d/components/graphics.ts +++ b/cocos/2d/components/graphics.ts @@ -630,9 +630,9 @@ export class Graphics extends UIRenderable { continue; } - ia.vertexBuffers[0].update(renderData.vData); + ia.vertexBuffers[0].update(renderData.vData, byteOffset >> 2); ia.vertexCount = renderData.vertexStart; - ia.indexBuffer!.update(renderData.iData); + ia.indexBuffer!.update(renderData.iData, renderData.indicesStart); ia.indexCount = renderData.indicesStart; renderData.lastFilledVertex = renderData.vertexStart; @@ -645,6 +645,15 @@ export class Graphics extends UIRenderable { protected _render (render: UI) { if (this._isNeedUploadData) { + if (this.impl) { + const renderDataList = this.impl.getRenderDataList(); + const len = this.model!.subModels.length; + if (renderDataList.length > len) { + for (let i = len; i < renderDataList.length; i++) { + this.activeSubModel(i); + } + } + } render.addUploadBuffersFunc(this, this._uploadData); } diff --git a/cocos/2d/renderer/ui.ts b/cocos/2d/renderer/ui.ts index 62c4b54e67..34c561aeb8 100644 --- a/cocos/2d/renderer/ui.ts +++ b/cocos/2d/renderer/ui.ts @@ -435,14 +435,16 @@ export class UI { const uiCanvas = this._currCanvas; if (!uiCanvas?.camera) { return; } - const curDrawBatch = this._drawBatchPool.alloc(); + const stamp = legacyCC.director.getTotalFrames(); if (model) { model.updateTransform(stamp); model.updateUBOs(stamp); } - const subModel = model!.subModels[0]; - if (subModel) { + + for (let i = 0; i < model!.subModels.length; i++) { + const curDrawBatch = this._drawBatchPool.alloc(); + const subModel = model!.subModels[i]; curDrawBatch.camera = uiCanvas && uiCanvas.camera; curDrawBatch.model = model; curDrawBatch.bufferBatch = null; @@ -453,18 +455,17 @@ export class UI { curDrawBatch.fillPasses(mat, depthStencil, null); curDrawBatch.hDescriptorSet = SubModelPool.get(subModel.handle, SubModelView.DESCRIPTOR_SET); curDrawBatch.hInputAssembler = SubModelPool.get(subModel.handle, SubModelView.INPUT_ASSEMBLER); - - // reset current render state to null - this._currMaterial = this._emptyMaterial; - this._currComponent = null; - this._currTransform = null; - this._currTexture = null; - this._currSampler = null; - this._currTextureHash = 0; - this._currSamplerHash = 0; - this._batches.push(curDrawBatch); } + + // reset current render state to null + this._currMaterial = this._emptyMaterial; + this._currComponent = null; + this._currTransform = null; + this._currTexture = null; + this._currSampler = null; + this._currTextureHash = 0; + this._currSamplerHash = 0; } /**