From ddeba2863cd84d1195b0840669e9db059b48caa6 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Thu, 8 Dec 2022 15:45:11 +0800 Subject: [PATCH] Update UIMeshRender model pre frame (#13738) --- cocos/2d/components/ui-mesh-renderer.ts | 20 ++++++++------------ cocos/2d/renderer/native-2d.ts | 1 + native/cocos/2d/renderer/UIModelProxy.cpp | 6 ++++++ native/cocos/2d/renderer/UIModelProxy.h | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cocos/2d/components/ui-mesh-renderer.ts b/cocos/2d/components/ui-mesh-renderer.ts index d723cf7627..bc68485378 100644 --- a/cocos/2d/components/ui-mesh-renderer.ts +++ b/cocos/2d/components/ui-mesh-renderer.ts @@ -70,8 +70,7 @@ export class UIMeshRenderer extends Component { //nativeObj private declare _UIModelNativeProxy: NativeUIModelProxy; - protected declare _renderEntity : RenderEntity; - private modelCount = 0; + protected declare _renderEntity: RenderEntity; public _dirtyVersion = -1; public _internalId = -1; @@ -156,13 +155,13 @@ export class UIMeshRenderer extends Component { const models = this._modelComponent._collectModels(); // @ts-expect-error: UIMeshRenderer do not attachToScene this._modelComponent._detachFromScene(); // JSB - if (models.length !== this.modelCount) { - for (let i = this.modelCount; i < models.length; i++) { - this._uploadRenderData(i); - this._UIModelNativeProxy.updateModels(models[i]); - } + // clear models + this._UIModelNativeProxy.clearModels(); + this._renderEntity.clearDynamicRenderDrawInfos(); + for (let i = 0; i < models.length; i++) { + this._uploadRenderData(i); + this._UIModelNativeProxy.updateModels(models[i]); } - this.modelCount = models.length; this._UIModelNativeProxy.attachDrawInfo(); } } @@ -193,10 +192,7 @@ export class UIMeshRenderer extends Component { public update () { if (JSB) { if (this._modelComponent) { - const models = this._modelComponent._collectModels(); - if (models.length !== this.modelCount) { - this.markForUpdateRenderData(); - } + this.markForUpdateRenderData(); } } this._fitUIRenderQueue(); diff --git a/cocos/2d/renderer/native-2d.ts b/cocos/2d/renderer/native-2d.ts index 4e843f70e1..abf1e47d1d 100644 --- a/cocos/2d/renderer/native-2d.ts +++ b/cocos/2d/renderer/native-2d.ts @@ -99,6 +99,7 @@ export declare class NativeUIModelProxy { updateModels(model); attachDrawInfo(); attachNode(node); + clearModels(); } export declare class NativeStencilManager { diff --git a/native/cocos/2d/renderer/UIModelProxy.cpp b/native/cocos/2d/renderer/UIModelProxy.cpp index 8c77bdabc7..da5ed53838 100644 --- a/native/cocos/2d/renderer/UIModelProxy.cpp +++ b/native/cocos/2d/renderer/UIModelProxy.cpp @@ -125,6 +125,8 @@ void UIModelProxy::destroy() { subMesh = nullptr; } _graphicsUseSubMeshes.clear(); + + _models.clear(); } void UIModelProxy::clear() { @@ -148,4 +150,8 @@ void UIModelProxy::attachNode(Node* node) { _node = node; } +void UIModelProxy::clearModels() { + _models.clear(); +} + } // namespace cc diff --git a/native/cocos/2d/renderer/UIModelProxy.h b/native/cocos/2d/renderer/UIModelProxy.h index d2f872f5e0..e19393b868 100644 --- a/native/cocos/2d/renderer/UIModelProxy.h +++ b/native/cocos/2d/renderer/UIModelProxy.h @@ -44,16 +44,17 @@ public: void updateModels(scene::Model* models); void attachDrawInfo(); void attachNode(Node* node); + void clearModels(); protected: CC_DISALLOW_COPY_MOVE_ASSIGN(UIModelProxy); private: Node* _node{nullptr}; - ccstd::vector _models{}; + IntrusivePtr _model; ccstd::vector> _graphicsUseSubMeshes{}; // For UIModel - IntrusivePtr _model; + ccstd::vector _models{}; gfx::Device* _device{nullptr}; uint32_t _stride{32};