dart:web_gl: RENDER WARNING: texture bound to texture unit 0 is not renderable

后端 未结 1 739
[愿得一人]
[愿得一人] 2021-01-04 10:04

I\'m getting the error [.WebGLRenderingContext]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture

相关标签:
1条回答
  • 2021-01-04 10:18

    Immediately after the code in my question I had bound the texture and send the sampler uniform. This was wrong because it was executed before the image loaded. To fix this, I put the calls to bind the texture and draw elements in the onload function:

      image.onLoad.listen((e) {
        gl.bindTexture(webGL.TEXTURE_2D, texture);
        gl.texImage2DImage(webGL.TEXTURE_2D, 0, webGL.RGBA, webGL.RGBA, 
                           webGL.UNSIGNED_BYTE, image);
        gl.texParameteri(webGL.TEXTURE_2D, webGL.TEXTURE_MAG_FILTER, webGL.NEAREST);
        gl.texParameteri(webGL.TEXTURE_2D, webGL.TEXTURE_MIN_FILTER, webGL.NEAREST);
        gl.bindTexture(webGL.TEXTURE_2D, null);
    
        gl.activeTexture(webGL.TEXTURE0);
        gl.bindTexture(webGL.TEXTURE_2D, texture);
        gl.uniform1i(gl.getUniformLocation(shader.program, "uSampler"), 0);
    
        gl.drawElements(webGL.TRIANGLES, 6, webGL.UNSIGNED_SHORT, 0); 
    
      });
    

    which makes sure the image has loaded.

    Before, it would just assign the onload callback and then execute the next set of commands - which involved binding the texture - but because the computer is very quick it had already bound the texture and tried to draw it before the image had finished loading.

    0 讨论(0)
提交回复
热议问题