【问题标题】:WebGL 'texture not renderable' warning logged, but all behaviour correct记录了 WebGL“纹理不可渲染”警告,但所有行为正确
【发布时间】:2015-09-11 07:47:37
【问题描述】:

我正在创作一个 WebGL 应用程序。一切都按预期工作,除了我在调试控制台中收到以下错误。

[.WebGLRenderingContext-0086F710]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.

让我们排除一些可能性

1- 这肯定不是纹理加载的问题,因为纹理在第一帧中正确显示。

2- 我知道使用二次幂纹理,这就是我所做的。在我真正拥有相关纹理之前,我一直在使用下面的填充纹理,除了一个是按比例放大的,使用的是 2x2。

2a- 我知道警告所指的incompatible texture filtering 是使用非二次幂纹理,但无论如何这里是相关的过滤代码。

// When creating the texture
var texture = gl.createTexture();
texture.image = new Image();
texture.image.onload = function() {
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    gl.generateMipmap(gl.TEXTURE_2D);
    gl.bindTexture(gl.TEXTURE_2D, null);
}
texture.image.src = src;

// At render time
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, item.texture);
gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"), 0);

我是否正确假设此错误对其发生原因的猜测是错误的?什么会满足(不仅仅是压制)它?

提前致谢。

【问题讨论】:

  • 你的“填充”纹理在你运行渲染循环之前加载了吗?
  • 是的。这就是为什么,在我的问题中,我说,1- This is most certainly not a problem of texture loading as the textures show up correctly in the first frame.

标签: javascript textures webgl


【解决方案1】:

您是否在纹理加载完成之前进行渲染?这是该错误的常见来源。我的解决方案是在创建时为每个纹理创建一个 1x1 像素纹理,然后在纹理加载时更新它。

添加这些行

var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA,
     gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255]));

要检查的另一件事是,如果未初始化,所有制服默认为零,这意味着所有采样器都指向纹理单元 0。

【讨论】:

  • Do you render before your textures have finished loading? 如果我理解正确的话,1- This is most certainly not a problem of texture loading as the textures show up correctly in the first frame. 解决了这个问题。请,如果您的问题与此无关并且我没有正确理解,请说出来。
  • 我对你的最后一句话很感兴趣。这条线是否将我的采样器设置为单元 0? gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"), 0);(问题代码的最后一行)
  • 也许您应该发布所有代码。您发布的代码显示了异步加载的纹理。您没有显示任何等待纹理加载的代码,因此您遇到的错误似乎是因为没有等待纹理加载。
猜你喜欢
  • 1970-01-01
  • 2015-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多