Skip to content
16 changes: 16 additions & 0 deletions cocos/2d/framework/ui-renderer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ export class UIRendererManager {
private _allRenderers: (UIRenderer | UIMeshRenderer)[] = [];
private _dirtyRenderers: (UIRenderer | UIMeshRenderer)[] = [];
private _dirtyVersion = 0;
private _dirty = false;

/**
* @engineInternal
*/
get dirty (): boolean {
return this._dirty;
}
/**
* @engineInternal
*/
set dirty (value: boolean) {
this._dirty = value;
}

public addRenderer (uiRenderer: UIRenderer | UIMeshRenderer): void {
if (uiRenderer._internalId === -1) {
uiRenderer._internalId = this._allRenderers.length;
Expand All @@ -57,6 +72,7 @@ export class UIRendererManager {

public markDirtyRenderer (uiRenderer: UIRenderer | UIMeshRenderer): void {
if (uiRenderer._dirtyVersion !== this._dirtyVersion && uiRenderer._internalId !== -1) {
this._dirty = true;
this._dirtyRenderers.push(uiRenderer);
uiRenderer._dirtyVersion = this._dirtyVersion;
}
Expand Down
3 changes: 3 additions & 0 deletions cocos/2d/framework/ui-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export class UIRenderer extends Renderer {
this.node.on(NodeEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
this.node.on(NodeEventType.SIZE_CHANGED, this._nodeStateChange, this);
this.node.on(NodeEventType.PARENT_CHANGED, this._colorDirty, this);
this.node.on(NodeEventType.NODE_DIRTY, this._nodeStateChange, this);
// If the renderData is invalid, it needs to be rebuilt to recalculate the batch processing.
if (!this._renderData && this._flushAssembler) {
this._flushAssembler();
Expand Down Expand Up @@ -398,6 +399,7 @@ export class UIRenderer extends Renderer {
this.node.off(NodeEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
this.node.off(NodeEventType.SIZE_CHANGED, this._nodeStateChange, this);
this.node.off(NodeEventType.PARENT_CHANGED, this._colorDirty, this);
this.node.off(NodeEventType.NODE_DIRTY, this._nodeStateChange, this);
// When disabling, it is necessary to free up idle space to fully utilize chunks
// and avoid breaking batch processing.
this._destroyData();
Expand Down Expand Up @@ -564,6 +566,7 @@ export class UIRenderer extends Renderer {
}
}
}
uiRendererManager.dirty = true;
}

private setEntityColorDirty (dirty: boolean): void {
Expand Down
4 changes: 4 additions & 0 deletions cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { RenderingSubMesh } from '../../asset/assets';
import { IAssembler } from './base';
import { RenderEntityFillColorType } from './render-entity';
import type { Director } from '../../game/director';
import { uiRendererManager } from '../framework/ui-renderer-manager';

let sorting2DCount = 0;

Expand Down Expand Up @@ -202,6 +203,7 @@ export class Batcher2D implements IBatcher {
if (this._maskClearMtl) {
this._maskClearMtl.destroy();
}
uiRendererManager.dirty = true;
}

private syncRootNodesToNative (): void {
Expand Down Expand Up @@ -230,6 +232,7 @@ export class Batcher2D implements IBatcher {
if (JSB) {
this.syncRootNodesToNative();
}
uiRendererManager.dirty = true;
}

/**
Expand All @@ -248,6 +251,7 @@ export class Batcher2D implements IBatcher {
if (JSB) {
this.syncRootNodesToNative();
}
uiRendererManager.dirty = true;
}

public sortScreens (): void {
Expand Down
8 changes: 5 additions & 3 deletions cocos/2d/renderer/mesh-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { JSB } from 'internal:constants';
import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo } from '../../gfx';
import { getAttributeStride } from './vertex-format';
import { sys, getError, warnID, assertIsTrue } from '../../core';
import { sys, getError, warnID, assertIsTrue, cclegacy } from '../../core';
import { NativeUIMeshBuffer } from './native-2d';

interface IIARef {
Expand Down Expand Up @@ -420,15 +420,17 @@ export class MeshBuffer {
if (sys.__isWebIOS14OrIPadOS14Env || !this._iaPool[0]) {
const vbStride = this._vertexFormatBytes = this._floatsPerVertex * Float32Array.BYTES_PER_ELEMENT;
const ibStride = Uint16Array.BYTES_PER_ELEMENT;
const enabledDeviceMem = (cclegacy.rendering && cclegacy.rendering.enableEffectImport)
? MemoryUsageBit.DEVICE : MemoryUsageBit.HOST | MemoryUsageBit.DEVICE;
const vertexBuffer = device.createBuffer(new BufferInfo(
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
enabledDeviceMem,
vbStride,
vbStride,
));
indexBuffer = device.createBuffer(new BufferInfo(
BufferUsageBit.INDEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
enabledDeviceMem,
ibStride,
ibStride,
));
Expand Down
4 changes: 2 additions & 2 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class Director extends EventTarget {

if (!EDITOR) {
if (isValid(this._scene)) {
this._scene!.destroy();
this._scene.destroy();
}
this._scene = null;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ export class Director extends EventTarget {
console.time('Destroy');
}
if (isValid(oldScene)) {
oldScene!.destroy();
oldScene.destroy();
}
if (!EDITOR) {
// auto release assets
Expand Down
3 changes: 3 additions & 0 deletions cocos/gfx/base/descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export abstract class DescriptorSet extends GFXObject {
/** @mangle */
protected _isDirty = false;

get gpuDescriptorSet (): any {
return {};
}
constructor () {
super(ObjectType.DESCRIPTOR_SET);
}
Expand Down
1 change: 0 additions & 1 deletion cocos/gfx/base/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { Swapchain } from './swapchain';
* @zh GFX 设备。
*/
export abstract class Device {

constructor () {}

/**
Expand Down
1 change: 0 additions & 1 deletion cocos/gfx/webgl/webgl-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,6 @@ export function WebGLCmdFuncBindStates (
gpuTexture.glMagFilter = gpuSampler.glMagFilter;
}
}

gpuDescriptor = gpuDescriptorSet.gpuDescriptors[++descriptorIndex];
}
}
Expand Down
4 changes: 4 additions & 0 deletions cocos/misc/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class Renderer extends Component {
if (this._materials.length === 1 && !this._materialInstances[0] && this._materials[0] === val) {
return;
}
this.node.dirty();
this.setMaterialInstance(val, 0);
}

Expand All @@ -131,6 +132,7 @@ export class Renderer extends Component {
// they could be either undefined or null
// eslint-disable-next-line eqeqeq
if (this._materialInstances[i] != val[i]) {
this.node.dirty();
this.setMaterialInstance(val[i], i);
}
}
Expand Down Expand Up @@ -185,6 +187,7 @@ export class Renderer extends Component {
inst.destroy();
this._materialInstances[index] = null;
}
this.node.dirty();
this._onMaterialModified(index, this._materials[index]);
}

Expand Down Expand Up @@ -229,6 +232,7 @@ export class Renderer extends Component {
if (matInst && matInst.parent) {
if (matInst !== curInst) {
this._materialInstances[index] = matInst as MaterialInstance;
this.node.dirty();
this._onMaterialModified(index, matInst);
}
return;
Expand Down
Loading