gpt4 book ai didi

javascript - 在WebGL程序中使用uniform[1234][uif]设置制服: is the vector version [v] better in any regard?

转载 作者:行者123 更新时间:2023-12-03 01:35:50 25 4
gpt4 key购买 nike

使用带有类似数组类型的 uniform[1234][uif][v] 而不是仅使用 uniform[1234] 设置 WebGL 程序的制服有什么显着的优点/缺点吗][uif] + 传播参数,例如。 :

gl.uniform3f (location, v0, v1, v2);   // GLSL type: vec3
// vs
gl.uniform3fv(location, [v0, v1, v2]); // GLSL type: vec3 (or vec3[] array)

显然忽略了该方法的一个版本处理数组这一事实。

我正在寻找性能、可读性和整体最佳实践方面的考虑因素。

谢谢!

最佳答案

数组版本本身稍慢。引用WebGL insights (第 19 页),

For example, comparing uniform4f to uniform4fv instead of uniform1f, we found that uniform4fv is slower than uniform4f in all browsers that we tried, despite taking as few parameters as uniform1f does. This is due to uniform4fv having inherently more work to do than uniform4f, since it can handle arbitrary uniform array uploads.

基本上,必须检查输入是否是数组(然后检查其元素类型)、类型化数组等,这会损失通过传递较少参数获得的性能。

但是,这主要意味着您应该使用与您的数据匹配的任何一个,因为解压现有数组可能会带来好处(不过请随意测试它)。

关于javascript - 在WebGL程序中使用uniform[1234][uif]设置制服: is the vector version [v] better in any regard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51082088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com