From f03f2a5d313ca98dfc0f77472eafa0c8e1c21f7f Mon Sep 17 00:00:00 2001 From: Aiosa <469130@mail.muni.cz> Date: Thu, 21 Nov 2024 16:51:38 +0100 Subject: [PATCH] Add fixes for working smoothing in the webgl renderer. --- src/drawerbase.js | 10 ++++++++++ src/tilecache.js | 17 ++++++++++++----- src/webgldrawer.js | 22 +++++++++++++++------- src/world.js | 2 +- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/drawerbase.js b/src/drawerbase.js index f2279b62..e2f32338 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -128,6 +128,16 @@ OpenSeadragon.DrawerBase = class DrawerBase{ return undefined; } + /** + * Retrieve required data formats the data must be converted to. + * This list MUST BE A VALID SUBSET OF getSupportedDataFormats() + * @abstract + * @return {string[]} + */ + getRequiredDataFormats() { + return this.getSupportedDataFormats(); + } + /** * Retrieve data types * @abstract diff --git a/src/tilecache.js b/src/tilecache.js index 87a1f0b7..e7f10b2b 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -256,22 +256,29 @@ } internalCache = internalCache[drawerId]; - if (internalCache) { + if (internalCache && supportedTypes.includes(internalCache.type)) { // already done return $.Promise.resolve(this); } - internalCache = this[DRAWER_INTERNAL_CACHE][drawerId] = new $.SimpleCacheRecord(); const conversionPath = $.convertor.getConversionPath(this.type, supportedTypes); if (!conversionPath) { $.console.error(`[getDataForRendering] Conversion ${this.type} ---> ${supportedTypes} cannot be done!`); return $.Promise.resolve(this); } - internalCache.withTileReference(this._tRef); + const newInternalCache = new $.SimpleCacheRecord(); + + newInternalCache.withTileReference(this._tRef); const selectedFormat = conversionPath[conversionPath.length - 1].target.value; return $.convertor.convert(this._tRef, this.data, this.type, selectedFormat).then(data => { - internalCache.setDataAs(data, selectedFormat); // synchronous, SimpleCacheRecord call - return internalCache; + newInternalCache.setDataAs(data, selectedFormat); // synchronous, SimpleCacheRecord call + + // if existed, delete + if (internalCache) { + internalCache.destroy(); + } + this[DRAWER_INTERNAL_CACHE][drawerId] = newInternalCache; + return newInternalCache; }); } diff --git a/src/webgldrawer.js b/src/webgldrawer.js index 6d01b6fe..57094e37 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -100,9 +100,9 @@ this._setupCanvases(); this._setupRenderer(); - this._supportedFormats = []; + this._supportedFormats = this._setupTextureHandlers(); + this._requiredFormats = this._supportedFormats; this._setupCallCount = 1; - this._setupTextureHandlers(); this.context = this._outputContext; // API required by tests } @@ -468,6 +468,10 @@ } + getRequiredDataFormats() { + return this._requiredFormats; + } + // Public API required by all Drawer implementations /** * Sets whether image smoothing is enabled or disabled @@ -476,7 +480,12 @@ setImageSmoothingEnabled(enabled){ if( this._imageSmoothingEnabled !== enabled ){ this._imageSmoothingEnabled = enabled; - this._setupTextureHandlers(); // re-sets the type to enforce re-initialization + + // Todo consider removing old type handlers if _supportedFormats had already types defined, + // and remove support for rendering old types... + const newFormats = this._setupTextureHandlers(); // re-sets the type to enforce re-initialization + this._supportedFormats.push(...newFormats); + this._requiredFormats = newFormats; return this.viewer.requestInvalidate(); } return $.Promise.resolve(); @@ -892,8 +901,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, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); + 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 @@ -919,8 +928,6 @@ // Differentiate type also based on type used to upload data: we can support bidirectional conversion. const c2dTexType = thisType + ":context2d", imageTexType = thisType + ":image"; - // Todo consider removing old type handlers if _supportedFormats had already types defined - this._supportedFormats = [c2dTexType, imageTexType]; // We should be OK uploading any of these types. The complexity is selected to be O(3n), should be // more than linear pass over pixels @@ -929,6 +936,7 @@ $.convertor.learnDestroy(c2dTexType, tex2DCompatibleDestructor); $.convertor.learnDestroy(imageTexType, tex2DCompatibleDestructor); + return [c2dTexType, imageTexType]; } // private diff --git a/src/world.js b/src/world.js index 84eb1df8..a2836028 100644 --- a/src/world.js +++ b/src/world.js @@ -303,7 +303,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W // We call the event on the parent viewer window no matter what const eventTarget = this.viewer.viewer || this.viewer; // However, we must pick the correct drawer reference (navigator VS viewer) - const supportedFormats = this.viewer.drawer.getSupportedDataFormats(); + const supportedFormats = this.viewer.drawer.getRequiredDataFormats(); const keepInternalCacheCopy = this.viewer.drawer.options.usePrivateCache; const drawerId = this.viewer.drawer.getId();