Attaining context

In WebGL 1, you'd attain a WebGL context with something that looks like the following:

const names = ['WebGL', 'experimental-WebGL', 'webkit-3d', 'moz-WebGL'];

for (let i = 0; i < names.length; ++i) {
try {
const context = canvas.getContext(names[i]);
// work with context
} catch (e) {
console.log('Error attaining WebGL context', e);
}
}

In WebGL 2, you'd simply attain the context with a single line, as follows:

const context = canvas.getContext('WebGL 2');
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.156.140