Created
March 5, 2023 23:18
-
-
Save j2is/e725b9e346d3390e46d7bbe78c143a4e to your computer and use it in GitHub Desktop.
detect max possible canvas capabilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import canvasSize from "canvas-size"; | |
const getMaxTextureSize = () => { | |
const canvas = document.createElement("canvas"); | |
const gl = canvas.getContext("experimental-webgl"); | |
if (!gl) return 2048; | |
return gl.getParameter(gl.MAX_TEXTURE_SIZE) || 2048; | |
}; | |
const maxTextureSize = getMaxTextureSize(); | |
canvasSize.test({ | |
sizes: [ | |
[maxTextureSize, maxTextureSize], | |
[8192, 8192], | |
[4096, 4096]], | |
onError: function(width, height, benchmark) { | |
console.log("Error:", width, height); | |
}, | |
onSuccess: function(width, height, benchmark) { | |
console.log('dimensions can be: ', width, height); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment