Canvas webgl FBO blend bug
发布于 6 年前 作者 guiyingmao 9989 次浏览 来自 问答

bug描述:

目前debug估计是blend的时候src color正常,dst color总是为(0,0,0,0)

  • 当前 Bug 的表现(可附上截图)

在小米8上,出现异常

  • 预期表现

在honor v20上,正常显示

关键代码:

_render = () => {

    const { gl } = this._glRenderer;

    

    gl.viewport(0, 0, this._width, this._height);

    

    const fb = gl.createFramebuffer();

    const rb = gl.createRenderbuffer();

    const texture = gl.createTexture();

    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

    gl.activeTexture(gl.TEXTURE0);

    gl.bindTexture(gl.TEXTURE_2D, texture);

    gl.texImage2D(

        gl.TEXTURE_2D,

        0,

        gl.RGBA,

        this._width,

        this._height,

        0,

        gl.RGBA,

        gl.UNSIGNED_BYTE,

        null

        );

    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.framebufferTexture2D(

        gl.FRAMEBUFFER,

        gl.COLOR_ATTACHMENT0,

        gl.TEXTURE_2D,

        texture,

        0

    );

    

    gl.bindRenderbuffer(gl.RENDERBUFFER, rb);

    gl.renderbufferStorage(

    gl.RENDERBUFFER,

    gl.DEPTH_COMPONENT16,

        this._width,

        this._height

    );

    

    gl.framebufferRenderbuffer(

        gl.FRAMEBUFFER,

        gl.DEPTH_ATTACHMENT,

        gl.RENDERBUFFER,

        rb

    );

    

    this._drawContent(gl);

    

    gl.deleteRenderbuffer(rb);

    gl.deleteFramebuffer(fb);

    gl.bindFramebuffer(gl.FRAMEBUFFER, null);

    

    const { _drawPath: drawPath } = this;

    drawPath.lassoTex.destroy(gl);

    drawPath.lassoTex.texture = texture;

    drawPath.lassoTex.scale = this._scale;

    drawPath.lassoTex.drawing = false;

    

    this._glRenderer.requestRender();

};

2 回复

发现是因为depth精度问题,会把相邻的几个depth,舍入同一层depth,在改变step大小之后可以解决这个问题。

但是,很奇怪的是,在默认buffer里面是可以识别高精度的,参看问题中图片,可以正常通过depth test。而在离屏渲染中(通过bindFramebuffer,attach depth 的renderbuffer),精度问题就出现了。希望有人来解决疑惑~

回到顶部