Skip to content

Commit 6851425

Browse files
authored
added improved texture compression, refactored texturecoord flow (#688)
2 parents cb202a0 + 0ad3817 commit 6851425

File tree

8 files changed

+585
-178
lines changed

8 files changed

+585
-178
lines changed

src/core/CoreNode.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ export class CoreNode extends EventEmitter {
728728
valid: false,
729729
};
730730
public textureCoords?: TextureCoords;
731-
public updateTextureCoords: boolean = false;
732731
public updateShaderUniforms: boolean = false;
733732
public isRenderable = false;
734733
public renderState: CoreNodeRenderState = CoreNodeRenderState.Init;
@@ -901,6 +900,13 @@ export class CoreNode extends EventEmitter {
901900
} satisfies NodeTextureLoadedPayload);
902901
}
903902

903+
if (
904+
this.stage.calculateTextureCoord === true &&
905+
this.props.textureOptions !== null
906+
) {
907+
this.textureCoords = this.stage.renderer.getTextureCoords!(this);
908+
}
909+
904910
// Trigger a local update if the texture is loaded and the resizeMode is 'contain'
905911
if (this.props.textureOptions?.resizeMode?.type === 'contain') {
906912
this.setUpdateType(UpdateType.Local);
@@ -1261,11 +1267,6 @@ export class CoreNode extends EventEmitter {
12611267
this.sortChildren();
12621268
}
12631269

1264-
if (this.updateTextureCoords === true) {
1265-
this.updateTextureCoords = false;
1266-
this.textureCoords = this.stage.renderer.getTextureCoords!(this);
1267-
}
1268-
12691270
// If we're out of bounds, apply the render state now
12701271
// this is done so nodes can finish their entire update loop before
12711272
// being marked as out of bounds
@@ -1497,14 +1498,6 @@ export class CoreNode extends EventEmitter {
14971498
isRenderable,
14981499
} satisfies NodeRenderablePayload);
14991500
}
1500-
1501-
if (
1502-
isRenderable === true &&
1503-
this.stage.calculateTextureCoord === true &&
1504-
this.textureCoords === undefined
1505-
) {
1506-
this.updateTextureCoords = true;
1507-
}
15081501
}
15091502

15101503
/**
@@ -1704,6 +1697,8 @@ export class CoreNode extends EventEmitter {
17041697
const t = this.globalTransform!;
17051698
const coords = this.renderCoords;
17061699
const texture = p.texture || this.stage.defaultTexture;
1700+
const textureCoords =
1701+
this.textureCoords || this.stage.renderer.defaultTextureCoords;
17071702

17081703
// There is a race condition where the texture can be null
17091704
// with RTT nodes. Adding this defensively to avoid errors.
@@ -1720,7 +1715,7 @@ export class CoreNode extends EventEmitter {
17201715
colorBr: this.premultipliedColorBr,
17211716
texture,
17221717
textureOptions: p.textureOptions,
1723-
textureCoords: this.textureCoords,
1718+
textureCoords: textureCoords,
17241719
shader: p.shader as CoreShaderNode<any>,
17251720
alpha: this.worldAlpha,
17261721
clippingRect: this.clippingRect,
@@ -1797,7 +1792,6 @@ export class CoreNode extends EventEmitter {
17971792

17981793
set w(value: number) {
17991794
if (this.props.w !== value) {
1800-
this.updateTextureCoords = true;
18011795
this.props.w = value;
18021796
this.setUpdateType(UpdateType.Local);
18031797

@@ -1819,7 +1813,6 @@ export class CoreNode extends EventEmitter {
18191813

18201814
set h(value: number) {
18211815
if (this.props.h !== value) {
1822-
this.updateTextureCoords = true;
18231816
this.props.h = value;
18241817
this.setUpdateType(UpdateType.Local);
18251818

@@ -2430,6 +2423,9 @@ export class CoreNode extends EventEmitter {
24302423

24312424
set textureOptions(value: TextureOptions) {
24322425
this.props.textureOptions = value;
2426+
if (this.stage.calculateTextureCoord === true && value !== null) {
2427+
this.textureCoords = this.stage.renderer.getTextureCoords!(this);
2428+
}
24332429
}
24342430

24352431
get textureOptions(): TextureOptions {

src/core/lib/WebGlContextWrapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class WebGlContextWrapper {
7373
public readonly TEXTURE_WRAP_S;
7474
public readonly TEXTURE_WRAP_T;
7575
public readonly LINEAR;
76+
public readonly LINEAR_MIPMAP_LINEAR;
7677
public readonly CLAMP_TO_EDGE;
7778
public readonly RGB;
7879
public readonly RGBA;
@@ -164,6 +165,7 @@ export class WebGlContextWrapper {
164165
this.TEXTURE_WRAP_S = gl.TEXTURE_WRAP_S;
165166
this.TEXTURE_WRAP_T = gl.TEXTURE_WRAP_T;
166167
this.LINEAR = gl.LINEAR;
168+
this.LINEAR_MIPMAP_LINEAR = gl.LINEAR_MIPMAP_LINEAR;
167169
this.CLAMP_TO_EDGE = gl.CLAMP_TO_EDGE;
168170
this.RGB = gl.RGB;
169171
this.RGBA = gl.RGBA;

0 commit comments

Comments
 (0)