When I tried to load the same PNG file into the canvas via both canvas.getContext('2d')
and canvas.getContext('webgl')
, found that compared with canvas2d, the PNG file rendered by webgl is NOT as smoothly as it rendered by canvas2d in detail. Is this caused by the GPU interpolation between points or texture setting/uploading issue? Any settings which could make the webgl version exactly the same as canvas 2d performs?
let FSHADER_SOURCE = `
precision mediump float;
uniform sampler2D u_image0;
varying vec2 v_texCoord;
void main() {
vec4 color0 = texture2D(u_image0, v_texCoord);
gl_FragColor = color0;
}
`
let texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
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.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.img);