Merge pull request #2492 from pearcetm/fix-webgl-tilepadding

Make WebGLDrawer deal with tiles with padding
This commit is contained in:
Ian Gilman 2024-03-07 09:29:19 -08:00 committed by GitHub
commit 262d04c6c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -897,19 +897,32 @@
let texture = gl.createTexture(); let texture = gl.createTexture();
let position; let position;
let overlap = tiledImage.source.tileOverlap; let overlap = tiledImage.source.tileOverlap;
// deal with tiles where there is padding, i.e. the pixel data doesn't take up the entire provided canvas
let sourceWidthFraction, sourceHeightFraction;
if (tile.sourceBounds) {
sourceWidthFraction = Math.min(tile.sourceBounds.width, canvas.width) / canvas.width;
sourceHeightFraction = Math.min(tile.sourceBounds.height, canvas.height) / canvas.height;
} else {
sourceWidthFraction = 1;
sourceHeightFraction = 1;
}
if( overlap > 0){ if( overlap > 0){
// calculate the normalized position of the rect to actually draw // calculate the normalized position of the rect to actually draw
// discarding overlap. // discarding overlap.
let overlapFraction = this._calculateOverlapFraction(tile, tiledImage); let overlapFraction = this._calculateOverlapFraction(tile, tiledImage);
let left = tile.x === 0 ? 0 : overlapFraction.x; let left = (tile.x === 0 ? 0 : overlapFraction.x) * sourceWidthFraction;
let top = tile.y === 0 ? 0 : overlapFraction.y; let top = (tile.y === 0 ? 0 : overlapFraction.y) * sourceHeightFraction;
let right = tile.isRightMost ? 1 : 1 - overlapFraction.x; let right = (tile.isRightMost ? 1 : 1 - overlapFraction.x) * sourceWidthFraction;
let bottom = tile.isBottomMost ? 1 : 1 - overlapFraction.y; let bottom = (tile.isBottomMost ? 1 : 1 - overlapFraction.y) * sourceHeightFraction;
position = this._makeQuadVertexBuffer(left, right, top, bottom); position = this._makeQuadVertexBuffer(left, right, top, bottom);
} else { } else if (sourceWidthFraction === 1 && sourceHeightFraction === 1) {
// no overlap: this texture can use the unit quad as its position data // no overlap and no padding: this texture can use the unit quad as its position data
position = this._unitQuad; position = this._unitQuad;
} else {
position = this._makeQuadVertexBuffer(0, sourceWidthFraction, 0, sourceHeightFraction);
} }
let textureInfo = { let textureInfo = {