Skip to content

Instantly share code, notes, and snippets.

@shrinktofit
Created September 22, 2020 06:26
Show Gist options
  • Save shrinktofit/d49a258e1ae4c76be9d45255ea111d30 to your computer and use it in GitHub Desktop.
Save shrinktofit/d49a258e1ae4c76be9d45255ea111d30 to your computer and use it in GitHub Desktop.
[WebGL] Print shader numeric type precisions
const shaderTypes: [number, string][] = [
[gl.VERTEX_SHADER, 'Vertex shader'],
[gl.FRAGMENT_SHADER, 'Fragment shader'],
];
const precisionTypes: [number, string][] = [
[gl.HIGH_FLOAT, 'High float'],
[gl.MEDIUM_FLOAT, 'Medium float'],
[gl.LOW_FLOAT, 'Low float'],
[gl.HIGH_INT, 'High int'],
[gl.MEDIUM_INT, 'Medium int'],
[gl.LOW_INT, 'Low int'],
];
for (const [shaderType, shaderTypeName] of shaderTypes) {
console.info(`${shaderTypeName} precisions:`);
for (const [precisionType, precisionTypeName] of precisionTypes) {
const precisionFormat = gl.getShaderPrecisionFormat(shaderType, precisionType);
if (precisionFormat) {
const { rangeMin, rangeMax, precision } = precisionFormat;
console.info(
`${precisionTypeName}: [-2^${rangeMin}, 2^${rangeMax}]` +
(precision ? `, 2^${-precision}` : '')
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment