Skip to content

Commit 217498b

Browse files
committed
Take render target size into account when drawing
1 parent b5059d1 commit 217498b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/RenderWebGL.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ class RenderWebGL extends EventEmitter {
626626
gl.clearColor.apply(gl, this._backgroundColor);
627627
gl.clear(gl.COLOR_BUFFER_BIT);
628628

629-
this._drawThese(this._drawList, ShaderManager.DRAW_MODE.default, this._projection);
629+
this._drawThese(this._drawList, ShaderManager.DRAW_MODE.default, this._projection, {
630+
framebufferWidth: gl.canvas.width,
631+
framebufferHeight: gl.canvas.height
632+
});
630633
if (this._snapshotCallbacks.length > 0) {
631634
const snapshot = gl.canvas.toDataURL();
632635
this._snapshotCallbacks.forEach(cb => cb(snapshot));
@@ -1674,13 +1677,20 @@ class RenderWebGL extends EventEmitter {
16741677
* @param {object.<string,*>} opts.extraUniforms Extra uniforms for the shaders.
16751678
* @param {int} opts.effectMask Bitmask for effects to allow
16761679
* @param {boolean} opts.ignoreVisibility Draw all, despite visibility (e.g. stamping, touching color)
1680+
* @param {int} opts.framebufferWidth The width of the framebuffer being drawn onto. Defaults to "native" width
1681+
* @param {int} opts.framebufferHeight The height of the framebuffer being drawn onto. Defaults to "native" height
16771682
* @private
16781683
*/
16791684
_drawThese (drawables, drawMode, projection, opts = {}) {
16801685

16811686
const gl = this._gl;
16821687
let currentShader = null;
16831688

1689+
const framebufferSpaceScaleDiffers = (
1690+
opts.framebufferWidth && opts.framebufferHeight &&
1691+
opts.framebufferWidth !== this._nativeSize[0] && opts.framebufferHeight !== this._nativeSize[1]
1692+
);
1693+
16841694
const numDrawables = drawables.length;
16851695
for (let drawableIndex = 0; drawableIndex < numDrawables; ++drawableIndex) {
16861696
const drawableID = drawables[drawableIndex];
@@ -1695,11 +1705,13 @@ class RenderWebGL extends EventEmitter {
16951705
// the ignoreVisibility flag is used (e.g. for stamping or touchingColor).
16961706
if (!drawable.getVisible() && !opts.ignoreVisibility) continue;
16971707

1698-
// Combine drawable scale with the native vs. backing pixel ratio
1699-
const drawableScale = [
1700-
drawable.scale[0] * this._gl.canvas.width / this._nativeSize[0],
1701-
drawable.scale[1] * this._gl.canvas.height / this._nativeSize[1]
1702-
];
1708+
// drawableScale is the "framebuffer-pixel-space" scale of the drawable, as percentages of the drawable's
1709+
// "native size" (so 100 = same as skin's "native size", 200 = twice "native size").
1710+
// If the framebuffer dimensions are the same as the stage's "native" size, there's no need to calculate it.
1711+
const drawableScale = framebufferSpaceScaleDiffers ? [
1712+
drawable.scale[0] * opts.framebufferWidth / this._nativeSize[0],
1713+
drawable.scale[1] * opts.framebufferHeight / this._nativeSize[1]
1714+
] : drawable.scale;
17031715

17041716
// If the skin or texture isn't ready yet, skip it.
17051717
if (!drawable.skin || !drawable.skin.getTexture(drawableScale)) continue;

0 commit comments

Comments
 (0)