Skip to content

Commit fc3c1da

Browse files
authored
fix: Fix RTT Clipping and improve RTT parent lookup (#453)
Fixes #452 Fixes #443
2 parents 71b04d4 + d50c499 commit fc3c1da

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

examples/tests/rtt-dimension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default async function test({ renderer, testRoot }: ExampleSettings) {
2929
height: 300,
3030
parent: node,
3131
rtt: true,
32+
clipping: true,
3233
zIndex: 5,
3334
colorTop: 0xfff00fff,
3435
colorBottom: 0x00ffffff,
@@ -262,6 +263,7 @@ export default async function test({ renderer, testRoot }: ExampleSettings) {
262263
switch (i) {
263264
case 1:
264265
rttNode.rtt = false;
266+
rttNode.clipping = false;
265267
rttNode2.rtt = false;
266268
rttNode3.rtt = false;
267269
break;
@@ -288,6 +290,7 @@ export default async function test({ renderer, testRoot }: ExampleSettings) {
288290
default:
289291
// Reset to initial state
290292
rttNode.rtt = true;
293+
rttNode.clipping = true;
291294
rttNode2.rtt = true;
292295
rttNode3.rtt = true;
293296
nestedRTTNode1.rtt = true;

src/core/CoreNode.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ export class CoreNode extends EventEmitter {
742742
public calcZIndex = 0;
743743
public hasRTTupdates = false;
744744
public parentHasRenderTexture = false;
745+
public rttParent: CoreNode | null = null;
745746

746747
constructor(readonly stage: Stage, props: CoreNodeProps) {
747748
super();
@@ -1134,7 +1135,18 @@ export class CoreNode extends EventEmitter {
11341135
continue;
11351136
}
11361137

1137-
child.update(delta, this.clippingRect);
1138+
let childClippingRect = this.clippingRect;
1139+
if (this.rtt === true) {
1140+
childClippingRect = {
1141+
x: 0,
1142+
y: 0,
1143+
width: 0,
1144+
height: 0,
1145+
valid: false,
1146+
};
1147+
}
1148+
1149+
child.update(delta, childClippingRect);
11381150
}
11391151
}
11401152

@@ -1165,17 +1177,20 @@ export class CoreNode extends EventEmitter {
11651177
this.childUpdateType = 0;
11661178
}
11671179

1168-
private notifyParentRTTOfUpdate() {
1169-
if (this.parent === null) {
1170-
return;
1171-
}
1172-
1180+
private findParentRTTNode(): CoreNode | null {
11731181
let rttNode: CoreNode | null = this.parent;
1174-
// Traverse up to find the RTT root node
11751182
while (rttNode && !rttNode.rtt) {
11761183
rttNode = rttNode.parent;
11771184
}
1185+
return rttNode;
1186+
}
1187+
1188+
private notifyParentRTTOfUpdate() {
1189+
if (this.parent === null) {
1190+
return;
1191+
}
11781192

1193+
const rttNode = this.rttParent || this.findParentRTTNode();
11791194
if (!rttNode) {
11801195
return;
11811196
}
@@ -1266,6 +1281,11 @@ export class CoreNode extends EventEmitter {
12661281
return CoreNodeRenderState.InViewport;
12671282
}
12681283

1284+
// if we are part of a parent render texture, we're always in bounds
1285+
if (this.parentHasRenderTexture === true) {
1286+
return CoreNodeRenderState.InBounds;
1287+
}
1288+
12691289
// check if we dont have dimensions, take our parent's render state
12701290
if (
12711291
this.parent !== null &&
@@ -1991,7 +2011,7 @@ export class CoreNode extends EventEmitter {
19912011
}
19922012
this.props.rtt = value;
19932013

1994-
if (value) {
2014+
if (value === true) {
19952015
this.initRenderTexture();
19962016
this.markChildrenWithRTT();
19972017
} else {
@@ -2000,7 +2020,7 @@ export class CoreNode extends EventEmitter {
20002020

20012021
this.setUpdateType(UpdateType.RenderTexture);
20022022

2003-
if (this.parentHasRenderTexture) {
2023+
if (this.parentHasRenderTexture === true) {
20042024
this.notifyParentRTTOfUpdate();
20052025
}
20062026
}
@@ -2054,6 +2074,7 @@ export class CoreNode extends EventEmitter {
20542074
for (const child of this.children) {
20552075
// force child to update everything as the RTT inheritance has changed
20562076
child.parentHasRenderTexture = false;
2077+
child.rttParent = null;
20572078
child.setUpdateType(UpdateType.All);
20582079
child.clearRTTInheritance();
20592080
}

0 commit comments

Comments
 (0)