Skip to content

Instantly share code, notes, and snippets.

@j2is
Created March 5, 2023 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j2is/e725b9e346d3390e46d7bbe78c143a4e to your computer and use it in GitHub Desktop.
Save j2is/e725b9e346d3390e46d7bbe78c143a4e to your computer and use it in GitHub Desktop.
detect max possible canvas capabilities
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