glGenerateMipmap - non-power-of-2

一笑奈何 提交于 2019-12-06 14:21:24

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);

Which means there's no reason to generate mips since they'll never be used. See this article.

WebGL is based on OpenGL ES 2.0. While online documentation for WebGL defines available functions, but for restrictions and some of specific behavior you would need to address OpenGL ES 2.0 full spec. It's available at https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf

For TexImage2D function in 3.7.1:

If level is greater than zero, and either width or height is not a power of two, the error INVALID_VALUE is generated

And for GenerateMipmap in 3.7.11:

If either the width or height of the level zero array are not a power or two, the error INVALID_OPERATION is generated

Conclusion

You can have only first(zero) level for non-power-of-two texture. And you cant generate mipmaps for non-power-of-two texture.


Also it's worth noting that non-power-of-two texture has additional limitations:

In article 3.7:

If any dimension of any array in a mipmap is not a power of two (e.g. if rounding down as described above is performed), then the mipmap is described as a non-power-of-two texture. Non-power-of-two textures have restrictions on the allowed texture wrap modes and filters, as described in section 3.8.2

In 3.8.2:

Calling a sampler from a fragment shader will return (R, G, B, A) = (0, 0, 0, 1) if any of the following conditions are true:

....

• A two-dimensional sampler is called, the corresponding texture image is a non-power-of-two image (as described in the Mipmapping discussion of section 3.7.7), and either the texture wrap mode is not CLAMP_TO_EDGE, or the minification filter is neither NEAREST nor LINEAR.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!