Max number of textures in WebGL?

落花浮王杯 提交于 2020-08-04 05:14:39

问题


I know that there is a limit of 8 textures in WebGL.

My question is that, is 8 the limit globally, or per shader/program wise?

If it's per shader/program wise limit, does that mean, once I load the textures to uniforms of one shader, I can start reusing these slots for other shaders? Say I used TEXTURE0 for one shape, can I use TEXTURE0 in another shape?


回答1:


The limit is per draw call. When you make a draw call, and invoke a particular shader program, you are constrained by the limit, but your next draw call can use completely different textures in the same animation frame.

Also, 8 is just the minimum guarantee. Systems are required to support at least eight to be considered WebGL conformant. But nicer graphics cards support more than eight. You can query the max number of image textures for the platform you're on like this:

var maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);

You can also look for vertex textures:

gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)

Or a combination of the two:

gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS)

You can also use a site like WebGL Report (Disclaimer, I'm a contributor) to look up this stat for the platform you're on (under Fragment Shader -> Max Texture Units).

You can also check WebGL Stats to see graphs of support for max image textures. The MAX_TEXTURE_IMAGE_UNITS graph there is showing that support for up to 16 image textures is fairly common, enjoying about 95% support rate on modern browsers.



来源:https://stackoverflow.com/questions/41020683/max-number-of-textures-in-webgl

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