glGenerateMipmap - 非 2 次幂 [英] glGenerateMipmap - non-power-of-2
问题描述
环境 Ubuntu 17.04、Chrome 60.
Environment Ubuntu 17.04, Chrome 60.
在没有警告/错误的情况下在本地运行此示例:https://github.com/mdn/webgl-examples/tree/gh-pages/tutorial/sample6
Runs this example local without warnings/errors : https://github.com/mdn/webgl-examples/tree/gh-pages/tutorial/sample6
然后在此处将 cubetexture.png
替换为 non-power-of-2
图像:https://github.com/mdn/webgl-examples/blob/gh-pages/tutorial/sample6/webgl-demo.js#L220
Then replace cubetexture.png
with an non-power-of-2
image here :
https://github.com/mdn/webgl-examples/blob/gh-pages/tutorial/sample6/webgl-demo.js#L220
得到预期的警告/错误:
Got as expected warnings/errors :
[.Offscreen-For-WebGL-0x13d050ba2c00]渲染警告:绑定到纹理单元 0 的纹理不可渲染.它可能不是 2 的幂并且具有不兼容的纹理过滤.
[.Offscreen-For-WebGL-0x13d050ba2c00]GL 错误:GL_INVALID_OPERATION:glGenerateMipmap:无法生成 mips
接下来添加参数:
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
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);
然后运行正常,没有警告,但仍然出乎意料的错误:
Then runs ok without warnings, but still unexpected got the error :
[.Offscreen-For-WebGL-0x13d050fb4000]GL错误:GL_INVALID_OPERATION:glGenerateMipmap:无法生成mips
除了错误消息之外,non-power-of-2
图像在立方体中渲染正常.Firefox 54 中的行为相同.这里有什么提示吗?
Apart from the error message the non-power-of-2
image is render ok, at the cube. Same behavior in Firefox 54. Any tips of what is going on here?
推荐答案
您不能在 WebGL1 中为非 2 次幂的纹理生成 mipmap.这就是重点,在 WebGL1 时期不支持 mipmapped 非 2 次幂纹理.所以你设置了过滤,让它只使用级别 0
You can not generate a mipmap for a non-power-of-2 texture in WebGL1. That's kind of the point, mipmapped non-power-of-2 textures are not supported in WebGL1 period. So you set the filtering so it uses only level 0
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
这意味着没有理由生成 mips,因为它们永远不会被使用.请参阅这篇文章.
Which means there's no reason to generate mips since they'll never be used. See this article.
这篇关于glGenerateMipmap - 非 2 次幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!