Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/render/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/shapes/SurfaceShapeTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down