From 17f13885c7dafcc5af1e884fcdf8e313a35db1d5 Mon Sep 17 00:00:00 2001 From: Aiosa <469130@mail.muni.cz> Date: Tue, 26 Nov 2024 00:48:43 +0100 Subject: [PATCH] Add back overlapFraction logic for webgl drawer. --- src/webgldrawer.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/webgldrawer.js b/src/webgldrawer.js index 57094e37..a7e596da 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -872,10 +872,18 @@ } _setupTextureHandlers() { - const _this = this; const tex2DCompatibleLoader = (tile, data) => { let tiledImage = tile.tiledImage; - let gl = _this._gl; + let gl = this._gl; + + let sourceWidthFraction, sourceHeightFraction; + if (tile.sourceBounds) { + sourceWidthFraction = Math.min(tile.sourceBounds.width, data.width) / data.width; + sourceHeightFraction = Math.min(tile.sourceBounds.height, data.height) / data.height; + } else { + sourceWidthFraction = 1; + sourceHeightFraction = 1; + } // create a gl Texture for this tile and bind the canvas with the image data let texture = gl.createTexture(); @@ -884,16 +892,18 @@ if( overlap > 0){ // calculate the normalized position of the rect to actually draw // discarding overlap. - let overlapFraction = _this._calculateOverlapFraction(tile, tiledImage); + let overlapFraction = this._calculateOverlapFraction(tile, tiledImage); - let left = tile.x === 0 ? 0 : overlapFraction.x; - let top = tile.y === 0 ? 0 : overlapFraction.y; - let right = tile.isRightMost ? 1 : 1 - overlapFraction.x; - let bottom = tile.isBottomMost ? 1 : 1 - overlapFraction.y; - position = _this._makeQuadVertexBuffer(left, right, top, bottom); + let left = (tile.x === 0 ? 0 : overlapFraction.x) * sourceWidthFraction; + let top = (tile.y === 0 ? 0 : overlapFraction.y) * sourceHeightFraction; + let right = (tile.isRightMost ? 1 : 1 - overlapFraction.x) * sourceWidthFraction; + let bottom = (tile.isBottomMost ? 1 : 1 - overlapFraction.y) * sourceHeightFraction; + position = this._makeQuadVertexBuffer(left, right, top, bottom); + } else if (sourceWidthFraction === 1 && sourceHeightFraction === 1) { + // no overlap and no padding: this texture can use the unit quad as its position data + position = this._unitQuad; } else { - // no overlap: this texture can use the unit quad as its position data - position = _this._unitQuad; + position = this._makeQuadVertexBuffer(0, sourceWidthFraction, 0, sourceHeightFraction); } gl.activeTexture(gl.TEXTURE0); @@ -901,8 +911,8 @@ // Set the parameters so we can render any size image. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, _this._textureFilter()); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, _this._textureFilter()); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this._textureFilter()); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this._textureFilter()); try{ // This depends on gl.TEXTURE_2D being bound to the texture