如何检测 WebGL 中的浮点精度?

How to detect float precisions in WebGL?

lowpmediumphighp 表示每个设备上的精度不同。如何检测它们的实际值(每个精度的浮点数的位长度)?

我的意思是:

- lowp:   16bit float
- mediump 32bit float
- highp   64bit float (double)

你可以打电话给gl.getShaderPrecisionFormat(shaderType, precisionType)

shaderTypegl.VERTEX_SHADERgl.FRAGMENT_SHADER

precisionTypegl.LOW_FLOATgl.GL_MEDIUM_FLOATgl.HIGH_FLOATgl.LOW_INTgl.MEDIUM_INTgl.GL_HIGH_INT 之一。

它returns一个看起来像这样的对象

{
    rangeMin,  // log 2 of the minimum representable magnitude
    rangeMax,  // log 2 of the maximum representable magnitude
    precision, // log 2 of the precision
};

If a high precision floating-point format is not supported for fragment shaders, calling gl.getShaderPrecisionFormat with arguments gl.FRAGMENT_SHADER and gl.HIGH_FLOAT will return 0 for both range and precision.

docs are here which link to the OpenGL ES 2.0 docs here