如何检测 WebGL 中的浮点精度?
How to detect float precisions in WebGL?
lowp
、mediump
和 highp
表示每个设备上的精度不同。如何检测它们的实际值(每个精度的浮点数的位长度)?
我的意思是:
- lowp: 16bit float
- mediump 32bit float
- highp 64bit float (double)
你可以打电话给gl.getShaderPrecisionFormat(shaderType, precisionType)
shaderType
是 gl.VERTEX_SHADER
或 gl.FRAGMENT_SHADER
。
precisionType
是 gl.LOW_FLOAT
、gl.GL_MEDIUM_FLOAT
、gl.HIGH_FLOAT
、gl.LOW_INT
、gl.MEDIUM_INT
、gl.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
lowp
、mediump
和 highp
表示每个设备上的精度不同。如何检测它们的实际值(每个精度的浮点数的位长度)?
我的意思是:
- lowp: 16bit float
- mediump 32bit float
- highp 64bit float (double)
你可以打电话给gl.getShaderPrecisionFormat(shaderType, precisionType)
shaderType
是 gl.VERTEX_SHADER
或 gl.FRAGMENT_SHADER
。
precisionType
是 gl.LOW_FLOAT
、gl.GL_MEDIUM_FLOAT
、gl.HIGH_FLOAT
、gl.LOW_INT
、gl.MEDIUM_INT
、gl.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