mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
activate model before drawing to avoid the user from filling the data without the node being activated (#8053)
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+14
-13
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user