diff --git a/src/render/Texture.js b/src/render/Texture.js index 2a163062c..ae159d3e5 100644 --- a/src/render/Texture.js +++ b/src/render/Texture.js @@ -80,11 +80,6 @@ define([ this.size = image.width * image.height * 4; gl.bindTexture(gl.TEXTURE_2D, textureId); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, - isPowerOfTwo ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapMode); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapMode); gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); gl.texImage2D(gl.TEXTURE_2D, 0, @@ -105,6 +100,9 @@ define([ // Internal use only. Intentionally not documented. this.texParameters = {}; + this.texParameters[gl.TEXTURE_MIN_FILTER] = isPowerOfTwo ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR; + this.texParameters[gl.TEXTURE_WRAP_S] = wrapMode; + this.texParameters[gl.TEXTURE_WRAP_T] = wrapMode; // Internal use only. Intentionally not documented. // https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotrop @@ -171,10 +169,17 @@ define([ Texture.prototype.applyTexParameters = function (dc) { var gl = dc.currentGlContext; - // Configure the OpenGL texture magnification function. Use linear by default. - var textureMagFilter = this.texParameters[gl.TEXTURE_MAG_FILTER] || gl.LINEAR; + // Configure the OpenGL texture minification function. Use nearest in pickingMode or linear by default. + var textureMinFilter = dc.pickingMode ? gl.NEAREST : this.texParameters[gl.TEXTURE_MIN_FILTER] || gl.LINEAR; + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, textureMinFilter); + + // Configure the OpenGL texture magnification function. Use nearest in pickingMode or linear by default. + var textureMagFilter = dc.pickingMode ? gl.NEAREST : this.texParameters[gl.TEXTURE_MAG_FILTER] || gl.LINEAR; gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, textureMagFilter); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.texParameters[gl.TEXTURE_WRAP_S] || gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.texParameters[gl.TEXTURE_WRAP_T] || gl.CLAMP_TO_EDGE); + // Try to enable the anisotropic texture filtering only if we have a linear magnification filter. // This can't be enabled all the time because Windows seems to ignore the TEXTURE_MAG_FILTER parameter when // this extension is enabled. diff --git a/src/shapes/SurfaceShapeTile.js b/src/shapes/SurfaceShapeTile.js index 74138401d..85e8de22e 100644 --- a/src/shapes/SurfaceShapeTile.js +++ b/src/shapes/SurfaceShapeTile.js @@ -223,6 +223,21 @@ define([ shape.renderToTexture(dc, ctx2D, xScale, yScale, xOffset, yOffset); } + // Remove semi-transparent pixels, which may contain wrong pick color due to anti-aliasing + // TODO Disable anti-aliasing of canvas stroke in renderToTexture instead of this hack, when it will be supported by browsers + if (dc.pickingMode) { + var imageData = ctx2D.getImageData(0, 0, canvas.width, canvas.height); + for (var i = 3, n = canvas.width * canvas.height * 4; i < n; i += 4) { + if (imageData.data[i] < 255) { + imageData.data[i - 3] = 0; + imageData.data[i - 2] = 0; + imageData.data[i - 1] = 0; + imageData.data[i] = 0; + } + } + ctx2D.putImageData(imageData, 0, 0); + } + this.gpuCacheKey = this.getCacheKey(); var gpuResourceCache = dc.gpuResourceCache;