Skip to content

Commit e616ab5

Browse files
authored
Merge pull request scratchfoundation#393 from LLK/revert-391-blurrybg
Revert "Increase maximum texture size and back it off if GL fails to render"
2 parents 230a68d + 6e072ea commit e616ab5

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/SVGSkin.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const twgl = require('twgl.js');
33
const Skin = require('./Skin');
44
const SvgRenderer = require('scratch-svg-renderer').SVGRenderer;
55

6-
const MAX_TEXTURE_DIMENSION = 10240;
6+
const MAX_TEXTURE_DIMENSION = 2048;
77

88
class SVGSkin extends Skin {
99
/**
@@ -68,30 +68,20 @@ class SVGSkin extends Skin {
6868
getTexture (scale) {
6969
// The texture only ever gets uniform scale. Take the larger of the two axes.
7070
const scaleMax = scale ? Math.max(Math.abs(scale[0]), Math.abs(scale[1])) : 100;
71-
const requestedScale = scaleMax / 100;
71+
const requestedScale = Math.min(scaleMax / 100, this._maxTextureScale);
7272
let newScale = this._textureScale;
7373
while ((newScale < this._maxTextureScale) && (requestedScale >= 1.5 * newScale)) {
7474
newScale *= 2;
7575
}
76-
77-
let error;
78-
const callback = () => {
79-
if (this._textureScale === newScale) {
80-
const gl = this._renderer.gl;
81-
gl.bindTexture(gl.TEXTURE_2D, this._texture);
82-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._svgRenderer.canvas);
83-
error = gl.getError();
84-
if (error && newScale > 1) {
85-
newScale /= 2;
86-
this._textureScale = newScale;
87-
this._maxTextureScale = newScale;
88-
this._svgRenderer._draw(this._textureScale, callback);
89-
}
90-
}
91-
};
9276
if (this._textureScale !== newScale) {
9377
this._textureScale = newScale;
94-
this._svgRenderer._draw(this._textureScale, callback);
78+
this._svgRenderer._draw(this._textureScale, () => {
79+
if (this._textureScale === newScale) {
80+
const gl = this._renderer.gl;
81+
gl.bindTexture(gl.TEXTURE_2D, this._texture);
82+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._svgRenderer.canvas);
83+
}
84+
});
9585
}
9686

9787
return this._texture;

0 commit comments

Comments
 (0)