Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function createContext(opts) {
let gl = null

const defaultOpts = {
pixelRatio: 1
pixelRatio: 1,
precision: 'highp'
}

opts = Object.assign({}, defaultOpts, opts)
Expand Down Expand Up @@ -297,6 +298,28 @@ function createContext(opts) {
capabilities.maxColorAttachments = gl.getParameter('MAX_COLOR_ATTACHMENTS')
}

function getMaxPrecision(precision = 'highp') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMaxPrecision is one of a kind API. More in the PR comments

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, {
Expand Down Expand Up @@ -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(
Expand Down