diff --git a/index.js b/index.js index 18655524..a9cecbd8 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,8 @@ function createContext(opts) { let gl = null const defaultOpts = { - pixelRatio: 1 + pixelRatio: 1, + precision: 'highp' } opts = Object.assign({}, defaultOpts, opts) @@ -297,6 +298,28 @@ function createContext(opts) { capabilities.maxColorAttachments = gl.getParameter('MAX_COLOR_ATTACHMENTS') } + function getMaxPrecision(precision = 'highp') { + if (precision === "highp") { + if ( + gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT).precision > 0 && + gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0 + ) { + return "highp"; + } + precision = "mediump"; + } + if (precision === "mediump") { + if ( + gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT).precision > 0 && + gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0 + ) { + return "mediump"; + } + } + return "lowp"; + } + capabilities.maxPrecision = getMaxPrecision(opts.precision) + log('capabilities', capabilities) Object.assign(ctx, { @@ -328,7 +351,8 @@ function createContext(opts) { } return str }, - set: function(opts) { + getMaxPrecision, + set: function (opts) { assert(isBrowser, 'changing resolution is not supported in Plask') if (opts.pixelRatio) { this.updatePixelRatio = Math.min(