Skip to content

Commit e53d9ad

Browse files
authored
Texture max size - Some devices enforce a max texture size of 4096 (#16670)
See - https://forum.babylonjs.com/t/problem-with-adapttodeviceratio-and-adaptivescaling/57373/11?u=raananw Android devices (tested on 2 different samsung devices) enfore a max texture size fot the ADT. It is set at 4096. This sets the max render scale at the ratio that gets us to 4096 (or, if it doesn[t get to 4096, the hardware scaling level)
1 parent 82dd24e commit e53d9ad

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/dev/gui/src/2D/advancedDynamicTexture.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,10 @@ export class AdvancedDynamicTexture extends DynamicTexture {
726726
const engine = scene.getEngine();
727727
if (this.adjustToEngineHardwareScalingLevel) {
728728
// force the renderScale to the engine's hardware scaling level
729-
this._renderScale = 1 / engine.getHardwareScalingLevel();
729+
this._renderScale = engine.getHardwareScalingLevel();
730+
// calculate the max renderScale, based on the max texture size of engine.getCaps().maxTextureSize (enforced by some mobile devices)
731+
this._renderScale =
732+
1 / Math.max(this._renderScale, engine.getRenderWidth() / engine.getCaps().maxTextureSize, engine.getRenderHeight() / engine.getCaps().maxTextureSize);
730733
}
731734
const textureSize = this.getSize();
732735
let renderWidth = engine.getRenderWidth() * this._renderScale;
@@ -744,7 +747,8 @@ export class AdvancedDynamicTexture extends DynamicTexture {
744747
if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
745748
this.scaleTo(renderWidth, renderHeight);
746749
if (this.adjustToEngineHardwareScalingLevel) {
747-
const scale = this._renderScale * this._renderScale;
750+
const engineRenderScale = 1 / engine.getHardwareScalingLevel();
751+
const scale = this._renderScale * engineRenderScale;
748752
this._rootContainer.scaleX = scale;
749753
this._rootContainer.scaleY = scale;
750754
this._rootContainer.widthInPixels = renderWidth / scale;

0 commit comments

Comments
 (0)