Javascript “precision mediump float”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13780609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does `precision mediump float` mean?
提问by Hard Rain
In the learningwebgl tutorial1I've found an interesting line in the fragment shader.
在learningwebgl 教程 1 中,我在片段着色器中发现了一条有趣的线。
precision mediump float;
I've found an article about it here, but I still can't understand what does it mean?
我在这里找到了一篇关于它的文章,但我仍然不明白它是什么意思?
And if I remove this line, nothing changes. Everything is the same.
So what does precision mediump floatmean?
如果我删除此行,则没有任何变化。一切都是一样的。那么是什么precision mediump float意思呢?
回答by HowDoIDoComputer
This determines how much precision the GPU uses when calculating floats. highpis high precision, and of course more intensive than mediump(medium precision) and lowp(low precision).
这决定了 GPU 在计算浮点数时使用的精度。highp是高精度,当然比mediump(中精度)和lowp(低精度)更密集。
Some systems do not support highpat all, which will cause code not to work at all on those systems.
有些系统根本不支持highp,这将导致代码在这些系统上根本无法运行。
On systems that DO support highp, you will see a performance hit, and should use mediumpand lowpwherever possible. A good rule of thumb that I saw was:
- highpfor vertex positions,
- mediumpfor texture coordinates,
- lowpfor colors.
在那些支持系统highp,你会看到一个性能命中,并应使用mediump和lowp尽可能。我看到的一个很好的经验法则是:
-highp顶点位置,
-mediump纹理坐标,
-lowp颜色。
Hope that helps!
希望有帮助!

